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 "bearerpropertiestest.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 BearerPropertiesTest::initTestCase()
0019 {
0020     fakeModem = new FakeModem();
0021 
0022     modem = new Modem();
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     bearer = new Bearer();
0064     // We need to set some default values
0065     bearer->setConnected(false);
0066     bearer->setInterface(QLatin1String("ttyUSB0"));
0067     bearer->setIp4Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_PPP}});
0068     bearer->setIp6Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_UNKNOWN}});
0069     bearer->setIpTimeout(20);
0070     bearer->setProperties({{QLatin1String("apn"), QLatin1String("internet")}, {QLatin1String("ip-type"), 1}, {QLatin1String("number"), QLatin1String("*99#")}});
0071     bearer->setSuspended(false);
0072 #if MM_CHECK_VERSION(1, 2, 0)
0073     ModemManager::Modem::Ptr modemInterface = ModemManager::modemDevices().constFirst()->modemInterface();
0074     QCOMPARE(modemInterface->listBearers().count(), 0);
0075     QSignalSpy bearerAddedSpy(modemInterface.data(), SIGNAL(bearerAdded(QString)));
0076     fakeModem->addBearer(bearer);
0077     QVERIFY(bearerAddedSpy.wait());
0078 #endif
0079 }
0080 
0081 #if MM_CHECK_VERSION(1, 2, 0)
0082 void BearerPropertiesTest::testBearerProperties()
0083 {
0084     ModemManager::Modem::Ptr modemInterface = ModemManager::modemDevices().first()->modemInterface();
0085     ModemManager::Bearer::Ptr modemBearer = modemInterface->listBearers().first();
0086 
0087     bearer->setConnected(true);
0088     QSignalSpy connectedChangedSpy(modemBearer.data(), SIGNAL(connectedChanged(bool)));
0089     QVERIFY(connectedChangedSpy.wait());
0090     QCOMPARE(modemBearer->isConnected(), connectedChangedSpy.at(0).at(0).toBool());
0091 
0092     bearer->setInterface(QLatin1String("ttyUSB1"));
0093     QSignalSpy interfaceChangedSpy(modemBearer.data(), SIGNAL(interfaceChanged(QString)));
0094     QVERIFY(interfaceChangedSpy.wait());
0095     QCOMPARE(modemBearer->interface(), interfaceChangedSpy.at(0).at(0).toString());
0096 
0097     bearer->setIp4Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_UNKNOWN}});
0098     QSignalSpy ip4ConfigChangedSpy(modemBearer.data(), SIGNAL(ip4ConfigChanged(ModemManager::IpConfig)));
0099     QVERIFY(ip4ConfigChangedSpy.wait());
0100     QCOMPARE(modemBearer->ip4Config().method(), ip4ConfigChangedSpy.at(0).at(0).value<ModemManager::IpConfig>().method());
0101 
0102     bearer->setIp6Config({{QLatin1String("method"), MM_BEARER_IP_METHOD_PPP}});
0103     QSignalSpy ip6ConfigChangedSpy(modemBearer.data(), SIGNAL(ip6ConfigChanged(ModemManager::IpConfig)));
0104     QVERIFY(ip6ConfigChangedSpy.wait());
0105     QCOMPARE(modemBearer->ip6Config().method(), ip6ConfigChangedSpy.at(0).at(0).value<ModemManager::IpConfig>().method());
0106 
0107     bearer->setIpTimeout(25);
0108     QSignalSpy ipTimeoutChangedSpy(modemBearer.data(), SIGNAL(ipTimeoutChanged(uint)));
0109     QVERIFY(ipTimeoutChangedSpy.wait());
0110     QCOMPARE(modemBearer->ipTimeout(), ipTimeoutChangedSpy.at(0).at(0).toUInt());
0111 
0112     bearer->setProperties(
0113         {{QLatin1String("apn"), QLatin1String("internet2")}, {QLatin1String("ip-type"), 2}, {QLatin1String("number"), QLatin1String("*98#")}});
0114     QSignalSpy propertiesChangedSpy(modemBearer.data(), SIGNAL(propertiesChanged(QVariantMap)));
0115     QVERIFY(propertiesChangedSpy.wait());
0116     QVERIFY(modemBearer->properties().contains(QLatin1String("apn")));
0117     QVERIFY(modemBearer->properties().contains(QLatin1String("number")));
0118     QVERIFY(modemBearer->properties().contains(QLatin1String("ip-type")));
0119     QCOMPARE(modemBearer->properties().value(QLatin1String("apn")).toString(), QLatin1String("internet2"));
0120     QCOMPARE(modemBearer->properties().value(QLatin1String("ip-type")).toUInt(), (uint)2);
0121     QCOMPARE(modemBearer->properties().value(QLatin1String("number")).toString(), QLatin1String("*98#"));
0122 
0123     bearer->setSuspended(true);
0124     QSignalSpy suspendedChangedSpy(modemBearer.data(), SIGNAL(suspendedChanged(bool)));
0125     QVERIFY(suspendedChangedSpy.wait());
0126     QCOMPARE(modemBearer->isSuspended(), suspendedChangedSpy.at(0).at(0).toBool());
0127 }
0128 #endif
0129 QTEST_MAIN(BearerPropertiesTest)
0130 
0131 #include "moc_bearerpropertiestest.cpp"