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 "modemtimepropertiestest.h"
0008 
0009 #include "dbus/fakedbus.h"
0010 #include "generictypes.h"
0011 #include "manager.h"
0012 #include "modem.h"
0013 #include "modemtime.h"
0014 
0015 #include "fakemodem/modem.h"
0016 
0017 #include <QSignalSpy>
0018 #include <QTest>
0019 
0020 void ModemTimePropertiesTest::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     modemTime = new ModemTime(modem);
0066     modemTime->setModemPath(modem->modemPath());
0067     QVariantMap timezone;
0068     timezone.insert(QLatin1String("offset"), 60);
0069     timezone.insert(QLatin1String("dst-offset"), 60);
0070     timezone.insert(QLatin1String("offset"), 60);
0071     timezone.insert(QLatin1String("leap-seconds"), 1);
0072     modemTime->setNetworkTimezone(timezone);
0073 
0074     ModemManager::MMVariantMapMap interfaces;
0075     interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEMCDMA), modemTime->toMap());
0076     fakeModem->addInterfaces(QDBusObjectPath(modem->modemPath()), interfaces);
0077     modemTime->setEnableNotifications(true);
0078 }
0079 
0080 void ModemTimePropertiesTest::testModemTimeProperties()
0081 {
0082     ModemManager::ModemDevice::Ptr modemDevice = ModemManager::modemDevices().first();
0083     QVERIFY(modemDevice);
0084     QVERIFY(modemDevice->hasInterface(ModemManager::ModemDevice::TimeInterface));
0085     ModemManager::ModemTime::Ptr modemTimeInterface = modemDevice->interface(ModemManager::ModemDevice::TimeInterface).objectCast<ModemManager::ModemTime>();
0086     QVERIFY(modemTimeInterface);
0087 
0088     QVariantMap timezone;
0089     timezone.insert(QLatin1String("offset"), 120);
0090     timezone.insert(QLatin1String("dst-offset"), 120);
0091     timezone.insert(QLatin1String("offset"), 120);
0092     timezone.insert(QLatin1String("leap-seconds"), 2);
0093     modemTime->setNetworkTimezone(timezone);
0094     QSignalSpy networkTimezoneChangedSpy(modemTimeInterface.data(), SIGNAL(networkTimezoneChanged(ModemManager::NetworkTimezone)));
0095     QVERIFY(networkTimezoneChangedSpy.wait());
0096     QCOMPARE(modemTimeInterface->networkTimezone().dstOffset(), networkTimezoneChangedSpy.at(0).at(0).value<ModemManager::NetworkTimezone>().dstOffset());
0097     QCOMPARE(modemTimeInterface->networkTimezone().offset(), networkTimezoneChangedSpy.at(0).at(0).value<ModemManager::NetworkTimezone>().offset());
0098     QCOMPARE(modemTimeInterface->networkTimezone().leapSecond(), networkTimezoneChangedSpy.at(0).at(0).value<ModemManager::NetworkTimezone>().leapSecond());
0099 }
0100 
0101 QTEST_MAIN(ModemTimePropertiesTest)
0102 
0103 #include "moc_modemtimepropertiestest.cpp"