aboutsummaryrefslogtreecommitdiff
path: root/unittest/test_offline.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-06-22 11:01:21 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-06-22 11:01:21 +0200
commit7c06025c9b9c28c642c8acc8bab7cbc974cd5575 (patch)
treecbd12a38b4cabb1517978c3d91de727738048da2 /unittest/test_offline.cc
parentee6c9c61b93fae7e041abb19e42134d3a831a846 (diff)
parentafb7a48046142fe666eda64338f89677e79db705 (diff)
downloadlibnitrokey-7c06025c9b9c28c642c8acc8bab7cbc974cd5575.tar.gz
libnitrokey-7c06025c9b9c28c642c8acc8bab7cbc974cd5575.tar.bz2
Merge branch 'pr_123'
Fix version getter test Closes #123
Diffstat (limited to 'unittest/test_offline.cc')
-rw-r--r--unittest/test_offline.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/unittest/test_offline.cc b/unittest/test_offline.cc
index 9d2f195..2ad6a0e 100644
--- a/unittest/test_offline.cc
+++ b/unittest/test_offline.cc
@@ -22,6 +22,8 @@
#include "catch.hpp"
#include <NitrokeyManager.h>
#include <memory>
+#include <string>
+#include <regex>
#include "../NK_C_API.h"
using namespace nitrokey::proto;
@@ -167,9 +169,16 @@ TEST_CASE("Test version getter", "[fast]") {
REQUIRE(nitrokey::get_minor_library_version() >= 3u);
const char *library_version = nitrokey::get_library_version();
REQUIRE(library_version != nullptr);
+
+ // The library version has to match the pattern returned by git describe:
+ // v<major>.<minor> or v<major>.<minor>-<n>-g<hash>, where <n> is the number
+ // of commits since the last tag, and <hash> is the hash of the current
+ // commit. (This assumes that all tags have the name v<major>.<minor>.)
std::string s = library_version;
- REQUIRE(s.length() >= 8);
- REQUIRE(s.find("g") != std::string::npos);
+ std::string version("v[0-9]+\\.[0-9]+");
+ std::string git_suffix("-[0-9]+-g[0-9a-z]+");
+ std::regex pattern(version + "(" + git_suffix + "|)");
+ REQUIRE(std::regex_match(s, pattern));
}
TEST_CASE("Connect should not return true after the second attempt", "[fast]") {