From ca821c261ca7ad3142647e1b69538279201d4ba7 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 2 Nov 2014 16:21:14 +0000 Subject: [PATCH] Added loot_get_build_id() to API. Also added tests for it, and fixed an undocumented return value for loot_get_version(). --- src/api/api.cpp | 11 ++++++++++- src/api/api.h | 10 ++++++++++ src/tests/api/api.h | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 43ba6660..d46f70ed 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -217,6 +217,15 @@ LOOT_API unsigned int loot_get_version(unsigned int * const versionMajor, unsign return loot_ok; } +LOOT_API unsigned int loot_get_build_id(const char ** const revision) { + if (revision == nullptr) + return c_error(loot_error_invalid_args, "Null message pointer passed."); + + *revision = loot::g_build_revision; + + return loot_ok; +} + //////////////////////////////////// // Lifecycle Management Functions //////////////////////////////////// @@ -263,7 +272,7 @@ LOOT_API unsigned int loot_create_db(loot_db * const db, return c_error(loot_error_invalid_args, "Given local data path \"" + std::string(gameLocalPath) + "\" is not a valid directory."); *db = new _loot_db_int(clientGame, game_path, game_local_path); -} + } catch (loot::error& e) { return c_error(e); } diff --git a/src/api/api.h b/src/api/api.h index 33d28310..605ebd35 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -312,11 +312,21 @@ extern "C" * A pointer to the minor version number. * @param versionPatch * A pointer to the patch version number. + * @returns A return code. */ LOOT_API unsigned int loot_get_version(unsigned int * const versionMajor, unsigned int * const versionMinor, unsigned int * const versionPatch); + /** + * @brief Get the Git revision of the code from which the binary was + * built. + * @param revision + * A pointer to the shortened Git revision ID string. + * @returns A return code. + */ + LOOT_API unsigned int loot_get_build_id(const char ** const revision); + /**@}*/ /**********************************************************************//** * @name Lifecycle Management Functions diff --git a/src/tests/api/api.h b/src/tests/api/api.h index fa3a1974..1581f0a3 100644 --- a/src/tests/api/api.h +++ b/src/tests/api/api.h @@ -41,6 +41,17 @@ TEST(GetVersion, HandlesValidInput) { EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch)); } +TEST(GetBuildID, HandlesNullInput) { + EXPECT_EQ(loot_error_invalid_args, loot_get_build_id(NULL)); +} + +TEST(GetBuildID, HandlesValidInput) { + const char * revision; + EXPECT_EQ(loot_ok, loot_get_build_id(&revision)); + EXPECT_STRNE(NULL, revision); + EXPECT_STRNE("@GIT_COMMIT_STRING@", revision); // The CMake placeholder. +} + TEST(IsCompatible, HandlesCompatibleVersion) { unsigned int vMajor, vMinor, vPatch; EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));