| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the QtSystems module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #include <QtTest/qtest.h> |
| 35 | #include "qdeviceinfo.h" |
| 36 | |
| 37 | QT_USE_NAMESPACE |
| 38 | |
| 39 | class tst_QDeviceInfo : public QObject |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | private slots: |
| 44 | void initTestCase(); |
| 45 | void cleanupTestCase(); |
| 46 | |
| 47 | void tst_imei(); |
| 48 | void tst_lockTypes(); |
| 49 | void tst_version(); |
| 50 | void tst_manufacturer(); |
| 51 | void tst_model(); |
| 52 | void tst_productName(); |
| 53 | void tst_uniqueDeviceID(); |
| 54 | void tst_hasFeature(); |
| 55 | void tst_thermalState(); |
| 56 | |
| 57 | private: |
| 58 | QDeviceInfo *deviceInfo; |
| 59 | |
| 60 | }; |
| 61 | |
| 62 | void tst_QDeviceInfo::initTestCase() |
| 63 | { |
| 64 | deviceInfo = new QDeviceInfo(); |
| 65 | } |
| 66 | |
| 67 | void tst_QDeviceInfo::cleanupTestCase() |
| 68 | { |
| 69 | delete deviceInfo; |
| 70 | } |
| 71 | |
| 72 | void tst_QDeviceInfo::tst_imei() |
| 73 | { |
| 74 | int imeiCount = deviceInfo->imeiCount(); |
| 75 | QVERIFY(imeiCount >= -1); |
| 76 | |
| 77 | QVERIFY(deviceInfo->imei(-1).isEmpty()); |
| 78 | QVERIFY(deviceInfo->imei(imeiCount).isEmpty()); |
| 79 | |
| 80 | QRegExp imeiPattern("(\\d{0,0}|\\d{15,15})"); |
| 81 | for (int i = 0; i < imeiCount; ++i) |
| 82 | QVERIFY(imeiPattern.exactMatch(deviceInfo->imei(i))); |
| 83 | } |
| 84 | |
| 85 | void tst_QDeviceInfo::tst_lockTypes() |
| 86 | { |
| 87 | QDeviceInfo::LockTypeFlags enabledLocks = deviceInfo->enabledLocks(); |
| 88 | QDeviceInfo::LockTypeFlags activeLocks = deviceInfo->activatedLocks(); |
| 89 | QVERIFY((activeLocks & enabledLocks) == activeLocks); |
| 90 | QVERIFY((activeLocks | enabledLocks) == enabledLocks); |
| 91 | } |
| 92 | |
| 93 | void tst_QDeviceInfo::tst_version() |
| 94 | { |
| 95 | QRegExp osversion(QString::fromLatin1(str: "(\\d+(\\.\\d+)*)?")); |
| 96 | QVERIFY(osversion.exactMatch(deviceInfo->version(QDeviceInfo::Os))); |
| 97 | |
| 98 | QRegExp firmwareversion(QString::fromLatin1(str: ".*")); |
| 99 | QVERIFY(firmwareversion.exactMatch(deviceInfo->version(QDeviceInfo::Firmware))); |
| 100 | } |
| 101 | |
| 102 | void tst_QDeviceInfo::tst_manufacturer() |
| 103 | { |
| 104 | QRegExp manufacturer(".*"); |
| 105 | QVERIFY(manufacturer.exactMatch(deviceInfo->manufacturer())); |
| 106 | } |
| 107 | |
| 108 | void tst_QDeviceInfo::tst_model() |
| 109 | { |
| 110 | QRegExp model(".*"); |
| 111 | QVERIFY(model.exactMatch(deviceInfo->model())); |
| 112 | } |
| 113 | |
| 114 | void tst_QDeviceInfo::tst_productName() |
| 115 | { |
| 116 | QRegExp productName(".*"); |
| 117 | QVERIFY(productName.exactMatch(deviceInfo->productName())); |
| 118 | } |
| 119 | |
| 120 | void tst_QDeviceInfo::tst_uniqueDeviceID() |
| 121 | { |
| 122 | QRegExp uniqueId("[A-Fa-f\\d-]*"); |
| 123 | QVERIFY(uniqueId.exactMatch(deviceInfo->uniqueDeviceID())); |
| 124 | } |
| 125 | |
| 126 | void tst_QDeviceInfo::tst_hasFeature() |
| 127 | { |
| 128 | QList<QDeviceInfo::Feature> featureList; |
| 129 | featureList << QDeviceInfo::BluetoothFeature |
| 130 | << QDeviceInfo::CameraFeature |
| 131 | << QDeviceInfo::FmRadioFeature |
| 132 | << QDeviceInfo::FmTransmitterFeature |
| 133 | << QDeviceInfo::HapticsFeature |
| 134 | << QDeviceInfo::InfraredFeature |
| 135 | << QDeviceInfo::LedFeature |
| 136 | << QDeviceInfo::MemoryCardFeature |
| 137 | << QDeviceInfo::PositioningFeature |
| 138 | << QDeviceInfo::SimFeature |
| 139 | << QDeviceInfo::UsbFeature |
| 140 | << QDeviceInfo::VibrationFeature |
| 141 | << QDeviceInfo::VideoOutFeature |
| 142 | << QDeviceInfo::WlanFeature; |
| 143 | |
| 144 | foreach (QDeviceInfo::Feature feature, featureList) { |
| 145 | bool isPresent = deviceInfo->hasFeature(feature); |
| 146 | QVERIFY(isPresent == true || isPresent == false); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void tst_QDeviceInfo::tst_thermalState() |
| 151 | { |
| 152 | QDeviceInfo::ThermalState state = deviceInfo->thermalState(); |
| 153 | QVERIFY(state == QDeviceInfo::UnknownThermal || |
| 154 | state == QDeviceInfo::NormalThermal || |
| 155 | state == QDeviceInfo::WarningThermal || |
| 156 | state == QDeviceInfo::AlertThermal || |
| 157 | state == QDeviceInfo::ErrorThermal); |
| 158 | } |
| 159 | |
| 160 | QTEST_APPLESS_MAIN(tst_QDeviceInfo) |
| 161 | #include "tst_qdeviceinfo.moc" |
| 162 |
