diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-11-03 13:51:59 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-11-26 18:56:29 +0100 |
commit | fe36daa38ab1995c8c7fc6470d06b8595efd2385 (patch) | |
tree | 1dd4b5bf18537ed16ac31df331b0983fd9d08a65 | |
parent | 130a33311567a1f0f6a9a2d8707bff20a558eb20 (diff) | |
download | libnitrokey-fe36daa38ab1995c8c7fc6470d06b8595efd2385.tar.gz libnitrokey-fe36daa38ab1995c8c7fc6470d06b8595efd2385.tar.bz2 |
Tests: remake fill SD card test. Get progress bar value when busy.
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | NK_C_API.cc | 7 | ||||
-rw-r--r-- | NK_C_API.h | 1 | ||||
-rw-r--r-- | NitrokeyManager.cc | 9 | ||||
-rw-r--r-- | include/NitrokeyManager.h | 2 | ||||
-rw-r--r-- | unittest/constants.py | 1 | ||||
-rw-r--r-- | unittest/test_storage.py | 15 |
6 files changed, 34 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index fc6d3c5..2a28ede 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -464,6 +464,13 @@ extern const char* NK_get_SD_usage_data() { }); } +extern int NK_get_progress_bar_value() { + auto m = NitrokeyManager::instance(); + return get_with_result([&](){ + return m->get_progress_bar_value(); + }); +} + } @@ -339,6 +339,7 @@ extern int NK_change_update_password(const char* current_update_password, const char* new_update_password); extern const char* NK_get_status_storage(); extern const char* NK_get_SD_usage_data(); +extern int NK_get_progress_bar_value(); } diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 49b34c4..fdf1e05 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -562,5 +562,14 @@ namespace nitrokey{ return strdup(p.data().dissect().c_str()); } + int NitrokeyManager::get_progress_bar_value(){ + try{ + stick20::GetDeviceStatus::CommandTransaction::run(*device); + return -1; + } + catch (LongOperationInProgressException &e){ + return e.progress_bar_value; + } + } } diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 7a3ffcc..2d5859f 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -106,6 +106,8 @@ namespace nitrokey { const char *get_SD_usage_data(); + int get_progress_bar_value(); + ~NitrokeyManager(); private: NitrokeyManager(); diff --git a/unittest/constants.py b/unittest/constants.py index 258619e..78a219b 100644 --- a/unittest/constants.py +++ b/unittest/constants.py @@ -18,6 +18,7 @@ class DefaultPasswords(Enum): class DeviceErrorCode(Enum): STATUS_OK = 0 + BUSY = 1 # busy or busy progressbar in place of wrong_CRC status NOT_PROGRAMMED = 3 WRONG_PASSWORD = 4 STATUS_NOT_AUTHORIZED = 5 diff --git a/unittest/test_storage.py b/unittest/test_storage.py index b02b1eb..600faf2 100644 --- a/unittest/test_storage.py +++ b/unittest/test_storage.py @@ -83,7 +83,20 @@ def test_clear_new_sd_card_notification(C): @pytest.mark.skip def test_fill_SD_card(C): - assert C.NK_fill_SD_card_with_random_data(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK + status = C.NK_fill_SD_card_with_random_data(DefaultPasswords.ADMIN) + assert status == DeviceErrorCode.STATUS_OK or status == DeviceErrorCode.BUSY + while 1: + value = C.NK_get_progress_bar_value() + if value == -1: break + assert 0 <= value <= 100 + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + wait(5) + + +def test_get_busy_progress_on_idle(C): + value = C.NK_get_progress_bar_value() + assert value == -1 + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK def test_change_update_password(C): |