diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-08 11:00:18 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-02-28 19:28:24 +0100 |
commit | e25a83d6d704db7b5505d113c2d89811c6c2fc60 (patch) | |
tree | 089323859de395377ff82915a13eeed92a184c72 | |
parent | 8bede81660658a3675f4b7f68835ef3a623c696f (diff) | |
download | libnitrokey-e25a83d6d704db7b5505d113c2d89811c6c2fc60.tar.gz libnitrokey-e25a83d6d704db7b5505d113c2d89811c6c2fc60.tar.bz2 |
Add tests for refreshed devices list and not refreshed in the loop
Add it to CMake
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittest/test_multiple_devices.cc | 37 |
2 files changed, 34 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d788cf..6037393 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,7 +192,7 @@ IF (COMPILE_TESTS) target_link_libraries (test_issues ${EXTRA_LIBS} nitrokey catch) add_executable (test_multiple_devices unittest/test_multiple_devices.cc) - target_link_libraries (test_multiple_devices ${EXTRA_LIBS} ${LIBNAME} catch) + target_link_libraries (test_multiple_devices ${EXTRA_LIBS} nitrokey catch) ENDIF() diff --git a/unittest/test_multiple_devices.cc b/unittest/test_multiple_devices.cc index 235a24d..65ae9ab 100644 --- a/unittest/test_multiple_devices.cc +++ b/unittest/test_multiple_devices.cc @@ -8,7 +8,6 @@ const char * RFC_SECRET = "12345678901234567890"; #include <iostream> #include <NitrokeyManager.h> -#include <iostream> #include <stick20_commands.h> using namespace nitrokey; @@ -99,13 +98,43 @@ TEST_CASE("Use API ID", "[BASIC]") { auto v = nm->list_devices_by_cpuID(); REQUIRE(v.size() > 0); - for(int i=0; i<1000; i++) { + //no refresh - should not reconnect to new devices + for (int j = 0; j < 100; j++) { + for (auto i : v) { + if (!nm->connect_with_ID(i)) continue; + int retry_count = 99; + try { + retry_count = nm->get_admin_retry_count(); + std::cout << j << " " << i << " " << to_string(retry_count) << std::endl; + } + catch (...) { + retry_count = 99; + //pass + } + } + } + std::cout << "finished" << std::endl; +} + +TEST_CASE("Use API ID refresh", "[BASIC]") { + auto nm = NitrokeyManager::instance(); + nm->set_loglevel(2); + + //refresh in each iteration - should reconnect to new devices + for(int j=0; j<100; j++) { auto v = nm->list_devices_by_cpuID(); REQUIRE(v.size() > 0); for (auto i : v) { nm->connect_with_ID(i); - auto retry_count = nm->get_admin_retry_count(); - std::cout << i << " " << to_string(retry_count) << std::endl; + int retry_count = 99; + try { + retry_count = nm->get_admin_retry_count(); + std::cout << j <<" " << i << " " << to_string(retry_count) << std::endl; + } + catch (...){ + retry_count = 99; + //pass + } } } std::cout << "finished" << std::endl; |