From 0c2b7b1020384c095500599a687a88306f98c0f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Mon, 20 Aug 2012 13:09:55 +0200 Subject: Fix default-constructed QFileSystemEntry Member variables for lastSeparator, first and lastDotInFileName are now initialized to -1 (non-existing), where the previous value of zero would mean a separator/dot at that position and resulted in path() returning '/', instead of '.'. Tests were expanded for better coverage of empty state and default-constructed instances. Change-Id: Ie27547886b52224d38b5be0b4f920c9927fd440f Reviewed-by: Andy Shaw Reviewed-by: Shane Kearns --- src/corelib/io/qfilesystementry.cpp | 6 ++-- .../io/qfilesystementry/tst_qfilesystementry.cpp | 41 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp index 4d5f9c6bb8..b4eff3db6e 100644 --- a/src/corelib/io/qfilesystementry.cpp +++ b/src/corelib/io/qfilesystementry.cpp @@ -75,9 +75,9 @@ static inline QString fixIfRelativeUncPath(const QString &path) #endif QFileSystemEntry::QFileSystemEntry() - : m_lastSeparator(0), - m_firstDotInFileName(0), - m_lastDotInFileName(0) + : m_lastSeparator(-1), + m_firstDotInFileName(-1), + m_lastDotInFileName(-1) { } diff --git a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp index 1ea5c93fe7..0ecadd17c4 100644 --- a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp +++ b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp @@ -64,6 +64,7 @@ private slots: #endif void isClean_data(); void isClean(); + void defaultCtor(); }; #if defined(Q_OS_WIN) @@ -169,10 +170,16 @@ void tst_QFileSystemEntry::getSetCheck_data() QTest::addColumn("completeSuffix"); QTest::addColumn("absolute"); + QTest::newRow("empty") + << QByteArray() + << QString() + << QString() << QString() << QString() << QString() << QString() << false; + QTest::newRow("simple") << QByteArray("/home/qt/in/a/dir.tar.gz") << "/home/qt/in/a/dir.tar.gz" << "dir.tar.gz" << "dir" << "dir.tar" << "gz" << "tar.gz" << true; + QTest::newRow("relative") << QByteArray("in/a/dir.tar.gz") << "in/a/dir.tar.gz" @@ -235,6 +242,7 @@ void tst_QFileSystemEntry::suffix_data() QTest::addColumn("file"); QTest::addColumn("expected"); + QTest::newRow("empty") << QString() << QString(); QTest::newRow("noextension0") << "file" << ""; QTest::newRow("noextension1") << "/path/to/file" << ""; QTest::newRow("data0") << "file.tar" << "tar"; @@ -273,6 +281,7 @@ void tst_QFileSystemEntry::completeSuffix_data() QTest::addColumn("file"); QTest::addColumn("expected"); + QTest::newRow("empty") << QString() << QString(); QTest::newRow("noextension0") << "file" << ""; QTest::newRow("noextension1") << "/path/to/file" << ""; QTest::newRow("data0") << "file.tar" << "tar"; @@ -302,6 +311,7 @@ void tst_QFileSystemEntry::baseName_data() QTest::addColumn("file"); QTest::addColumn("expected"); + QTest::newRow("empty") << QString() << QString(); QTest::newRow("data0") << "file.tar" << "file"; QTest::newRow("data1") << "file.tar.gz" << "file"; QTest::newRow("data2") << "/path/file/file.tar.gz" << "file"; @@ -330,6 +340,7 @@ void tst_QFileSystemEntry::completeBaseName_data() QTest::addColumn("file"); QTest::addColumn("expected"); + QTest::newRow("empty") << QString() << QString(); QTest::newRow("data0") << "file.tar" << "file"; QTest::newRow("data1") << "file.tar.gz" << "file.tar"; QTest::newRow("data2") << "/path/file/file.tar.gz" << "file.tar"; @@ -360,6 +371,7 @@ void tst_QFileSystemEntry::absoluteOrRelative_data() QTest::addColumn("isAbsolute"); QTest::addColumn("isRelative"); + QTest::newRow("empty") << QString() << false << true; QTest::newRow("data0") << "file.tar" << false << true; QTest::newRow("data1") << "/path/file/file.tar.gz" << false << false; QTest::newRow("data1") << "C:path/file/file.tar.gz" << false << false; @@ -384,6 +396,7 @@ void tst_QFileSystemEntry::isClean_data() QTest::addColumn("path"); QTest::addColumn("isClean"); + QTest::newRow("empty") << QString() << true; QTest::newRow("simple") << "foo" << true; QTest::newRow("complex") << "/foo/bar/bz" << true; QTest::newRow(".file") << "/foo/.file" << true; @@ -409,5 +422,33 @@ void tst_QFileSystemEntry::isClean() QCOMPARE(fi.isClean(), isClean); } +void tst_QFileSystemEntry::defaultCtor() +{ + QFileSystemEntry entry; + + QVERIFY(entry.filePath().isNull()); + QVERIFY(entry.nativeFilePath().isNull()); + + QVERIFY(entry.fileName().isNull()); + QCOMPARE(entry.path(), QString(".")); + + QVERIFY(entry.baseName().isNull()); + QVERIFY(entry.completeBaseName().isNull()); + QVERIFY(entry.suffix().isNull()); + QVERIFY(entry.completeSuffix().isNull()); + + QVERIFY(!entry.isAbsolute()); + QVERIFY(entry.isRelative()); + + QVERIFY(entry.isClean()); + +#if defined(Q_OS_WIN) + QVERIFY(!entry.isDriveRoot()); +#endif + QVERIFY(!entry.isRoot()); + + QVERIFY(entry.isEmpty()); +} + QTEST_MAIN(tst_QFileSystemEntry) #include -- cgit v1.2.3