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

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 "modemomapropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modemoma.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void ModemOmaPropertiesTest::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     modemOma = new ModemOma(modem);
0066     modemOma->setModemPath(modem->modemPath());
0067     modemOma->setFeatures(MM_OMA_FEATURE_NONE);
0068     ModemManager::OmaSessionType sessionType;
0069     sessionType.id = 1;
0070     sessionType.type = MM_OMA_SESSION_TYPE_CLIENT_INITIATED_DEVICE_CONFIGURE;
0071     ModemManager::OmaSessionTypes sessions;
0072     sessions << sessionType;
0073     modemOma->setPendingNetworkInitiatedSessions(sessions);
0074     modemOma->setSessionState(MM_OMA_SESSION_STATE_STARTED);
0075     modemOma->setSessionType(MM_OMA_SESSION_TYPE_CLIENT_INITIATED_PRL_UPDATE);
0076 
0077     ModemManager::MMVariantMapMap interfaces;
0078     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_OMA), modemOma->toMap());
0079     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0080     modemOma->setEnableNotifications(true);
0081 }
0082 
0083 void ModemOmaPropertiesTest::testModemOmaProperties()
0084 {
0085     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0086     QVERIFY(modemDevice);
0087     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::OmaInterface));
0088     ModemManager::ModemOma::Ptr modemOmaInterface = modemDevice->interface(ModemManager::ModemDevice::OmaInterface).objectCast<ModemManager::ModemOma>();
0089     QVERIFY(modemOmaInterface);
0090 
0091     modemOma->setFeatures(MM_OMA_FEATURE_DEVICE_PROVISIONING);
0092     QSignalSpy featuresChangedSpy(modemOmaInterface.data(), SIGNAL(featuresChanged(QFlags<MMOmaFeature>)));
0093     QVERIFY(featuresChangedSpy.wait());
0094     QCOMPARE(modemOmaInterface->features(), featuresChangedSpy.at(0).at(0).value<QFlags<MMOmaFeature>>());
0095 
0096     ModemManager::OmaSessionType sessionType;
0097     sessionType.id = 2;
0098     sessionType.type = MM_OMA_SESSION_TYPE_CLIENT_INITIATED_HANDS_FREE_ACTIVATION;
0099     ModemManager::OmaSessionTypes sessions;
0100     sessions << sessionType;
0101     modemOma->setPendingNetworkInitiatedSessions(sessions);
0102     QSignalSpy sessionsChangedSpy(modemOmaInterface.data(), SIGNAL(pendingNetworkInitiatedSessionsChanged(ModemManager::OmaSessionTypes)));
0103     QVERIFY(sessionsChangedSpy.wait());
0104     QCOMPARE(modemOmaInterface->pendingNetworkInitiatedSessions().first().id, sessionsChangedSpy.at(0).at(0).value<ModemManager::OmaSessionTypes>().first().id);
0105     QCOMPARE(modemOmaInterface->pendingNetworkInitiatedSessions().first().type,
0106              sessionsChangedSpy.at(0).at(0).value<ModemManager::OmaSessionTypes>().first().type);
0107 
0108     modemOma->setSessionState(MM_OMA_SESSION_STATE_CONNECTING);
0109     QSignalSpy sessionStateChangedSpy(modemOmaInterface.data(),
0110                                       SIGNAL(sessionStateChanged(MMOmaSessionState, MMOmaSessionState, MMOmaSessionStateFailedReason)));
0111     QVERIFY(sessionStateChangedSpy.wait());
0112     QCOMPARE(modemOmaInterface->sessionState(), sessionStateChangedSpy.at(0).at(1).value<MMOmaSessionState>());
0113 
0114     modemOma->setSessionType(MM_OMA_SESSION_TYPE_NETWORK_INITIATED_PRL_UPDATE);
0115     QSignalSpy sessionTypeChangedSpy(modemOmaInterface.data(), SIGNAL(sessionTypeChanged(MMOmaSessionType)));
0116     QVERIFY(sessionTypeChangedSpy.wait());
0117     QCOMPARE(modemOmaInterface->sessionType(), sessionTypeChangedSpy.at(0).at(0).value<MMOmaSessionType>());
0118 }
0119 
0120 QTEST_MAIN(ModemOmaPropertiesTest)
0121 
0122 #include "moc_modemomapropertiestest.cpp"