From 2f53a2f4be86c0829213e2a9f846b7f8f0b106dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Thu, 15 Oct 2020 16:45:31 +0200 Subject: [PATCH] cpp, qt: Fix version info comparison * lang/cpp/src/engineinfo.h (EngineInfo::Version::operator>(const Version &)): Fix logic. (EngineInfo::Version::operator>(const char *)): Use Version-overload of operator>. * lang/qt/tests/t-various.cpp: Add test. -- This fixes a logic error that 2.0.0 > 2.0.0 would return true. --- lang/cpp/src/engineinfo.h | 5 +++-- lang/qt/tests/t-various.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lang/cpp/src/engineinfo.h b/lang/cpp/src/engineinfo.h index cd1b7a72..0bf7d0e8 100644 --- a/lang/cpp/src/engineinfo.h +++ b/lang/cpp/src/engineinfo.h @@ -87,13 +87,14 @@ public: bool operator > (const char* other) { - return !operator<(Version(other)); + return operator>(Version(other)); } bool operator > (const Version & other) { - return !operator<(other); + return !operator<(other) && !operator==(other); } + bool operator == (const Version& other) { return major == other.major diff --git a/lang/qt/tests/t-various.cpp b/lang/qt/tests/t-various.cpp index 1e6bba41..9f7b1cec 100644 --- a/lang/qt/tests/t-various.cpp +++ b/lang/qt/tests/t-various.cpp @@ -241,6 +241,7 @@ private Q_SLOTS: QVERIFY(EngineInfo::Version("1.0.0") < EngineInfo::Version("2.0.0")); QVERIFY(EngineInfo::Version("0.1.0") < EngineInfo::Version("1.0.0")); QVERIFY(!(EngineInfo::Version("2.0.0") < EngineInfo::Version("2.0.0"))); + QVERIFY(!(EngineInfo::Version("2.0.0") > EngineInfo::Version("2.0.0"))); QVERIFY(EngineInfo::Version("3.0.0") > EngineInfo::Version("2.3.20")); QVERIFY(EngineInfo::Version("3.0.1") > EngineInfo::Version("3.0.0")); QVERIFY(EngineInfo::Version("3.1.0") > EngineInfo::Version("3.0.20"));