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 "modem3gppussdpropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modem3gppussd.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void Modem3gppUssdPropertiesTest::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     modem3gppUssd = new Modem3gppUssd(modem);
0066     modem3gppUssd->setModemPath(modem->modemPath());
0067     modem3gppUssd->setNetworkNotification(QLatin1String("notification"));
0068     modem3gppUssd->setNetworkRequest(QLatin1String("request"));
0069     modem3gppUssd->setState(MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN);
0070 
0071     ModemManager::MMVariantMapMap interfaces;
0072     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP_USSD), modem3gppUssd->toMap());
0073     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0074     modem3gppUssd->setEnableNotifications(true);
0075 }
0076 
0077 void Modem3gppUssdPropertiesTest::testModem3gppUssdProperties()
0078 {
0079     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0080     QVERIFY(modemDevice);
0081     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::GsmUssdInterface));
0082     ModemManager::Modem3gppUssd::Ptr modem3gppUssdInterface =
0083         modemDevice->interface(ModemManager::ModemDevice::GsmUssdInterface).objectCast<ModemManager::Modem3gppUssd>();
0084     QVERIFY(modem3gppUssdInterface);
0085 
0086     modem3gppUssd->setNetworkNotification(QLatin1String("notification1"));
0087     QSignalSpy networkNotificationChangedSpy(modem3gppUssdInterface.data(), SIGNAL(networkNotificationChanged(QString)));
0088     QVERIFY(networkNotificationChangedSpy.wait());
0089     QCOMPARE(modem3gppUssdInterface->networkNotification(), networkNotificationChangedSpy.at(0).at(0).toString());
0090 
0091     modem3gppUssd->setNetworkRequest(QLatin1String("notification1"));
0092     QSignalSpy networkRequestChangedSpy(modem3gppUssdInterface.data(), SIGNAL(networkRequestChanged(QString)));
0093     QVERIFY(networkRequestChangedSpy.wait());
0094     QCOMPARE(modem3gppUssdInterface->networkRequest(), networkRequestChangedSpy.at(0).at(0).toString());
0095 
0096     modem3gppUssd->setState(MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE);
0097     QSignalSpy stateChangedSpy(modem3gppUssdInterface.data(), SIGNAL(stateChanged(MMModem3gppUssdSessionState)));
0098     QVERIFY(stateChangedSpy.wait());
0099     QCOMPARE(modem3gppUssdInterface->state(), stateChangedSpy.at(0).at(0).value<MMModem3gppUssdSessionState>());
0100 }
0101 
0102 QTEST_MAIN(Modem3gppUssdPropertiesTest)
0103 
0104 #include "moc_modem3gppussdpropertiestest.cpp"