File indexing completed on 2024-04-28 11:47:30
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 "modempropertiestest.h" 0008 0009 #include "generictypes.h" 0010 #include "manager.h" 0011 #include "modem.h" 0012 0013 #include "fakemodem/modem.h" 0014 0015 #include <QSignalSpy> 0016 #include <QTest> 0017 0018 void ModemPropertiesTest::initTestCase() 0019 { 0020 fakeModem = new FakeModem(); 0021 modem = new Modem(); 0022 0023 modem->setAccessTechnologies(16); 0024 modem->SetCurrentBands({0}); 0025 modem->SetCurrentCapabilities(4); 0026 modem->SetCurrentModes({MM_MODEM_MODE_ANY, MM_MODEM_MODE_NONE}); 0027 modem->setDevice(QLatin1String("/sys/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2")); 0028 modem->setDeviceIdentifier(QLatin1String("1c435eb6d74494b5f78d7221e2c5ae9ec526a981")); 0029 modem->setDrivers({QLatin1String("option1")}); 0030 modem->setEquipmentIdentifier(QLatin1String("353475021085110")); 0031 modem->setManufacturer(QLatin1String("huawei")); 0032 modem->setMaxActiveBearers(1); 0033 modem->setMaxBearers(1); 0034 modem->setModel(QLatin1String("K2540")); 0035 // modem->setOwnNumbers(); 0036 modem->setPlugin(QLatin1String("Huawei")); 0037 modem->setPorts({{QLatin1String("ttyUSB0"), MM_MODEM_PORT_TYPE_AT}, 0038 {QLatin1String("ttyUSB1"), MM_MODEM_PORT_TYPE_QCDM}, 0039 {QLatin1String("ttyUSB2"), MM_MODEM_PORT_TYPE_AT}}); 0040 modem->SetPowerState(3); 0041 modem->setPrimaryPort(QLatin1String("ttyUSB2")); 0042 modem->setRevision(QLatin1String("11.001.05.00.11")); 0043 modem->setSignalQuality({93, true}); 0044 modem->setSim(QDBusObjectPath("/org/kde/fakemodem/SIM/1")); 0045 modem->setState(8); 0046 modem->setStateFailedReason(0); 0047 modem->setSupportedBands({0}); 0048 modem->setSupportedCapabilities({4}); 0049 modem->setSupportedIpFamilies(3); 0050 ModemManager::SupportedModesType supportedModes; 0051 ModemManager::CurrentModesType supportedMode1 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE}; 0052 ModemManager::CurrentModesType supportedMode2 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_2G}; 0053 ModemManager::CurrentModesType supportedMode3 = {MM_MODEM_MODE_4G & MM_MODEM_MODE_3G & MM_MODEM_MODE_2G, MM_MODEM_MODE_3G}; 0054 supportedModes << supportedMode1 << supportedMode2 << supportedMode3; 0055 modem->setSupportedModes(supportedModes); 0056 modem->setUnlockRequired(1); 0057 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}}); 0058 0059 QSignalSpy addModemSpy(ModemManager::notifier(), SIGNAL(modemAdded(QString))); 0060 fakeModem->addModem(modem); 0061 QVERIFY(addModemSpy.wait()); 0062 } 0063 0064 void ModemPropertiesTest::testModemProperties() 0065 { 0066 ModemManager::Modem::Ptr modemInterface = ModemManager::modemDevices().first()->modemInterface(); 0067 QVERIFY(modemInterface); 0068 0069 modem->setAccessTechnologies(5); 0070 QSignalSpy accessTechnologiesChangedSpy(modemInterface.data(), SIGNAL(accessTechnologiesChanged(QFlags<MMModemAccessTechnology>))); 0071 QVERIFY(accessTechnologiesChangedSpy.wait()); 0072 QCOMPARE(modemInterface->accessTechnologies(), accessTechnologiesChangedSpy.at(0).at(0).value<QFlags<MMModemAccessTechnology>>()); 0073 0074 modem->SetCurrentBands({1}); 0075 QSignalSpy currentBandsChangedSpy(modemInterface.data(), SIGNAL(currentBandsChanged(QList<MMModemBand>))); 0076 QVERIFY(currentBandsChangedSpy.wait()); 0077 QCOMPARE(modemInterface->currentBands().first(), currentBandsChangedSpy.at(0).at(0).value<QList<MMModemBand>>().first()); 0078 0079 modem->SetCurrentCapabilities(5); 0080 QSignalSpy currentCapabilitiesChangedSpy(modemInterface.data(), SIGNAL(currentCapabilitiesChanged(QFlags<MMModemCapability>))); 0081 QVERIFY(currentCapabilitiesChangedSpy.wait()); 0082 QCOMPARE(modemInterface->currentCapabilities(), currentCapabilitiesChangedSpy.at(0).at(0).value<QFlags<MMModemCapability>>()); 0083 0084 modem->SetCurrentModes({MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE}); 0085 QSignalSpy currentModesChangedSpy(modemInterface.data(), SIGNAL(currentModesChanged(ModemManager::CurrentModesType))); 0086 QVERIFY(currentModesChangedSpy.wait()); 0087 QCOMPARE(modemInterface->currentModes().allowed, currentModesChangedSpy.at(0).at(0).value<ModemManager::CurrentModesType>().allowed); 0088 QCOMPARE(modemInterface->currentModes().preferred, currentModesChangedSpy.at(0).at(0).value<ModemManager::CurrentModesType>().preferred); 0089 0090 modem->setDevice(QLatin1String("/sys/devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1.2")); 0091 QSignalSpy deviceChangedSpy(modemInterface.data(), SIGNAL(deviceChanged(QString))); 0092 QVERIFY(deviceChangedSpy.wait()); 0093 QCOMPARE(modemInterface->device(), deviceChangedSpy.at(0).at(0).toString()); 0094 0095 modem->setDeviceIdentifier(QLatin1String("1c435eb6d74494b5f98d7221e2c6ae9ec526a981")); 0096 QSignalSpy deviceIdentifierChangedSpy(modemInterface.data(), SIGNAL(deviceIdentifierChanged(QString))); 0097 QVERIFY(deviceIdentifierChangedSpy.wait()); 0098 QCOMPARE(modemInterface->deviceIdentifier(), deviceIdentifierChangedSpy.at(0).at(0).toString()); 0099 0100 modem->setDrivers({QLatin1String("option2")}); 0101 QSignalSpy driversChangedSpy(modemInterface.data(), SIGNAL(driversChanged(QStringList))); 0102 QVERIFY(driversChangedSpy.wait()); 0103 QCOMPARE(modemInterface->drivers(), driversChangedSpy.at(0).at(0).toStringList()); 0104 0105 modem->setEquipmentIdentifier(QLatin1String("353895021085110")); 0106 QSignalSpy equipmentIdentifierChangedSpy(modemInterface.data(), SIGNAL(equipmentIdentifierChanged(QString))); 0107 QVERIFY(equipmentIdentifierChangedSpy.wait()); 0108 QCOMPARE(modemInterface->equipmentIdentifier(), equipmentIdentifierChangedSpy.at(0).at(0).toString()); 0109 0110 modem->setManufacturer(QLatin1String("huawey")); 0111 QSignalSpy manufacturerChangedSpy(modemInterface.data(), SIGNAL(manufacturerChanged(QString))); 0112 QVERIFY(manufacturerChangedSpy.wait()); 0113 QCOMPARE(modemInterface->manufacturer(), manufacturerChangedSpy.at(0).at(0).toString()); 0114 0115 modem->setMaxActiveBearers(2); 0116 QSignalSpy maxActiveBearersChangedSpy(modemInterface.data(), SIGNAL(maxActiveBearersChanged(uint))); 0117 QVERIFY(maxActiveBearersChangedSpy.wait()); 0118 QCOMPARE(modemInterface->maxActiveBearers(), maxActiveBearersChangedSpy.at(0).at(0).toUInt()); 0119 0120 modem->setMaxBearers(2); 0121 QSignalSpy maxBearersChangedSpy(modemInterface.data(), SIGNAL(maxBearersChanged(uint))); 0122 QVERIFY(maxBearersChangedSpy.wait()); 0123 QCOMPARE(modemInterface->maxBearers(), maxBearersChangedSpy.at(0).at(0).toUInt()); 0124 0125 modem->setModel(QLatin1String("K5658")); 0126 QSignalSpy modelChangedSpy(modemInterface.data(), SIGNAL(modelChanged(QString))); 0127 QVERIFY(modelChangedSpy.wait()); 0128 QCOMPARE(modemInterface->model(), modelChangedSpy.at(0).at(0).toString()); 0129 0130 modem->setPlugin(QLatin1String("Huawey")); 0131 QSignalSpy pluginChangedSpy(modemInterface.data(), SIGNAL(pluginChanged(QString))); 0132 QVERIFY(pluginChangedSpy.wait()); 0133 QCOMPARE(modemInterface->plugin(), pluginChangedSpy.at(0).at(0).toString()); 0134 0135 modem->setPorts({{QLatin1String("ttyUSB5"), MM_MODEM_PORT_TYPE_QCDM}, 0136 {QLatin1String("ttyUSB6"), MM_MODEM_PORT_TYPE_AT}, 0137 {QLatin1String("ttyUSB7"), MM_MODEM_PORT_TYPE_AT}}); 0138 QSignalSpy portsChangedSpy(modemInterface.data(), SIGNAL(portsChanged(ModemManager::PortList))); 0139 QVERIFY(portsChangedSpy.wait()); 0140 ModemManager::PortList ports = modemInterface->ports(); 0141 ModemManager::PortList signalPorts = portsChangedSpy.at(0).at(0).value<ModemManager::PortList>(); 0142 QCOMPARE(ports.count(), signalPorts.count()); 0143 Q_FOREACH (const ModemManager::Port port, ports) { 0144 bool found = false; 0145 Q_FOREACH (const ModemManager::Port signalPort, signalPorts) { 0146 if (port.name == signalPort.name) { 0147 found = true; 0148 QCOMPARE(port.type, signalPort.type); 0149 } 0150 } 0151 QVERIFY(found); 0152 } 0153 QCOMPARE(modemInterface->plugin(), pluginChangedSpy.at(0).at(0).toString()); 0154 0155 modem->SetPowerState(2); 0156 QSignalSpy powerStateChangedSpy(modemInterface.data(), SIGNAL(powerStateChanged(MMModemPowerState))); 0157 QVERIFY(powerStateChangedSpy.wait()); 0158 QCOMPARE(modemInterface->powerState(), powerStateChangedSpy.at(0).at(0).value<MMModemPowerState>()); 0159 0160 modem->setPrimaryPort(QLatin1String("ttyUSB5")); 0161 QSignalSpy primaryPortChangedSpy(modemInterface.data(), SIGNAL(primaryPortChanged(QString))); 0162 QVERIFY(primaryPortChangedSpy.wait()); 0163 QCOMPARE(modemInterface->primaryPort(), primaryPortChangedSpy.at(0).at(0).toString()); 0164 0165 modem->setRevision(QLatin1String("11.002.06.00.11")); 0166 QSignalSpy revisionChangedSpy(modemInterface.data(), SIGNAL(revisionChanged(QString))); 0167 QVERIFY(revisionChangedSpy.wait()); 0168 QCOMPARE(modemInterface->revision(), revisionChangedSpy.at(0).at(0).toString()); 0169 0170 modem->setSignalQuality({85, true}); 0171 QSignalSpy signalQualityChangedSpy(modemInterface.data(), SIGNAL(signalQualityChanged(ModemManager::SignalQualityPair))); 0172 QVERIFY(signalQualityChangedSpy.wait()); 0173 QCOMPARE(modemInterface->signalQuality().recent, signalQualityChangedSpy.at(0).at(0).value<ModemManager::SignalQualityPair>().recent); 0174 QCOMPARE(modemInterface->signalQuality().signal, signalQualityChangedSpy.at(0).at(0).value<ModemManager::SignalQualityPair>().signal); 0175 0176 modem->setSim(QDBusObjectPath("/org/kde/fakemodem/SIM/2")); 0177 QSignalSpy simChangedSpy(modemInterface.data(), SIGNAL(simPathChanged(QString, QString))); 0178 QVERIFY(simChangedSpy.wait()); 0179 QCOMPARE(modemInterface->simPath(), simChangedSpy.at(0).at(1).toString()); 0180 0181 modem->setState(5); 0182 QSignalSpy stateChangedSpy(modemInterface.data(), SIGNAL(stateChanged(MMModemState, MMModemState, MMModemStateChangeReason))); 0183 QVERIFY(stateChangedSpy.wait()); 0184 QCOMPARE(MM_MODEM_STATE_REGISTERED, stateChangedSpy.at(0).at(0).value<MMModemState>()); 0185 QCOMPARE(MM_MODEM_STATE_ENABLING, stateChangedSpy.at(0).at(1).value<MMModemState>()); 0186 QCOMPARE(MM_MODEM_STATE_CHANGE_REASON_UNKNOWN, stateChangedSpy.at(0).at(2).value<MMModemStateChangeReason>()); 0187 0188 modem->setStateFailedReason(1); 0189 QSignalSpy stateFailedReasonChangedSpy(modemInterface.data(), SIGNAL(stateFailedReasonChanged(MMModemStateFailedReason))); 0190 QVERIFY(stateFailedReasonChangedSpy.wait()); 0191 QCOMPARE(modemInterface->stateFailedReason(), stateFailedReasonChangedSpy.at(0).at(0).value<MMModemStateFailedReason>()); 0192 0193 modem->setSupportedBands({1}); 0194 QSignalSpy supportedBandsChangedSpy(modemInterface.data(), SIGNAL(supportedBandsChanged(QList<MMModemBand>))); 0195 QVERIFY(supportedBandsChangedSpy.wait()); 0196 QCOMPARE(modemInterface->supportedBands().first(), supportedBandsChangedSpy.at(0).at(0).value<QList<MMModemBand>>().first()); 0197 0198 modem->setSupportedCapabilities({3}); 0199 QSignalSpy supportedCapabilitiesChangedSpy(modemInterface.data(), SIGNAL(supportedCapabilitiesChanged(QList<MMModemCapability>))); 0200 QVERIFY(supportedCapabilitiesChangedSpy.wait()); 0201 QCOMPARE(modemInterface->supportedCapabilities().first(), supportedCapabilitiesChangedSpy.at(0).at(0).value<QList<MMModemCapability>>().first()); 0202 0203 modem->setSupportedIpFamilies(2); 0204 QSignalSpy supportedIpFamiliesChangedSpy(modemInterface.data(), SIGNAL(supportedIpFamiliesChanged(QFlags<MMBearerIpFamily>))); 0205 QVERIFY(supportedIpFamiliesChangedSpy.wait()); 0206 QCOMPARE(modemInterface->supportedIpFamilies(), supportedIpFamiliesChangedSpy.at(0).at(0).value<QFlags<MMBearerIpFamily>>()); 0207 0208 ModemManager::SupportedModesType supportedModes; 0209 ModemManager::CurrentModesType supportedMode1 = {MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE}; 0210 supportedModes << supportedMode1; 0211 modem->setSupportedModes(supportedModes); 0212 QSignalSpy supportedModesChangedSpy(modemInterface.data(), SIGNAL(supportedModesChanged(ModemManager::SupportedModesType))); 0213 QVERIFY(supportedModesChangedSpy.wait()); 0214 QCOMPARE(modemInterface->supportedModes().first().allowed, supportedModesChangedSpy.at(0).at(0).value<ModemManager::SupportedModesType>().first().allowed); 0215 QCOMPARE(modemInterface->supportedModes().first().preferred, 0216 supportedModesChangedSpy.at(0).at(0).value<ModemManager::SupportedModesType>().first().preferred); 0217 0218 modem->setUnlockRequired(2); 0219 QSignalSpy unlockRequiredChangedSpy(modemInterface.data(), SIGNAL(unlockRequiredChanged(MMModemLock))); 0220 QVERIFY(unlockRequiredChangedSpy.wait()); 0221 QCOMPARE(modemInterface->unlockRequired(), unlockRequiredChangedSpy.at(0).at(0).value<MMModemLock>()); 0222 0223 modem->setUnlockRetries({{MM_MODEM_LOCK_SIM_PIN, 2}}); 0224 QSignalSpy unlockRetriesChangedSpy(modemInterface.data(), SIGNAL(unlockRetriesChanged(ModemManager::UnlockRetriesMap))); 0225 QVERIFY(unlockRetriesChangedSpy.wait()); 0226 QCOMPARE(modemInterface->unlockRetries().count(), 1); 0227 QVERIFY(modemInterface->unlockRetries().contains(MM_MODEM_LOCK_SIM_PIN)); 0228 QCOMPARE(modemInterface->unlockRetries().value(MM_MODEM_LOCK_SIM_PIN), 0229 unlockRetriesChangedSpy.at(0).at(0).value<ModemManager::UnlockRetriesMap>().value(MM_MODEM_LOCK_SIM_PIN)); 0230 } 0231 0232 QTEST_MAIN(ModemPropertiesTest) 0233 0234 #include "moc_modempropertiestest.cpp"