diff options
author | Daiki Ueno <dueno@redhat.com> | 2017-10-02 11:36:20 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2017-11-15 11:26:21 +0100 |
commit | b889dec9e3493efb72c9903bb4d6007ec00e1c89 (patch) | |
tree | 26303e9571b84d9f1a594b2a0df914d3138e75ba /p11-kit | |
parent | 64b96efca97479a67e2ac1fcbf1492fceab64ba8 (diff) |
test: Improve code coverage of filter.c
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/test-filter.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/p11-kit/test-filter.c b/p11-kit/test-filter.c index 72272db..74f8d4e 100644 --- a/p11-kit/test-filter.c +++ b/p11-kit/test-filter.c @@ -73,6 +73,12 @@ static void test_allowed (void) { CK_FUNCTION_LIST_PTR module; + CK_SLOT_ID slots[1], slot; + CK_SLOT_INFO slot_info; + CK_TOKEN_INFO token_info; + CK_MECHANISM_TYPE mechs[8]; + CK_MECHANISM_INFO mech; + CK_SESSION_HANDLE session = 0; p11_virtual virt; p11_virtual *filter; CK_ULONG count; @@ -88,10 +94,71 @@ test_allowed (void) rv = (module->C_Initialize) (NULL); assert_num_eq (CKR_OK, rv); + rv = (module->C_GetSlotList) (CK_TRUE, NULL, NULL); + assert_num_eq (CKR_ARGUMENTS_BAD, rv); + rv = (module->C_GetSlotList) (CK_TRUE, NULL, &count); assert_num_eq (CKR_OK, rv); assert_num_eq (count, 1); + count = 0; + rv = (module->C_GetSlotList) (CK_TRUE, slots, &count); + assert_num_eq (CKR_BUFFER_TOO_SMALL, rv); + + count = 1; + rv = (module->C_GetSlotList) (CK_TRUE, slots, &count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (count, 1); + + rv = (module->C_GetSlotInfo) (99, &slot_info); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_GetSlotInfo) (slots[0], &slot_info); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_GetTokenInfo) (99, &token_info); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_GetTokenInfo) (slots[0], &token_info); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_GetMechanismList) (99, NULL, &count); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_GetMechanismList) (slots[0], NULL, &count); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_GetMechanismList) (slots[0], mechs, &count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (2, count); + + rv = (module->C_GetMechanismInfo) (99, mechs[0], &mech); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_GetMechanismInfo) (slots[0], mechs[0], &mech); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_InitToken) (99, (CK_UTF8CHAR_PTR)"TEST PIN", 8, (CK_UTF8CHAR_PTR)"TEST LABEL"); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_InitToken) (slots[0], (CK_UTF8CHAR_PTR)"TEST PIN", 8, (CK_UTF8CHAR_PTR)"TEST LABEL"); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_WaitForSlotEvent) (0, &slot, NULL); + assert_num_eq (CKR_FUNCTION_NOT_SUPPORTED, rv); + + rv = (module->C_OpenSession) (99, CKF_SERIAL_SESSION, NULL, NULL, &session); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_OpenSession) (slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); + assert_num_eq (CKR_OK, rv); + + rv = (module->C_CloseAllSessions) (99); + assert_num_eq (CKR_SLOT_ID_INVALID, rv); + + rv = (module->C_CloseAllSessions) (slots[0]); + assert_num_eq (CKR_OK, rv); + rv = (module->C_Finalize) (NULL); assert_num_eq (CKR_OK, rv); |