diff --git a/tests/jwt_dump.c b/tests/jwt_dump.c index 99d53b9..104be73 100644 --- a/tests/jwt_dump.c +++ b/tests/jwt_dump.c @@ -373,31 +373,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT Dump - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT Dump"); } diff --git a/tests/jwt_ec.c b/tests/jwt_ec.c index 8592075..8e3886a 100644 --- a/tests/jwt_ec.c +++ b/tests/jwt_ec.c @@ -319,31 +319,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT EC Sign/Verify - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT EC Sign/Verify"); } diff --git a/tests/jwt_eddsa.c b/tests/jwt_eddsa.c index 2405eb6..879c245 100644 --- a/tests/jwt_eddsa.c +++ b/tests/jwt_eddsa.c @@ -182,31 +182,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT EdDSA Sign/Verify - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT EdDSA Sign/Verify"); } diff --git a/tests/jwt_encode.c b/tests/jwt_encode.c index 1d404ad..9eef6df 100644 --- a/tests/jwt_encode.c +++ b/tests/jwt_encode.c @@ -392,31 +392,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT Encode - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT Encode"); } diff --git a/tests/jwt_grant.c b/tests/jwt_grant.c index 9346570..09b74e9 100644 --- a/tests/jwt_grant.c +++ b/tests/jwt_grant.c @@ -253,31 +253,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT Grant - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT Grant"); } diff --git a/tests/jwt_header.c b/tests/jwt_header.c index a767a23..32c7d82 100644 --- a/tests/jwt_header.c +++ b/tests/jwt_header.c @@ -253,31 +253,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT Header - %s", jwt_test_ops[i]) < 1) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT Header"); } diff --git a/tests/jwt_new.c b/tests/jwt_new.c index d38c5be..81b8653 100644 --- a/tests/jwt_new.c +++ b/tests/jwt_new.c @@ -484,31 +484,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT New - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT New"); } diff --git a/tests/jwt_rsa.c b/tests/jwt_rsa.c index f2b110c..87f3dc8 100644 --- a/tests/jwt_rsa.c +++ b/tests/jwt_rsa.c @@ -402,31 +402,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT RSA Sign/Verify - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT RSA Sign/Verify"); } diff --git a/tests/jwt_rsa_pss.c b/tests/jwt_rsa_pss.c index 94e6ce7..b9c9fe9 100644 --- a/tests/jwt_rsa_pss.c +++ b/tests/jwt_rsa_pss.c @@ -233,31 +233,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT RSA-PSS Sign/Verify - %s", jwt_test_ops[i]) < 0) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT RSA-PSS Sign/Verify"); } diff --git a/tests/jwt_tests.h b/tests/jwt_tests.h index 39991f3..887bd34 100644 --- a/tests/jwt_tests.h +++ b/tests/jwt_tests.h @@ -15,4 +15,34 @@ static const char *jwt_test_ops[] = { NULL }; +#define JWT_TEST_MAIN(__title) ({ \ + int number_failed = 0; \ + int i; \ + \ + for (i = 0; jwt_test_ops[i] != NULL; i++) { \ + SRunner *sr; \ + Suite *s; \ + char *title; \ + const char *name = jwt_test_ops[i]; \ + \ + if (jwt_set_crypto_ops(name)) \ + continue; \ + \ + if (asprintf(&title, __title " - %s", jwt_test_ops[i]) < 0) \ + exit(1); \ + \ + /* Set this because we fork */ \ + setenv("JWT_CRYPTO", name, 1); \ + \ + s = libjwt_suite(title); \ + sr = srunner_create(s); \ + \ + srunner_run_all(sr, CK_VERBOSE); \ + number_failed += srunner_ntests_failed(sr); \ + srunner_free(sr); \ + } \ + \ + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; \ +}) + #endif /* JWT_TESTS_H */ diff --git a/tests/jwt_validate.c b/tests/jwt_validate.c index e6bfb9f..4183c18 100644 --- a/tests/jwt_validate.c +++ b/tests/jwt_validate.c @@ -646,9 +646,9 @@ static Suite *libjwt_suite(const char *title) Suite *s; TCase *tc_core; - s = suite_create("LibJWT Grant"); + s = suite_create(title); - tc_core = tcase_create("jwt_grant"); + tc_core = tcase_create("jwt_validate"); tcase_add_test(tc_core, test_jwt_validate_errno); tcase_add_test(tc_core, test_jwt_valid_algorithm); @@ -676,31 +676,5 @@ static Suite *libjwt_suite(const char *title) int main(int argc, char *argv[]) { - int number_failed = 0; - Suite *s; - SRunner *sr; - int i; - - for (i = 0; jwt_test_ops[i] != NULL; i++) { - char *title; - const char *name = jwt_test_ops[i]; - - if (jwt_set_crypto_ops(name)) - continue; - - if (asprintf(&title, "LibJWT EC Sign/Verify - %s", jwt_test_ops[i]) < 1) - exit(1); - - /* Set this because we fork */ - setenv("JWT_CRYPTO", name, 1); - - s = libjwt_suite(title); - sr = srunner_create(s); - - srunner_run_all(sr, CK_VERBOSE); - number_failed += srunner_ntests_failed(sr); - srunner_free(sr); - } - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + JWT_TEST_MAIN("LibJWT Validate"); }