INSTALL.md: Restore $ as command prompt indicator
[oweals/openssl.git] / test / enginetest.c
index 096a334d1f552fe66d82d1c3afa0c96c5e26abeb..9957f59dc3d6cbcaeba127155e437726c239b140 100644 (file)
@@ -44,8 +44,9 @@ static void display_engine_list(void)
 static int test_engines(void)
 {
     ENGINE *block[NUMTOADD];
+    char *eid[NUMTOADD];
+    char *ename[NUMTOADD];
     char buf[256];
-    const char *id, *name;
     ENGINE *ptr;
     int loop;
     int to_return = 0;
@@ -120,8 +121,12 @@ static int test_engines(void)
     display_engine_list();
 
     /*
-     * Depending on whether there's any hardware support compiled in, this
-     * remove may be destined to fail.
+     * At this point, we should have an empty list, unless some hardware
+     * support engine got added.  However, since we don't allow the config
+     * file to be loaded and don't otherwise load any built in engines,
+     * that is unlikely.  Still, we check, if for nothing else, then to
+     * notify that something is a little off (and might mean that |new_h1|
+     * wasn't unloaded when it should have)
      */
     if ((ptr = ENGINE_get_first()) != NULL) {
         if (!ENGINE_remove(ptr))
@@ -138,12 +143,12 @@ static int test_engines(void)
     TEST_info("About to beef up the engine-type list");
     for (loop = 0; loop < NUMTOADD; loop++) {
         sprintf(buf, "id%d", loop);
-        id = OPENSSL_strdup(buf);
+        eid[loop] = OPENSSL_strdup(buf);
         sprintf(buf, "Fake engine type %d", loop);
-        name = OPENSSL_strdup(buf);
+        ename[loop] = OPENSSL_strdup(buf);
         if (!TEST_ptr(block[loop] = ENGINE_new())
-                || !TEST_true(ENGINE_set_id(block[loop], id))
-                || !TEST_true(ENGINE_set_name(block[loop], name)))
+                || !TEST_true(ENGINE_set_id(block[loop], eid[loop]))
+                || !TEST_true(ENGINE_set_name(block[loop], ename[loop])))
             goto end;
     }
     for (loop = 0; loop < NUMTOADD; loop++) {
@@ -162,8 +167,8 @@ static int test_engines(void)
         ENGINE_free(ptr);
     }
     for (loop = 0; loop < NUMTOADD; loop++) {
-        OPENSSL_free((void *)ENGINE_get_id(block[loop]));
-        OPENSSL_free((void *)ENGINE_get_name(block[loop]));
+        OPENSSL_free(eid[loop]);
+        OPENSSL_free(ename[loop]);
     }
     to_return = 1;
 
@@ -278,7 +283,7 @@ static int test_redirect(void)
      * Try setting test key engine. Both should fail because the
      * engine has no public key methods.
      */
-    if (!TEST_ptr_null(EVP_PKEY_CTX_new(pkey, e))
+    if (!TEST_ptr_null(ctx = EVP_PKEY_CTX_new(pkey, e))
             || !TEST_int_le(EVP_PKEY_set1_engine(pkey, e), 0))
         goto err;
 
@@ -346,6 +351,15 @@ static int test_redirect(void)
 }
 #endif
 
+int global_init(void)
+{
+    /*
+     * If the config file gets loaded, the dynamic engine will be loaded,
+     * and that interferes with our test above.
+     */
+    return OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL);
+}
+
 int setup_tests(void)
 {
 #ifdef OPENSSL_NO_ENGINE