diff options
-rw-r--r-- | NitrokeyManager.cc | 4 | ||||
-rw-r--r-- | device.cc | 6 | ||||
-rw-r--r-- | unittest/test_offline.cc | 25 |
3 files changed, 32 insertions, 3 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index addfdbf..ab4cac5 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -234,12 +234,14 @@ using nitrokey::misc::strcpyT; bool NitrokeyManager::connect() { std::lock_guard<std::mutex> lock(mex_dev_com_manager); vector< shared_ptr<Device> > devices = { make_shared<Stick10>(), make_shared<Stick20>() }; + bool connected = false; for( auto & d : devices ){ if (d->connect()){ device = std::shared_ptr<Device>(d); + connected = true; } } - return device != nullptr; + return connected; } @@ -69,8 +69,10 @@ bool Device::_disconnect() { LOG(std::string(__FUNCTION__) + std::string(m_model == DeviceModel::PRO ? "PRO" : "STORAGE"), Loglevel::DEBUG_L2); LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - LOG(std::string("Disconnection: handle already freed: ") + std::to_string(mp_devhandle == nullptr) + " ("+m_path+")", Loglevel::DEBUG_L1); - if(mp_devhandle == nullptr) return false; + if(mp_devhandle == nullptr) { + LOG(std::string("Disconnection: handle already freed: ") + std::to_string(mp_devhandle == nullptr) + " ("+m_path+")", Loglevel::DEBUG_L1); + return false; + } hid_close(mp_devhandle); mp_devhandle = nullptr; diff --git a/unittest/test_offline.cc b/unittest/test_offline.cc index 6f52a61..2ad6a0e 100644 --- a/unittest/test_offline.cc +++ b/unittest/test_offline.cc @@ -180,3 +180,28 @@ TEST_CASE("Test version getter", "[fast]") { std::regex pattern(version + "(" + git_suffix + "|)"); REQUIRE(std::regex_match(s, pattern)); } + +TEST_CASE("Connect should not return true after the second attempt", "[fast]") { + int result = 0; + + result = NK_login("S"); + REQUIRE(result == 0); + + result = NK_login_auto(); + REQUIRE(result == 0); + + result = NK_logout(); + REQUIRE(result == 0); + + result = NK_logout(); + REQUIRE(result == 0); + + result = NK_login("P"); + REQUIRE(result == 0); + + result = NK_login_auto(); + REQUIRE(result == 0); + + result = NK_logout(); + REQUIRE(result == 0); +} |