File indexing completed on 2024-05-19 04:02:17

0001 /*
0002     SPDX-FileCopyrightText: 2015 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 "modem3gpppropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modem3gpp.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void Modem3gppPropertiesTest::initTestCase()
0021 {
0022     fakeModem = new FakeModem();
0023 
0024     modem = new Modem();
0025     modem->setAccessTechnologies(16);
0026     modem->SetCurrentBands({0});
0027     modem->SetCurrentCapabilities(4);
0028     modem->SetCurrentModes({MM_MODEM_MODE_ANY, MM_MODEM_MODE_NONE});
0029     modem->setDevice(QLatin1String("/sys/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2"));
0030     modem->setDeviceIdentifier(QLatin1String("1c435eb6d74494b5f78d7221e2c5ae9ec526a981"));
0031     modem->setDrivers({QLatin1String("option1")});
0032     modem->setEquipmentIdentifier(QLatin1String("353475021085110"));
0033     modem->setManufacturer(QLatin1String("huawei"));
0034     modem->setMaxActiveBearers(1);
0035     modem->setMaxBearers(1);
0036     modem->setModel(QLatin1String("K2540"));
0037     // modem->setOwnNumbers();
0038     modem->setPlugin(QLatin1String("Huawei"));
0039     modem->setPorts({{QLatin1String("ttyUSB0"), MM_MODEM_PORT_TYPE_AT},
0040                      {QLatin1String("ttyUSB1"), MM_MODEM_PORT_TYPE_QCDM},
0041                      {QLatin1String("ttyUSB2"), MM_MODEM_PORT_TYPE_AT}});
0042     modem->SetPowerState(3);
0043     modem->setPrimaryPort(QLatin1String("ttyUSB2"));
0044     modem->setRevision(QLatin1String("11.001.05.00.11"));
0045     modem->setSignalQuality({93, true});
0046     modem->setSim(QDBusObjectPath("/org/kde/fakemodem/SIM/1"));
0047     modem->setState(8);
0048     modem->setStateFailedReason(0);
0049     modem->setSupportedBands({0});
0050     modem->setSupportedCapabilities({4});
0051     modem->setSupportedIpFamilies(3);
0052     ModemManager::SupportedModesType supportedModes;
0053     ModemManager::CurrentModesType supportedMode1 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE};
0054     ModemManager::CurrentModesType supportedMode2 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_2G};
0055     ModemManager::CurrentModesType supportedMode3 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_3G};
0056     supportedModes << supportedMode1 << supportedMode2 << supportedMode3;
0057     modem->setSupportedModes(supportedModes);
0058     modem->setUnlockRequired(1);
0059     modem->setUnlockRetries({{MM_MODEM_LOCK_SIM_PIN, 3}, {MM_MODEM_LOCK_SIM_PIN2, 3}, {MM_MODEM_LOCK_SIM_PUK, 10}, {MM_MODEM_LOCK_SIM_PUK2, 10}});
0060 
0061     QSignalSpy addModemSpy(ModemManager::notifier(), SIGNAL(modemAdded(QString)));
0062     fakeModem->addModem(modem);
0063     QVERIFY(addModemSpy.wait());
0064 
0065     modem3gpp = new Modem3gpp(modem);
0066     modem3gpp->setModemPath(modem->modemPath());
0067     modem3gpp->setEnabledFacilityLocks(MM_MODEM_3GPP_FACILITY_NONE);
0068     modem3gpp->setImei(QLatin1String("IMEI"));
0069     modem3gpp->setOperatorCode(QLatin1String("31026"));
0070     modem3gpp->setOperatorName(QLatin1String("op-name"));
0071     modem3gpp->setRegistrationState(MM_MODEM_3GPP_REGISTRATION_STATE_HOME);
0072 #if MM_CHECK_VERSION(1, 2, 0)
0073     modem3gpp->setSubscriptionState(MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNKNOWN);
0074 #endif
0075 
0076     ModemManager::MMVariantMapMap interfaces;
0077     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP), modem3gpp->toMap());
0078     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0079     modem3gpp->setEnableNotifications(true);
0080 }
0081 
0082 void Modem3gppPropertiesTest::testModem3gppProperties()
0083 {
0084     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0085     QVERIFY(modemDevice);
0086     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::GsmInterface));
0087     ModemManager::Modem3gpp::Ptr modem3gppInterface = modemDevice->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
0088     QVERIFY(modem3gppInterface);
0089 
0090     modem3gpp->setEnabledFacilityLocks(MM_MODEM_3GPP_FACILITY_SIM);
0091     QSignalSpy enabledFacilityLocksChangedSpy(modem3gppInterface.data(), SIGNAL(enabledFacilityLocksChanged(QFlags<MMModem3gppFacility>)));
0092     QVERIFY(enabledFacilityLocksChangedSpy.wait());
0093     QCOMPARE(modem3gppInterface->enabledFacilityLocks(), enabledFacilityLocksChangedSpy.at(0).at(0).value<QFlags<MMModem3gppFacility>>());
0094 
0095     modem3gpp->setImei(QLatin1String("IMEI2"));
0096     QSignalSpy imeiChangedSpy(modem3gppInterface.data(), SIGNAL(imeiChanged(QString)));
0097     QVERIFY(imeiChangedSpy.wait());
0098     QCOMPARE(modem3gppInterface->imei(), imeiChangedSpy.at(0).at(0).toString());
0099 
0100     modem3gpp->setOperatorCode(QLatin1String("21025"));
0101     QSignalSpy operatorCodeChangedSpy(modem3gppInterface.data(), SIGNAL(operatorCodeChanged(QString)));
0102     QVERIFY(operatorCodeChangedSpy.wait());
0103     QCOMPARE(modem3gppInterface->operatorCode(), operatorCodeChangedSpy.at(0).at(0).toString());
0104 
0105     modem3gpp->setOperatorCode(QLatin1String("25011"));
0106     QSignalSpy countryCodeChangedSpy(modem3gppInterface.data(), SIGNAL(countryCodeChanged(QString)));
0107     QVERIFY(countryCodeChangedSpy.wait());
0108     QCOMPARE(modem3gppInterface->countryCode(), countryCodeChangedSpy.at(0).at(0).toString());
0109 
0110     modem3gpp->setOperatorName(QLatin1String("op-name2"));
0111     QSignalSpy operatorNameChangedSpy(modem3gppInterface.data(), SIGNAL(operatorNameChanged(QString)));
0112     QVERIFY(operatorNameChangedSpy.wait());
0113     QCOMPARE(modem3gppInterface->operatorName(), operatorNameChangedSpy.at(0).at(0).toString());
0114 
0115     modem3gpp->setRegistrationState(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE);
0116     QSignalSpy registrationStateChangedSpy(modem3gppInterface.data(), SIGNAL(registrationStateChanged(MMModem3gppRegistrationState)));
0117     QVERIFY(registrationStateChangedSpy.wait());
0118     QCOMPARE(modem3gppInterface->registrationState(), registrationStateChangedSpy.at(0).at(0).value<MMModem3gppRegistrationState>());
0119 
0120 #if MM_CHECK_VERSION(1, 2, 0)
0121     modem3gpp->setSubscriptionState(MM_MODEM_3GPP_SUBSCRIPTION_STATE_PROVISIONED);
0122     QSignalSpy subscriptionStateChangedSpy(modem3gppInterface.data(), SIGNAL(subscriptionStateChanged(MMModem3gppSubscriptionState)));
0123     QVERIFY(subscriptionStateChangedSpy.wait());
0124     QCOMPARE(modem3gppInterface->subscriptionState(), subscriptionStateChangedSpy.at(0).at(0).value<MMModem3gppSubscriptionState>());
0125 #endif
0126 }
0127 
0128 QTEST_MAIN(Modem3gppPropertiesTest)
0129 
0130 #include "moc_modem3gpppropertiestest.cpp"