File indexing completed on 2024-09-29 09:33:29

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 "vlansettingtest.h"
0008 
0009 #include "settings/vlansetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 void VlanSettingTest::testSetting_data()
0016 {
0017     QTest::addColumn<QString>("interfaceName");
0018     QTest::addColumn<QString>("parent");
0019     QTest::addColumn<quint32>("id");
0020     QTest::addColumn<quint32>("flags");
0021     QTest::addColumn<QStringList>("ingressPriorityMap");
0022     QTest::addColumn<QStringList>("egressPriorityMap");
0023 
0024     QStringList mapping;
0025     mapping << "7:3";
0026     mapping << "8:4";
0027 
0028     QTest::newRow("setting1") << QString("eth2.1") // interfaceName
0029                               << QString("2815492f-7e56-435e-b2e9-246bd7cdc668") // parent
0030                               << (quint32)2 // id
0031                               << (quint32)0x02 // flags
0032                               << mapping // ingressPriorityMap
0033                               << mapping; // egressPriorityMap
0034 }
0035 
0036 void VlanSettingTest::testSetting()
0037 {
0038     QFETCH(QString, interfaceName);
0039     QFETCH(QString, parent);
0040     QFETCH(quint32, id);
0041     QFETCH(quint32, flags);
0042     QFETCH(QStringList, ingressPriorityMap);
0043     QFETCH(QStringList, egressPriorityMap);
0044 
0045     QVariantMap map;
0046 
0047     map.insert(QLatin1String("interface-name"), interfaceName);
0048     map.insert(QLatin1String(NM_SETTING_VLAN_PARENT), parent);
0049     map.insert(QLatin1String(NM_SETTING_VLAN_ID), id);
0050     map.insert(QLatin1String(NM_SETTING_VLAN_FLAGS), flags);
0051     map.insert(QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), ingressPriorityMap);
0052     map.insert(QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), egressPriorityMap);
0053 
0054     NetworkManager::VlanSetting setting;
0055     setting.fromMap(map);
0056 
0057     QVariantMap map1 = setting.toMap();
0058     QVariantMap::const_iterator it = map.constBegin();
0059     while (it != map.constEnd()) {
0060         QCOMPARE(it.value(), map1.value(it.key()));
0061         ++it;
0062     }
0063 }
0064 
0065 QTEST_MAIN(VlanSettingTest)
0066 
0067 #include "moc_vlansettingtest.cpp"