File indexing completed on 2024-04-21 03:59:54

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 "ovsbridgesettingtest.h"
0008 
0009 #include "settings/ovsbridgesetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 #if !NM_CHECK_VERSION(1, 10, 0)
0016 #define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge"
0017 #define NM_SETTING_OVS_BRIDGE_FAIL_MODE "fail-mode"
0018 #define NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE "mcast-snooping-enable"
0019 #define NM_SETTING_OVS_BRIDGE_RSTP_ENABLE "rstp-enable"
0020 #define NM_SETTING_OVS_BRIDGE_STP_ENABLE "stp-enable"
0021 #endif
0022 
0023 void OvsBridgeSettingTest::testSetting_data()
0024 {
0025     QTest::addColumn<bool>("mcastSnoopingEnable");
0026     QTest::addColumn<bool>("rstpEnable");
0027     QTest::addColumn<bool>("stpEnable");
0028     QTest::addColumn<QString>("failMode");
0029 
0030     QTest::newRow("setting1") << true // mcastSnoopingEnable
0031                               << true // rstpEnable
0032                               << true // stpEnable
0033                               << QString("secure"); // failMode
0034 }
0035 
0036 void OvsBridgeSettingTest::testSetting()
0037 {
0038     QFETCH(bool, mcastSnoopingEnable);
0039     QFETCH(bool, rstpEnable);
0040     QFETCH(bool, stpEnable);
0041     QFETCH(QString, failMode);
0042 
0043     QVariantMap map;
0044 
0045     map.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE), mcastSnoopingEnable);
0046     map.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE), rstpEnable);
0047     map.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE), stpEnable);
0048     map.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE), failMode);
0049 
0050     NetworkManager::OvsBridgeSetting setting;
0051     setting.fromMap(map);
0052 
0053     QVariantMap map1 = setting.toMap();
0054 
0055     // Will fail if set some default values, because they are skipped in toMap() method
0056     QVariantMap::const_iterator it = map.constBegin();
0057     while (it != map.constEnd()) {
0058         QCOMPARE(it.value(), map1.value(it.key()));
0059         ++it;
0060     }
0061 }
0062 
0063 QTEST_MAIN(OvsBridgeSettingTest)
0064 
0065 #include "moc_ovsbridgesettingtest.cpp"