Improve API version compatibility check

It has worked so far, but generally pre-1.0.0 versions use the minor
version number to determine compatibility.
This commit is contained in:
Oliver Hamlet
2015-12-11 18:08:06 +00:00
parent 9e28bfa31d
commit 2c9d92487d
2 changed files with 8 additions and 13 deletions
+4 -1
View File
@@ -203,7 +203,10 @@ LOOT_API void loot_cleanup() {
// Returns whether this version of LOOT supports the API from the given
// LOOT version. Abstracts LOOT API stability policy away from clients.
LOOT_API bool loot_is_compatible(const unsigned int versionMajor, const unsigned int versionMinor, const unsigned int versionPatch) {
return versionMajor == loot::g_version_major;
if (versionMajor > 0)
return versionMajor == loot::g_version_major;
else
return versionMinor == loot::g_version_minor;
}
// Returns the version string for this version of LOOT.
+4 -12
View File
@@ -54,26 +54,18 @@ TEST(GetBuildID, HandlesValidInput) {
EXPECT_STRNE("@GIT_COMMIT_STRING@", revision); // The CMake placeholder.
}
TEST(IsCompatible, HandlesCompatibleVersion) {
TEST(IsCompatible, shouldReturnTrueWithEqualMajorAndMinorVersionsAndUnequalPatchVersion) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));
EXPECT_TRUE(loot_is_compatible(vMajor, vMinor, vPatch));
// Test somewhat arbitrary variations.
EXPECT_TRUE(loot_is_compatible(vMajor, vMinor + 1, vPatch + 1));
if (vMinor > 0 && vPatch > 0)
EXPECT_TRUE(loot_is_compatible(vMajor, vMinor - 1, vPatch - 1));
EXPECT_TRUE(loot_is_compatible(vMajor, vMinor, vPatch + 1));
}
TEST(IsCompatible, HandlesIncompatibleVersion) {
TEST(IsCompatible, shouldReturnFalseWithEqualMajorVersionAndUnequalMinorAndPatchVersions) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));
EXPECT_FALSE(loot_is_compatible(vMajor + 1, vMinor, vPatch));
// Test somewhat arbitrary variations.
EXPECT_FALSE(loot_is_compatible(vMajor + 1, vMinor + 1, vPatch + 1));
if (vMinor > 0 && vPatch > 0)
EXPECT_FALSE(loot_is_compatible(vMajor + 1, vMinor - 1, vPatch - 1));
EXPECT_FALSE(loot_is_compatible(vMajor, vMinor + 1, vPatch + 1));
}
TEST(GetErrorMessage, HandlesInputCorrectly) {