aboutsummaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2018-05-25 00:15:40 +0200
committerRobin Krahl <me@robin-krahl.de>2018-05-25 00:15:40 +0200
commit6e44c2b11bd1be9e080f1179283c49f9bb8955a5 (patch)
tree2394d3c79376a34e2b6b65120b3c8c1ec3a6a92a /unittest
parent391a276ba35216337b777c65fda62561a6e9383f (diff)
downloadlibnitrokey-6e44c2b11bd1be9e080f1179283c49f9bb8955a5.tar.gz
libnitrokey-6e44c2b11bd1be9e080f1179283c49f9bb8955a5.tar.bz2
Expose device model in C API
The C++ API already provides access to the model of the connected device in NitrokeyManager::get_connected_device_model(). This patch also exposes this information in the C API by adding NK_get_device_model. As there might be no device connected, the function returns a boolean indicating the connection status and writes the model of the connected device to a pointer passed as an argument.
Diffstat (limited to 'unittest')
-rw-r--r--unittest/test_C_API.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/unittest/test_C_API.cpp b/unittest/test_C_API.cpp
index acfadd2..f38d0b6 100644
--- a/unittest/test_C_API.cpp
+++ b/unittest/test_C_API.cpp
@@ -84,4 +84,21 @@ TEST_CASE("multiple devices with ID", "[BASIC]") {
}
free (string);
-} \ No newline at end of file
+}
+
+TEST_CASE("Get device model", "[BASIC]") {
+ auto success = NK_get_device_model(nullptr);
+ REQUIRE(!success);
+
+ NK_logout();
+ NK_device_model model = static_cast<NK_device_model>(3);
+ success = NK_get_device_model(&model);
+ REQUIRE(!success);
+
+ auto result = NK_login_auto();
+ REQUIRE(result != 0);
+ success = NK_get_device_model(&model);
+ REQUIRE(success);
+ REQUIRE((model == NK_PRO || model == NK_STORAGE));
+ NK_logout();
+}