From 6e44c2b11bd1be9e080f1179283c49f9bb8955a5 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 25 May 2018 00:15:40 +0200 Subject: 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. --- unittest/test_C_API.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'unittest/test_C_API.cpp') 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(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(); +} -- cgit v1.2.1 From f0f1691bc741da48bc2e1adfa4535026ae42d6d3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 20 Jun 2018 12:03:28 +0200 Subject: Replace *out function parameter with return value Using return value instead of memory manipulation seem to be cleaner solution and less error prone due to avoiding pointer usage. Signed-off-by: Szczepan Zalega --- unittest/test_C_API.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'unittest/test_C_API.cpp') diff --git a/unittest/test_C_API.cpp b/unittest/test_C_API.cpp index f38d0b6..1964738 100644 --- a/unittest/test_C_API.cpp +++ b/unittest/test_C_API.cpp @@ -87,18 +87,15 @@ TEST_CASE("multiple devices with ID", "[BASIC]") { } TEST_CASE("Get device model", "[BASIC]") { - auto success = NK_get_device_model(nullptr); - REQUIRE(!success); - NK_logout(); - NK_device_model model = static_cast(3); - success = NK_get_device_model(&model); - REQUIRE(!success); + NK_device_model model = NK_get_device_model(); + REQUIRE(model == NK_device_model::NK_DISCONNECTED); - auto result = NK_login_auto(); - REQUIRE(result != 0); - success = NK_get_device_model(&model); + auto success = NK_login_auto() == 1; REQUIRE(success); + model = NK_get_device_model(); + REQUIRE(model != NK_device_model::NK_DISCONNECTED); + REQUIRE((model == NK_PRO || model == NK_STORAGE)); NK_logout(); } -- cgit v1.2.1