2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "../testutil.h"
14 #include <openssl/crypto.h>
15 #include <openssl/bio.h>
17 /* These are available for any test program */
21 /* These are available for TAP output only (internally) */
22 static BIO *tap_out = NULL;
23 static BIO *tap_err = NULL;
25 void test_open_streams(void)
27 tap_out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
28 tap_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
30 tap_out = BIO_push(BIO_new(BIO_f_linebuffer()), tap_out);
31 tap_err = BIO_push(BIO_new(BIO_f_linebuffer()), tap_err);
33 tap_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
34 tap_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
36 bio_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
37 bio_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
38 BIO_set_prefix(bio_out, "# ");
39 BIO_set_prefix(bio_err, "# ");
41 OPENSSL_assert(bio_out != NULL);
42 OPENSSL_assert(bio_err != NULL);
45 void test_adjust_streams_tap_level(int level)
47 BIO_set_indent(tap_out, level);
48 BIO_set_indent(tap_err, level);
51 void test_close_streams(void)
54 * The rest of the chain is freed by the BIO_free_all() calls below, so
55 * we only need to free the last one in the bio_out and bio_err chains.
60 BIO_free_all(tap_out);
61 BIO_free_all(tap_err);
64 int test_vprintf_stdout(const char *fmt, va_list ap)
66 return BIO_vprintf(bio_out, fmt, ap);
69 int test_vprintf_stderr(const char *fmt, va_list ap)
71 return BIO_vprintf(bio_err, fmt, ap);
74 int test_flush_stdout(void)
76 return BIO_flush(bio_out);
79 int test_flush_stderr(void)
81 return BIO_flush(bio_err);
84 int test_vprintf_tapout(const char *fmt, va_list ap)
86 return BIO_vprintf(tap_out, fmt, ap);
89 int test_vprintf_taperr(const char *fmt, va_list ap)
91 return BIO_vprintf(tap_err, fmt, ap);
94 int test_flush_tapout(void)
96 return BIO_flush(tap_out);
99 int test_flush_taperr(void)
101 return BIO_flush(tap_err);