Loading test/cipherlist_test.c +5 −1 Original line number Original line Diff line number Diff line Loading @@ -181,7 +181,7 @@ static int execute_test(CIPHERLIST_TEST_FIXTURE *fixture) } } #define SETUP_CIPHERLIST_TEST_FIXTURE() \ #define SETUP_CIPHERLIST_TEST_FIXTURE() \ SETUP_TEST_FIXTURE(CIPHERLIST_TEST_FIXTURE *, set_up) SETUP_TEST_FIXTURE(CIPHERLIST_TEST_FIXTURE, set_up) #define EXECUTE_CIPHERLIST_TEST() \ #define EXECUTE_CIPHERLIST_TEST() \ EXECUTE_TEST(execute_test, tear_down) EXECUTE_TEST(execute_test, tear_down) Loading @@ -189,7 +189,10 @@ static int execute_test(CIPHERLIST_TEST_FIXTURE *fixture) static int test_default_cipherlist_implicit() static int test_default_cipherlist_implicit() { { SETUP_CIPHERLIST_TEST_FIXTURE(); SETUP_CIPHERLIST_TEST_FIXTURE(); if (fixture == NULL) return 0; EXECUTE_CIPHERLIST_TEST(); EXECUTE_CIPHERLIST_TEST(); return result; } } static int test_default_cipherlist_explicit() static int test_default_cipherlist_explicit() Loading @@ -201,6 +204,7 @@ static int test_default_cipherlist_explicit() || !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT"))) || !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT"))) tear_down(fixture); tear_down(fixture); EXECUTE_CIPHERLIST_TEST(); EXECUTE_CIPHERLIST_TEST(); return result; } } int setup_tests() int setup_tests() Loading test/ct_test.c +25 −1 Original line number Original line Diff line number Diff line Loading @@ -344,22 +344,27 @@ end: return success; return success; } } # define SETUP_CT_TEST_FIXTURE() SETUP_TEST_FIXTURE(CT_TEST_FIXTURE *, set_up) # define SETUP_CT_TEST_FIXTURE() SETUP_TEST_FIXTURE(CT_TEST_FIXTURE, set_up) # define EXECUTE_CT_TEST() EXECUTE_TEST(execute_cert_test, tear_down) # define EXECUTE_CT_TEST() EXECUTE_TEST(execute_cert_test, tear_down) static int test_no_scts_in_certificate(void) static int test_no_scts_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "leaf.pem"; fixture->certificate_file = "leaf.pem"; fixture->issuer_file = "subinterCA.pem"; fixture->issuer_file = "subinterCA.pem"; fixture->expected_sct_count = 0; fixture->expected_sct_count = 0; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_one_sct_in_certificate(void) static int test_one_sct_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; Loading @@ -367,11 +372,14 @@ static int test_one_sct_in_certificate(void) fixture->sct_dir = certs_dir; fixture->sct_dir = certs_dir; fixture->sct_text_file = "embeddedSCTs1.sct"; fixture->sct_text_file = "embeddedSCTs1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_multiple_scts_in_certificate(void) static int test_multiple_scts_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; Loading @@ -379,33 +387,42 @@ static int test_multiple_scts_in_certificate(void) fixture->sct_dir = certs_dir; fixture->sct_dir = certs_dir; fixture->sct_text_file = "embeddedSCTs3.sct"; fixture->sct_text_file = "embeddedSCTs3.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_one_sct(void) static int test_verify_one_sct(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->expected_sct_count = fixture->expected_valid_sct_count = 1; fixture->expected_sct_count = fixture->expected_valid_sct_count = 1; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_multiple_scts(void) static int test_verify_multiple_scts(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->expected_sct_count = fixture->expected_valid_sct_count = 3; fixture->expected_sct_count = fixture->expected_valid_sct_count = 3; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_fails_for_future_sct(void) static int test_verify_fails_for_future_sct(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */ fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */ fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; Loading @@ -414,6 +431,7 @@ static int test_verify_fails_for_future_sct(void) fixture->expected_valid_sct_count = 0; fixture->expected_valid_sct_count = 0; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_decode_tls_sct(void) static int test_decode_tls_sct(void) Loading @@ -437,11 +455,14 @@ static int test_decode_tls_sct(void) "\xED\xBF\x08"; "\xED\xBF\x08"; SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->tls_sct_list = tls_sct_list; fixture->tls_sct_list = tls_sct_list; fixture->tls_sct_list_len = 0x7a; fixture->tls_sct_list_len = 0x7a; fixture->sct_dir = ct_dir; fixture->sct_dir = ct_dir; fixture->sct_text_file = "tls1.sct"; fixture->sct_text_file = "tls1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_encode_tls_sct(void) static int test_encode_tls_sct(void) Loading @@ -454,6 +475,8 @@ static int test_encode_tls_sct(void) SCT *sct = NULL; SCT *sct = NULL; SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->sct_list = sk_SCT_new_null(); fixture->sct_list = sk_SCT_new_null(); if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id, if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id, Loading @@ -466,6 +489,7 @@ static int test_encode_tls_sct(void) fixture->sct_dir = ct_dir; fixture->sct_dir = ct_dir; fixture->sct_text_file = "tls1.sct"; fixture->sct_text_file = "tls1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } /* /* Loading test/ssl_test_ctx_test.c +7 −3 Original line number Original line Diff line number Diff line Loading @@ -133,23 +133,26 @@ static void tear_down(SSL_TEST_CTX_TEST_FIXTURE *fixture) } } #define SETUP_SSL_TEST_CTX_TEST_FIXTURE() \ #define SETUP_SSL_TEST_CTX_TEST_FIXTURE() \ SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE *, set_up); \ SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE, set_up); if (fixture == NULL) \ return 0 #define EXECUTE_SSL_TEST_CTX_TEST() \ #define EXECUTE_SSL_TEST_CTX_TEST() \ EXECUTE_TEST(execute_test, tear_down) EXECUTE_TEST(execute_test, tear_down) static int test_empty_configuration() static int test_empty_configuration() { { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); SETUP_SSL_TEST_CTX_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->test_section = "ssltest_default"; fixture->test_section = "ssltest_default"; fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS; fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS; EXECUTE_SSL_TEST_CTX_TEST(); EXECUTE_SSL_TEST_CTX_TEST(); return result; } } static int test_good_configuration() static int test_good_configuration() { { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); SETUP_SSL_TEST_CTX_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->test_section = "ssltest_good"; fixture->test_section = "ssltest_good"; fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS; fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS; fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME; fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME; Loading Loading @@ -186,6 +189,7 @@ static int test_good_configuration() SSL_TEST_CT_VALIDATION_STRICT; SSL_TEST_CT_VALIDATION_STRICT; EXECUTE_SSL_TEST_CTX_TEST(); EXECUTE_SSL_TEST_CTX_TEST(); return result; err: err: tear_down(fixture); tear_down(fixture); Loading test/testutil.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -65,12 +65,13 @@ * SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE * SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE * object called "fixture". It will also allocate the "result" variable used * object called "fixture". It will also allocate the "result" variable used * by EXECUTE_TEST. set_up() should take a const char* specifying the test * by EXECUTE_TEST. set_up() should take a const char* specifying the test * case name and return a TEST_FIXTURE_TYPE by value. * case name and return a TEST_FIXTURE_TYPE by reference. * * * EXECUTE_TEST will pass fixture to execute_func() by value, call * EXECUTE_TEST will pass fixture to execute_func() by reference, call * tear_down(), and return the result of execute_func(). execute_func() should * tear_down(), and return the result of execute_func(). execute_func() should * take a TEST_FIXTURE_TYPE by value and return 1 on success and 0 on * take a TEST_FIXTURE_TYPE by reference and return 1 on success and 0 on * failure. * failure. The tear_down function is responsible for deallocation of the * result variable, if required. * * * Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST * Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST * variations like so: * variations like so: Loading @@ -91,13 +92,14 @@ * } * } */ */ # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\ # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\ TEST_FIXTURE_TYPE fixture = set_up(TEST_CASE_NAME); \ TEST_FIXTURE_TYPE *fixture = set_up(TEST_CASE_NAME); \ int result = 0 int result = 0 # define EXECUTE_TEST(execute_func, tear_down)\ # define EXECUTE_TEST(execute_func, tear_down)\ if (fixture != NULL) {\ result = execute_func(fixture);\ result = execute_func(fixture);\ tear_down(fixture);\ tear_down(fixture);\ return result } /* /* * TEST_CASE_NAME is defined as the name of the test case function where * TEST_CASE_NAME is defined as the name of the test case function where Loading Loading
test/cipherlist_test.c +5 −1 Original line number Original line Diff line number Diff line Loading @@ -181,7 +181,7 @@ static int execute_test(CIPHERLIST_TEST_FIXTURE *fixture) } } #define SETUP_CIPHERLIST_TEST_FIXTURE() \ #define SETUP_CIPHERLIST_TEST_FIXTURE() \ SETUP_TEST_FIXTURE(CIPHERLIST_TEST_FIXTURE *, set_up) SETUP_TEST_FIXTURE(CIPHERLIST_TEST_FIXTURE, set_up) #define EXECUTE_CIPHERLIST_TEST() \ #define EXECUTE_CIPHERLIST_TEST() \ EXECUTE_TEST(execute_test, tear_down) EXECUTE_TEST(execute_test, tear_down) Loading @@ -189,7 +189,10 @@ static int execute_test(CIPHERLIST_TEST_FIXTURE *fixture) static int test_default_cipherlist_implicit() static int test_default_cipherlist_implicit() { { SETUP_CIPHERLIST_TEST_FIXTURE(); SETUP_CIPHERLIST_TEST_FIXTURE(); if (fixture == NULL) return 0; EXECUTE_CIPHERLIST_TEST(); EXECUTE_CIPHERLIST_TEST(); return result; } } static int test_default_cipherlist_explicit() static int test_default_cipherlist_explicit() Loading @@ -201,6 +204,7 @@ static int test_default_cipherlist_explicit() || !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT"))) || !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT"))) tear_down(fixture); tear_down(fixture); EXECUTE_CIPHERLIST_TEST(); EXECUTE_CIPHERLIST_TEST(); return result; } } int setup_tests() int setup_tests() Loading
test/ct_test.c +25 −1 Original line number Original line Diff line number Diff line Loading @@ -344,22 +344,27 @@ end: return success; return success; } } # define SETUP_CT_TEST_FIXTURE() SETUP_TEST_FIXTURE(CT_TEST_FIXTURE *, set_up) # define SETUP_CT_TEST_FIXTURE() SETUP_TEST_FIXTURE(CT_TEST_FIXTURE, set_up) # define EXECUTE_CT_TEST() EXECUTE_TEST(execute_cert_test, tear_down) # define EXECUTE_CT_TEST() EXECUTE_TEST(execute_cert_test, tear_down) static int test_no_scts_in_certificate(void) static int test_no_scts_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "leaf.pem"; fixture->certificate_file = "leaf.pem"; fixture->issuer_file = "subinterCA.pem"; fixture->issuer_file = "subinterCA.pem"; fixture->expected_sct_count = 0; fixture->expected_sct_count = 0; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_one_sct_in_certificate(void) static int test_one_sct_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; Loading @@ -367,11 +372,14 @@ static int test_one_sct_in_certificate(void) fixture->sct_dir = certs_dir; fixture->sct_dir = certs_dir; fixture->sct_text_file = "embeddedSCTs1.sct"; fixture->sct_text_file = "embeddedSCTs1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_multiple_scts_in_certificate(void) static int test_multiple_scts_in_certificate(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; Loading @@ -379,33 +387,42 @@ static int test_multiple_scts_in_certificate(void) fixture->sct_dir = certs_dir; fixture->sct_dir = certs_dir; fixture->sct_text_file = "embeddedSCTs3.sct"; fixture->sct_text_file = "embeddedSCTs3.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_one_sct(void) static int test_verify_one_sct(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; fixture->expected_sct_count = fixture->expected_valid_sct_count = 1; fixture->expected_sct_count = fixture->expected_valid_sct_count = 1; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_multiple_scts(void) static int test_verify_multiple_scts(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; fixture->expected_sct_count = fixture->expected_valid_sct_count = 3; fixture->expected_sct_count = fixture->expected_valid_sct_count = 3; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_verify_fails_for_future_sct(void) static int test_verify_fails_for_future_sct(void) { { SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */ fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */ fixture->certs_dir = certs_dir; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->certificate_file = "embeddedSCTs1.pem"; Loading @@ -414,6 +431,7 @@ static int test_verify_fails_for_future_sct(void) fixture->expected_valid_sct_count = 0; fixture->expected_valid_sct_count = 0; fixture->test_validity = 1; fixture->test_validity = 1; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_decode_tls_sct(void) static int test_decode_tls_sct(void) Loading @@ -437,11 +455,14 @@ static int test_decode_tls_sct(void) "\xED\xBF\x08"; "\xED\xBF\x08"; SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->tls_sct_list = tls_sct_list; fixture->tls_sct_list = tls_sct_list; fixture->tls_sct_list_len = 0x7a; fixture->tls_sct_list_len = 0x7a; fixture->sct_dir = ct_dir; fixture->sct_dir = ct_dir; fixture->sct_text_file = "tls1.sct"; fixture->sct_text_file = "tls1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } static int test_encode_tls_sct(void) static int test_encode_tls_sct(void) Loading @@ -454,6 +475,8 @@ static int test_encode_tls_sct(void) SCT *sct = NULL; SCT *sct = NULL; SETUP_CT_TEST_FIXTURE(); SETUP_CT_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->sct_list = sk_SCT_new_null(); fixture->sct_list = sk_SCT_new_null(); if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id, if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id, Loading @@ -466,6 +489,7 @@ static int test_encode_tls_sct(void) fixture->sct_dir = ct_dir; fixture->sct_dir = ct_dir; fixture->sct_text_file = "tls1.sct"; fixture->sct_text_file = "tls1.sct"; EXECUTE_CT_TEST(); EXECUTE_CT_TEST(); return result; } } /* /* Loading
test/ssl_test_ctx_test.c +7 −3 Original line number Original line Diff line number Diff line Loading @@ -133,23 +133,26 @@ static void tear_down(SSL_TEST_CTX_TEST_FIXTURE *fixture) } } #define SETUP_SSL_TEST_CTX_TEST_FIXTURE() \ #define SETUP_SSL_TEST_CTX_TEST_FIXTURE() \ SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE *, set_up); \ SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE, set_up); if (fixture == NULL) \ return 0 #define EXECUTE_SSL_TEST_CTX_TEST() \ #define EXECUTE_SSL_TEST_CTX_TEST() \ EXECUTE_TEST(execute_test, tear_down) EXECUTE_TEST(execute_test, tear_down) static int test_empty_configuration() static int test_empty_configuration() { { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); SETUP_SSL_TEST_CTX_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->test_section = "ssltest_default"; fixture->test_section = "ssltest_default"; fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS; fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS; EXECUTE_SSL_TEST_CTX_TEST(); EXECUTE_SSL_TEST_CTX_TEST(); return result; } } static int test_good_configuration() static int test_good_configuration() { { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); SETUP_SSL_TEST_CTX_TEST_FIXTURE(); if (fixture == NULL) return 0; fixture->test_section = "ssltest_good"; fixture->test_section = "ssltest_good"; fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS; fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS; fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME; fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME; Loading Loading @@ -186,6 +189,7 @@ static int test_good_configuration() SSL_TEST_CT_VALIDATION_STRICT; SSL_TEST_CT_VALIDATION_STRICT; EXECUTE_SSL_TEST_CTX_TEST(); EXECUTE_SSL_TEST_CTX_TEST(); return result; err: err: tear_down(fixture); tear_down(fixture); Loading
test/testutil.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -65,12 +65,13 @@ * SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE * SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE * object called "fixture". It will also allocate the "result" variable used * object called "fixture". It will also allocate the "result" variable used * by EXECUTE_TEST. set_up() should take a const char* specifying the test * by EXECUTE_TEST. set_up() should take a const char* specifying the test * case name and return a TEST_FIXTURE_TYPE by value. * case name and return a TEST_FIXTURE_TYPE by reference. * * * EXECUTE_TEST will pass fixture to execute_func() by value, call * EXECUTE_TEST will pass fixture to execute_func() by reference, call * tear_down(), and return the result of execute_func(). execute_func() should * tear_down(), and return the result of execute_func(). execute_func() should * take a TEST_FIXTURE_TYPE by value and return 1 on success and 0 on * take a TEST_FIXTURE_TYPE by reference and return 1 on success and 0 on * failure. * failure. The tear_down function is responsible for deallocation of the * result variable, if required. * * * Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST * Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST * variations like so: * variations like so: Loading @@ -91,13 +92,14 @@ * } * } */ */ # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\ # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\ TEST_FIXTURE_TYPE fixture = set_up(TEST_CASE_NAME); \ TEST_FIXTURE_TYPE *fixture = set_up(TEST_CASE_NAME); \ int result = 0 int result = 0 # define EXECUTE_TEST(execute_func, tear_down)\ # define EXECUTE_TEST(execute_func, tear_down)\ if (fixture != NULL) {\ result = execute_func(fixture);\ result = execute_func(fixture);\ tear_down(fixture);\ tear_down(fixture);\ return result } /* /* * TEST_CASE_NAME is defined as the name of the test case function where * TEST_CASE_NAME is defined as the name of the test case function where Loading