File indexing completed on 2024-10-06 03:43:32
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 "iptunnelsettingtest.h" 0008 0009 #include "settings/iptunnelsetting.h" 0010 0011 #include <libnm/NetworkManager.h> 0012 0013 #include <QTest> 0014 0015 #if !NM_CHECK_VERSION(1, 12, 0) 0016 #define NM_SETTING_IP_TUNNEL_FLAGS "flags" 0017 #endif 0018 0019 void IpTunnelSettingTest::testSetting_data() 0020 { 0021 QTest::addColumn<quint32>("mode"); 0022 QTest::addColumn<bool>("pathMtuDiscovery"); 0023 QTest::addColumn<quint32>("encapsulationLimit"); 0024 QTest::addColumn<quint32>("flags"); 0025 QTest::addColumn<quint32>("flowLabel"); 0026 QTest::addColumn<quint32>("mtu"); 0027 QTest::addColumn<quint32>("tos"); 0028 QTest::addColumn<quint32>("ttl"); 0029 QTest::addColumn<QString>("inputKey"); 0030 QTest::addColumn<QString>("local"); 0031 QTest::addColumn<QString>("parent"); 0032 QTest::addColumn<QString>("outputKey"); 0033 QTest::addColumn<QString>("remote"); 0034 0035 QTest::newRow("setting1") << (quint32)2 // mode 0036 << false // pathMtuDiscovery 0037 << (quint32)1 // encapsulationLimit 0038 << (quint32)0x02 // flags 0039 << (quint32)1 // flowLabel 0040 << (quint32)1 // mtu 0041 << (quint32)1 // tos 0042 << (quint32)1 // ttl 0043 << QString("key") // inputKey 0044 << QString("abc") // local 0045 << QString("par") // parent 0046 << QString("out") // outputKey 0047 << QString("rem"); // remote 0048 } 0049 0050 void IpTunnelSettingTest::testSetting() 0051 { 0052 QFETCH(quint32, mode); 0053 QFETCH(bool, pathMtuDiscovery); 0054 QFETCH(quint32, encapsulationLimit); 0055 QFETCH(quint32, flags); 0056 QFETCH(quint32, flowLabel); 0057 QFETCH(quint32, mtu); 0058 QFETCH(quint32, tos); 0059 QFETCH(quint32, ttl); 0060 QFETCH(QString, inputKey); 0061 QFETCH(QString, local); 0062 QFETCH(QString, parent); 0063 QFETCH(QString, outputKey); 0064 QFETCH(QString, remote); 0065 0066 QVariantMap map; 0067 0068 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MODE), mode); 0069 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), pathMtuDiscovery); 0070 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), encapsulationLimit); 0071 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS), flags); 0072 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL), flowLabel); 0073 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MTU), mtu); 0074 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TOS), tos); 0075 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TTL), ttl); 0076 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY), inputKey); 0077 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL), local); 0078 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT), parent); 0079 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY), outputKey); 0080 map.insert(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE), remote); 0081 0082 NetworkManager::IpTunnelSetting setting; 0083 setting.fromMap(map); 0084 0085 QVariantMap map1 = setting.toMap(); 0086 0087 // Will fail if set some default values, because they are skipped in toMap() method 0088 QVariantMap::const_iterator it = map.constBegin(); 0089 while (it != map.constEnd()) { 0090 QCOMPARE(it.value(), map1.value(it.key())); 0091 ++it; 0092 } 0093 } 0094 0095 QTEST_MAIN(IpTunnelSettingTest) 0096 0097 #include "moc_iptunnelsettingtest.cpp"