improve CMP logging according to comments on CMP chunk 7 preview
[openssl.git] / test / cmp_ctx_test.c
index c007cfb35e54750a76fea367de74c043faf0de79..e6b6f24854f65b6036f32c5cf531b49c64d72fec 100644 (file)
@@ -195,7 +195,7 @@ static int execute_CTX_reqExtensions_have_SAN_test(
 {
     OSSL_CMP_CTX *ctx = fixture->ctx;
     const int len = 16;
-    unsigned char str[16 /* = len */ ];
+    unsigned char str[16 /* = len */];
     ASN1_OCTET_STRING *data = NULL;
     X509_EXTENSION *ext = NULL;
     X509_EXTENSIONS *exts = NULL;
@@ -234,7 +234,6 @@ static int test_CTX_reqExtensions_have_SAN(void)
     return result;
 }
 
-#ifndef OPENSSL_NO_TRACE
 static int test_log_line;
 static int test_log_cb_res = 0;
 static int test_log_cb(const char *func, const char *file, int line,
@@ -242,21 +241,20 @@ static int test_log_cb(const char *func, const char *file, int line,
 {
     test_log_cb_res =
 # ifndef PEDANTIC
-        (strcmp(func, "execute_cmp_ctx_log_cb_test") == 0
-         || strcmp(func, "(unknown function)") == 0) &&
+        (TEST_str_eq(func, "execute_cmp_ctx_log_cb_test")
+         || TEST_str_eq(func, "(unknown function)")) &&
 # endif
-        (strcmp(file, OPENSSL_FILE) == 0 || strcmp(file, "(no file)") == 0)
-        && (line == test_log_line || line == 0)
-        && (level == OSSL_CMP_LOG_INFO || level == -1)
-        && strcmp(msg, "ok\n") == 0;
+        (TEST_str_eq(file, OPENSSL_FILE)
+         || TEST_str_eq(file, "(no file)"))
+        && (TEST_int_eq(line, test_log_line) || TEST_int_eq(line, 0))
+        && (TEST_int_eq(level, OSSL_CMP_LOG_INFO) || TEST_int_eq(level, -1))
+        && TEST_str_eq(msg, "ok");
     return 1;
 }
-#endif
 
 static int execute_cmp_ctx_log_cb_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
 {
     int res = 1;
-#if !defined OPENSSL_NO_TRACE && !defined OPENSSL_NO_STDIO
     OSSL_CMP_CTX *ctx = fixture->ctx;
 
     OSSL_TRACE(ALL, "this general trace message is not shown by default\n");
@@ -267,30 +265,29 @@ static int execute_cmp_ctx_log_cb_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
     if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, NULL))) {
         res = 0;
     } else {
-        OSSL_CMP_err("this should be printed as CMP error message");
-        OSSL_CMP_warn("this should be printed as CMP warning message");
-        OSSL_CMP_debug("this should not be printed");
+        ossl_cmp_err(ctx, "this should be printed as CMP error message");
+        ossl_cmp_warn(ctx, "this should be printed as CMP warning message");
+        ossl_cmp_debug(ctx, "this should not be printed");
         TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_DEBUG));
-        OSSL_CMP_debug("this should be printed as CMP debug message");
+        ossl_cmp_debug(ctx, "this should be printed as CMP debug message");
         TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_INFO));
     }
     if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, test_log_cb))) {
         res = 0;
     } else {
         test_log_line = OPENSSL_LINE + 1;
-        OSSL_CMP_log2(INFO, "%s%c", "o", 'k');
+        ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k');
         if (!TEST_int_eq(test_log_cb_res, 1))
             res = 0;
         OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_ERR);
         test_log_cb_res = -1; /* callback should not be called at all */
         test_log_line = OPENSSL_LINE + 1;
-        OSSL_CMP_log2(INFO, "%s%c", "o", 'k');
+        ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k');
         if (!TEST_int_eq(test_log_cb_res, -1))
             res = 0;
     }
     OSSL_CMP_log_close();
     OSSL_CMP_log_close(); /* multiple calls should be harmless */
-#endif
     return res;
 }
 
@@ -715,9 +712,7 @@ DEFINE_SET_GET_ARG_FN(set, get, option, 16, int)
 DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, option_16, int, -1, IS_0, \
                          1 /* true */, DROP)
 
-#ifndef OPENSSL_NO_TRACE
 DEFINE_SET_CB_TEST(log_cb)
-#endif
 
 DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, serverPath, char, IS_0)
 DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, serverName, char)
@@ -788,13 +783,11 @@ int setup_tests(void)
     /* various CMP options: */
     ADD_TEST(test_CTX_set_get_option_16);
     /* CMP-specific callback for logging and outputting the error queue: */
-#ifndef OPENSSL_NO_TRACE
     ADD_TEST(test_CTX_set_get_log_cb);
-#endif
     /*
      * also tests OSSL_CMP_log_open(), OSSL_CMP_CTX_set_log_verbosity(),
-     * OSSL_CMP_err(), OSSL_CMP_warn(), * OSSL_CMP_debug(),
-     * OSSL_CMP_log2(), ossl_cmp_log_parse_metadata(), and OSSL_CMP_log_close()
+     * ossl_cmp_err(), ossl_cmp_warn(), * ossl_cmp_debug(),
+     * ossl_cmp_log2(), ossl_cmp_log_parse_metadata(), and OSSL_CMP_log_close()
      * with OSSL_CMP_severity OSSL_CMP_LOG_ERR/WARNING/DEBUG/INFO:
      */
     ADD_TEST(test_cmp_ctx_log_cb);