mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-26 01:28:38 +08:00
Add wxVersionInfo::AtLeast()
Allow easily checking if the version is at least equal to the given one.
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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).
|
||||
|
||||
|
||||
@@ -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) );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user