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 "modemcdmapropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modemcdma.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void ModemCdmaPropertiesTest::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     modemCdma = new ModemCdma(modem);
0066     modemCdma->setModemPath(modem->modemPath());
0067     modemCdma->setActivationState(MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
0068     modemCdma->setCdma1xRegistrationState(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED);
0069     modemCdma->setEsn(QLatin1String("esn"));
0070     modemCdma->setEvdoRegistrationState(MM_MODEM_CDMA_REGISTRATION_STATE_HOME);
0071     modemCdma->setMeid(QLatin1String("meid"));
0072     modemCdma->setNid(5);
0073     modemCdma->setSid(10);
0074 
0075     ModemManager::MMVariantMapMap interfaces;
0076     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEMCDMA), modemCdma->toMap());
0077     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0078     modemCdma->setEnableNotifications(true);
0079 }
0080 
0081 void ModemCdmaPropertiesTest::testModemCdmaProperties()
0082 {
0083     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0084     QVERIFY(modemDevice);
0085     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::CdmaInterface));
0086     ModemManager::ModemCdma::Ptr modemCdmaInterface = modemDevice->interface(ModemManager::ModemDevice::CdmaInterface).objectCast<ModemManager::ModemCdma>();
0087     QVERIFY(modemCdmaInterface);
0088 
0089     modemCdma->setActivationState(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
0090     QSignalSpy activationChangedSpy(modemCdmaInterface.data(), SIGNAL(activationStateChanged(MMModemCdmaActivationState, MMCdmaActivationError, QVariantMap)));
0091     QVERIFY(activationChangedSpy.wait());
0092     QCOMPARE(modemCdmaInterface->activationState(), activationChangedSpy.at(0).at(0).value<MMModemCdmaActivationState>());
0093 
0094     modemCdma->setCdma1xRegistrationState(MM_MODEM_CDMA_REGISTRATION_STATE_HOME);
0095     QSignalSpy cdma1xRegistrationStateChangedSpy(modemCdmaInterface.data(), SIGNAL(cdma1xRegistrationStateChanged(MMModemCdmaRegistrationState)));
0096     QVERIFY(cdma1xRegistrationStateChangedSpy.wait());
0097     QCOMPARE(modemCdmaInterface->cdma1xRegistrationState(), cdma1xRegistrationStateChangedSpy.at(0).at(0).value<MMModemCdmaRegistrationState>());
0098 
0099     modemCdma->setEsn(QLatin1String("esn1"));
0100     QSignalSpy esnChangedSpy(modemCdmaInterface.data(), SIGNAL(esnChanged(QString)));
0101     QVERIFY(esnChangedSpy.wait());
0102     QCOMPARE(modemCdmaInterface->esn(), esnChangedSpy.at(0).at(0).toString());
0103 
0104     modemCdma->setEvdoRegistrationState(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED);
0105     QSignalSpy evdoRegistrationStateChangedSpy(modemCdmaInterface.data(), SIGNAL(evdoRegistrationStateChanged(MMModemCdmaRegistrationState)));
0106     QVERIFY(evdoRegistrationStateChangedSpy.wait());
0107     QCOMPARE(modemCdmaInterface->evdoRegistrationState(), evdoRegistrationStateChangedSpy.at(0).at(0).value<MMModemCdmaRegistrationState>());
0108 
0109     modemCdma->setMeid(QLatin1String("meid1"));
0110     QSignalSpy meidChangedSpy(modemCdmaInterface.data(), SIGNAL(meidChanged(QString)));
0111     QVERIFY(meidChangedSpy.wait());
0112     QCOMPARE(modemCdmaInterface->meid(), meidChangedSpy.at(0).at(0).toString());
0113 
0114     modemCdma->setNid(10);
0115     QSignalSpy nidChangedSpy(modemCdmaInterface.data(), SIGNAL(nidChanged(uint)));
0116     QVERIFY(nidChangedSpy.wait());
0117     QCOMPARE(modemCdmaInterface->nid(), nidChangedSpy.at(0).at(0).toUInt());
0118 
0119     modemCdma->setSid(5);
0120     QSignalSpy sidChangedSpy(modemCdmaInterface.data(), SIGNAL(sidChanged(uint)));
0121     QVERIFY(sidChangedSpy.wait());
0122     QCOMPARE(modemCdmaInterface->sid(), sidChangedSpy.at(0).at(0).toUInt());
0123 }
0124 
0125 QTEST_MAIN(ModemCdmaPropertiesTest)
0126 
0127 #include "moc_modemcdmapropertiestest.cpp"