File indexing completed on 2024-12-01 03:44:39
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 "modemmessagingpropertiestest.h" 0008 0009 #include "dbus/fakedbus.h" 0010 #include "generictypes.h" 0011 #include "manager.h" 0012 #include "modem.h" 0013 #include "modemmessaging.h" 0014 0015 #include "fakemodem/modem.h" 0016 0017 #include <QSignalSpy> 0018 #include <QTest> 0019 0020 void ModemMessagingPropertiesTest::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 modemMessaging = new ModemMessaging(modem); 0066 modemMessaging->setModemPath(modem->modemPath()); 0067 modemMessaging->setSupportedStorages({MM_SMS_STORAGE_SM, MM_SMS_STORAGE_ME}); 0068 modemMessaging->setDefaultStorage(MM_SMS_STORAGE_SM); 0069 0070 sms = new Sms(); 0071 sms->setData(QByteArray("data")); 0072 sms->setDeliveryReportRequest(true); 0073 sms->setDeliveryState(MM_SMS_DELIVERY_STATE_COMPLETED_RECEIVED); 0074 sms->setDischargeTimestamp(QLatin1String("2015-03-30T16:31:53+00:00")); 0075 sms->setMessageReference(1); 0076 sms->setNumber(QLatin1String("+420777888999")); 0077 sms->setPduType(MM_SMS_PDU_TYPE_DELIVER); 0078 sms->setSMSC(QLatin1String("+420777666555")); 0079 sms->setSmsClass(1); 0080 sms->setState(MM_SMS_STATE_STORED); 0081 sms->setStorage(MM_SMS_STORAGE_SM); 0082 #if MM_CHECK_VERSION(1, 2, 0) 0083 sms->setServiceCategory(MM_SMS_CDMA_SERVICE_CATEGORY_EMERGENCY_BROADCAST); 0084 sms->setTeleserviceId(MM_SMS_CDMA_TELESERVICE_ID_UNKNOWN); 0085 #endif 0086 sms->setText(QLatin1String("hello")); 0087 sms->setTimestamp(QLatin1String("2015-03-30T16:31:53+00:00")); 0088 sms->setValidity({MM_SMS_VALIDITY_TYPE_RELATIVE, 0}); 0089 0090 ModemManager::MMVariantMapMap interfaces; 0091 interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MESSAGING), modemMessaging->toMap()); 0092 fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces); 0093 modemMessaging->setEnableNotifications(true); 0094 } 0095 0096 void ModemMessagingPropertiesTest::testModemMessagingProperties() 0097 { 0098 ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first(); 0099 QVERIFY(modemDevice); 0100 QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::MessagingInterface)); 0101 ModemManager::ModemMessaging::Ptr modemMessagingInterface = 0102 modemDevice->interface(ModemManager::ModemDevice::MessagingInterface).objectCast<ModemManager::ModemMessaging>(); 0103 QVERIFY(modemMessagingInterface); 0104 QSignalSpy smsAddedSpy(modemMessagingInterface.data(), SIGNAL(messageAdded(QString, bool))); 0105 modemMessaging->addMessage(sms); 0106 QVERIFY(smsAddedSpy.wait()); 0107 QCOMPARE(modemMessagingInterface->messages().count(), 1); 0108 0109 ModemManager::Sms::Ptr modemSms = modemMessagingInterface->messages().first(); 0110 QVERIFY(modemSms); 0111 0112 sms->setData(QByteArray("data2")); 0113 QSignalSpy dataChangedSpy(modemSms.data(), SIGNAL(dataChanged(QByteArray))); 0114 QVERIFY(dataChangedSpy.wait()); 0115 QCOMPARE(modemSms->data(), dataChangedSpy.at(0).at(0).toByteArray()); 0116 0117 sms->setDeliveryReportRequest(false); 0118 QSignalSpy deliveryReportRequestChangedSpy(modemSms.data(), SIGNAL(deliveryReportRequestChanged(bool))); 0119 QVERIFY(deliveryReportRequestChangedSpy.wait()); 0120 QCOMPARE(modemSms->deliveryReportRequest(), deliveryReportRequestChangedSpy.at(0).at(0).toBool()); 0121 0122 sms->setDeliveryState(MM_SMS_DELIVERY_STATE_TEMPORARY_ERROR_SME_BUSY); 0123 QSignalSpy deliveryStateChangedSpy(modemSms.data(), SIGNAL(deliveryStateChanged(MMSmsDeliveryState))); 0124 QVERIFY(deliveryStateChangedSpy.wait()); 0125 QCOMPARE(modemSms->deliveryState(), deliveryStateChangedSpy.at(0).at(0).value<MMSmsDeliveryState>()); 0126 0127 sms->setDischargeTimestamp(QLatin1String("2014-03-30T16:31:53+00:00")); 0128 QSignalSpy dischargeTimestampChangedSpy(modemSms.data(), SIGNAL(dischargeTimestampChanged(QDateTime))); 0129 QVERIFY(dischargeTimestampChangedSpy.wait()); 0130 QCOMPARE(modemSms->dischargeTimestamp(), dischargeTimestampChangedSpy.at(0).at(0).toDateTime()); 0131 0132 sms->setMessageReference(2); 0133 QSignalSpy messageReferenceChangedSpy(modemSms.data(), SIGNAL(messageReferenceChanged(uint))); 0134 QVERIFY(messageReferenceChangedSpy.wait()); 0135 QCOMPARE(modemSms->messageReference(), messageReferenceChangedSpy.at(0).at(0).toUInt()); 0136 0137 sms->setNumber(QLatin1String("+420777111222")); 0138 QSignalSpy numberChangedSpy(modemSms.data(), SIGNAL(numberChanged(QString))); 0139 QVERIFY(numberChangedSpy.wait()); 0140 QCOMPARE(modemSms->number(), numberChangedSpy.at(0).at(0).toString()); 0141 0142 sms->setPduType(MM_SMS_PDU_TYPE_SUBMIT); 0143 QSignalSpy pduTypeChangedSpy(modemSms.data(), SIGNAL(pduTypeChanged(MMSmsPduType))); 0144 QVERIFY(pduTypeChangedSpy.wait()); 0145 QCOMPARE(modemSms->pduType(), pduTypeChangedSpy.at(0).at(0).value<MMSmsPduType>()); 0146 0147 sms->setSMSC(QLatin1String("+420777878978")); 0148 QSignalSpy SMSCChangedSpy(modemSms.data(), SIGNAL(SMSCChanged(QString))); 0149 QVERIFY(SMSCChangedSpy.wait()); 0150 QCOMPARE(modemSms->SMSC(), SMSCChangedSpy.at(0).at(0).toString()); 0151 0152 sms->setSmsClass(2); 0153 QSignalSpy smsClassChangedSpy(modemSms.data(), SIGNAL(smsClassChanged(int))); 0154 QVERIFY(smsClassChangedSpy.wait()); 0155 QCOMPARE(modemSms->smsClass(), smsClassChangedSpy.at(0).at(0).toInt()); 0156 0157 sms->setState(MM_SMS_STATE_SENT); 0158 QSignalSpy stateChangedSpy(modemSms.data(), SIGNAL(stateChanged(MMSmsState))); 0159 QVERIFY(stateChangedSpy.wait()); 0160 QCOMPARE(modemSms->state(), stateChangedSpy.at(0).at(0).value<MMSmsState>()); 0161 0162 sms->setStorage(MM_SMS_STORAGE_MT); 0163 QSignalSpy storageChangedSpy(modemSms.data(), SIGNAL(storageChanged(MMSmsStorage))); 0164 QVERIFY(storageChangedSpy.wait()); 0165 QCOMPARE(modemSms->storage(), storageChangedSpy.at(0).at(0).value<MMSmsStorage>()); 0166 0167 #if MM_CHECK_VERSION(1, 2, 0) 0168 sms->setServiceCategory(MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN); 0169 QSignalSpy serviceCategoryChangedSpy(modemSms.data(), SIGNAL(serviceCategoryChanged(MMSmsCdmaServiceCategory))); 0170 QVERIFY(serviceCategoryChangedSpy.wait()); 0171 QCOMPARE(modemSms->serviceCategory(), serviceCategoryChangedSpy.at(0).at(0).value<MMSmsCdmaServiceCategory>()); 0172 0173 sms->setTeleserviceId(MM_SMS_CDMA_TELESERVICE_ID_CMT91); 0174 QSignalSpy teleserviceIdChangedSpy(modemSms.data(), SIGNAL(teleserviceIdChanged(MMSmsCdmaTeleserviceId))); 0175 QVERIFY(teleserviceIdChangedSpy.wait()); 0176 QCOMPARE(modemSms->teleserviceId(), teleserviceIdChangedSpy.at(0).at(0).value<MMSmsCdmaTeleserviceId>()); 0177 #endif 0178 0179 sms->setText(QLatin1String("hello2")); 0180 QSignalSpy textChangedSpy(modemSms.data(), SIGNAL(textChanged(QString))); 0181 QVERIFY(textChangedSpy.wait()); 0182 QCOMPARE(modemSms->text(), textChangedSpy.at(0).at(0).toString()); 0183 0184 sms->setTimestamp(QLatin1String("2014-03-30T16:31:53+00:00")); 0185 QSignalSpy timestampChangedSpy(modemSms.data(), SIGNAL(timestampChanged(QDateTime))); 0186 QVERIFY(timestampChangedSpy.wait()); 0187 QCOMPARE(modemSms->timestamp(), timestampChangedSpy.at(0).at(0).toDateTime()); 0188 0189 sms->setValidity({MM_SMS_VALIDITY_TYPE_ABSOLUTE, 1}); 0190 QSignalSpy validityChangedSpy(modemSms.data(), SIGNAL(validityChanged(ModemManager::ValidityPair))); 0191 QVERIFY(validityChangedSpy.wait()); 0192 QCOMPARE(modemSms->validity().validity, validityChangedSpy.at(0).at(0).value<ModemManager::ValidityPair>().validity); 0193 QCOMPARE(modemSms->validity().value, validityChangedSpy.at(0).at(0).value<ModemManager::ValidityPair>().value); 0194 0195 QSignalSpy smsDeletedSpy(modemMessagingInterface.data(), SIGNAL(messageDeleted(QString))); 0196 modemMessaging->Delete(QDBusObjectPath(sms->smsPath())); 0197 QVERIFY(smsDeletedSpy.wait()); 0198 QCOMPARE(modemMessagingInterface->messages().count(), 0); 0199 } 0200 0201 QTEST_MAIN(ModemMessagingPropertiesTest) 0202 0203 #include "moc_modemmessagingpropertiestest.cpp"