summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2018-12-30 14:44:16 +0100
committerSamuel Gaist <samuel.gaist@idiap.ch>2019-01-03 11:37:58 +0000
commitedf52a175c324e8b0defd8e216dd2bfd53547bd6 (patch)
tree71f95336aa776ceff5d99c85a5539a82b6506a98
parent66e45676f5f5c6251ccab36906c6324fd0065e08 (diff)
Migrate the QDeviceInfo class to QRegularExpression
This patch updates the QDeviceInfo code to use QRegularExpression in place of QRegExp which is to be considered deprecated. Task-number: QTBUG-72593 Change-Id: I5abdeb2c0ccd343e93ad529d6e68a463a6e44fcd Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/systeminfo/qdeviceinfo.cpp2
-rw-r--r--tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp39
2 files changed, 25 insertions, 16 deletions
diff --git a/src/systeminfo/qdeviceinfo.cpp b/src/systeminfo/qdeviceinfo.cpp
index 20ebec44..63a6a79c 100644
--- a/src/systeminfo/qdeviceinfo.cpp
+++ b/src/systeminfo/qdeviceinfo.cpp
@@ -165,9 +165,7 @@ QDeviceInfo::QDeviceInfo(QObject *parent)
*/
QDeviceInfo::~QDeviceInfo()
{
-#if !defined(Q_OS_LINUX)
delete d_ptr;
-#endif
}
/*!
diff --git a/tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp b/tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp
index d843ec9a..d2ad9504 100644
--- a/tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp
+++ b/tests/auto/systeminfo/qdeviceinfo/tst_qdeviceinfo.cpp
@@ -26,6 +26,7 @@
**
****************************************************************************/
+#include <QtCore/qregularexpression.h>
#include <QtTest/qtest.h>
#include "qdeviceinfo.h"
@@ -35,6 +36,9 @@ class tst_QDeviceInfo : public QObject
{
Q_OBJECT
+private:
+ bool hasExactMatch(const QString& needle, const QString& haystack);
+
private slots:
void initTestCase();
void cleanupTestCase();
@@ -54,6 +58,12 @@ private:
};
+bool tst_QDeviceInfo::hasExactMatch(const QString& needle, const QString& haystack)
+{
+ QRegularExpression pattern(QRegularExpression::anchoredPattern(needle));
+ return pattern.match(haystack).hasMatch();
+}
+
void tst_QDeviceInfo::initTestCase()
{
deviceInfo = new QDeviceInfo();
@@ -72,9 +82,9 @@ void tst_QDeviceInfo::tst_imei()
QVERIFY(deviceInfo->imei(-1).isEmpty());
QVERIFY(deviceInfo->imei(imeiCount).isEmpty());
- QRegExp imeiPattern("(\\d{0,0}|\\d{15,15})");
+ QRegularExpression imeiPattern(QRegularExpression::anchoredPattern("(\\d{0,0}|\\d{15,15})"));
for (int i = 0; i < imeiCount; ++i)
- QVERIFY(imeiPattern.exactMatch(deviceInfo->imei(i)));
+ QVERIFY(imeiPattern.match(deviceInfo->imei(i)).hasMatch());
}
void tst_QDeviceInfo::tst_lockTypes()
@@ -87,35 +97,36 @@ void tst_QDeviceInfo::tst_lockTypes()
void tst_QDeviceInfo::tst_version()
{
- QRegExp osversion(QString::fromLatin1("(\\d+(\\.\\d+)*)?"));
- QVERIFY(osversion.exactMatch(deviceInfo->version(QDeviceInfo::Os)));
+ QVERIFY(hasExactMatch(QString::fromLatin1("(\\d+(\\.\\d+)*)?"),
+ deviceInfo->version(QDeviceInfo::Os)));
- QRegExp firmwareversion(QString::fromLatin1(".*"));
- QVERIFY(firmwareversion.exactMatch(deviceInfo->version(QDeviceInfo::Firmware)));
+ QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
+ deviceInfo->version(QDeviceInfo::Firmware)));
}
void tst_QDeviceInfo::tst_manufacturer()
{
- QRegExp manufacturer(".*");
- QVERIFY(manufacturer.exactMatch(deviceInfo->manufacturer()));
+ QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
+ deviceInfo->manufacturer()));
}
void tst_QDeviceInfo::tst_model()
{
- QRegExp model(".*");
- QVERIFY(model.exactMatch(deviceInfo->model()));
+ QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
+ deviceInfo->model()));
}
void tst_QDeviceInfo::tst_productName()
{
- QRegExp productName(".*");
- QVERIFY(productName.exactMatch(deviceInfo->productName()));
+ QVERIFY(hasExactMatch(QString::fromLatin1(".*"),
+ deviceInfo->productName()));
+
}
void tst_QDeviceInfo::tst_uniqueDeviceID()
{
- QRegExp uniqueId("[A-Fa-f\\d-]*");
- QVERIFY(uniqueId.exactMatch(deviceInfo->uniqueDeviceID()));
+ QVERIFY(hasExactMatch(QString::fromLatin1("[A-Fa-f\\d-]*"),
+ deviceInfo->uniqueDeviceID()));
}
void tst_QDeviceInfo::tst_hasFeature()