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.
This commit is contained in:
Ingo Klöcker 2020-10-15 16:45:31 +02:00
parent 25e2d717f4
commit 2f53a2f4be
2 changed files with 4 additions and 2 deletions

View File

@ -87,13 +87,14 @@ public:
bool operator > (const char* other) bool operator > (const char* other)
{ {
return !operator<(Version(other)); return operator>(Version(other));
} }
bool operator > (const Version & other) bool operator > (const Version & other)
{ {
return !operator<(other); return !operator<(other) && !operator==(other);
} }
bool operator == (const Version& other) bool operator == (const Version& other)
{ {
return major == other.major return major == other.major

View File

@ -241,6 +241,7 @@ private Q_SLOTS:
QVERIFY(EngineInfo::Version("1.0.0") < EngineInfo::Version("2.0.0")); 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("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("2.0.0") > EngineInfo::Version("2.0.0")));
QVERIFY(EngineInfo::Version("3.0.0") > EngineInfo::Version("2.3.20")); 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.0.1") > EngineInfo::Version("3.0.0"));
QVERIFY(EngineInfo::Version("3.1.0") > EngineInfo::Version("3.0.20")); QVERIFY(EngineInfo::Version("3.1.0") > EngineInfo::Version("3.0.20"));