File indexing completed on 2024-12-08 06:44:03

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 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 "gsmsettingtest.h"
0008 
0009 #include "settings/gsmsetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 void GsmSettingTest::testSetting_data()
0016 {
0017     QTest::addColumn<QString>("number");
0018     QTest::addColumn<QString>("username");
0019     QTest::addColumn<QString>("password");
0020     QTest::addColumn<qint32>("passwordFlags");
0021     QTest::addColumn<QString>("apn");
0022     QTest::addColumn<QString>("networkId");
0023     QTest::addColumn<qint32>("networkType");
0024     QTest::addColumn<QString>("pin");
0025     QTest::addColumn<qint32>("pinFlags");
0026     QTest::addColumn<quint32>("allowedBand");
0027     QTest::addColumn<bool>("homeOnly");
0028     QTest::addColumn<QString>("deviceId");
0029     QTest::addColumn<QString>("simId");
0030     QTest::addColumn<QString>("simOperatorId");
0031 
0032     QTest::newRow("setting1") << QString("0123456789") // number
0033                               << QString("foo") // username
0034                               << QString("bar") // password
0035                               << (qint32)2 // passwordFlags
0036                               << QString("test") // apn
0037                               << QString("MCC-MNC") // networkId
0038                               << (qint32)1 // networkType
0039                               << QString("1010") // pin
0040                               << (qint32)4 // pinFlags
0041                               << (quint32)0 // allowedBand
0042                               << true // homeOnly
0043                               << QString("someDeviceId") // deviceId
0044                               << QString("someSimId") // simId
0045                               << QString("someSimOperatorId"); // simOperatorId
0046 }
0047 
0048 void GsmSettingTest::testSetting()
0049 {
0050     QFETCH(QString, number);
0051     QFETCH(QString, username);
0052     QFETCH(QString, password);
0053     QFETCH(qint32, passwordFlags);
0054     QFETCH(QString, apn);
0055     QFETCH(QString, networkId);
0056     QFETCH(qint32, networkType);
0057     QFETCH(QString, pin);
0058     QFETCH(qint32, pinFlags);
0059     QFETCH(quint32, allowedBand);
0060     QFETCH(bool, homeOnly);
0061     QFETCH(QString, deviceId);
0062     QFETCH(QString, simId);
0063     QFETCH(QString, simOperatorId);
0064 
0065     QVariantMap map;
0066 
0067     map.insert(QLatin1String(NM_SETTING_GSM_NUMBER), number);
0068     map.insert(QLatin1String(NM_SETTING_GSM_USERNAME), username);
0069     map.insert(QLatin1String(NM_SETTING_GSM_PASSWORD), password);
0070     map.insert(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS), passwordFlags);
0071     map.insert(QLatin1String(NM_SETTING_GSM_APN), apn);
0072     map.insert(QLatin1String(NM_SETTING_GSM_NETWORK_ID), networkId);
0073     map.insert(QLatin1String("network-type"), networkType);
0074     map.insert(QLatin1String("allowed-bands"), allowedBand);
0075     map.insert(QLatin1String(NM_SETTING_GSM_PIN), pin);
0076     map.insert(QLatin1String(NM_SETTING_GSM_PIN_FLAGS), pinFlags);
0077     map.insert(QLatin1String(NM_SETTING_GSM_HOME_ONLY), homeOnly);
0078     map.insert(QLatin1String(NM_SETTING_GSM_DEVICE_ID), deviceId);
0079     map.insert(QLatin1String(NM_SETTING_GSM_SIM_ID), simId);
0080     map.insert(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID), simOperatorId);
0081 
0082     NetworkManager::GsmSetting 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(GsmSettingTest)
0096 
0097 #include "moc_gsmsettingtest.cpp"