Add wxVersionInfo::AtLeast()

Allow easily checking if the version is at least equal to the given one.
This commit is contained in:
Vadim Zeitlin
2022-12-04 00:44:09 +01:00
parent 7ccd305c84
commit 2a39377ca4
3 changed files with 43 additions and 0 deletions
+18
View File
@@ -43,6 +43,24 @@ public:
// Default copy ctor, assignment operator and dtor are ok.
// Check if this version is at least equal to the given one.
bool AtLeast(int major, int minor = 0, int micro = 0) const
{
if ( m_major > major )
return true;
if ( m_major < major )
return false;
if ( m_minor > minor )
return true;
if ( m_minor < minor )
return false;
return m_micro >= micro;
}
const wxString& GetName() const { return m_name; }
int GetMajor() const { return m_major; }
+12
View File
@@ -50,6 +50,18 @@ public:
const wxString& description = wxString(),
const wxString& copyright = wxString());
/**
Return true if the version is at least equal to the given one.
@param major Major version to compare with.
@param minor Optional minor version to compare with.
@param micro Optional micro version to compare with.
@return @true if this version is equal to or greater than the given one.
@since 3.3.0
*/
bool AtLeast(int major, int minor = 0, int micro = 0) const;
/**
Get the name of the object (library).
+13
View File
@@ -18,6 +18,7 @@
#include "wx/math.h"
#include "wx/mimetype.h"
#include "wx/versioninfo.h"
// just some classes using wxRTTI for wxStaticCast() test
#include "wx/tarstrm.h"
@@ -241,3 +242,15 @@ TEST_CASE("wxFileTypeInfo", "[mime]")
}
}
#endif // wxUSE_MIMETYPE
TEST_CASE("wxVersionInfo", "[version]")
{
wxVersionInfo ver120("test", 1, 2);
CHECK( ver120.AtLeast(1, 2) );
CHECK( ver120.AtLeast(1, 0) );
CHECK( ver120.AtLeast(0, 9) );
CHECK_FALSE( ver120.AtLeast(1, 2, 1) );
CHECK_FALSE( ver120.AtLeast(1, 3) );
CHECK_FALSE( ver120.AtLeast(2, 0) );
}