diff options
Diffstat (limited to 'trust/tests/test-module.c')
-rw-r--r-- | trust/tests/test-module.c | 470 |
1 files changed, 193 insertions, 277 deletions
diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c index 16d8037..45ec74d 100644 --- a/trust/tests/test-module.c +++ b/trust/tests/test-module.c @@ -32,21 +32,21 @@ * Author: Stef Walter <stefw@gnome.org> */ +#define CRYPTOKI_EXPORTS + #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-trust.h" #include <stdlib.h> #include <stdio.h> #include <string.h> -#define CRYPTOKI_EXPORTS - #include "attrs.h" #include "hash.h" #include "library.h" #include "path.h" #include "pkcs11x.h" -#include "test-data.h" #include "token.h" #include <assert.h> @@ -67,7 +67,7 @@ struct { } test; static void -setup (CuTest *cu) +setup (void *unused) { CK_C_INITIALIZE_ARGS args; const char *paths; @@ -79,72 +79,68 @@ setup (CuTest *cu) /* This is the entry point of the trust module, linked to this test */ rv = C_GetFunctionList (&test.module); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); memset (&args, 0, sizeof (args)); paths = SRCDIR "/input" P11_PATH_SEP \ SRCDIR "/files/self-signed-with-ku.der" P11_PATH_SEP \ SRCDIR "/files/thawte.pem"; if (asprintf (&arguments, "paths='%s'", paths) < 0) - CuAssertTrue (cu, false && "not reached"); + assert (false && "not reached"); args.pReserved = arguments; args.flags = CKF_OS_LOCKING_OK; rv = test.module->C_Initialize (&args); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); free (arguments); count = NUM_SLOTS; rv = test.module->C_GetSlotList (CK_TRUE, test.slots, &count); - CuAssertTrue (cu, rv == CKR_OK); - CuAssertTrue (cu, count == NUM_SLOTS); + assert (rv == CKR_OK); + assert (count == NUM_SLOTS); } static void -teardown (CuTest *cu) +teardown (void *unused) { CK_RV rv; rv = test.module->C_Finalize (NULL); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); memset (&test, 0, sizeof (test)); } static void -test_get_slot_list (CuTest *cu) +test_get_slot_list (void) { CK_SLOT_ID slots[NUM_SLOTS]; CK_ULONG count; CK_RV rv; int i; - setup (cu); - rv = test.module->C_GetSlotList (TRUE, NULL, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (NUM_SLOTS, count); count = 1; rv = test.module->C_GetSlotList (TRUE, slots, &count); - CuAssertIntEquals (cu, CKR_BUFFER_TOO_SMALL, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_BUFFER_TOO_SMALL, rv); + assert_num_eq (NUM_SLOTS, count); count = NUM_SLOTS; memset (slots, 0, sizeof (slots)); rv = test.module->C_GetSlotList (TRUE, slots, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (NUM_SLOTS, count); for (i = 0; i < NUM_SLOTS; i++) - CuAssertTrue (cu, slots[i] != 0); - - teardown (cu); + assert (slots[i] != 0); } static void -test_get_slot_info (CuTest *cu) +test_get_slot_info (void) { CK_SLOT_ID slots[NUM_SLOTS]; CK_SLOT_INFO info; @@ -161,30 +157,26 @@ test_get_slot_info (CuTest *cu) SRCDIR "/files/thawte.pem" }; - setup (cu); - count = NUM_SLOTS; rv = test.module->C_GetSlotList (TRUE, slots, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (NUM_SLOTS, count); for (i = 0; i < NUM_SLOTS; i++) { rv = test.module->C_GetSlotInfo (slots[i], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); memset (description, ' ', sizeof (description)); length = strlen(paths[i]); if (length > sizeof (description)) length = sizeof (description); memcpy (description, paths[i], length); - CuAssertTrue (cu, memcmp (info.slotDescription, description, sizeof (description)) == 0); + assert (memcmp (info.slotDescription, description, sizeof (description)) == 0); } - - teardown (cu); } static void -test_get_token_info (CuTest *cu) +test_get_token_info (void) { CK_C_INITIALIZE_ARGS args; CK_FUNCTION_LIST *module; @@ -204,7 +196,7 @@ test_get_token_info (CuTest *cu) /* This is the entry point of the trust module, linked to this test */ rv = C_GetFunctionList (&module); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); memset (&args, 0, sizeof (args)); args.pReserved = "paths='" \ @@ -214,28 +206,28 @@ test_get_token_info (CuTest *cu) args.flags = CKF_OS_LOCKING_OK; rv = module->C_Initialize (&args); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); count = NUM_SLOTS; rv = module->C_GetSlotList (CK_TRUE, slots, &count); - CuAssertTrue (cu, rv == CKR_OK); - CuAssertTrue (cu, count == NUM_SLOTS); + assert (rv == CKR_OK); + assert (count == NUM_SLOTS); for (i = 0; i < NUM_SLOTS; i++) { rv = module->C_GetTokenInfo (slots[i], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); memset (label, ' ', sizeof (label)); memcpy (label, labels[i], strlen (labels[i])); - CuAssertTrue (cu, memcmp (info.label, label, sizeof (label)) == 0); + assert (memcmp (info.label, label, sizeof (label)) == 0); } rv = module->C_Finalize (NULL); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } static void -test_get_session_info (CuTest *cu) +test_get_session_info (void) { CK_SLOT_ID slots[NUM_SLOTS]; CK_SESSION_HANDLE sessions[NUM_SLOTS]; @@ -244,30 +236,26 @@ test_get_session_info (CuTest *cu) CK_RV rv; int i; - setup (cu); - count = NUM_SLOTS; rv = test.module->C_GetSlotList (TRUE, slots, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (NUM_SLOTS, count); /* Open two sessions with each token */ for (i = 0; i < NUM_SLOTS; i++) { rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i]); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_GetSessionInfo (sessions[i], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); - CuAssertIntEquals (cu, slots[i], info.slotID); - CuAssertIntEquals (cu, CKF_SERIAL_SESSION, info.flags); + assert_num_eq (slots[i], info.slotID); + assert_num_eq (CKF_SERIAL_SESSION, info.flags); } - - teardown (cu); } static void -test_close_all_sessions (CuTest *cu) +test_close_all_sessions (void) { CK_SLOT_ID slots[NUM_SLOTS]; CK_SESSION_HANDLE sessions[NUM_SLOTS][2]; @@ -276,52 +264,47 @@ test_close_all_sessions (CuTest *cu) CK_RV rv; int i; - setup (cu); - count = NUM_SLOTS; rv = test.module->C_GetSlotList (TRUE, slots, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, NUM_SLOTS, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (NUM_SLOTS, count); /* Open two sessions with each token */ for (i = 0; i < NUM_SLOTS; i++) { rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i][0]); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_GetSessionInfo (sessions[i][0], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, &sessions[i][1]); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_GetSessionInfo (sessions[i][0], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } /* Close all the sessions on the first token */ rv = test.module->C_CloseAllSessions (slots[0]); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Those sessions should be closed */ rv = test.module->C_GetSessionInfo (sessions[0][0], &info); - CuAssertIntEquals (cu, CKR_SESSION_HANDLE_INVALID, rv); + assert_num_eq (CKR_SESSION_HANDLE_INVALID, rv); rv = test.module->C_GetSessionInfo (sessions[0][1], &info); - CuAssertIntEquals (cu, CKR_SESSION_HANDLE_INVALID, rv); + assert_num_eq (CKR_SESSION_HANDLE_INVALID, rv); /* Other sessions should still be open */ for (i = 1; i < NUM_SLOTS; i++) { rv = test.module->C_GetSessionInfo (sessions[i][0], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_GetSessionInfo (sessions[i][0], &info); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } - - teardown (cu); } static CK_ULONG -find_objects (CuTest *cu, - CK_ATTRIBUTE *match, +find_objects (CK_ATTRIBUTE *match, CK_OBJECT_HANDLE *sessions, CK_OBJECT_HANDLE *objects, CK_ULONG max_objects) @@ -335,14 +318,14 @@ find_objects (CuTest *cu, found = 0; for (i = 0; i < NUM_SLOTS; i++) { rv = test.module->C_OpenSession (test.slots[i], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjectsInit (session, match, p11_attrs_count (match)); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjects (session, objects + found, max_objects - found, &count); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjectsFinal (session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); for (j = found ; j < found + count; j++) sessions[j] = session; @@ -354,8 +337,7 @@ find_objects (CuTest *cu, } static void -check_trust_object_equiv (CuTest *cu, - CK_SESSION_HANDLE session, +check_trust_object_equiv (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE trust, CK_ATTRIBUTE *cert) { @@ -379,14 +361,13 @@ check_trust_object_equiv (CuTest *cu, }; rv = test.module->C_GetAttributeValue (session, trust, equiv, 6); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); - test_check_attrs (cu, equiv, cert); + test_check_attrs (equiv, cert); } static void -check_trust_object_hashes (CuTest *cu, - CK_SESSION_HANDLE session, +check_trust_object_hashes (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE trust, CK_ATTRIBUTE *cert) { @@ -403,21 +384,20 @@ check_trust_object_hashes (CuTest *cu, }; rv = test.module->C_GetAttributeValue (session, trust, hashes, 2); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); value = p11_attrs_find_valid (cert, CKA_VALUE); - CuAssertPtrNotNull (cu, value); + assert_ptr_not_null (value); p11_hash_md5 (check, value->pValue, value->ulValueLen, NULL); - CuAssertTrue (cu, memcmp (md5, check, sizeof (md5)) == 0); + assert (memcmp (md5, check, sizeof (md5)) == 0); p11_hash_sha1 (check, value->pValue, value->ulValueLen, NULL); - CuAssertTrue (cu, memcmp (sha1, check, sizeof (sha1)) == 0); + assert (memcmp (sha1, check, sizeof (sha1)) == 0); } static void -check_has_trust_object (CuTest *cu, - CK_ATTRIBUTE *cert) +check_has_trust_object (CK_ATTRIBUTE *cert) { CK_OBJECT_CLASS trust_object = CKO_NSS_TRUST; CK_ATTRIBUTE klass = { CKA_CLASS, &trust_object, sizeof (trust_object) }; @@ -428,21 +408,20 @@ check_has_trust_object (CuTest *cu, CK_ULONG count; attr = p11_attrs_find_valid (cert, CKA_ID); - CuAssertPtrNotNull (cu, attr); + assert_ptr_not_null (attr); match = p11_attrs_build (NULL, &klass, attr, NULL); - count = find_objects (cu, match, sessions, objects, 2); - CuAssertIntEquals (cu, 1, count); + count = find_objects (match, sessions, objects, 2); + assert_num_eq (1, count); - check_trust_object_equiv (cu, sessions[0], objects[0], cert); - check_trust_object_hashes (cu, sessions[0], objects[0], cert); + check_trust_object_equiv (sessions[0], objects[0], cert); + check_trust_object_hashes (sessions[0], objects[0], cert); p11_attrs_free (match); } static void -check_certificate (CuTest *cu, - CK_SESSION_HANDLE session, +check_certificate (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE handle) { unsigned char label[4096]= { 0, }; @@ -483,7 +462,7 @@ check_certificate (CuTest *cu, /* Note that we don't pass the CKA_INVALID attribute in */ rv = test.module->C_GetAttributeValue (session, handle, attrs, 15); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); /* If this is the cacert3 certificate, check its values */ if (memcmp (value, test_cacert3_ca_der, sizeof (test_cacert3_ca_der)) == 0) { @@ -500,25 +479,25 @@ check_certificate (CuTest *cu, { CKA_INVALID, }, }; - test_check_cacert3_ca (cu, attrs, NULL); + test_check_cacert3_ca (attrs, NULL); /* Get anchor specific attributes */ rv = test.module->C_GetAttributeValue (session, handle, anchor, 1); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); /* It lives in the trusted directory */ - test_check_attrs (cu, check, anchor); + test_check_attrs (check, anchor); /* Other certificates, we can't check the values */ } else { - test_check_object (cu, attrs, CKO_CERTIFICATE, NULL); + test_check_object (attrs, CKO_CERTIFICATE, NULL); } - check_has_trust_object (cu, attrs); + check_has_trust_object (attrs); } static void -test_find_certificates (CuTest *cu) +test_find_certificates (void) { CK_OBJECT_CLASS klass = CKO_CERTIFICATE; @@ -532,19 +511,15 @@ test_find_certificates (CuTest *cu) CK_ULONG count; CK_ULONG i; - setup (cu); - - count = find_objects (cu, match, sessions, objects, 16); - CuAssertIntEquals (cu, 8, count); + count = find_objects (match, sessions, objects, 16); + assert_num_eq (8, count); for (i = 0; i < count; i++) - check_certificate (cu, sessions[i], objects[i]); - - teardown (cu); + check_certificate (sessions[i], objects[i]); } static void -test_find_builtin (CuTest *cu) +test_find_builtin (void) { CK_OBJECT_CLASS klass = CKO_NSS_BUILTIN_ROOT_LIST; CK_BBOOL vtrue = CK_TRUE; @@ -562,17 +537,13 @@ test_find_builtin (CuTest *cu) CK_SESSION_HANDLE sessions[16]; CK_ULONG count; - setup (cu); - /* One per token */ - count = find_objects (cu, match, sessions, objects, 16); - CuAssertIntEquals (cu, NUM_SLOTS, count); - - teardown (cu); + count = find_objects (match, sessions, objects, 16); + assert_num_eq (NUM_SLOTS, count); } static void -test_session_object (CuTest *cu) +test_session_object (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -586,22 +557,18 @@ test_session_object (CuTest *cu) CK_ULONG size; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_CreateObject (session, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_GetObjectSize (session, handle, &size); - CuAssertTrue (cu, rv == CKR_OK); - - teardown (cu); + assert (rv == CKR_OK); } static void -test_session_find (CuTest *cu) +test_session_find (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -616,30 +583,26 @@ test_session_find (CuTest *cu) CK_ULONG count; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CreateObject (session, original, 2, &handle); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjectsInit (session, original, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 1, count); - CuAssertIntEquals (cu, handle, check); + assert_num_eq (CKR_OK, rv); + assert_num_eq (1, count); + assert_num_eq (handle, check); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); - - teardown (cu); + assert_num_eq (CKR_OK, rv); } static void -test_session_find_no_attr (CuTest *cu) +test_session_find_no_attr (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -659,71 +622,59 @@ test_session_find_no_attr (CuTest *cu) CK_ULONG count; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CreateObject (session, original, 3, &handle); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjectsInit (session, match, 1); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 0, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (0, count); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); - - teardown (cu); + assert_num_eq (CKR_OK, rv); } static void -test_lookup_invalid (CuTest *cu) +test_lookup_invalid (void) { CK_SESSION_HANDLE session; CK_ULONG size; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_GetObjectSize (session, 88888, &size); - CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID); - - teardown (cu); + assert (rv == CKR_OBJECT_HANDLE_INVALID); } static void -test_remove_token (CuTest *cu) +test_remove_token (void) { CK_SESSION_HANDLE session; CK_OBJECT_HANDLE handle; CK_ULONG count; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjectsInit (session, NULL, 0); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjects (session, &handle, 1, &count); - CuAssertTrue (cu, rv == CKR_OK); - CuAssertIntEquals (cu, 1, count); + assert (rv == CKR_OK); + assert_num_eq (1, count); rv = test.module->C_DestroyObject (session, handle); - CuAssertTrue (cu, rv == CKR_TOKEN_WRITE_PROTECTED); - - teardown (cu); + assert (rv == CKR_TOKEN_WRITE_PROTECTED); } static void -test_setattr_token (CuTest *cu) +test_setattr_token (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -737,26 +688,22 @@ test_setattr_token (CuTest *cu) CK_ULONG count; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjectsInit (session, NULL, 0); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_FindObjects (session, &handle, 1, &count); - CuAssertTrue (cu, rv == CKR_OK); - CuAssertIntEquals (cu, 1, count); + assert (rv == CKR_OK); + assert_num_eq (1, count); rv = test.module->C_SetAttributeValue (session, handle, original, 2); - CuAssertTrue (cu, rv == CKR_TOKEN_WRITE_PROTECTED); - - teardown (cu); + assert (rv == CKR_TOKEN_WRITE_PROTECTED); } static void -test_session_copy (CuTest *cu) +test_session_copy (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -771,25 +718,21 @@ test_session_copy (CuTest *cu) CK_ULONG size; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CreateObject (session, original, 2, &handle); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CopyObject (session, handle, original, 2, ©); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_GetObjectSize (session, copy, &size); - CuAssertIntEquals (cu, CKR_OK, rv); - - teardown (cu); + assert_num_eq (CKR_OK, rv); } static void -test_session_setattr (CuTest *cu) +test_session_setattr (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -802,22 +745,18 @@ test_session_setattr (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_CreateObject (session, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_SetAttributeValue (session, handle, original, 2); - CuAssertTrue (cu, rv == CKR_OK); - - teardown (cu); + assert (rv == CKR_OK); } static void -test_session_remove (CuTest *cu) +test_session_remove (void) { CK_ATTRIBUTE original[] = { { CKA_CLASS, &data, sizeof (data) }, @@ -830,25 +769,21 @@ test_session_remove (CuTest *cu) CK_OBJECT_HANDLE handle; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_CreateObject (session, original, 2, &handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_DestroyObject (session, handle); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); rv = test.module->C_DestroyObject (session, handle); - CuAssertTrue (cu, rv == CKR_OBJECT_HANDLE_INVALID); - - teardown (cu); + assert (rv == CKR_OBJECT_HANDLE_INVALID); } static void -test_find_serial_der_decoded (CuTest *cu) +test_find_serial_der_decoded (void) { CK_OBJECT_CLASS nss_trust = CKO_NSS_TRUST; @@ -881,39 +816,35 @@ test_find_serial_der_decoded (CuTest *cu) * See work_around_broken_nss_serial_number_lookups(). */ - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CreateObject (session, object, 2, &handle); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Do a standard find for the same object */ rv = test.module->C_FindObjectsInit (session, object, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 1, count); - CuAssertIntEquals (cu, handle, check); + assert_num_eq (CKR_OK, rv); + assert_num_eq (1, count); + assert_num_eq (handle, check); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Do a find for the serial number decoded */ rv = test.module->C_FindObjectsInit (session, match_decoded, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 1, count); - CuAssertIntEquals (cu, handle, check); + assert_num_eq (CKR_OK, rv); + assert_num_eq (1, count); + assert_num_eq (handle, check); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); - - teardown (cu); + assert_num_eq (CKR_OK, rv); } static void -test_find_serial_der_mismatch (CuTest *cu) +test_find_serial_der_mismatch (void) { CK_OBJECT_CLASS nss_trust = CKO_NSS_TRUST; @@ -935,107 +866,92 @@ test_find_serial_der_mismatch (CuTest *cu) CK_ULONG count; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_CreateObject (session, object, 2, &handle); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Do a find with a null serial number, no match */ rv = test.module->C_FindObjectsInit (session, match, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 0, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (0, count); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Do a find with a wrong length, no match */ match[0].pValue = "at"; match[0].ulValueLen = 2; rv = test.module->C_FindObjectsInit (session, match, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 0, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (0, count); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); /* Do a find with a right length, wrong value, no match */ match[0].pValue = "one"; match[0].ulValueLen = 3; rv = test.module->C_FindObjectsInit (session, match, 2); - CuAssertIntEquals (cu, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = test.module->C_FindObjects (session, &check, 1, &count); - CuAssertIntEquals (cu, CKR_OK, rv); - CuAssertIntEquals (cu, 0, count); + assert_num_eq (CKR_OK, rv); + assert_num_eq (0, count); rv = test.module->C_FindObjectsFinal (session); - CuAssertIntEquals (cu, CKR_OK, rv); - - teardown (cu); + assert_num_eq (CKR_OK, rv); } static void -test_login_logout (CuTest *cu) +test_login_logout (void) { CK_SESSION_HANDLE session; CK_RV rv; - setup (cu); - rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session); - CuAssertTrue (cu, rv == CKR_OK); + assert (rv == CKR_OK); /* Just testing our stubs for now */ rv = test.module->C_Login (session, CKU_USER, NULL, 0); - CuAssertTrue (cu, rv == CKR_USER_TYPE_INVALID); + assert (rv == CKR_USER_TYPE_INVALID); rv = test.module->C_Logout (session); - CuAssertTrue (cu, rv == CKR_USER_NOT_LOGGED_IN); - - teardown (cu); + assert (rv == CKR_USER_NOT_LOGGED_IN); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); p11_library_init (); - SUITE_ADD_TEST (suite, test_get_slot_list); - SUITE_ADD_TEST (suite, test_get_slot_info); - SUITE_ADD_TEST (suite, test_get_token_info); - SUITE_ADD_TEST (suite, test_get_session_info); - SUITE_ADD_TEST (suite, test_close_all_sessions); - SUITE_ADD_TEST (suite, test_find_certificates); - SUITE_ADD_TEST (suite, test_find_builtin); - SUITE_ADD_TEST (suite, test_lookup_invalid); - SUITE_ADD_TEST (suite, test_remove_token); - SUITE_ADD_TEST (suite, test_setattr_token); - SUITE_ADD_TEST (suite, test_session_object); - SUITE_ADD_TEST (suite, test_session_find); - SUITE_ADD_TEST (suite, test_session_find_no_attr); - SUITE_ADD_TEST (suite, test_session_copy); - SUITE_ADD_TEST (suite, test_session_remove); - SUITE_ADD_TEST (suite, test_session_setattr); - SUITE_ADD_TEST (suite, test_find_serial_der_decoded); - SUITE_ADD_TEST (suite, test_find_serial_der_mismatch); - SUITE_ADD_TEST (suite, test_login_logout); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_fixture (setup, teardown); + p11_test (test_get_slot_list, "/module/get_slot_list"); + p11_test (test_get_slot_info, "/module/get_slot_info"); + + p11_fixture (NULL, NULL); + p11_test (test_get_token_info, "/module/get_token_info"); + + p11_fixture (setup, teardown); + p11_test (test_get_session_info, "/module/get_session_info"); + p11_test (test_close_all_sessions, "/module/close_all_sessions"); + p11_test (test_find_certificates, "/module/find_certificates"); + p11_test (test_find_builtin, "/module/find_builtin"); + p11_test (test_lookup_invalid, "/module/lookup_invalid"); + p11_test (test_remove_token, "/module/remove_token"); + p11_test (test_setattr_token, "/module/setattr_token"); + p11_test (test_session_object, "/module/session_object"); + p11_test (test_session_find, "/module/session_find"); + p11_test (test_session_find_no_attr, "/module/session_find_no_attr"); + p11_test (test_session_copy, "/module/session_copy"); + p11_test (test_session_remove, "/module/session_remove"); + p11_test (test_session_setattr, "/module/session_setattr"); + p11_test (test_find_serial_der_decoded, "/module/find_serial_der_decoded"); + p11_test (test_find_serial_der_mismatch, "/module/find_serial_der_mismatch"); + p11_test (test_login_logout, "/module/login_logout"); + + return p11_test_run (argc, argv); } |