File indexing completed on 2024-07-21 03:45:08

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 "wirelesssettingtest.h"
0008 
0009 #include "settings/wirelesssetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #define NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS "assigned-mac-address"
0014 
0015 #include <QTest>
0016 
0017 void WirelessSettingTest::testSetting_data()
0018 {
0019     QTest::addColumn<QByteArray>("ssid");
0020     QTest::addColumn<QString>("mode");
0021     QTest::addColumn<QString>("band");
0022     QTest::addColumn<quint32>("channel");
0023     QTest::addColumn<QByteArray>("bssid");
0024     QTest::addColumn<quint32>("rate");
0025     QTest::addColumn<quint32>("txPower");
0026     QTest::addColumn<QByteArray>("macAddress");
0027     QTest::addColumn<QString>("generateMacAddressMask");
0028     QTest::addColumn<QStringList>("macAddressBlacklist");
0029     QTest::addColumn<uint>("macAddressRandomization");
0030     QTest::addColumn<quint32>("mtu");
0031     QTest::addColumn<QStringList>("seenBssids");
0032     QTest::addColumn<uint>("powerSave");
0033     QTest::addColumn<QString>("security");
0034     QTest::addColumn<bool>("hidden");
0035     QTest::addColumn<QString>("assignedMacAddress");
0036 
0037     QStringList macAddressBlacklist;
0038     macAddressBlacklist << "00:08:C7:1B:8C:02";
0039 
0040     QStringList seenBssids;
0041     seenBssids << "0005.9a3e.7c0f";
0042 
0043     QTest::newRow("setting1") << QByteArray("test") // ssid
0044                               << QString("adhoc") // mode
0045                               << QString("bg") // band
0046                               << (quint32)1 // channel
0047                               << QByteArray("0011.2161.b7c0") // bssid
0048                               << (quint32)2 // rate
0049                               << (quint32)3 // txPower
0050                               << QByteArray("00-B0-D0-86-BB-F7") // macAddress
0051                               << QString("FE:FF:FF:00:00:00 68:F7:28:00:00:00") // generateMacAddressMask
0052                               << macAddressBlacklist // macAddressBlacklist
0053                               << (uint)1 // macAddressRandomization
0054                               << (quint32)4 // mtu
0055                               << seenBssids // seenBssids
0056                               << (uint)2 // powerSave
0057                               << QString("802-11-wireless-security") // security
0058                               << true // hidden
0059                               << QString("random"); // assignedMacAddress
0060 }
0061 
0062 void WirelessSettingTest::testSetting()
0063 {
0064     QFETCH(QByteArray, ssid);
0065     QFETCH(QString, mode);
0066     QFETCH(QString, band);
0067     QFETCH(quint32, channel);
0068     QFETCH(QByteArray, bssid);
0069     QFETCH(quint32, rate);
0070     QFETCH(quint32, txPower);
0071     QFETCH(QByteArray, macAddress);
0072     QFETCH(QString, generateMacAddressMask);
0073     QFETCH(QStringList, macAddressBlacklist);
0074     QFETCH(uint, macAddressRandomization);
0075     QFETCH(quint32, mtu);
0076     QFETCH(QStringList, seenBssids);
0077     QFETCH(uint, powerSave);
0078     QFETCH(QString, security);
0079     QFETCH(bool, hidden);
0080     QFETCH(QString, assignedMacAddress);
0081 
0082     QVariantMap map;
0083 
0084     map.insert(QLatin1String(NM_SETTING_WIRELESS_SSID), ssid);
0085     map.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), mode);
0086     map.insert(QLatin1String(NM_SETTING_WIRELESS_BAND), band);
0087     map.insert(QLatin1String(NM_SETTING_WIRELESS_CHANNEL), channel);
0088     map.insert(QLatin1String(NM_SETTING_WIRELESS_BSSID), bssid);
0089     map.insert(QLatin1String(NM_SETTING_WIRELESS_RATE), rate);
0090     map.insert(QLatin1String(NM_SETTING_WIRELESS_TX_POWER), txPower);
0091     map.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS), macAddress);
0092     map.insert(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask);
0093     map.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), macAddressBlacklist);
0094     map.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), macAddressRandomization);
0095     map.insert(QLatin1String(NM_SETTING_WIRELESS_MTU), mtu);
0096     map.insert(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS), seenBssids);
0097     map.insert(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE), powerSave);
0098     map.insert(QLatin1String("security"), security);
0099 
0100     map.insert(QLatin1String(NM_SETTING_WIRELESS_HIDDEN), hidden);
0101     map.insert(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS), assignedMacAddress);
0102 
0103     NetworkManager::WirelessSetting setting;
0104     setting.fromMap(map);
0105 
0106     QVariantMap map1 = setting.toMap();
0107 
0108     // Will fail if set some default values, because they are skipped in toMap() method
0109     QVariantMap::const_iterator it = map.constBegin();
0110     while (it != map.constEnd()) {
0111         QCOMPARE(it.value(), map1.value(it.key()));
0112         ++it;
0113     }
0114 }
0115 
0116 QTEST_MAIN(WirelessSettingTest)
0117 
0118 #include "moc_wirelesssettingtest.cpp"