File indexing completed on 2024-10-13 03:41:52

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 "ovsportsettingtest.h"
0008 
0009 #include "settings/ovsportsetting.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_PORT_VLAN_MODE "vlan-mode"
0017 #define NM_SETTING_OVS_PORT_TAG "tag"
0018 #define NM_SETTING_OVS_PORT_LACP "lacp"
0019 #define NM_SETTING_OVS_PORT_BOND_MODE "bond-mode"
0020 #define NM_SETTING_OVS_PORT_BOND_UPDELAY "bond-updelay"
0021 #define NM_SETTING_OVS_PORT_BOND_DOWNDELAY "bond-downdelay"
0022 #endif
0023 
0024 void OvsPortSettingTest::testSetting_data()
0025 {
0026     QTest::addColumn<quint32>("bondDowndelay");
0027     QTest::addColumn<quint32>("bondUpdelay");
0028     QTest::addColumn<quint32>("tag");
0029     QTest::addColumn<QString>("lacp");
0030     QTest::addColumn<QString>("bondMode");
0031     QTest::addColumn<QString>("vlanMode");
0032 
0033     QTest::newRow("setting1") << (quint32)1 // bondDowndelay
0034                               << (quint32)1 // bondUpdelay
0035                               << (quint32)1 // tag
0036                               << QString("off") // lacp
0037                               << QString("active-backup") // bondMode
0038                               << QString("trunk"); // vlanMode
0039 }
0040 
0041 void OvsPortSettingTest::testSetting()
0042 {
0043     QFETCH(quint32, bondDowndelay);
0044     QFETCH(quint32, bondUpdelay);
0045     QFETCH(quint32, tag);
0046     QFETCH(QString, lacp);
0047     QFETCH(QString, bondMode);
0048     QFETCH(QString, vlanMode);
0049 
0050     QVariantMap map;
0051 
0052     map.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY), bondDowndelay);
0053     map.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY), bondUpdelay);
0054     map.insert(QLatin1String(NM_SETTING_OVS_PORT_TAG), tag);
0055     map.insert(QLatin1String(NM_SETTING_OVS_PORT_LACP), lacp);
0056     map.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE), bondMode);
0057     map.insert(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE), vlanMode);
0058 
0059     NetworkManager::OvsPortSetting setting;
0060     setting.fromMap(map);
0061 
0062     QVariantMap map1 = setting.toMap();
0063 
0064     // Will fail if set some default values, because they are skipped in toMap() method
0065     QVariantMap::const_iterator it = map.constBegin();
0066     while (it != map.constEnd()) {
0067         QCOMPARE(it.value(), map1.value(it.key()));
0068         ++it;
0069     }
0070 }
0071 
0072 QTEST_MAIN(OvsPortSettingTest)
0073 
0074 #include "moc_ovsportsettingtest.cpp"