Debian Codegraph @

tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 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:GPL-EXCEPT$
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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 #include <QtCore/qregularexpression.h>
30 #include <QtTest/qtest.h>
31 #include "qdeviceinfo.h"
32
33 QT_USE_NAMESPACE
34
35 class tst_QDeviceInfo : public QObject
36 {
37 Q_OBJECT
38
39 private:
40 bool hasExactMatch(const QString& needle, const QString& haystack);
41
42 private slots:
43 void initTestCase();
44 void cleanupTestCase();
45
46 void tst_imei();
47 void tst_lockTypes();
48 void tst_version();
49 void tst_manufacturer();
50 void tst_model();
51 void tst_productName();
52 void tst_uniqueDeviceID();
53 void tst_hasFeature();
54 void tst_thermalState();
55
56 private:
57 QDeviceInfo *deviceInfo;
58
59 };
60
61 bool tst_QDeviceInfo::hasExactMatch(const QString& needle, const QString& haystack)
62 {
63 QRegularExpression pattern(QRegularExpression::anchoredPattern(needle));
64 return pattern.match(haystack).hasMatch();
65 }
66
67 void tst_QDeviceInfo::initTestCase()
68 {
69 deviceInfo = new QDeviceInfo();
70 }
71
72 void tst_QDeviceInfo::cleanupTestCase()
73 {
74 delete deviceInfo;
75 }
76
77 void tst_QDeviceInfo::tst_imei()
78 {
79 int imeiCount = deviceInfo->imeiCount();
80 QVERIFY(imeiCount >= -1);
81
82 QVERIFY(deviceInfo->imei(-1).isEmpty());
83 QVERIFY(deviceInfo->imei(imeiCount).isEmpty());
84
85 QRegularExpression imeiPattern(QRegularExpression::anchoredPattern("(\\d{0,0}|\\d{15,15})"));
86 for (int i = 0; i < imeiCount; ++i)
87 QVERIFY(imeiPattern.match(deviceInfo->imei(i)).hasMatch());
88 }
89
90 void tst_QDeviceInfo::tst_lockTypes()
91 {
92 QDeviceInfo::LockTypeFlags enabledLocks = deviceInfo->enabledLocks();
93 QDeviceInfo::LockTypeFlags activeLocks = deviceInfo->activatedLocks();
94 QVERIFY((activeLocks & enabledLocks) == activeLocks);
95 QVERIFY((activeLocks | enabledLocks) == enabledLocks);
96 }
97
98 void tst_QDeviceInfo::tst_version()
99 {
100 QVERIFY(hasExactMatch(QString::fromLatin1("(\\d+(\\.\\d+)*)?"),
101 deviceInfo->version(QDeviceInfo::Os)));
102
103 QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
104 deviceInfo->version(QDeviceInfo::Firmware)));
105 }
106
107 void tst_QDeviceInfo::tst_manufacturer()
108 {
109 QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
110 deviceInfo->manufacturer()));
111 }
112
113 void tst_QDeviceInfo::tst_model()
114 {
115 QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
116 deviceInfo->model()));
117 }
118
119 void tst_QDeviceInfo::tst_productName()
120 {
121 QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
122 deviceInfo->productName()));
123
124 }
125
126 void tst_QDeviceInfo::tst_uniqueDeviceID()
127 {
128 QVERIFY(hasExactMatch(QString::fromLatin1("[A-Fa-f\\d-]*"),
129 deviceInfo->uniqueDeviceID()));
130 }
131
132 void tst_QDeviceInfo::tst_hasFeature()
133 {
134 QList<QDeviceInfo::Feature> featureList;
135 featureList << QDeviceInfo::BluetoothFeature
136 << QDeviceInfo::CameraFeature
137 << QDeviceInfo::FmRadioFeature
138 << QDeviceInfo::FmTransmitterFeature
139 << QDeviceInfo::HapticsFeature
140 << QDeviceInfo::InfraredFeature
141 << QDeviceInfo::LedFeature
142 << QDeviceInfo::MemoryCardFeature
143 << QDeviceInfo::PositioningFeature
144 << QDeviceInfo::SimFeature
145 << QDeviceInfo::UsbFeature
146 << QDeviceInfo::VibrationFeature
147 << QDeviceInfo::VideoOutFeature
148 << QDeviceInfo::WlanFeature;
149
150 foreach (QDeviceInfo::Feature feature, featureList) {
151 bool isPresent = deviceInfo->hasFeature(feature);
152 QVERIFY(isPresent == true || isPresent == false);
153 }
154 }
155
156 void tst_QDeviceInfo::tst_thermalState()
157 {
158 QDeviceInfo::ThermalState state = deviceInfo->thermalState();
159 QVERIFY(state == QDeviceInfo::UnknownThermal ||
160 state == QDeviceInfo::NormalThermal ||
161 state == QDeviceInfo::WarningThermal ||
162 state == QDeviceInfo::AlertThermal ||
163 state == QDeviceInfo::ErrorThermal);
164 }
165
166 QTEST_APPLESS_MAIN(tst_QDeviceInfo)
167 #include "tst_qdeviceinfo.moc"