From 27d23edaccbf239881e23824cfd9e1de7d04e545 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 12 Oct 2016 14:48:00 +0200 Subject: Utility: Add a function to check if two filenames are equal plus test. It calls canonical path always and works with the correct case preserving depending on the platform. --- test/testutility.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test/testutility.cpp') diff --git a/test/testutility.cpp b/test/testutility.cpp index 16fd3066b..63015f053 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -5,6 +5,9 @@ */ #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) +#include +#endif #include "utility.h" @@ -158,6 +161,50 @@ private slots: s = timeAgoInWords(earlyTS, laterTS ); QCOMPARE(s, QLatin1String("Less than a minute ago")); } + + void testFsCasePreserving() + { + qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "1"); + QVERIFY(fsCasePreserving()); + qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "0"); + QVERIFY(! fsCasePreserving()); + qunsetenv("OWNCLOUD_TEST_CASE_PRESERVING"); + QVERIFY(isMac() || isWindows() ? fsCasePreserving() : ! fsCasePreserving()); + } + + void testFileNamesEqual() + { +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + qDebug() << "*** checking fileNamesEqual function"; + QTemporaryDir dir; + QVERIFY(dir.isValid()); + QDir dir2(dir.path()); + QVERIFY(dir2.mkpath("test")); + if( !fsCasePreserving() ) { + QVERIFY(dir2.mkpath("TEST")); + } + QVERIFY(dir2.mkpath("test/TESTI")); + QVERIFY(dir2.mkpath("TESTI")); + + QString a = dir.path(); + QString b = dir.path(); + + QVERIFY(fileNamesEqual(a, b)); + + QVERIFY(fileNamesEqual(a+"/test", b+"/test")); // both exist + QVERIFY(fileNamesEqual(a+"/test/TESTI", b+"/test/../test/TESTI")); // both exist + + qputenv("OWNCLOUD_TEST_CASE_PRESERVING", "1"); + QVERIFY(fileNamesEqual(a+"/test", b+"/TEST")); // both exist + + QVERIFY(!fileNamesEqual(a+"/test", b+"/test/TESTI")); // both are different + + dir.remove(); + qunsetenv("OWNCLOUD_TEST_CASE_PRESERVING"); +#endif + } + + }; QTEST_APPLESS_MAIN(TestUtility) -- cgit v1.2.3