diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-29 16:37:22 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-29 16:37:22 +0100 |
commit | 1bf90425d2006558ce4f4aac0ed5680d31b77918 (patch) | |
tree | c6789df5d10d1b5f6b83c5d1c7c2889e5ad2a6d9 /unittest | |
parent | b0d1d6a1a44210a25b3d0e6950ec08f551714ccf (diff) | |
parent | dc9dd81105634aeb100c47637fedef425f0ac6f9 (diff) | |
download | libnitrokey-1bf90425d2006558ce4f4aac0ed5680d31b77918.tar.gz libnitrokey-1bf90425d2006558ce4f4aac0ed5680d31b77918.tar.bz2 |
Merge branch 'pr_155'
Add Status structure, and a general command for using it as a result.
Usable to limit calls to the device, when multiple status fields are
required at given time.
Tested on Nitrokey Pro v0.7 and v0.10.
Run offline tests as well (C++ and Python).
Fixes #155
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/test_multiple_devices.cc | 2 | ||||
-rw-r--r-- | unittest/test_pro.py | 18 | ||||
-rw-r--r-- | unittest/test_safe.cpp | 2 | ||||
-rw-r--r-- | unittest/test_strdup.cpp | 4 |
4 files changed, 19 insertions, 7 deletions
diff --git a/unittest/test_multiple_devices.cc b/unittest/test_multiple_devices.cc index 4b1e2c1..7e10a42 100644 --- a/unittest/test_multiple_devices.cc +++ b/unittest/test_multiple_devices.cc @@ -117,7 +117,7 @@ TEST_CASE("Use C API", "[BASIC]") { while (ptr) { std::cout << "Connect with: " << ptr->model << " " << ptr->path << " " << ptr->serial_number << " | " << NK_connect_with_path(ptr->path) << " | "; - auto status = NK_status(); + auto status = NK_get_status_as_string(); std::cout << status << std::endl; free(status); ptr = ptr->next; diff --git a/unittest/test_pro.py b/unittest/test_pro.py index afa9505..6ab7c1d 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -674,11 +674,23 @@ def test_factory_reset(C): @pytest.mark.status -def test_get_status(C): - status = C.NK_status() +def test_get_status_as_string(C): + status = C.NK_get_status_as_string() s = gs(status) assert len(s) > 0 + +@pytest.mark.status +def test_get_status(C): + status_st = ffi.new('struct NK_status *') + if not status_st: + raise Exception("Could not allocate status") + err = C.NK_get_status(status_st) + assert err == 0 + assert status_st.firmware_version_major == 0 + assert status_st.firmware_version_minor != 0 + + @pytest.mark.status def test_get_serial_number(C): sn = C.NK_device_serial_number() @@ -926,4 +938,4 @@ def test_TOTP_codes_from_nitrokeyapp(secret, C): def test_get_device_model(C): assert C.NK_get_device_model() != 0 - # assert C.NK_get_device_model() != C.NK_DISCONNECTED
\ No newline at end of file + # assert C.NK_get_device_model() != C.NK_DISCONNECTED diff --git a/unittest/test_safe.cpp b/unittest/test_safe.cpp index d6f8b63..a244027 100644 --- a/unittest/test_safe.cpp +++ b/unittest/test_safe.cpp @@ -60,7 +60,7 @@ TEST_CASE("Status command for Pro or Storage", "[BASIC]") { auto const m = NK_get_device_model(); REQUIRE(m != NK_DISCONNECTED); if (m == NK_PRO) - s = NK_status(); + s = NK_get_status_as_string(); else if (m == NK_STORAGE){ s = NK_get_status_storage_as_string(); } diff --git a/unittest/test_strdup.cpp b/unittest/test_strdup.cpp index 4f77b7f..c7f4ea8 100644 --- a/unittest/test_strdup.cpp +++ b/unittest/test_strdup.cpp @@ -34,7 +34,7 @@ static const int SHORT_STRING_LENGTH = 10; TEST_CASE("Test strdup memory free error", "[BASIC]") { NK_set_debug(false); - char *c = NK_status(); /* error --> string literal */ + char *c = NK_get_status_as_string(); /* error --> string literal */ REQUIRE(c != nullptr); REQUIRE(strnlen(c, SHORT_STRING_LENGTH) == 0); puts(c); @@ -48,7 +48,7 @@ TEST_CASE("Test strdup memory leak", "[BASIC]") if (!connected) return; REQUIRE(connected); - char *c = NK_status(); /* no error --> dynamically allocated */ + char *c = NK_get_status_as_string(); /* no error --> dynamically allocated */ REQUIRE(c != nullptr); REQUIRE(strnlen(c, SHORT_STRING_LENGTH) > 0); puts(c); |