From e25a83d6d704db7b5505d113c2d89811c6c2fc60 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 8 Dec 2017 11:00:18 +0100 Subject: Add tests for refreshed devices list and not refreshed in the loop Add it to CMake Signed-off-by: Szczepan Zalega --- unittest/test_multiple_devices.cc | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'unittest') 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 #include -#include #include 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; -- cgit v1.2.1