diff options
Diffstat (limited to 'common/tests/test-constants.c')
-rw-r--r-- | common/tests/test-constants.c | 85 |
1 files changed, 35 insertions, 50 deletions
diff --git a/common/tests/test-constants.c b/common/tests/test-constants.c index 4cd4472..9adc81a 100644 --- a/common/tests/test-constants.c +++ b/common/tests/test-constants.c @@ -33,7 +33,7 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" #include <stdlib.h> #include <stdio.h> @@ -44,50 +44,38 @@ #include "debug.h" static void -test_constants (CuTest *tc) +test_constants (void *arg) { - const p11_constant *constant; + const p11_constant *constant = arg; p11_dict *nicks, *names; CK_ULONG check; - int i, j; - - static const p11_constant *constants[] = { - p11_constant_types, - p11_constant_classes, - p11_constant_trusts, - p11_constant_certs, - p11_constant_keys, - p11_constant_asserts, - p11_constant_categories, - NULL - }; + int i; nicks = p11_constant_reverse (true); names = p11_constant_reverse (false); - for (j = 0; constants[j] != NULL; j++) { - constant = constants[j]; - for (i = 1; constant[i].value != CKA_INVALID; i++) { - if (constant[i].value < constant[i - 1].value) { - CuFail_Line (tc, __FILE__, __LINE__, - "attr constant out of order", constant[i].name); - } + for (i = 1; constant[i].value != CKA_INVALID; i++) { + if (constant[i].value < constant[i - 1].value) + assert_fail ("attr constant out of order", constant[i].name); + } + for (i = 0; constant[i].value != CKA_INVALID; i++) { + assert_ptr_not_null (constant[i].name); + + if (constant[i].nick) { + assert_str_eq (constant[i].nick, + p11_constant_nick (constant, constant[i].value)); } - for (i = 0; constant[i].value != CKA_INVALID; i++) { - CuAssertPtrNotNull (tc, constant[i].nick); - CuAssertPtrNotNull (tc, constant[i].name); - CuAssertStrEquals (tc, constant[i].nick, - p11_constant_nick (constant, constant[i].value)); - CuAssertStrEquals (tc, constant[i].name, - p11_constant_name (constant, constant[i].value)); + assert_str_eq (constant[i].name, + p11_constant_name (constant, constant[i].value)); + if (constant[i].nick) { check = p11_constant_resolve (nicks, constant[i].nick); - CuAssertIntEquals (tc, constant[i].value, check); - - check = p11_constant_resolve (names, constant[i].name); - CuAssertIntEquals (tc, constant[i].value, check); + assert_num_eq (constant[i].value, check); } + + check = p11_constant_resolve (names, constant[i].name); + assert_num_eq (constant[i].value, check); } p11_dict_free (names); @@ -95,23 +83,20 @@ test_constants (CuTest *tc) } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - SUITE_ADD_TEST (suite, test_constants); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); + p11_testx (test_constants, (void *)p11_constant_types, "/constants/types"); + p11_testx (test_constants, (void *)p11_constant_classes, "/constants/classes"); + p11_testx (test_constants, (void *)p11_constant_trusts, "/constants/trusts"); + p11_testx (test_constants, (void *)p11_constant_certs, "/constants/certs"); + p11_testx (test_constants, (void *)p11_constant_keys, "/constants/keys"); + p11_testx (test_constants, (void *)p11_constant_asserts, "/constants/asserts"); + p11_testx (test_constants, (void *)p11_constant_categories, "/constants/categories"); + p11_testx (test_constants, (void *)p11_constant_mechanisms, "/constants/mechanisms"); + p11_testx (test_constants, (void *)p11_constant_users, "/constants/users"); + p11_testx (test_constants, (void *)p11_constant_states, "/constants/states"); + p11_testx (test_constants, (void *)p11_constant_returns, "/constants/returns"); - return ret; + return p11_test_run (argc, argv); } |