File indexing completed on 2024-12-08 03:44:11
0001 /* 0002 SPDX-FileCopyrightText: 2018 Pranav Gade <pranavgade20@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "teamportsettingtest.h" 0008 0009 #include "settings/teamportsetting.h" 0010 0011 #include <libnm/NetworkManager.h> 0012 0013 #include <QTest> 0014 0015 #if !NM_CHECK_VERSION(1, 10, 0) 0016 #define NM_SETTING_TEAM_PORT_CONFIG "config" 0017 #define NM_SETTING_TEAM_PORT_QUEUE_ID "queue-id" 0018 #define NM_SETTING_TEAM_PORT_PRIO "prio" 0019 #define NM_SETTING_TEAM_PORT_STICKY "sticky" 0020 #define NM_SETTING_TEAM_PORT_LACP_PRIO "lacp-prio" 0021 #define NM_SETTING_TEAM_PORT_LACP_KEY "lacp-key" 0022 #define NM_SETTING_TEAM_PORT_LINK_WATCHERS "link-watchers" 0023 #endif 0024 0025 void TeamPortSettingTest::testSetting_data() 0026 { 0027 QTest::addColumn<QString>("config"); 0028 QTest::addColumn<qint32>("lacpKey"); 0029 QTest::addColumn<qint32>("lacpPrio"); 0030 QTest::addColumn<qint32>("prio"); 0031 QTest::addColumn<qint32>("queueId"); 0032 QTest::addColumn<bool>("sticky"); 0033 QTest::addColumn<NMVariantMapList>("linkWatchers"); 0034 0035 NMVariantMapList linkWatchers; 0036 QVariantMap linkWatcher; 0037 linkWatcher["one"] = "1"; 0038 linkWatcher["two"] = 2; 0039 linkWatchers.append(linkWatcher); 0040 0041 QTest::newRow("setting1") << QString("abc") // config 0042 << (qint32)1 // lacpKey 0043 << (qint32)1 // lacpPrio 0044 << (qint32)1 // prio 0045 << (qint32)1 // queueId 0046 << true // sticky 0047 << linkWatchers; // linkWatchers 0048 } 0049 0050 void TeamPortSettingTest::testSetting() 0051 { 0052 QFETCH(QString, config); 0053 QFETCH(qint32, lacpKey); 0054 QFETCH(qint32, lacpPrio); 0055 QFETCH(qint32, prio); 0056 QFETCH(qint32, queueId); 0057 QFETCH(bool, sticky); 0058 QFETCH(NMVariantMapList, linkWatchers); 0059 0060 QVariantMap map; 0061 0062 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG), config); 0063 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY), lacpKey); 0064 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO), lacpPrio); 0065 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_PRIO), prio); 0066 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID), queueId); 0067 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_STICKY), sticky); 0068 map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS), QVariant::fromValue(linkWatchers)); 0069 0070 NetworkManager::TeamPortSetting setting; 0071 setting.fromMap(map); 0072 0073 QVariantMap map1 = setting.toMap(); 0074 0075 // Will fail if set some default values, because they are skipped in toMap() method 0076 QVariantMap::const_iterator it = map.constBegin(); 0077 while (it != map.constEnd()) { 0078 if (it.key() != QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)) { 0079 QCOMPARE(it.value(), map1.value(it.key())); 0080 } 0081 ++it; 0082 } 0083 0084 NMVariantMapList list = map.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)).value<NMVariantMapList>(); 0085 NMVariantMapList list1 = map1.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)).value<NMVariantMapList>(); 0086 0087 QCOMPARE(list.count(), list1.count()); 0088 0089 int comparedMaps = 0; 0090 for (int i = 0; i < list.size(); ++i) { 0091 QVariantMap varMap = list.at(i); 0092 for (int j = 0; j < list1.size(); ++j) { 0093 QVariantMap varMap1 = list1.at(i); 0094 QVariantMap::const_iterator ite = varMap.constBegin(); 0095 int comparedvals = 0; 0096 while (ite != varMap.constEnd()) { 0097 QVariantMap::const_iterator val1 = varMap1.constFind(ite.key()); 0098 if (val1 != varMap1.constEnd()) { 0099 if (varMap.value(ite.key()) == val1.value()) { 0100 ++comparedvals; 0101 } 0102 } 0103 ++ite; 0104 } 0105 if (comparedvals == varMap.size()) { 0106 comparedMaps++; 0107 } 0108 } 0109 } 0110 ++it; 0111 QCOMPARE(comparedMaps, list.count()); 0112 } 0113 0114 QTEST_MAIN(TeamPortSettingTest) 0115 0116 #include "moc_teamportsettingtest.cpp"