diff options
Diffstat (limited to 'p11-kit/test-iter.c')
-rw-r--r-- | p11-kit/test-iter.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/p11-kit/test-iter.c b/p11-kit/test-iter.c index 055a4b3..07b8e32 100644 --- a/p11-kit/test-iter.c +++ b/p11-kit/test-iter.c @@ -697,6 +697,108 @@ test_module_mismatch (void) } static void +test_slot_match (void) +{ + CK_FUNCTION_LIST_PTR *modules; + P11KitIter *iter; + P11KitUri *uri; + CK_RV rv; + int count; + int ret; + + modules = initialize_and_get_modules (); + + uri = p11_kit_uri_new (); + ret = p11_kit_uri_parse ("pkcs11:slot-manufacturer=TEST%20MANUFACTURER", P11_KIT_URI_FOR_SLOT, uri); + assert_num_eq (P11_KIT_URI_OK, ret); + + iter = p11_kit_iter_new (uri, 0); + p11_kit_uri_free (uri); + + p11_kit_iter_begin (iter, modules); + + count = 0; + while ((rv = p11_kit_iter_next (iter)) == CKR_OK) + count++; + + assert (rv == CKR_CANCEL); + + /* Three modules, each with 1 slot, and 3 public objects */ + assert_num_eq (9, count); + + p11_kit_iter_free (iter); + + finalize_and_free_modules (modules); +} + +static void +test_slot_mismatch (void) +{ + CK_FUNCTION_LIST_PTR *modules; + P11KitIter *iter; + P11KitUri *uri; + CK_RV rv; + int count; + int ret; + + modules = initialize_and_get_modules (); + + uri = p11_kit_uri_new (); + ret = p11_kit_uri_parse ("pkcs11:slot-manufacturer=blah", P11_KIT_URI_FOR_SLOT, uri); + assert_num_eq (P11_KIT_URI_OK, ret); + + iter = p11_kit_iter_new (uri, 0); + p11_kit_uri_free (uri); + + p11_kit_iter_begin (iter, modules); + + count = 0; + while ((rv = p11_kit_iter_next (iter)) == CKR_OK) + count++; + + assert (rv == CKR_CANCEL); + + /* Nothing should have matched */ + assert_num_eq (0, count); + + p11_kit_iter_free (iter); + + finalize_and_free_modules (modules); +} + +static void +test_slot_info (void) +{ + CK_FUNCTION_LIST_PTR *modules; + CK_SLOT_INFO *info; + P11KitIter *iter; + char *string; + CK_RV rv; + + modules = initialize_and_get_modules (); + + iter = p11_kit_iter_new (NULL, 0); + p11_kit_iter_begin (iter, modules); + + rv = p11_kit_iter_next (iter); + assert_num_eq (rv, CKR_OK); + + info = p11_kit_iter_get_slot_info (iter); + assert_ptr_not_null (info); + + string = p11_kit_space_strdup (info->slotDescription, + sizeof (info->slotDescription)); + assert_ptr_not_null (string); + + assert_str_eq (string, "TEST SLOT"); + + free (string); + p11_kit_iter_free (iter); + + finalize_and_free_modules (modules); +} + +static void test_token_match (void) { CK_FUNCTION_LIST_PTR *modules; @@ -1311,6 +1413,9 @@ main (int argc, p11_test (test_token_match, "/iter/test_token_match"); p11_test (test_token_mismatch, "/iter/test_token_mismatch"); p11_test (test_token_info, "/iter/token-info"); + p11_test (test_slot_match, "/iter/test_slot_match"); + p11_test (test_slot_mismatch, "/iter/test_slot_mismatch"); + p11_test (test_slot_info, "/iter/slot-info"); p11_test (test_module_match, "/iter/test_module_match"); p11_test (test_module_mismatch, "/iter/test_module_mismatch"); p11_test (test_getslotlist_fail_first, "/iter/test_getslotlist_fail_first"); |