File indexing completed on 2024-10-06 03:43:33

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 "usersettingtest.h"
0008 
0009 #include "settings/usersetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 #if !NM_CHECK_VERSION(1, 8, 0)
0016 #define NM_SETTING_USER_DATA "data"
0017 #endif
0018 
0019 void UserSettingTest::testSetting_data()
0020 {
0021     QTest::addColumn<NMStringMap>("data");
0022 
0023     NMStringMap data;
0024     data.insert("dat", "abc");
0025 
0026     QTest::newRow("setting1") << data; // data
0027 }
0028 
0029 void UserSettingTest::testSetting()
0030 {
0031     QFETCH(NMStringMap, data);
0032 
0033     QVariantMap map;
0034 
0035     map.insert(QLatin1String(NM_SETTING_USER_DATA), QVariant::fromValue<NMStringMap>(data));
0036 
0037     NetworkManager::UserSetting setting;
0038     setting.fromMap(map);
0039 
0040     QVariantMap map1 = setting.toMap();
0041 
0042     NMStringMap stringMap1 = map.value(QLatin1String(NM_SETTING_USER_DATA)).value<NMStringMap>();
0043     NMStringMap stringMap2 = map1.value(QLatin1String(NM_SETTING_USER_DATA)).value<NMStringMap>();
0044 
0045     NMStringMap::const_iterator it = stringMap1.constBegin();
0046     while (it != stringMap1.constEnd()) {
0047         QCOMPARE(it.value(), stringMap2.value(it.key()));
0048         ++it;
0049     }
0050 }
0051 
0052 QTEST_MAIN(UserSettingTest)
0053 
0054 #include "moc_usersettingtest.cpp"