2
0

basic_output.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. #include "../testutil.h"
  10. #include "output.h"
  11. #include "tu_local.h"
  12. #include <openssl/crypto.h>
  13. #include <openssl/bio.h>
  14. /* These are available for any test program */
  15. BIO *bio_out = NULL;
  16. BIO *bio_err = NULL;
  17. /* These are available for TAP output only (internally) */
  18. static BIO *tap_out = NULL;
  19. static BIO *tap_err = NULL;
  20. void test_open_streams(void)
  21. {
  22. tap_out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
  23. tap_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
  24. #ifdef __VMS
  25. tap_out = BIO_push(BIO_new(BIO_f_linebuffer()), tap_out);
  26. tap_err = BIO_push(BIO_new(BIO_f_linebuffer()), tap_err);
  27. #endif
  28. tap_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
  29. tap_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
  30. bio_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
  31. bio_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
  32. BIO_set_prefix(bio_out, "# ");
  33. BIO_set_prefix(bio_err, "# ");
  34. OPENSSL_assert(bio_out != NULL);
  35. OPENSSL_assert(bio_err != NULL);
  36. }
  37. void test_adjust_streams_tap_level(int level)
  38. {
  39. BIO_set_indent(tap_out, level);
  40. BIO_set_indent(tap_err, level);
  41. }
  42. void test_close_streams(void)
  43. {
  44. /*
  45. * The rest of the chain is freed by the BIO_free_all() calls below, so
  46. * we only need to free the last one in the bio_out and bio_err chains.
  47. */
  48. BIO_free(bio_out);
  49. BIO_free(bio_err);
  50. BIO_free_all(tap_out);
  51. BIO_free_all(tap_err);
  52. }
  53. int test_vprintf_stdout(const char *fmt, va_list ap)
  54. {
  55. return BIO_vprintf(bio_out, fmt, ap);
  56. }
  57. int test_vprintf_stderr(const char *fmt, va_list ap)
  58. {
  59. return BIO_vprintf(bio_err, fmt, ap);
  60. }
  61. int test_flush_stdout(void)
  62. {
  63. return BIO_flush(bio_out);
  64. }
  65. int test_flush_stderr(void)
  66. {
  67. return BIO_flush(bio_err);
  68. }
  69. int test_vprintf_tapout(const char *fmt, va_list ap)
  70. {
  71. return BIO_vprintf(tap_out, fmt, ap);
  72. }
  73. int test_vprintf_taperr(const char *fmt, va_list ap)
  74. {
  75. return BIO_vprintf(tap_err, fmt, ap);
  76. }
  77. int test_flush_tapout(void)
  78. {
  79. return BIO_flush(tap_out);
  80. }
  81. int test_flush_taperr(void)
  82. {
  83. return BIO_flush(tap_err);
  84. }