reference not by value. This allows an error return from the setup function.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4083)
}
#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() \
EXECUTE_TEST(execute_test, tear_down)
static int test_default_cipherlist_implicit()
{
SETUP_CIPHERLIST_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
EXECUTE_CIPHERLIST_TEST();
+ return result;
}
static int test_default_cipherlist_explicit()
|| !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT")))
tear_down(fixture);
EXECUTE_CIPHERLIST_TEST();
+ return result;
}
int setup_tests()
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)
static int test_no_scts_in_certificate(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->certs_dir = certs_dir;
fixture->certificate_file = "leaf.pem";
fixture->issuer_file = "subinterCA.pem";
fixture->expected_sct_count = 0;
EXECUTE_CT_TEST();
+ return result;
}
static int test_one_sct_in_certificate(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs1.pem";
fixture->issuer_file = "embeddedSCTs1_issuer.pem";
fixture->sct_dir = certs_dir;
fixture->sct_text_file = "embeddedSCTs1.sct";
EXECUTE_CT_TEST();
+ return result;
}
static int test_multiple_scts_in_certificate(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs3.pem";
fixture->issuer_file = "embeddedSCTs3_issuer.pem";
fixture->sct_dir = certs_dir;
fixture->sct_text_file = "embeddedSCTs3.sct";
EXECUTE_CT_TEST();
+ return result;
}
static int test_verify_one_sct(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs1.pem";
fixture->issuer_file = "embeddedSCTs1_issuer.pem";
fixture->expected_sct_count = fixture->expected_valid_sct_count = 1;
fixture->test_validity = 1;
EXECUTE_CT_TEST();
+ return result;
}
static int test_verify_multiple_scts(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs3.pem";
fixture->issuer_file = "embeddedSCTs3_issuer.pem";
fixture->expected_sct_count = fixture->expected_valid_sct_count = 3;
fixture->test_validity = 1;
EXECUTE_CT_TEST();
+ return result;
}
static int test_verify_fails_for_future_sct(void)
{
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->epoch_time_in_ms = 1365094800000; /* Apr 4 17:00:00 2013 GMT */
fixture->certs_dir = certs_dir;
fixture->certificate_file = "embeddedSCTs1.pem";
fixture->expected_valid_sct_count = 0;
fixture->test_validity = 1;
EXECUTE_CT_TEST();
+ return result;
}
static int test_decode_tls_sct(void)
"\xED\xBF\x08";
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->tls_sct_list = tls_sct_list;
fixture->tls_sct_list_len = 0x7a;
fixture->sct_dir = ct_dir;
fixture->sct_text_file = "tls1.sct";
EXECUTE_CT_TEST();
+ return result;
}
static int test_encode_tls_sct(void)
SCT *sct = NULL;
SETUP_CT_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->sct_list = sk_SCT_new_null();
if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id,
fixture->sct_dir = ct_dir;
fixture->sct_text_file = "tls1.sct";
EXECUTE_CT_TEST();
+ return result;
}
/*
}
#define SETUP_SSL_TEST_CTX_TEST_FIXTURE() \
- SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE *, set_up); \
- if (fixture == NULL) \
- return 0
+ SETUP_TEST_FIXTURE(SSL_TEST_CTX_TEST_FIXTURE, set_up);
#define EXECUTE_SSL_TEST_CTX_TEST() \
EXECUTE_TEST(execute_test, tear_down)
static int test_empty_configuration()
{
SETUP_SSL_TEST_CTX_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->test_section = "ssltest_default";
fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS;
EXECUTE_SSL_TEST_CTX_TEST();
+ return result;
}
static int test_good_configuration()
{
SETUP_SSL_TEST_CTX_TEST_FIXTURE();
+ if (fixture == NULL)
+ return 0;
fixture->test_section = "ssltest_good";
fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS;
fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME;
SSL_TEST_CT_VALIDATION_STRICT;
EXECUTE_SSL_TEST_CTX_TEST();
+ return result;
err:
tear_down(fixture);
* 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
* 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
- * take a TEST_FIXTURE_TYPE by value and return 1 on success and 0 on
- * failure.
+ * take a TEST_FIXTURE_TYPE by reference and return 1 on success and 0 on
+ * 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
* variations like so:
* }
*/
# 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
# define EXECUTE_TEST(execute_func, tear_down)\
+ if (fixture != NULL) {\
result = execute_func(fixture);\
tear_down(fixture);\
- return result
+ }
/*
* TEST_CASE_NAME is defined as the name of the test case function where