TEST: Adjust test/bioprinttest.c to behave like the testutil routines
[openssl.git] / test / bioprinttest.c
index 3dd5b3efa2665b27ef08793b92ac96bfd15e23b7..04d1613c6cf499a701497c1eea9fb79f94d7381f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -241,48 +241,15 @@ static int test_fp(int i)
     return r;
 }
 
-extern double zero_value;
-double zero_value = 0.0;
-
 static int test_big(void)
 {
     char buf[80];
-    double d, z, inf, nan;
 
     /* Test excessively big number. Should fail */
     if (!TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
                                   "%f\n", 2 * (double)ULONG_MAX), -1))
         return 0;
 
-    d = 1.0;
-    z = zero_value;
-    inf = d / z;
-    nan = z / z;
-
-    /*
-     * Test +/-inf, nan. Should fail.
-     * Test +/-1.0, +/-0.0. Should work.
-     */
-    if (!TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                  "%f", inf), -1)
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", -inf), -1)
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", nan), -1)
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", d), 8)
-            || !TEST_str_eq(buf, "1.000000")
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", z), 8)
-            || !TEST_str_eq(buf, "0.000000")
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", -d), 9)
-            || !TEST_str_eq(buf, "-1.000000")
-            || !TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
-                                         "%f", -z), 8)
-            || !TEST_str_eq(buf, "0.000000"))
-        return 0;
-
     return 1;
 }
 
@@ -330,10 +297,20 @@ int setup_tests(void)
  * Replace testutil output routines.  We do this to eliminate possible sources
  * of BIO error
  */
+BIO *bio_out = NULL;
+BIO *bio_err = NULL;
+
+static int tap_level = 0;
+
 void test_open_streams(void)
 {
 }
 
+void test_adjust_streams_tap_level(int level)
+{
+    tap_level = level;
+}
+
 void test_close_streams(void)
 {
 }
@@ -345,12 +322,12 @@ void test_close_streams(void)
  */
 int test_vprintf_stdout(const char *fmt, va_list ap)
 {
-    return vfprintf(stdout, fmt, ap);
+    return fprintf(stdout, "%*s# ", tap_level, "") + vfprintf(stdout, fmt, ap);
 }
 
 int test_vprintf_stderr(const char *fmt, va_list ap)
 {
-    return vfprintf(stderr, fmt, ap);
+    return fprintf(stderr, "%*s# ", tap_level, "") + vfprintf(stderr, fmt, ap);
 }
 
 int test_flush_stdout(void)
@@ -363,3 +340,23 @@ int test_flush_stderr(void)
     return fflush(stderr);
 }
 
+int test_vprintf_tapout(const char *fmt, va_list ap)
+{
+    return fprintf(stdout, "%*s", tap_level, "") + vfprintf(stdout, fmt, ap);
+}
+
+int test_vprintf_taperr(const char *fmt, va_list ap)
+{
+    return fprintf(stderr, "%*s", tap_level, "") + vfprintf(stderr, fmt, ap);
+}
+
+int test_flush_tapout(void)
+{
+    return fflush(stdout);
+}
+
+int test_flush_taperr(void)
+{
+    return fflush(stderr);
+}
+