include/openssl/macros.h: better OPENSSL_FUNC fallback
[openssl.git] / test / context_internal_test.c
index 7052de2322fa35ccf3d4f44d58f7cd9884c9b9ac..6c675bcf9dc99bc5bb5651c61b4b31da6530e05c 100644 (file)
  * BEGIN EXAMPLE
  */
 
-/* The index will always be entirely global, and dynamically allocated */
-static int foo_index = -1;
-
 typedef struct foo_st {
     int i;
     void *data;
 } FOO;
 
-static void *foo_new(void)
+static void *foo_new(OPENSSL_CTX *ctx)
 {
     FOO *ptr = OPENSSL_zalloc(sizeof(*ptr));
     if (ptr != NULL)
@@ -46,12 +43,6 @@ static const OPENSSL_CTX_METHOD foo_method = {
     foo_free
 };
 
-static int foo_init(void) {
-    foo_index = openssl_ctx_new_index(&foo_method);
-
-    return foo_index != -1;
-}
-
 /*
  * END EXAMPLE
  * ======================================================================
@@ -61,15 +52,17 @@ static int test_context(OPENSSL_CTX *ctx)
 {
     FOO *data = NULL;
 
-    return (TEST_ptr(data = openssl_ctx_get_data(ctx, foo_index))
-            /* OPENSSL_zalloc in foo_new() initialized it to zero */
-            && TEST_int_eq(data->i, 42));
+    return TEST_ptr(data = openssl_ctx_get_data(ctx, 0, &foo_method))
+        /* OPENSSL_zalloc in foo_new() initialized it to zero */
+        && TEST_int_eq(data->i, 42);
 }
 
 static int test_app_context(void)
 {
     OPENSSL_CTX *ctx = NULL;
-    int result = (TEST_ptr(ctx = OPENSSL_CTX_new()) && test_context(ctx));
+    int result =
+        TEST_ptr(ctx = OPENSSL_CTX_new())
+        && test_context(ctx);
 
     OPENSSL_CTX_free(ctx);
     return result;
@@ -82,7 +75,6 @@ static int test_def_context(void)
 
 int setup_tests(void)
 {
-    ADD_TEST(foo_init);
     ADD_TEST(test_app_context);
     ADD_TEST(test_def_context);
     return 1;