cpp, qt: Add missing comparison operators for version info comparison

* lang/cpp/src/engineinfo.h (EngineInfo::Version::operator<=,
EngineInfo::Version::operator>=, EngineInfo::Version::operator!=):
New.
* lang/qt/tests/t-various.cpp (TestVarious::testVersion): Add tests for
new comparison operators.
* NEWS: Mention added API
This commit is contained in:
Ingo Klöcker 2020-10-15 16:50:32 +02:00
parent 2f53a2f4be
commit c3406462d1
3 changed files with 65 additions and 0 deletions

3
NEWS
View File

@ -15,6 +15,9 @@ Noteworthy changes in version 1.14.1 (unreleased)
gpgme_op_setexpire NEW. gpgme_op_setexpire NEW.
cpp: Context::setExpire NEW. cpp: Context::setExpire NEW.
cpp: Context::startSetExpire NEW. cpp: Context::startSetExpire NEW.
cpp: EngineInfo::Version::operator<= NEW.
cpp: EngineInfo::Version::operator>= NEW.
cpp: EngineInfo::Version::operator!= NEW.
Noteworthy changes in version 1.14.0 (2020-07-16) Noteworthy changes in version 1.14.0 (2020-07-16)

View File

@ -85,6 +85,16 @@ public:
return operator<(Version(other)); return operator<(Version(other));
} }
bool operator <= (const Version &other)
{
return !operator>(other);
}
bool operator <= (const char *other)
{
return operator<=(Version(other));
}
bool operator > (const char* other) bool operator > (const char* other)
{ {
return operator>(Version(other)); return operator>(Version(other));
@ -95,6 +105,16 @@ public:
return !operator<(other) && !operator==(other); return !operator<(other) && !operator==(other);
} }
bool operator >= (const Version &other)
{
return !operator<(other);
}
bool operator >= (const char *other)
{
return operator>=(Version(other));
}
bool operator == (const Version& other) bool operator == (const Version& other)
{ {
return major == other.major return major == other.major
@ -107,6 +127,16 @@ public:
return operator==(Version(other)); return operator==(Version(other));
} }
bool operator != (const Version &other)
{
return !operator==(other);
}
bool operator != (const char *other)
{
return operator!=(Version(other));
}
friend std::ostream& operator << (std::ostream& stream, const Version& ver) friend std::ostream& operator << (std::ostream& stream, const Version& ver)
{ {
stream << ver.major; stream << ver.major;

View File

@ -245,6 +245,38 @@ private Q_SLOTS:
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"));
QVERIFY(EngineInfo::Version("1.1.1") <= "2.0.0");
QVERIFY(EngineInfo::Version("1.1.1") <= "1.2.0");
QVERIFY(EngineInfo::Version("1.1.1") <= "1.1.2");
QVERIFY(EngineInfo::Version("1.1.1") <= "1.1.1");
QVERIFY(!(EngineInfo::Version("1.1.1") <= "1.1.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") <= "1.0.9"));
QVERIFY(!(EngineInfo::Version("1.1.1") <= "0.9.9"));
QVERIFY(!(EngineInfo::Version("1.1.1") == "2.0.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") == "1.2.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") == "1.1.2"));
QVERIFY(EngineInfo::Version("1.1.1") == "1.1.1");
QVERIFY(!(EngineInfo::Version("1.1.1") == "1.1.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") == "1.0.9"));
QVERIFY(!(EngineInfo::Version("1.1.1") == "0.9.9"));
QVERIFY(EngineInfo::Version("1.1.1") != "2.0.0");
QVERIFY(EngineInfo::Version("1.1.1") != "1.2.0");
QVERIFY(EngineInfo::Version("1.1.1") != "1.1.2");
QVERIFY(!(EngineInfo::Version("1.1.1") != "1.1.1"));
QVERIFY(EngineInfo::Version("1.1.1") != "1.1.0");
QVERIFY(EngineInfo::Version("1.1.1") != "1.0.9");
QVERIFY(EngineInfo::Version("1.1.1") != "0.9.9");
QVERIFY(!(EngineInfo::Version("1.1.1") >= "2.0.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") >= "1.2.0"));
QVERIFY(!(EngineInfo::Version("1.1.1") >= "1.1.2"));
QVERIFY(EngineInfo::Version("1.1.1") >= "1.1.1");
QVERIFY(EngineInfo::Version("1.1.1") >= "1.1.0");
QVERIFY(EngineInfo::Version("1.1.1") >= "1.0.9");
QVERIFY(EngineInfo::Version("1.1.1") >= "0.9.9");
} }
void initTestCase() void initTestCase()