summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2020-11-05 11:03:12 +0100
committerIvan Solovev <ivan.solovev@qt.io>2020-11-09 16:01:33 +0100
commit85a9f5420fd08f6e5e316c2f3d607e0a2ed10df6 (patch)
tree7cd6e65bbb00bbfc4e6a41e6e9d74d563e84a303 /tests/auto/corelib/global
parent223e409efbf29f7c06bec7a403403c9689f42b3e (diff)
Add tests for QOperatingSystemVersion
Task-number: QTBUG-88183 Change-Id: I7083dae5bf9ef8cc5eb18e68052706cc3f7c66ab Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r--tests/auto/corelib/global/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/global/global.pro3
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/.gitignore1
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt13
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/qoperatingsystemversion.pro7
-rw-r--r--tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp181
6 files changed, 205 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/CMakeLists.txt b/tests/auto/corelib/global/CMakeLists.txt
index 2aa86c533e..91890462fe 100644
--- a/tests/auto/corelib/global/CMakeLists.txt
+++ b/tests/auto/corelib/global/CMakeLists.txt
@@ -12,6 +12,7 @@ add_subdirectory(qlogging)
add_subdirectory(qtendian)
add_subdirectory(qglobalstatic)
add_subdirectory(qhooks)
+add_subdirectory(qoperatingsystemversion)
if(WIN32)
add_subdirectory(qwinregistry)
endif()
diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro
index f3d1bbaaf5..80ac1a3f83 100644
--- a/tests/auto/corelib/global/global.pro
+++ b/tests/auto/corelib/global/global.pro
@@ -11,7 +11,8 @@ SUBDIRS=\
qlogging \
qtendian \
qglobalstatic \
- qhooks
+ qhooks \
+ qoperatingsystemversion
win32: SUBDIRS += \
qwinregistry
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/.gitignore b/tests/auto/corelib/global/qoperatingsystemversion/.gitignore
new file mode 100644
index 0000000000..8fb5143f7c
--- /dev/null
+++ b/tests/auto/corelib/global/qoperatingsystemversion/.gitignore
@@ -0,0 +1 @@
+tst_qoperatingsystemversion
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt b/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt
new file mode 100644
index 0000000000..619297fdab
--- /dev/null
+++ b/tests/auto/corelib/global/qoperatingsystemversion/CMakeLists.txt
@@ -0,0 +1,13 @@
+# Generated from qoperatingsystemversion.pro.
+
+#####################################################################
+## tst_qoperatingsystemversion Test:
+#####################################################################
+
+qt_internal_add_test(tst_qoperatingsystemversion
+ SOURCES
+ tst_qoperatingsystemversion.cpp
+)
+
+## Scopes:
+#####################################################################
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/qoperatingsystemversion.pro b/tests/auto/corelib/global/qoperatingsystemversion/qoperatingsystemversion.pro
new file mode 100644
index 0000000000..f9384643ef
--- /dev/null
+++ b/tests/auto/corelib/global/qoperatingsystemversion/qoperatingsystemversion.pro
@@ -0,0 +1,7 @@
+CONFIG += testcase
+TARGET = tst_qoperatingsystemversion
+QT = core testlib
+SOURCES = tst_qoperatingsystemversion.cpp
+qtConfig(c++11): CONFIG += c++11
+qtConfig(c++14): CONFIG += c++14
+qtConfig(c++1z): CONFIG += c++1z
diff --git a/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp b/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp
new file mode 100644
index 0000000000..5fae598fc6
--- /dev/null
+++ b/tests/auto/corelib/global/qoperatingsystemversion/tst_qoperatingsystemversion.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <qoperatingsystemversion.h>
+
+class tst_QOperatingSystemVersion : public QObject
+{
+ Q_OBJECT
+private slots:
+ void construction_data();
+ void construction();
+
+ void anyOf();
+
+ void comparison_data();
+ void comparison();
+};
+
+void tst_QOperatingSystemVersion::construction_data()
+{
+ QTest::addColumn<QOperatingSystemVersion::OSType>("osType");
+ QTest::addColumn<int>("majorVersion");
+ QTest::addColumn<int>("minorVersion");
+ QTest::addColumn<int>("microVersion");
+ QTest::addColumn<int>("segmentCount");
+
+ QTest::newRow("Major only") << QOperatingSystemVersion::OSType::Windows << 1 << -1 << -1 << 1;
+ QTest::newRow("Major and minor") << QOperatingSystemVersion::OSType::MacOS
+ << 1 << 2 << -1 << 2;
+ QTest::newRow("Major, minor and micro") << QOperatingSystemVersion::OSType::Android
+ << 1 << 2 << 3 << 3;
+}
+
+void tst_QOperatingSystemVersion::construction()
+{
+ QFETCH(QOperatingSystemVersion::OSType, osType);
+ QFETCH(int, majorVersion);
+ QFETCH(int, minorVersion);
+ QFETCH(int, microVersion);
+ QFETCH(int, segmentCount);
+
+ const QOperatingSystemVersion systemVersion(osType, majorVersion, minorVersion, microVersion);
+ QCOMPARE(systemVersion.type(), osType);
+ QCOMPARE(systemVersion.segmentCount(), segmentCount);
+ QCOMPARE(systemVersion.majorVersion(), majorVersion);
+ QCOMPARE(systemVersion.minorVersion(), minorVersion);
+ QCOMPARE(systemVersion.microVersion(), microVersion);
+ if (osType != QOperatingSystemVersion::OSType::Unknown)
+ QVERIFY(!systemVersion.name().isEmpty());
+}
+
+void tst_QOperatingSystemVersion::anyOf()
+{
+ std::initializer_list<QOperatingSystemVersion::OSType> typesToCheck = {
+ QOperatingSystemVersion::OSType::Windows, QOperatingSystemVersion::OSType::Android,
+ QOperatingSystemVersion::OSType::MacOS, QOperatingSystemVersion::OSType::Unknown
+ };
+ {
+ // type found case
+ const QOperatingSystemVersion systemVersion(QOperatingSystemVersion::OSType::MacOS, 1);
+ QCOMPARE(systemVersion.isAnyOfType(typesToCheck), true);
+ }
+ {
+ // type NOT found case
+ const QOperatingSystemVersion systemVersion(QOperatingSystemVersion::OSType::WatchOS, 1);
+ QCOMPARE(systemVersion.isAnyOfType(typesToCheck), false);
+ }
+}
+
+void tst_QOperatingSystemVersion::comparison_data()
+{
+ QTest::addColumn<QOperatingSystemVersion::OSType>("lhsType");
+ QTest::addColumn<int>("lhsMajor");
+ QTest::addColumn<int>("lhsMinor");
+ QTest::addColumn<int>("lhsMicro");
+
+ QTest::addColumn<QOperatingSystemVersion::OSType>("rhsType");
+ QTest::addColumn<int>("rhsMajor");
+ QTest::addColumn<int>("rhsMinor");
+ QTest::addColumn<int>("rhsMicro");
+
+ QTest::addColumn<bool>("lessResult");
+ QTest::addColumn<bool>("lessEqualResult");
+ QTest::addColumn<bool>("moreResult");
+ QTest::addColumn<bool>("moreEqualResult");
+
+ QTest::addRow("mismatching types") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << QOperatingSystemVersion::OSType::MacOS << 1 << 2 << 3
+ << false << false << false << false;
+
+ QTest::addRow("equal versions") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << false << true << false << true;
+
+ QTest::addRow("lhs micro less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << true << true << false << false;
+
+ QTest::addRow("rhs micro less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 1
+ << false << false << true << true;
+
+ QTest::addRow("lhs minor less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << QOperatingSystemVersion::OSType::Windows << 1 << 3 << 3
+ << true << true << false << false;
+
+ QTest::addRow("rhs minor less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 2
+ << QOperatingSystemVersion::OSType::Windows << 1 << 1 << 3
+ << false << false << true << true;
+
+ QTest::addRow("lhs major less") << QOperatingSystemVersion::OSType::Windows << 0 << 5 << 6
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << true << true << false << false;
+
+ QTest::addRow("rhs major less") << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << QOperatingSystemVersion::OSType::Windows << 0 << 2 << 3
+ << false << false << true << true;
+
+ QTest::addRow("different segmentCount")
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << 3
+ << QOperatingSystemVersion::OSType::Windows << 1 << 2 << -1
+ << false << true << false << true;
+}
+
+void tst_QOperatingSystemVersion::comparison()
+{
+ QFETCH(QOperatingSystemVersion::OSType, lhsType);
+ QFETCH(int, lhsMajor);
+ QFETCH(int, lhsMinor);
+ QFETCH(int, lhsMicro);
+
+ const QOperatingSystemVersion lhsSystemInfo(lhsType, lhsMajor, lhsMinor, lhsMicro);
+
+ QFETCH(QOperatingSystemVersion::OSType, rhsType);
+ QFETCH(int, rhsMajor);
+ QFETCH(int, rhsMinor);
+ QFETCH(int, rhsMicro);
+
+ const QOperatingSystemVersion rhsSystemInfo(rhsType, rhsMajor, rhsMinor, rhsMicro);
+
+ QFETCH(bool, lessResult);
+ QCOMPARE(lhsSystemInfo < rhsSystemInfo, lessResult);
+
+ QFETCH(bool, lessEqualResult);
+ QCOMPARE(lhsSystemInfo <= rhsSystemInfo, lessEqualResult);
+
+ QFETCH(bool, moreResult);
+ QCOMPARE(lhsSystemInfo > rhsSystemInfo, moreResult);
+
+ QFETCH(bool, moreEqualResult);
+ QCOMPARE(lhsSystemInfo >= rhsSystemInfo, moreEqualResult);
+}
+
+QTEST_MAIN(tst_QOperatingSystemVersion)
+#include "tst_qoperatingsystemversion.moc"