aboutsummaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2020-06-13 19:39:14 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2020-06-13 19:39:14 +0200
commit9849224e27c3c82e2f4efb6e491b6975bb4ecb25 (patch)
tree67c6f11d43e844c8f60642daa4c0f35701930296 /unittest
parent9b929a0bacd03657ddc232e6b4a9ed0fade82f68 (diff)
parent0270a9b3de4b45fcfcb83f8e20a78702811d4192 (diff)
downloadlibnitrokey-9849224e27c3c82e2f4efb6e491b6975bb4ecb25.tar.gz
libnitrokey-9849224e27c3c82e2f4efb6e491b6975bb4ecb25.tar.bz2
Merge branch 'read-config-struct'
Add NK_config struct and read/write functions Fixes #176
Diffstat (limited to 'unittest')
-rw-r--r--unittest/test_pro.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/unittest/test_pro.py b/unittest/test_pro.py
index d25a50e..0d8c536 100644
--- a/unittest/test_pro.py
+++ b/unittest/test_pro.py
@@ -647,6 +647,30 @@ def test_read_write_config(C):
config = cast_pointer_to_tuple(config_raw_data, 'uint8_t', 5)
assert config == (0, 1, 2, True, False)
+ # use structs: read I
+ config_st = ffi.new('struct NK_config *')
+ if not config_st:
+ raise Exception("Could not allocate config")
+ assert C.NK_read_config_struct(config_st) == DeviceErrorCode.STATUS_OK
+ assert config_st.numlock == 0
+ assert config_st.capslock == 1
+ assert config_st.scrolllock == 2
+ assert config_st.enable_user_password
+ assert not config_st.disable_user_password
+
+ # use structs: write
+ config_st.numlock = 3
+ assert C.NK_write_config_struct(config_st[0], DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+
+ # use structs: read II
+ err = C.NK_read_config_struct(config_st)
+ assert err == 0
+ assert config_st.numlock == 3
+ assert config_st.capslock == 1
+ assert config_st.scrolllock == 2
+ assert config_st.enable_user_password
+ assert not config_st.disable_user_password
+
# restore defaults and check
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
assert C.NK_write_config(255, 255, 255, False, True, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK