File indexing completed on 2024-12-08 06:43:56

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 "modemlocationpropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modemlocation.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void ModemLocationPropertiesTest::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     modemLocation = new ModemLocation(modem);
0066     modemLocation->setModemPath(modem->modemPath());
0067     modemLocation->setCapabilities(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI & MM_MODEM_LOCATION_SOURCE_GPS_RAW);
0068     modemLocation->setEnabled(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI & MM_MODEM_LOCATION_SOURCE_GPS_RAW);
0069     QMap<MMModemLocationSource, QVariant> location;
0070     location.insert(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI, QLatin1String("310,26,85CD,D30156"));
0071     modemLocation->setLocation(location);
0072     modemLocation->setSignalsLocation(true);
0073 
0074     ModemManager::MMVariantMapMap interfaces;
0075     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_LOCATION), modemLocation->toMap());
0076     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0077     modemLocation->setEnableNotifications(true);
0078 }
0079 
0080 void ModemLocationPropertiesTest::testModemLocationProperties()
0081 {
0082     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0083     QVERIFY(modemDevice);
0084     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::LocationInterface));
0085     ModemManager::ModemLocation::Ptr modemLocationInterface =
0086         modemDevice->interface(ModemManager::ModemDevice::LocationInterface).objectCast<ModemManager::ModemLocation>();
0087     QVERIFY(modemLocationInterface);
0088 
0089     modemLocation->setCapabilities(MM_MODEM_LOCATION_SOURCE_GPS_RAW);
0090     QSignalSpy capabilitiesChangedSpy(modemLocationInterface.data(), SIGNAL(capabilitiesChanged(QFlags<MMModemLocationSource>)));
0091     QVERIFY(capabilitiesChangedSpy.wait());
0092     QCOMPARE(modemLocationInterface->capabilities(), capabilitiesChangedSpy.at(0).at(0).value<QFlags<MMModemLocationSource>>());
0093 
0094     modemLocation->setEnabled(MM_MODEM_LOCATION_SOURCE_GPS_RAW);
0095     QSignalSpy enabledChangedSpy(modemLocationInterface.data(), SIGNAL(enabledCapabilitiesChanged(QFlags<MMModemLocationSource>)));
0096     QVERIFY(enabledChangedSpy.wait());
0097     QCOMPARE(modemLocationInterface->enabledCapabilities(), enabledChangedSpy.at(0).at(0).value<QFlags<MMModemLocationSource>>());
0098 
0099     QMap<MMModemLocationSource, QVariant> location;
0100     location.insert(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI, QLatin1String("312,27,85CD,D30156"));
0101     modemLocation->setLocation(location);
0102     QSignalSpy locationChangedSpy(modemLocationInterface.data(), SIGNAL(locationChanged(ModemManager::LocationInformationMap)));
0103     QVERIFY(locationChangedSpy.wait());
0104     QCOMPARE(modemLocationInterface->location().value(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI).toString(),
0105              locationChangedSpy.at(0).at(0).value<ModemManager::LocationInformationMap>().value(MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI).toString());
0106 
0107     modemLocation->setSignalsLocation(true);
0108     QSignalSpy signalsLocationChangedSpy(modemLocationInterface.data(), SIGNAL(signalsLocationChanged(bool)));
0109     QVERIFY(signalsLocationChangedSpy.wait());
0110     QCOMPARE(modemLocationInterface->signalsLocation(), signalsLocationChangedSpy.at(0).at(0).toBool());
0111 }
0112 
0113 QTEST_MAIN(ModemLocationPropertiesTest)
0114 
0115 #include "moc_modemlocationpropertiestest.cpp"