File indexing completed on 2024-10-06 03:43:32
0001 /* 0002 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "connectionsettingtest.h" 0008 0009 #include "settings/connectionsettings.h" 0010 0011 #include <libnm/NetworkManager.h> 0012 0013 #if !NM_CHECK_VERSION(1, 6, 0) 0014 #define NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES "autoconnect-retries" 0015 #endif 0016 0017 #include <QTest> 0018 0019 void ConnectionSettingTest::testSetting_data() 0020 { 0021 QTest::addColumn<QString>("id"); 0022 QTest::addColumn<QString>("uuid"); 0023 QTest::addColumn<QString>("type"); 0024 QTest::addColumn<QStringList>("permissions"); 0025 QTest::addColumn<bool>("autoconnect"); 0026 QTest::addColumn<quint64>("timestamp"); 0027 QTest::addColumn<bool>("readOnly"); 0028 QTest::addColumn<QString>("zone"); 0029 QTest::addColumn<QString>("master"); 0030 QTest::addColumn<QString>("slaveType"); 0031 QTest::addColumn<QStringList>("secondaries"); 0032 QTest::addColumn<uint>("gatewayPingTimeout"); 0033 QTest::addColumn<int>("autoconnectPriority"); 0034 QTest::addColumn<int>("autoconnectRetries"); 0035 QTest::addColumn<int>("autoconnectSlaves"); 0036 QTest::addColumn<int>("lldp"); 0037 QTest::addColumn<int>("metered"); 0038 QTest::addColumn<QString>("stableId"); 0039 0040 QStringList permissions; 0041 permissions << "user:foo:bar"; 0042 0043 QTest::newRow("setting1") << QString("test") // id 0044 << QString("2815492f-7e56-435e-b2e9-246bd7cdc664") // uuid 0045 << QString("802-3-ethernet") // type 0046 << permissions // permissions 0047 << false // autoconnect 0048 << (quint64)1355945444 // timestamp 0049 << true // readOnly 0050 << QString("Home") // zone 0051 << QString("3ba0ba8c-58f3-427d-bce4-3c8200277a5c") // master 0052 << QString("bond") // slaveType 0053 << QStringList{{"2d331115-a2f4-4376-b24e-b8ba6e71abcf"}} // secondaries 0054 << (uint)10 // gatewayPingTimeout 0055 << 10 // autoconnectPriority 0056 << 5 // autoconnectRetries 0057 << 1 // autoconnectSlaves 0058 << 1 // lldp 0059 << 1 // metered 0060 << QString("${CONNECTION}/${BOOT}"); // stableId 0061 } 0062 0063 void ConnectionSettingTest::testSetting() 0064 { 0065 QFETCH(QString, id); 0066 QFETCH(QString, uuid); 0067 QFETCH(QString, type); 0068 QFETCH(QStringList, permissions); 0069 QFETCH(bool, autoconnect); 0070 QFETCH(quint64, timestamp); 0071 QFETCH(bool, readOnly); 0072 QFETCH(QString, zone); 0073 QFETCH(QString, master); 0074 QFETCH(QString, slaveType); 0075 QFETCH(QStringList, secondaries); 0076 QFETCH(uint, gatewayPingTimeout); 0077 QFETCH(int, autoconnectPriority); 0078 QFETCH(int, autoconnectRetries); 0079 QFETCH(int, autoconnectSlaves); 0080 QFETCH(int, lldp); 0081 QFETCH(int, metered); 0082 QFETCH(QString, stableId); 0083 0084 NMVariantMapMap mapmap; 0085 QVariantMap map; 0086 0087 map.insert(QLatin1String(NM_SETTING_CONNECTION_ID), id); 0088 map.insert(QLatin1String(NM_SETTING_CONNECTION_UUID), uuid); 0089 map.insert(QLatin1String(NM_SETTING_CONNECTION_TYPE), type); 0090 map.insert(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS), permissions); 0091 map.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT), autoconnect); 0092 map.insert(QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP), timestamp); 0093 map.insert(QLatin1String(NM_SETTING_CONNECTION_READ_ONLY), readOnly); 0094 map.insert(QLatin1String(NM_SETTING_CONNECTION_ZONE), zone); 0095 map.insert(QLatin1String(NM_SETTING_CONNECTION_MASTER), master); 0096 map.insert(QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE), slaveType); 0097 map.insert(QLatin1String(NM_SETTING_CONNECTION_SECONDARIES), secondaries); 0098 map.insert(QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), gatewayPingTimeout); 0099 map.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), autoconnectPriority); 0100 map.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), autoconnectRetries); 0101 map.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), autoconnectSlaves); 0102 map.insert(QLatin1String(NM_SETTING_CONNECTION_LLDP), lldp); 0103 map.insert(QLatin1String(NM_SETTING_CONNECTION_METERED), metered); 0104 map.insert(QLatin1String(NM_SETTING_CONNECTION_STABLE_ID), stableId); 0105 0106 mapmap.insert(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME), map); 0107 0108 NetworkManager::ConnectionSettings setting; 0109 setting.fromMap(mapmap); 0110 0111 NMVariantMapMap mapmap1 = setting.toMap(); 0112 QVariantMap map1 = mapmap1.value(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME)); 0113 QVariantMap::const_iterator it = map.constBegin(); 0114 while (it != map.constEnd()) { 0115 QCOMPARE(it.value(), map1.value(it.key())); 0116 ++it; 0117 } 0118 } 0119 0120 QTEST_MAIN(ConnectionSettingTest) 0121 0122 #include "moc_connectionsettingtest.cpp"