Utils: Make tst_fileutils::fromString() independent of host os

Also, add checks for the resulting root() bits

Change-Id: I3f82b5be95ab89c65d904fc941d537582bd54876
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2022-09-08 13:03:16 +02:00
parent d956ddee71
commit e197acd97b
+40 -29
View File
@@ -327,43 +327,52 @@ void tst_fileutils::fromString_data()
QTest::addColumn<QString>("scheme");
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("path");
QTest::addColumn<QString>("root");
QTest::addColumn<OsType>("osType");
QTest::newRow("empty") << "" << "" << "" << "" << HostOsInfo::hostOs();
QTest::newRow("single-slash") << ":" << "" << "" << ":" << HostOsInfo::hostOs();
QTest::newRow("single-colon") << "/" << "" << "" << "/" << HostOsInfo::hostOs();
QTest::newRow("single-char") << "a" << "" << "" << "a" << HostOsInfo::hostOs();
QTest::newRow("qrc-no-slash") << ":test.txt" << "" << "" << ":test.txt" << HostOsInfo::hostOs();
QTest::newRow("qrc") << ":/test.txt" << "" << "" << ":/test.txt" << HostOsInfo::hostOs();
QTest::newRow("unc-incomplete") << "//" << "" << "" << "" << OsType::OsTypeWindows;
QTest::newRow("unc-incomplete-only-server") << "//server" << "" << "" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-incomplete-only-server-2") << "//server/" << "" << "" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-server-and-share") << "//server/share" << "" << "" << "//server/share" << OsType::OsTypeWindows;
QTest::newRow("unc-server-and-share-2") << "//server/share/" << "" << "" << "//server/share/" << OsType::OsTypeWindows;
QTest::newRow("unc-full") << "//server/share/test.txt" << "" << "" << "//server/share/test.txt" << OsType::OsTypeWindows;
QTest::newRow("empty-linux") << "" << "" << "" << "" << "" << OsType::OsTypeLinux;
QTest::newRow("empty-win") << "" << "" << "" << "" << "" << OsType::OsTypeWindows;
QTest::newRow("single-colon-linux") << ":" << "" << "" << ":" << ":" << OsType::OsTypeLinux;
QTest::newRow("single-colon-win") << ":" << "" << "" << ":" << ":" << OsType::OsTypeWindows;
QTest::newRow("single-slash-linux") << "/" << "" << "" << "/" << "/" << OsType::OsTypeLinux;
QTest::newRow("single-slash-win") << "/" << "" << "" << "/" << "/" << OsType::OsTypeWindows;
QTest::newRow("single-char-linux") << "a" << "" << "" << "a" << "" << OsType::OsTypeLinux;
QTest::newRow("single-char-win") << "a" << "" << "" << "a" << "" << OsType::OsTypeWindows;
QTest::newRow("qrc-linux") << ":/test.txt" << "" << "" << ":/test.txt" << ":/" << OsType::OsTypeLinux;
QTest::newRow("qrc-win") << ":/test.txt" << "" << "" << ":/test.txt" << ":/" << OsType::OsTypeWindows;
QTest::newRow("qrc-no-slash-linux") << ":test.txt" << "" << "" << ":test.txt" << ":" << OsType::OsTypeLinux;
QTest::newRow("qrc-no-slash-win") << ":test.txt" << "" << "" << ":test.txt" << ":" << OsType::OsTypeWindows;
QTest::newRow("unc-incomplete") << "//" << "" << "" << "" << "" << OsType::OsTypeWindows;
QTest::newRow("unc-incomplete-only-server") << "//server" << "" << "" << "//server/" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-incomplete-only-server-2") << "//server/" << "" << "" << "//server/" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-server-and-share") << "//server/share" << "" << "" << "//server/share" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-server-and-share-2") << "//server/share/" << "" << "" << "//server/share/" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-full") << "//server/share/test.txt" << "" << "" << "//server/share/test.txt" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unix-root") << "/" << "" << "" << "/" << OsType::OsTypeLinux;
QTest::newRow("unix-folder") << "/tmp" << "" << "" << "/tmp" << OsType::OsTypeLinux;
QTest::newRow("unix-folder-with-trailing-slash") << "/tmp/" << "" << "" << "/tmp/" << OsType::OsTypeLinux;
QTest::newRow("unix-root") << "/" << "" << "" << "/" << "/" << OsType::OsTypeLinux;
QTest::newRow("unix-folder") << "/tmp" << "" << "" << "/tmp" << "/" << OsType::OsTypeLinux;
QTest::newRow("unix-folder-with-trailing-slash") << "/tmp/" << "" << "" << "/tmp/" << "/" << OsType::OsTypeLinux;
QTest::newRow("windows-root") << "c:" << "" << "" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("windows-folder") << "c:\\Windows" << "" << "" << "c:/Windows" << OsType::OsTypeWindows;
QTest::newRow("windows-folder-with-trailing-slash") << "c:\\Windows\\" << "" << "" << "c:/Windows\\" << OsType::OsTypeWindows;
QTest::newRow("windows-folder-slash") << "C:/Windows" << "" << "" << "C:/Windows" << OsType::OsTypeWindows;
QTest::newRow("windows-root") << "c:" << "" << "" << "c:/" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("windows-folder") << "c:\\Windows" << "" << "" << "c:/Windows" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("windows-folder-with-trailing-slash") << "c:\\Windows\\" << "" << "" << "c:/Windows\\" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("windows-folder-slash") << "C:/Windows" << "" << "" << "C:/Windows" << "C:/" << OsType::OsTypeWindows;
QTest::newRow("docker-root-url") << "docker://1234/" << "docker" << "1234" << "/" << OsType::OsTypeLinux;
QTest::newRow("docker-root-url-special") << QDir::rootPath() + "__qtc_devices__/docker/1234/" << "docker" << "1234" << "/" << OsType::OsTypeLinux;
QTest::newRow("docker-root-url") << "docker://1234/" << "docker" << "1234" << "/" << "/" << OsType::OsTypeLinux;
QTest::newRow("docker-root-url-special") << QDir::rootPath() + "__qtc_devices__/docker/1234/" << "docker" << "1234" << "/" << "/" << OsType::OsTypeLinux;
QTest::newRow("qtc-dev") << QDir::rootPath() + "__qtc_devices__" << "" << "" << QDir::rootPath() + "__qtc_devices__" << HostOsInfo::hostOs();
QTest::newRow("qtc-dev-type") << QDir::rootPath() + "__qtc_devices__/docker" << "" << "" << QDir::rootPath() + "__qtc_devices__/docker" << HostOsInfo::hostOs();
QTest::newRow("qtc-dev-type-dev") << QDir::rootPath() + "__qtc_devices__/docker/1234" << "docker" << "1234" << "/" << OsType::OsTypeLinux;
QTest::newRow("qtc-dev-linux") << QDir::rootPath() + "__qtc_devices__" << "" << "" << QDir::rootPath() + "__qtc_devices__" << "/" << OsType::OsTypeLinux;
QTest::newRow("qtc-dev-win") << QDir::rootPath() + "__qtc_devices__" << "" << "" << QDir::rootPath() + "__qtc_devices__" << "/" << OsType::OsTypeWindows;
QTest::newRow("qtc-dev-type-linux") << QDir::rootPath() + "__qtc_devices__/docker" << "" << "" << QDir::rootPath() + "__qtc_devices__/docker" << "" << OsType::OsTypeLinux;
QTest::newRow("qtc-dev-type-win") << QDir::rootPath() + "__qtc_devices__/docker" << "" << "" << QDir::rootPath() + "__qtc_devices__/docker" << "" << OsType::OsTypeWindows;
QTest::newRow("qtc-dev-type-dev") << QDir::rootPath() + "__qtc_devices__/docker/1234" << "docker" << "1234" << "/" << "/" << OsType::OsTypeLinux;
QTest::newRow("cross-os") << QDir::rootPath() + "__qtc_devices__/docker/1234/c:/test.txt" << "docker" << "1234" << "c:/test.txt" << OsType::OsTypeWindows;
QTest::newRow("cross-os-unclean") << QDir::rootPath() + "__qtc_devices__/docker/1234/c:\\test.txt" << "docker" << "1234" << "c:/test.txt" << OsType::OsTypeWindows;
QTest::newRow("unc-full-in-docker") << QDir::rootPath() + "__qtc_devices__/docker/1234//server/share/test.txt" << "docker" << "1234" << "//server/share/test.txt" << OsType::OsTypeWindows;
QTest::newRow("cross-os") << QDir::rootPath() + "__qtc_devices__/docker/1234/c:/test.txt" << "docker" << "1234" << "c:/test.txt" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("cross-os-unclean") << QDir::rootPath() + "__qtc_devices__/docker/1234/c:\\test.txt" << "docker" << "1234" << "c:/test.txt" << "c:/" << OsType::OsTypeWindows;
QTest::newRow("unc-full-in-docker") << QDir::rootPath() + "__qtc_devices__/docker/1234//server/share/test.txt" << "docker" << "1234" << "//server/share/test.txt" << "//server/" << OsType::OsTypeWindows;
QTest::newRow("unc-dos-1") << "//?/c:" << "" << "" << "//?/c:" << OsType::OsTypeWindows;
QTest::newRow("unc-dos-com") << "//./com1" << "" << "" << "//./com1" << OsType::OsTypeWindows;
QTest::newRow("unc-dos-1") << "//?/c:" << "" << "" << "//?/c:" << "//?/" << OsType::OsTypeWindows;
QTest::newRow("unc-dos-com") << "//./com1" << "" << "" << "//./com1" << "//./" << OsType::OsTypeWindows;
}
void tst_fileutils::fromString()
@@ -372,12 +381,14 @@ void tst_fileutils::fromString()
QFETCH(QString, scheme);
QFETCH(QString, host);
QFETCH(QString, path);
QFETCH(QString, root);
QFETCH(OsType, osType);
FilePath filePath = FilePath::fromStringAndOs(input, osType);
QCOMPARE(filePath.scheme(), scheme);
QCOMPARE(filePath.host(), host);
QCOMPARE(filePath.path(), path);
QCOMPARE(filePath.root(), root);
}
void tst_fileutils::fromToString_data()