diff --git a/include/wx/versioninfo.h b/include/wx/versioninfo.h index 436fcbbba6..1aa9f89557 100644 --- a/include/wx/versioninfo.h +++ b/include/wx/versioninfo.h @@ -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; } diff --git a/interface/wx/versioninfo.h b/interface/wx/versioninfo.h index f557534a10..2fbe99e92b 100644 --- a/interface/wx/versioninfo.h +++ b/interface/wx/versioninfo.h @@ -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). diff --git a/tests/misc/misctests.cpp b/tests/misc/misctests.cpp index 39edeae3dd..4fe17aed21 100644 --- a/tests/misc/misctests.cpp +++ b/tests/misc/misctests.cpp @@ -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) ); +}