File indexing completed on 2024-11-03 03:44:52
0001 /* 0002 SPDX-FileCopyrightText: 2017 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 "vpnsettingtest.h" 0008 0009 #include "settings/vpnsetting.h" 0010 0011 #include <libnm/NetworkManager.h> 0012 0013 #include <QTest> 0014 0015 void VpnSettingTest::testSetting_data() 0016 { 0017 QTest::addColumn<NMStringMap>("data"); 0018 QTest::addColumn<bool>("persistent"); 0019 QTest::addColumn<NMStringMap>("secrets"); 0020 QTest::addColumn<QString>("serviceType"); 0021 QTest::addColumn<uint>("timeout"); 0022 QTest::addColumn<QString>("userName"); 0023 0024 QTest::newRow("setting1") << NMStringMap{{"gateway", "kde.org"}} // data 0025 << true // persistent 0026 << NMStringMap{{"password", "kde"}} // secrets 0027 << QString("openvpn") // service-type 0028 << (uint)30 // timeout 0029 << QString("test-user"); // user-name 0030 } 0031 0032 void VpnSettingTest::testSetting() 0033 { 0034 QFETCH(NMStringMap, data); 0035 QFETCH(bool, persistent); 0036 QFETCH(NMStringMap, secrets); 0037 QFETCH(QString, serviceType); 0038 QFETCH(uint, timeout); 0039 QFETCH(QString, userName); 0040 0041 QVariantMap map; 0042 0043 map.insert(QLatin1String(NM_SETTING_VPN_DATA), QVariant::fromValue<NMStringMap>(data)); 0044 map.insert(QLatin1String(NM_SETTING_VPN_PERSISTENT), persistent); 0045 map.insert(QLatin1String(NM_SETTING_VPN_SECRETS), QVariant::fromValue<NMStringMap>(secrets)); 0046 map.insert(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE), serviceType); 0047 map.insert(QLatin1String(NM_SETTING_VPN_TIMEOUT), timeout); 0048 map.insert(QLatin1String(NM_SETTING_VPN_USER_NAME), userName); 0049 0050 NetworkManager::VpnSetting 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(VpnSettingTest) 0064 0065 #include "moc_vpnsettingtest.cpp"