Create Certificate messages in TLS1.3 format
[openssl.git] / test / ssl_test.c
index fb6214e9fed14d916bf6e430a6043dd44233d7cd..2003fd70a3947d99da8d782459a16f80d634bd4c 100644 (file)
 #include "handshake_helper.h"
 #include "ssl_test_ctx.h"
 #include "testutil.h"
+#include "test_main_custom.h"
 
 static CONF *conf = NULL;
 
 /* Currently the section names are of the form test-<number>, e.g. test-15. */
 #define MAX_TESTCASE_NAME_LENGTH 100
 
-typedef struct ssl_test_ctx_test_fixture {
-    const char *test_case_name;
-    char test_app[MAX_TESTCASE_NAME_LENGTH];
-} SSL_TEST_FIXTURE;
-
-static SSL_TEST_FIXTURE set_up(const char *const test_case_name)
-{
-    SSL_TEST_FIXTURE fixture;
-    fixture.test_case_name = test_case_name;
-    return fixture;
-}
-
 static const char *print_alert(int alert)
 {
     return alert ? SSL_alert_desc_string_long(alert) : "no alert";
@@ -222,15 +211,18 @@ static int check_test(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
     return ret;
 }
 
-static int execute_test(SSL_TEST_FIXTURE fixture)
+static int test_handshake(int idx)
 {
     int ret = 0;
     SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL,
         *resume_server_ctx = NULL, *resume_client_ctx = NULL;
     SSL_TEST_CTX *test_ctx = NULL;
     HANDSHAKE_RESULT *result = NULL;
+    char test_app[MAX_TESTCASE_NAME_LENGTH];
+
+    BIO_snprintf(test_app, sizeof(test_app), "test-%d", idx);
 
-    test_ctx = SSL_TEST_CTX_create(conf, fixture.test_app);
+    test_ctx = SSL_TEST_CTX_create(conf, test_app);
     if (test_ctx == NULL)
         goto err;
 
@@ -272,7 +264,7 @@ static int execute_test(SSL_TEST_FIXTURE fixture)
     TEST_check(server_ctx != NULL);
     TEST_check(client_ctx != NULL);
 
-    TEST_check(CONF_modules_load(conf, fixture.test_app, 0) > 0);
+    TEST_check(CONF_modules_load(conf, test_app, 0) > 0);
 
     if (!SSL_CTX_config(server_ctx, "server")
         || !SSL_CTX_config(client_ctx, "client")) {
@@ -305,24 +297,7 @@ err:
     return ret;
 }
 
-static void tear_down(SSL_TEST_FIXTURE fixture)
-{
-}
-
-#define SETUP_SSL_TEST_FIXTURE()                        \
-    SETUP_TEST_FIXTURE(SSL_TEST_FIXTURE, set_up)
-#define EXECUTE_SSL_TEST()             \
-    EXECUTE_TEST(execute_test, tear_down)
-
-static int test_handshake(int idx)
-{
-    SETUP_SSL_TEST_FIXTURE();
-    BIO_snprintf(fixture.test_app, sizeof(fixture.test_app),
-                 "test-%d", idx);
-    EXECUTE_SSL_TEST();
-}
-
-int main(int argc, char **argv)
+int test_main(int argc, char **argv)
 {
     int result = 0;
     long num_tests;
@@ -341,5 +316,6 @@ int main(int argc, char **argv)
     ADD_ALL_TESTS(test_handshake, (int)(num_tests));
     result = run_tests(argv[0]);
 
+    NCONF_free(conf);
     return result;
 }