summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qtyperevision
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2024-03-01 19:22:49 +0100
committerIvan Solovev <ivan.solovev@qt.io>2024-03-13 20:34:22 +0100
commite55ee873e9f3e9f6047333434d5c9a4ddfe2bf6b (patch)
tree601c243f8806754dd27ee159761c7d02f5460369 /tests/auto/corelib/tools/qtyperevision
parent81dcb7c8be963faece04dc8a674fdd89c34b7d92 (diff)
QTypeRevision: use comparison helper macros
QTypeRevision consists of two quint8 values: major and minor version. Each of the versions can be unknown. The rules for comparing with the unknown version are as follows: zero version < unknown version < non-zero version At the same time, two unknown versions are considered equal. This makes the comparison a bit tricky, but it still fits into the category of strong ordering. Replace the existing friend relational operators with helper functions and comparison helper macros, making this type strongly ordered. Update the unit-tests to use the new comparison helper test functions. As the test functions check the reversed arguments as well, we can reduce the number of rows for the data-driven comparison test. Fixes: QTBUG-120359 Change-Id: Ib6f1037fc7b5fed148e35ee48b56b05dcd36b3b4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qtyperevision')
-rw-r--r--tests/auto/corelib/tools/qtyperevision/CMakeLists.txt2
-rw-r--r--tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp29
2 files changed, 18 insertions, 13 deletions
diff --git a/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt b/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt
index d39d051a51..527156e3c2 100644
--- a/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt
+++ b/tests/auto/corelib/tools/qtyperevision/CMakeLists.txt
@@ -10,4 +10,6 @@ endif()
qt_internal_add_test(tst_qtyperevision
SOURCES
tst_qtyperevision.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp b/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp
index 7fc4754a64..66c746382a 100644
--- a/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp
+++ b/tests/auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp
@@ -4,6 +4,7 @@
#include <QTest>
#include <QtCore/qtyperevision.h>
+#include <QtTest/private/qcomparisontesthelper_p.h>
using namespace Qt::StringLiterals;
@@ -15,6 +16,7 @@ private slots:
void qTypeRevision_data();
void qTypeRevision();
void qTypeRevisionTypes();
+ void qTypeRevisionComparisonCompiles();
void qTypeRevisionComparison_data();
void qTypeRevisionComparison();
};
@@ -131,11 +133,16 @@ void tst_QTypeRevision::qTypeRevisionTypes()
QVERIFY(maxRevision.hasMinorVersion());
}
+void tst_QTypeRevision::qTypeRevisionComparisonCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QTypeRevision>();
+}
+
void tst_QTypeRevision::qTypeRevisionComparison_data()
{
QTest::addColumn<QTypeRevision>("lhs");
QTest::addColumn<QTypeRevision>("rhs");
- QTest::addColumn<int>("expectedResult");
+ QTest::addColumn<Qt::strong_ordering>("expectedResult");
static auto versionStr = [](QTypeRevision r) {
QByteArray res = r.hasMajorVersion() ? QByteArray::number(r.majorVersion())
@@ -167,10 +174,11 @@ void tst_QTypeRevision::qTypeRevisionComparison_data()
const int length = sizeof(revisions) / sizeof(QTypeRevision);
for (int i = 0; i < length; ++i) {
- for (int j = 0; j < length; ++j) {
- const int expectedRes = (i == j)
- ? 0
- : (i < j) ? -1 : 1;
+ for (int j = i; j < length; ++j) {
+ const Qt::strong_ordering expectedRes = (i == j)
+ ? Qt::strong_ordering::equal
+ : (i < j) ? Qt::strong_ordering::less
+ : Qt::strong_ordering::greater;
const auto lhs = revisions[i];
const auto rhs = revisions[j];
@@ -184,14 +192,9 @@ void tst_QTypeRevision::qTypeRevisionComparison()
{
QFETCH(const QTypeRevision, lhs);
QFETCH(const QTypeRevision, rhs);
- QFETCH(const int, expectedResult);
-
- QCOMPARE(lhs == rhs, expectedResult == 0);
- QCOMPARE(lhs != rhs, expectedResult != 0);
- QCOMPARE(lhs < rhs, expectedResult < 0);
- QCOMPARE(lhs > rhs, expectedResult > 0);
- QCOMPARE(lhs <= rhs, expectedResult <= 0);
- QCOMPARE(lhs >= rhs, expectedResult >= 0);
+ QFETCH(const Qt::strong_ordering, expectedResult);
+
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expectedResult);
}
QTEST_APPLESS_MAIN(tst_QTypeRevision)