testutil: Move printing function declarations to "internal" header
[openssl.git] / test / bioprinttest.c
index 418d6e4c8d9a4fac8dde8196775d9b710f42e984..8ae0a5a04b9dff3c79428980746f775aa6030750 100644 (file)
@@ -7,11 +7,14 @@
  * https://www.openssl.org/source/license.html
  */
 
+#define TESTUTIL_NO_size_t_COMPARISON
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/bio.h>
 #include "internal/numbers.h"
 #include "testutil.h"
+#include "testutil/output.h"
 
 #define nelem(x) (int)(sizeof(x) / sizeof((x)[0]))
 
@@ -245,3 +248,60 @@ int test_main(int argc, char **argv)
 
     return run_tests(argv[0]);
 }
+
+/*
+ * Replace testutil output routines.  We do this to eliminate possible sources
+ * of BIO error
+ */
+void test_open_streams(void)
+{
+}
+
+void test_close_streams(void)
+{
+}
+
+int test_puts_stdout(const char *str)
+{
+    return fputs(str, stdout);
+}
+
+int test_puts_stderr(const char *str)
+{
+    return fputs(str, stderr);
+}
+
+static char vprint_buf[10240];
+
+/*
+ * This works out as long as caller doesn't use any "fancy" formats.
+ * But we are caller's caller, and test_str_eq is the only one called,
+ * and it uses only "%s", which is not "fancy"...
+ */
+int test_vprintf_stdout(const char *fmt, va_list ap)
+{
+    size_t len = vsnprintf(vprint_buf, sizeof(vprint_buf), fmt, ap);
+
+    if (len >= sizeof(vprint_buf))
+        return -1;
+    return test_puts_stdout(vprint_buf);
+}
+
+int test_vprintf_stderr(const char *fmt, va_list ap)
+{
+    size_t len = vsnprintf(vprint_buf, sizeof(vprint_buf), fmt, ap);
+
+    if (len >= sizeof(vprint_buf))
+        return -1;
+    return test_puts_stderr(vprint_buf);
+}
+
+int test_flush_stdout(void)
+{
+    return fflush(stdout);
+}
+
+int test_flush_stderr(void)
+{
+    return fflush(stderr);
+}