File indexing completed on 2024-09-08 03:37:39
0001 /* 0002 This software is a contribution of the LiMux project of the city of Munich. 0003 SPDX-FileCopyrightText: 2021 Robert Hoffmann <robert@roberthoffmann.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "knetworkmountsteststatic.h" 0009 0010 // include static functions 0011 #include "knetworkmounts_p.h" 0012 0013 #include <KNetworkMounts> 0014 0015 #include <QFile> 0016 #include <QStandardPaths> 0017 #include <QTest> 0018 0019 QTEST_MAIN(KNetworkMountsTestStatic) 0020 0021 void KNetworkMountsTestStatic::testStaticFunctions_data() 0022 { 0023 QTest::addColumn<QString>("path"); 0024 QTest::addColumn<QStringList>("paths"); 0025 QTest::addColumn<bool>("expected_is_slash_added_to_path"); 0026 QTest::addColumn<QString>("expected_path_str"); 0027 QTest::addColumn<bool>("expected_is_slash_added_to_paths"); 0028 QTest::addColumn<QStringList>("expected_paths_str"); 0029 QTest::addColumn<QString>("expected_matching"); 0030 0031 QTest::newRow("empty1") << QString() << QStringList() << false << "" << false << QStringList() << QString(); 0032 QTest::newRow("empty2") << "" << QStringList{QString(), QString()} << false << "" << false << QStringList{QString(), QString()} << QString(); 0033 0034 QTest::newRow("/1") << "/" << QStringList() << false << "/" << false << QStringList() << QString(); 0035 QTest::newRow("/2") << "/" << QStringList{QString(), QString()} << false << "/" << false << QStringList{QString(), QString()} << QString(); 0036 QTest::newRow("/3") << "/" << (QStringList{QStringLiteral("/")}) << false << "/" << false << QStringList{QStringLiteral("/")} << "/"; 0037 QTest::newRow("/4") << "/" << QStringList{QStringLiteral("/"), QString()} << false << "/" << false << QStringList{QStringLiteral("/"), QString()} << "/"; 0038 0039 QTest::newRow("/mnt1") << "/mnt" << QStringList() << true << "/mnt/" << false << QStringList() << QString(); 0040 QTest::newRow("/mnt2") << "/mnt" << QStringList{QStringLiteral("/mnt")} << true << "/mnt/" << true << QStringList{QStringLiteral("/mnt/")} << "/mnt"; 0041 QTest::newRow("/mnt3") << "/mnt" << QStringList{QStringLiteral("/mnt/")} << true << "/mnt/" << false << QStringList{QStringLiteral("/mnt/")} << "/mnt/"; 0042 0043 QTest::newRow("/mnt/test1") << "/mnt" << (QStringList() << QStringLiteral("/mnt/test1") << QStringLiteral("/mnt/test2/")) << true << "/mnt/" << true 0044 << QStringList{QStringLiteral("/mnt/test1/"), QStringLiteral("/mnt/test2/")} << ""; 0045 QTest::newRow("/mnt/test2") << "/mnt/test2" << QStringList{QStringLiteral("/mnt/test1/"), QStringLiteral("/mnt/test2/")} << true << "/mnt/test2/" << false 0046 << QStringList{QStringLiteral("/mnt/test1/"), QStringLiteral("/mnt/test2/")} << "/mnt/test2/"; 0047 QTest::newRow("/mnt/test3") << "/mnt/test2/" << (QStringList() << QStringLiteral("/mnt/test1/") << QStringLiteral("/mnt/test2/")) << false << "/mnt/test2/" 0048 << false << QStringList{QStringLiteral("/mnt/test1/"), QStringLiteral("/mnt/test2/")} << "/mnt/test2/"; 0049 } 0050 0051 void KNetworkMountsTestStatic::testStaticFunctions() 0052 { 0053 QFETCH(QString, path); 0054 QFETCH(QStringList, paths); 0055 QFETCH(bool, expected_is_slash_added_to_path); 0056 QFETCH(QString, expected_path_str); 0057 QFETCH(bool, expected_is_slash_added_to_paths); 0058 QFETCH(QStringList, expected_paths_str); 0059 QFETCH(QString, expected_matching); 0060 0061 QCOMPARE(getMatchingPath(path, paths), expected_matching); 0062 0063 QCOMPARE(ensureTrailingSlash(&path), expected_is_slash_added_to_path); 0064 QCOMPARE(path, expected_path_str); 0065 QCOMPARE(ensureTrailingSlashes(&paths), expected_is_slash_added_to_paths); 0066 QCOMPARE(paths, expected_paths_str); 0067 } 0068 0069 void KNetworkMountsTestStatic::testStaticKNetworkMountOptionToString_data() 0070 { 0071 QTest::addColumn<KNetworkMounts::KNetworkMountOption>("option"); 0072 QTest::addColumn<QString>("string"); 0073 0074 QTest::newRow("LowSideEffectsOptimizations") << KNetworkMounts::LowSideEffectsOptimizations << "LowSideEffectsOptimizations"; 0075 QTest::newRow("MediumSideEffectsOptimizations") << KNetworkMounts::MediumSideEffectsOptimizations << "MediumSideEffectsOptimizations"; 0076 QTest::newRow("StrongSideEffectsOptimizations") << KNetworkMounts::StrongSideEffectsOptimizations << "StrongSideEffectsOptimizations"; 0077 QTest::newRow("KDirWatchDontAddWatches") << KNetworkMounts::KDirWatchDontAddWatches << "KDirWatchDontAddWatches"; 0078 QTest::newRow("SymlinkPathsUseCache") << KNetworkMounts::SymlinkPathsUseCache << "SymlinkPathsUseCache"; 0079 } 0080 void KNetworkMountsTestStatic::testStaticKNetworkMountOptionToString() 0081 { 0082 QFETCH(KNetworkMounts::KNetworkMountOption, option); 0083 QFETCH(QString, string); 0084 0085 QCOMPARE(enumToString(option), string); 0086 } 0087 0088 void KNetworkMountsTestStatic::testStaticKNetworkMountsTypeToString_data() 0089 { 0090 QTest::addColumn<KNetworkMounts::KNetworkMountsType>("type"); 0091 QTest::addColumn<QString>("string"); 0092 0093 QTest::newRow("NfsPaths") << KNetworkMounts::NfsPaths << "NfsPaths"; 0094 QTest::newRow("SmbPaths") << KNetworkMounts::SmbPaths << "SmbPaths"; 0095 QTest::newRow("SymlinkDirectory") << KNetworkMounts::SymlinkDirectory << "SymlinkDirectory"; 0096 QTest::newRow("SymlinkToNetworkMount") << KNetworkMounts::SymlinkToNetworkMount << "SymlinkToNetworkMount"; 0097 QTest::newRow("Any") << KNetworkMounts::Any << "Any"; 0098 } 0099 void KNetworkMountsTestStatic::testStaticKNetworkMountsTypeToString() 0100 { 0101 QFETCH(KNetworkMounts::KNetworkMountsType, type); 0102 QFETCH(QString, string); 0103 0104 QCOMPARE(enumToString(type), string); 0105 } 0106 0107 #include "moc_knetworkmountsteststatic.cpp"