File indexing completed on 2024-12-08 03:44:11
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 "wiredsettingtest.h" 0008 0009 #include "generictypes.h" 0010 #include "settings/wiredsetting.h" 0011 0012 #include <libnm/NetworkManager.h> 0013 0014 #include <QTest> 0015 0016 #define NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS "assigned-mac-address" 0017 0018 void WiredSettingTest::testSetting_data() 0019 { 0020 QTest::addColumn<QString>("port"); 0021 QTest::addColumn<quint32>("speed"); 0022 QTest::addColumn<QString>("duplex"); 0023 QTest::addColumn<bool>("autoNegotiate"); 0024 QTest::addColumn<QString>("generateMacAddressMask"); 0025 QTest::addColumn<QByteArray>("macAddress"); 0026 QTest::addColumn<QByteArray>("clonedMacAddress"); 0027 QTest::addColumn<QStringList>("macAddressBlacklist"); 0028 QTest::addColumn<quint32>("mtu"); 0029 QTest::addColumn<QStringList>("s390Subchannels"); 0030 QTest::addColumn<QString>("s390NetType"); 0031 QTest::addColumn<NMStringMap>("s390Options"); 0032 QTest::addColumn<uint>("wakeOnLan"); 0033 QTest::addColumn<QString>("wakeOnLanPassword"); 0034 QTest::addColumn<QString>("assignedMacAddress"); 0035 0036 QStringList macAddressBlacklist; 0037 macAddressBlacklist << "00:08:C7:1B:8C:02"; 0038 0039 QStringList s390Subchannels; 0040 s390Subchannels << "0.0.09a0"; 0041 s390Subchannels << "0.0.09a1"; 0042 s390Subchannels << "0.0.09a2"; 0043 0044 QMap<QString, QString> s390Options; 0045 s390Options.insert("portno", "0"); 0046 0047 QTest::newRow("setting1") << QString("tp") // port 0048 << (quint32)100 // speed 0049 << QString("full") // duplex 0050 << false // autoNegotiate 0051 << QString("FE:FF:FF:00:00:00 68:F7:28:00:00:00") // generateMacAddressMask 0052 << QByteArray("00-B0-D0-86-BB-F7") // macAddress 0053 << QByteArray("00-14-22-01-23-4") // clonedMacAddress 0054 << macAddressBlacklist // macAddressBlacklist 0055 << (quint32)200 // mtu 0056 << s390Subchannels // s390Subchannels 0057 << QString("qeth") // s390NetType 0058 << s390Options // s390Options 0059 << (uint)(NetworkManager::WiredSetting::WakeOnLanMulticast | NetworkManager::WiredSetting::WakeOnLanMagic) // wakeOnLan 0060 << QString("password") // wakeOnLanPassword 0061 << QString("random"); // assignedMacAddress 0062 } 0063 0064 void WiredSettingTest::testSetting() 0065 { 0066 QFETCH(QString, port); 0067 QFETCH(quint32, speed); 0068 QFETCH(QString, duplex); 0069 QFETCH(bool, autoNegotiate); 0070 QFETCH(QString, generateMacAddressMask); 0071 QFETCH(QByteArray, macAddress); 0072 QFETCH(QByteArray, clonedMacAddress); 0073 QFETCH(QStringList, macAddressBlacklist); 0074 QFETCH(quint32, mtu); 0075 QFETCH(QStringList, s390Subchannels); 0076 QFETCH(QString, s390NetType); 0077 QFETCH(NMStringMap, s390Options); 0078 QFETCH(uint, wakeOnLan); 0079 QFETCH(QString, wakeOnLanPassword); 0080 QFETCH(QString, assignedMacAddress); 0081 0082 QVariantMap map; 0083 0084 map.insert(QLatin1String(NM_SETTING_WIRED_PORT), port); 0085 map.insert(QLatin1String(NM_SETTING_WIRED_SPEED), speed); 0086 map.insert(QLatin1String(NM_SETTING_WIRED_DUPLEX), duplex); 0087 map.insert(QLatin1String(NM_SETTING_WIRED_AUTO_NEGOTIATE), autoNegotiate); 0088 map.insert(QLatin1String(NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask); 0089 map.insert(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS), macAddress); 0090 map.insert(QLatin1String(NM_SETTING_WIRED_CLONED_MAC_ADDRESS), clonedMacAddress); 0091 map.insert(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST), macAddressBlacklist); 0092 map.insert(QLatin1String(NM_SETTING_WIRED_MTU), mtu); 0093 map.insert(QLatin1String(NM_SETTING_WIRED_S390_SUBCHANNELS), s390Subchannels); 0094 map.insert(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE), s390NetType); 0095 map.insert(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS), QVariant::fromValue(s390Options)); 0096 map.insert(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN), wakeOnLan); 0097 map.insert(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD), wakeOnLanPassword); 0098 map.insert(QLatin1String(NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS), assignedMacAddress); 0099 0100 NetworkManager::WiredSetting setting; 0101 setting.fromMap(map); 0102 0103 QVariantMap map1 = setting.toMap(); 0104 QVariantMap::const_iterator it = map.constBegin(); 0105 while (it != map.constEnd()) { 0106 if (it.key() != QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)) { 0107 QCOMPARE(it.value(), map1.value(it.key())); 0108 } 0109 ++it; 0110 } 0111 0112 QCOMPARE(map.value(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)).value<NMStringMap>(), 0113 map1.value(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)).value<NMStringMap>()); 0114 } 0115 0116 QTEST_MAIN(WiredSettingTest) 0117 0118 #include "moc_wiredsettingtest.cpp"