From 4f0ac5678fd9c854f6321b608cbb8e1a7bdb4838 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 16 Aug 2022 09:47:23 +0200 Subject: [PATCH] FilePath: Fix operator+ to use stringAppend instead of pathAppended Change-Id: I643a2e9eed22fafc793bbc75cba0344c4005b3f3 Reviewed-by: Reviewed-by: David Schulz --- src/libs/utils/filepath.cpp | 6 ++--- tests/auto/utils/fileutils/tst_fileutils.cpp | 24 +++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index ddfe6e3d5f5..b2c4ae4da1b 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -969,7 +969,7 @@ bool FilePath::operator>=(const FilePath &other) const FilePath FilePath::operator+(const QString &s) const { - return pathAppended(s); + return stringAppended(s); } /// \returns whether FilePath is a child of \a s @@ -1277,9 +1277,7 @@ FilePath FilePath::pathAppended(const QString &path) const FilePath FilePath::stringAppended(const QString &str) const { - FilePath fn = *this; - fn.m_path.append(str); - return fn; + return FilePath::fromString(toString() + str); } size_t FilePath::hash(uint seed) const diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index d4b293e0beb..77b0e4dcb33 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -783,21 +783,29 @@ void tst_fileutils::onDevice() { } void tst_fileutils::plus_data() { - tst_fileutils::pathAppended_data(); + QTest::addColumn("left"); + QTest::addColumn("right"); + QTest::addColumn("expected"); + + QTest::newRow("empty") << FilePath() << QString() << FilePath(); + QTest::newRow("empty-left") << FilePath() << "a" << FilePath("a"); + QTest::newRow("empty-right") << FilePath("a") << QString() << FilePath("a"); + QTest::newRow("add-root") << FilePath() << QString("/") << FilePath("/"); + QTest::newRow("add-root-and-more") << FilePath() << QString("/test/blah") << FilePath("/test/blah"); + QTest::newRow("add-extension") << FilePath::fromString("/a") << QString(".txt") << FilePath("/a.txt"); + QTest::newRow("trailing-slash") << FilePath::fromString("/a") << QString("b/") << FilePath("/ab/"); + QTest::newRow("slash-trailing-slash") << FilePath::fromString("/a/") << QString("b/") << FilePath("/a/b/"); } void tst_fileutils::plus() { - QFETCH(QString, left); + QFETCH(FilePath, left); QFETCH(QString, right); - QFETCH(QString, expected); + QFETCH(FilePath, expected); - const FilePath fleft = FilePath::fromString(left); - const FilePath fexpected = FilePath::fromString(expected); + const FilePath result = left + right; - const FilePath result = fleft + right; - - QCOMPARE(fexpected, result); + QCOMPARE(expected, result); } QTEST_GUILESS_MAIN(tst_fileutils)