1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"). You may not use
5*e0c4386eSCy Schubert * this file except in compliance with the License. You can obtain a copy
6*e0c4386eSCy Schubert * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert */
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert #define TESTUTIL_NO_size_t_COMPARISON
11*e0c4386eSCy Schubert
12*e0c4386eSCy Schubert #include <stdio.h>
13*e0c4386eSCy Schubert #include <string.h>
14*e0c4386eSCy Schubert #include <openssl/bio.h>
15*e0c4386eSCy Schubert #include "internal/numbers.h"
16*e0c4386eSCy Schubert #include "testutil.h"
17*e0c4386eSCy Schubert #include "testutil/output.h"
18*e0c4386eSCy Schubert
19*e0c4386eSCy Schubert #define nelem(x) (int)(sizeof(x) / sizeof((x)[0]))
20*e0c4386eSCy Schubert
21*e0c4386eSCy Schubert static int justprint = 0;
22*e0c4386eSCy Schubert
23*e0c4386eSCy Schubert static char *fpexpected[][10][5] = {
24*e0c4386eSCy Schubert {
25*e0c4386eSCy Schubert /* 00 */ { "0.0000e+00", "0.0000", "0", "0.0000E+00", "0" },
26*e0c4386eSCy Schubert /* 01 */ { "6.7000e-01", "0.6700", "0.67", "6.7000E-01", "0.67" },
27*e0c4386eSCy Schubert /* 02 */ { "6.6667e-01", "0.6667", "0.6667", "6.6667E-01", "0.6667" },
28*e0c4386eSCy Schubert /* 03 */ { "6.6667e-04", "0.0007", "0.0006667", "6.6667E-04", "0.0006667" },
29*e0c4386eSCy Schubert /* 04 */ { "6.6667e-05", "0.0001", "6.667e-05", "6.6667E-05", "6.667E-05" },
30*e0c4386eSCy Schubert /* 05 */ { "6.6667e+00", "6.6667", "6.667", "6.6667E+00", "6.667" },
31*e0c4386eSCy Schubert /* 06 */ { "6.6667e+01", "66.6667", "66.67", "6.6667E+01", "66.67" },
32*e0c4386eSCy Schubert /* 07 */ { "6.6667e+02", "666.6667", "666.7", "6.6667E+02", "666.7" },
33*e0c4386eSCy Schubert /* 08 */ { "6.6667e+03", "6666.6667", "6667", "6.6667E+03", "6667" },
34*e0c4386eSCy Schubert /* 09 */ { "6.6667e+04", "66666.6667", "6.667e+04", "6.6667E+04", "6.667E+04" },
35*e0c4386eSCy Schubert },
36*e0c4386eSCy Schubert {
37*e0c4386eSCy Schubert /* 10 */ { "0.00000e+00", "0.00000", "0", "0.00000E+00", "0" },
38*e0c4386eSCy Schubert /* 11 */ { "6.70000e-01", "0.67000", "0.67", "6.70000E-01", "0.67" },
39*e0c4386eSCy Schubert /* 12 */ { "6.66667e-01", "0.66667", "0.66667", "6.66667E-01", "0.66667" },
40*e0c4386eSCy Schubert /* 13 */ { "6.66667e-04", "0.00067", "0.00066667", "6.66667E-04", "0.00066667" },
41*e0c4386eSCy Schubert /* 14 */ { "6.66667e-05", "0.00007", "6.6667e-05", "6.66667E-05", "6.6667E-05" },
42*e0c4386eSCy Schubert /* 15 */ { "6.66667e+00", "6.66667", "6.6667", "6.66667E+00", "6.6667" },
43*e0c4386eSCy Schubert /* 16 */ { "6.66667e+01", "66.66667", "66.667", "6.66667E+01", "66.667" },
44*e0c4386eSCy Schubert /* 17 */ { "6.66667e+02", "666.66667", "666.67", "6.66667E+02", "666.67" },
45*e0c4386eSCy Schubert /* 18 */ { "6.66667e+03", "6666.66667", "6666.7", "6.66667E+03", "6666.7" },
46*e0c4386eSCy Schubert /* 19 */ { "6.66667e+04", "66666.66667", "66667", "6.66667E+04", "66667" },
47*e0c4386eSCy Schubert },
48*e0c4386eSCy Schubert {
49*e0c4386eSCy Schubert /* 20 */ { " 0.0000e+00", " 0.0000", " 0", " 0.0000E+00", " 0" },
50*e0c4386eSCy Schubert /* 21 */ { " 6.7000e-01", " 0.6700", " 0.67", " 6.7000E-01", " 0.67" },
51*e0c4386eSCy Schubert /* 22 */ { " 6.6667e-01", " 0.6667", " 0.6667", " 6.6667E-01", " 0.6667" },
52*e0c4386eSCy Schubert /* 23 */ { " 6.6667e-04", " 0.0007", " 0.0006667", " 6.6667E-04", " 0.0006667" },
53*e0c4386eSCy Schubert /* 24 */ { " 6.6667e-05", " 0.0001", " 6.667e-05", " 6.6667E-05", " 6.667E-05" },
54*e0c4386eSCy Schubert /* 25 */ { " 6.6667e+00", " 6.6667", " 6.667", " 6.6667E+00", " 6.667" },
55*e0c4386eSCy Schubert /* 26 */ { " 6.6667e+01", " 66.6667", " 66.67", " 6.6667E+01", " 66.67" },
56*e0c4386eSCy Schubert /* 27 */ { " 6.6667e+02", " 666.6667", " 666.7", " 6.6667E+02", " 666.7" },
57*e0c4386eSCy Schubert /* 28 */ { " 6.6667e+03", " 6666.6667", " 6667", " 6.6667E+03", " 6667" },
58*e0c4386eSCy Schubert /* 29 */ { " 6.6667e+04", " 66666.6667", " 6.667e+04", " 6.6667E+04", " 6.667E+04" },
59*e0c4386eSCy Schubert },
60*e0c4386eSCy Schubert {
61*e0c4386eSCy Schubert /* 30 */ { " 0.00000e+00", " 0.00000", " 0", " 0.00000E+00", " 0" },
62*e0c4386eSCy Schubert /* 31 */ { " 6.70000e-01", " 0.67000", " 0.67", " 6.70000E-01", " 0.67" },
63*e0c4386eSCy Schubert /* 32 */ { " 6.66667e-01", " 0.66667", " 0.66667", " 6.66667E-01", " 0.66667" },
64*e0c4386eSCy Schubert /* 33 */ { " 6.66667e-04", " 0.00067", " 0.00066667", " 6.66667E-04", " 0.00066667" },
65*e0c4386eSCy Schubert /* 34 */ { " 6.66667e-05", " 0.00007", " 6.6667e-05", " 6.66667E-05", " 6.6667E-05" },
66*e0c4386eSCy Schubert /* 35 */ { " 6.66667e+00", " 6.66667", " 6.6667", " 6.66667E+00", " 6.6667" },
67*e0c4386eSCy Schubert /* 36 */ { " 6.66667e+01", " 66.66667", " 66.667", " 6.66667E+01", " 66.667" },
68*e0c4386eSCy Schubert /* 37 */ { " 6.66667e+02", " 666.66667", " 666.67", " 6.66667E+02", " 666.67" },
69*e0c4386eSCy Schubert /* 38 */ { " 6.66667e+03", " 6666.66667", " 6666.7", " 6.66667E+03", " 6666.7" },
70*e0c4386eSCy Schubert /* 39 */ { " 6.66667e+04", " 66666.66667", " 66667", " 6.66667E+04", " 66667" },
71*e0c4386eSCy Schubert },
72*e0c4386eSCy Schubert {
73*e0c4386eSCy Schubert /* 40 */ { "0e+00", "0", "0", "0E+00", "0" },
74*e0c4386eSCy Schubert /* 41 */ { "7e-01", "1", "0.7", "7E-01", "0.7" },
75*e0c4386eSCy Schubert /* 42 */ { "7e-01", "1", "0.7", "7E-01", "0.7" },
76*e0c4386eSCy Schubert /* 43 */ { "7e-04", "0", "0.0007", "7E-04", "0.0007" },
77*e0c4386eSCy Schubert /* 44 */ { "7e-05", "0", "7e-05", "7E-05", "7E-05" },
78*e0c4386eSCy Schubert /* 45 */ { "7e+00", "7", "7", "7E+00", "7" },
79*e0c4386eSCy Schubert /* 46 */ { "7e+01", "67", "7e+01", "7E+01", "7E+01" },
80*e0c4386eSCy Schubert /* 47 */ { "7e+02", "667", "7e+02", "7E+02", "7E+02" },
81*e0c4386eSCy Schubert /* 48 */ { "7e+03", "6667", "7e+03", "7E+03", "7E+03" },
82*e0c4386eSCy Schubert /* 49 */ { "7e+04", "66667", "7e+04", "7E+04", "7E+04" },
83*e0c4386eSCy Schubert },
84*e0c4386eSCy Schubert {
85*e0c4386eSCy Schubert /* 50 */ { "0.000000e+00", "0.000000", "0", "0.000000E+00", "0" },
86*e0c4386eSCy Schubert /* 51 */ { "6.700000e-01", "0.670000", "0.67", "6.700000E-01", "0.67" },
87*e0c4386eSCy Schubert /* 52 */ { "6.666667e-01", "0.666667", "0.666667", "6.666667E-01", "0.666667" },
88*e0c4386eSCy Schubert /* 53 */ { "6.666667e-04", "0.000667", "0.000666667", "6.666667E-04", "0.000666667" },
89*e0c4386eSCy Schubert /* 54 */ { "6.666667e-05", "0.000067", "6.66667e-05", "6.666667E-05", "6.66667E-05" },
90*e0c4386eSCy Schubert /* 55 */ { "6.666667e+00", "6.666667", "6.66667", "6.666667E+00", "6.66667" },
91*e0c4386eSCy Schubert /* 56 */ { "6.666667e+01", "66.666667", "66.6667", "6.666667E+01", "66.6667" },
92*e0c4386eSCy Schubert /* 57 */ { "6.666667e+02", "666.666667", "666.667", "6.666667E+02", "666.667" },
93*e0c4386eSCy Schubert /* 58 */ { "6.666667e+03", "6666.666667", "6666.67", "6.666667E+03", "6666.67" },
94*e0c4386eSCy Schubert /* 59 */ { "6.666667e+04", "66666.666667", "66666.7", "6.666667E+04", "66666.7" },
95*e0c4386eSCy Schubert },
96*e0c4386eSCy Schubert {
97*e0c4386eSCy Schubert /* 60 */ { "0.0000e+00", "000.0000", "00000000", "0.0000E+00", "00000000" },
98*e0c4386eSCy Schubert /* 61 */ { "6.7000e-01", "000.6700", "00000.67", "6.7000E-01", "00000.67" },
99*e0c4386eSCy Schubert /* 62 */ { "6.6667e-01", "000.6667", "000.6667", "6.6667E-01", "000.6667" },
100*e0c4386eSCy Schubert /* 63 */ { "6.6667e-04", "000.0007", "0.0006667", "6.6667E-04", "0.0006667" },
101*e0c4386eSCy Schubert /* 64 */ { "6.6667e-05", "000.0001", "6.667e-05", "6.6667E-05", "6.667E-05" },
102*e0c4386eSCy Schubert /* 65 */ { "6.6667e+00", "006.6667", "0006.667", "6.6667E+00", "0006.667" },
103*e0c4386eSCy Schubert /* 66 */ { "6.6667e+01", "066.6667", "00066.67", "6.6667E+01", "00066.67" },
104*e0c4386eSCy Schubert /* 67 */ { "6.6667e+02", "666.6667", "000666.7", "6.6667E+02", "000666.7" },
105*e0c4386eSCy Schubert /* 68 */ { "6.6667e+03", "6666.6667", "00006667", "6.6667E+03", "00006667" },
106*e0c4386eSCy Schubert /* 69 */ { "6.6667e+04", "66666.6667", "6.667e+04", "6.6667E+04", "6.667E+04" },
107*e0c4386eSCy Schubert },
108*e0c4386eSCy Schubert };
109*e0c4386eSCy Schubert
110*e0c4386eSCy Schubert typedef struct z_data_st {
111*e0c4386eSCy Schubert size_t value;
112*e0c4386eSCy Schubert const char *format;
113*e0c4386eSCy Schubert const char *expected;
114*e0c4386eSCy Schubert } z_data;
115*e0c4386eSCy Schubert
116*e0c4386eSCy Schubert static z_data zu_data[] = {
117*e0c4386eSCy Schubert { SIZE_MAX, "%zu", (sizeof(size_t) == 4 ? "4294967295"
118*e0c4386eSCy Schubert : sizeof(size_t) == 8 ? "18446744073709551615"
119*e0c4386eSCy Schubert : "") },
120*e0c4386eSCy Schubert /*
121*e0c4386eSCy Schubert * in 2-complement, the unsigned number divided by two plus one becomes the
122*e0c4386eSCy Schubert * smallest possible negative signed number of the corresponding type
123*e0c4386eSCy Schubert */
124*e0c4386eSCy Schubert { SIZE_MAX / 2 + 1, "%zi", (sizeof(size_t) == 4 ? "-2147483648"
125*e0c4386eSCy Schubert : sizeof(size_t) == 8 ? "-9223372036854775808"
126*e0c4386eSCy Schubert : "") },
127*e0c4386eSCy Schubert { 0, "%zu", "0" },
128*e0c4386eSCy Schubert { 0, "%zi", "0" },
129*e0c4386eSCy Schubert };
130*e0c4386eSCy Schubert
test_zu(int i)131*e0c4386eSCy Schubert static int test_zu(int i)
132*e0c4386eSCy Schubert {
133*e0c4386eSCy Schubert char bio_buf[80];
134*e0c4386eSCy Schubert const z_data *data = &zu_data[i];
135*e0c4386eSCy Schubert
136*e0c4386eSCy Schubert BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value);
137*e0c4386eSCy Schubert if (!TEST_str_eq(bio_buf, data->expected))
138*e0c4386eSCy Schubert return 0;
139*e0c4386eSCy Schubert return 1;
140*e0c4386eSCy Schubert }
141*e0c4386eSCy Schubert
142*e0c4386eSCy Schubert typedef struct j_data_st {
143*e0c4386eSCy Schubert uint64_t value;
144*e0c4386eSCy Schubert const char *format;
145*e0c4386eSCy Schubert const char *expected;
146*e0c4386eSCy Schubert } j_data;
147*e0c4386eSCy Schubert
148*e0c4386eSCy Schubert static j_data jf_data[] = {
149*e0c4386eSCy Schubert { 0xffffffffffffffffULL, "%ju", "18446744073709551615" },
150*e0c4386eSCy Schubert { 0xffffffffffffffffULL, "%jx", "ffffffffffffffff" },
151*e0c4386eSCy Schubert { 0x8000000000000000ULL, "%ju", "9223372036854775808" },
152*e0c4386eSCy Schubert /*
153*e0c4386eSCy Schubert * These tests imply two's-complement, but it's the only binary
154*e0c4386eSCy Schubert * representation we support, see test/sanitytest.c...
155*e0c4386eSCy Schubert */
156*e0c4386eSCy Schubert { 0x8000000000000000ULL, "%ji", "-9223372036854775808" },
157*e0c4386eSCy Schubert };
158*e0c4386eSCy Schubert
test_j(int i)159*e0c4386eSCy Schubert static int test_j(int i)
160*e0c4386eSCy Schubert {
161*e0c4386eSCy Schubert const j_data *data = &jf_data[i];
162*e0c4386eSCy Schubert char bio_buf[80];
163*e0c4386eSCy Schubert
164*e0c4386eSCy Schubert BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value);
165*e0c4386eSCy Schubert if (!TEST_str_eq(bio_buf, data->expected))
166*e0c4386eSCy Schubert return 0;
167*e0c4386eSCy Schubert return 1;
168*e0c4386eSCy Schubert }
169*e0c4386eSCy Schubert
170*e0c4386eSCy Schubert
171*e0c4386eSCy Schubert /* Precision and width. */
172*e0c4386eSCy Schubert typedef struct pw_st {
173*e0c4386eSCy Schubert int p;
174*e0c4386eSCy Schubert const char *w;
175*e0c4386eSCy Schubert } pw;
176*e0c4386eSCy Schubert
177*e0c4386eSCy Schubert static pw pw_params[] = {
178*e0c4386eSCy Schubert { 4, "" },
179*e0c4386eSCy Schubert { 5, "" },
180*e0c4386eSCy Schubert { 4, "12" },
181*e0c4386eSCy Schubert { 5, "12" },
182*e0c4386eSCy Schubert { 0, "" },
183*e0c4386eSCy Schubert { -1, "" },
184*e0c4386eSCy Schubert { 4, "08" }
185*e0c4386eSCy Schubert };
186*e0c4386eSCy Schubert
dofptest(int test,int sub,double val,const char * width,int prec)187*e0c4386eSCy Schubert static int dofptest(int test, int sub, double val, const char *width, int prec)
188*e0c4386eSCy Schubert {
189*e0c4386eSCy Schubert static const char *fspecs[] = {
190*e0c4386eSCy Schubert "e", "f", "g", "E", "G"
191*e0c4386eSCy Schubert };
192*e0c4386eSCy Schubert char format[80], result[80];
193*e0c4386eSCy Schubert int ret = 1, i;
194*e0c4386eSCy Schubert
195*e0c4386eSCy Schubert for (i = 0; i < nelem(fspecs); i++) {
196*e0c4386eSCy Schubert const char *fspec = fspecs[i];
197*e0c4386eSCy Schubert
198*e0c4386eSCy Schubert if (prec >= 0)
199*e0c4386eSCy Schubert BIO_snprintf(format, sizeof(format), "%%%s.%d%s", width, prec,
200*e0c4386eSCy Schubert fspec);
201*e0c4386eSCy Schubert else
202*e0c4386eSCy Schubert BIO_snprintf(format, sizeof(format), "%%%s%s", width, fspec);
203*e0c4386eSCy Schubert BIO_snprintf(result, sizeof(result), format, val);
204*e0c4386eSCy Schubert
205*e0c4386eSCy Schubert if (justprint) {
206*e0c4386eSCy Schubert if (i == 0)
207*e0c4386eSCy Schubert printf(" /* %d%d */ { \"%s\"", test, sub, result);
208*e0c4386eSCy Schubert else
209*e0c4386eSCy Schubert printf(", \"%s\"", result);
210*e0c4386eSCy Schubert } else if (!TEST_str_eq(fpexpected[test][sub][i], result)) {
211*e0c4386eSCy Schubert TEST_info("test %d format=|%s| exp=|%s|, ret=|%s|",
212*e0c4386eSCy Schubert test, format, fpexpected[test][sub][i], result);
213*e0c4386eSCy Schubert ret = 0;
214*e0c4386eSCy Schubert }
215*e0c4386eSCy Schubert }
216*e0c4386eSCy Schubert if (justprint)
217*e0c4386eSCy Schubert printf(" },\n");
218*e0c4386eSCy Schubert return ret;
219*e0c4386eSCy Schubert }
220*e0c4386eSCy Schubert
test_fp(int i)221*e0c4386eSCy Schubert static int test_fp(int i)
222*e0c4386eSCy Schubert {
223*e0c4386eSCy Schubert int t = 0, r;
224*e0c4386eSCy Schubert const double frac = 2.0 / 3.0;
225*e0c4386eSCy Schubert const pw *pwp = &pw_params[i];
226*e0c4386eSCy Schubert
227*e0c4386eSCy Schubert if (justprint)
228*e0c4386eSCy Schubert printf(" {\n");
229*e0c4386eSCy Schubert r = TEST_true(dofptest(i, t++, 0.0, pwp->w, pwp->p))
230*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 0.67, pwp->w, pwp->p))
231*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, frac, pwp->w, pwp->p))
232*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, frac / 1000, pwp->w, pwp->p))
233*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, frac / 10000, pwp->w, pwp->p))
234*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 6.0 + frac, pwp->w, pwp->p))
235*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 66.0 + frac, pwp->w, pwp->p))
236*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 666.0 + frac, pwp->w, pwp->p))
237*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 6666.0 + frac, pwp->w, pwp->p))
238*e0c4386eSCy Schubert && TEST_true(dofptest(i, t++, 66666.0 + frac, pwp->w, pwp->p));
239*e0c4386eSCy Schubert if (justprint)
240*e0c4386eSCy Schubert printf(" },\n");
241*e0c4386eSCy Schubert return r;
242*e0c4386eSCy Schubert }
243*e0c4386eSCy Schubert
test_big(void)244*e0c4386eSCy Schubert static int test_big(void)
245*e0c4386eSCy Schubert {
246*e0c4386eSCy Schubert char buf[80];
247*e0c4386eSCy Schubert
248*e0c4386eSCy Schubert /* Test excessively big number. Should fail */
249*e0c4386eSCy Schubert if (!TEST_int_eq(BIO_snprintf(buf, sizeof(buf),
250*e0c4386eSCy Schubert "%f\n", 2 * (double)ULONG_MAX), -1))
251*e0c4386eSCy Schubert return 0;
252*e0c4386eSCy Schubert
253*e0c4386eSCy Schubert return 1;
254*e0c4386eSCy Schubert }
255*e0c4386eSCy Schubert
256*e0c4386eSCy Schubert typedef enum OPTION_choice {
257*e0c4386eSCy Schubert OPT_ERR = -1,
258*e0c4386eSCy Schubert OPT_EOF = 0,
259*e0c4386eSCy Schubert OPT_PRINT,
260*e0c4386eSCy Schubert OPT_TEST_ENUM
261*e0c4386eSCy Schubert } OPTION_CHOICE;
262*e0c4386eSCy Schubert
test_get_options(void)263*e0c4386eSCy Schubert const OPTIONS *test_get_options(void)
264*e0c4386eSCy Schubert {
265*e0c4386eSCy Schubert static const OPTIONS options[] = {
266*e0c4386eSCy Schubert OPT_TEST_OPTIONS_DEFAULT_USAGE,
267*e0c4386eSCy Schubert { "expected", OPT_PRINT, '-', "Output values" },
268*e0c4386eSCy Schubert { NULL }
269*e0c4386eSCy Schubert };
270*e0c4386eSCy Schubert return options;
271*e0c4386eSCy Schubert }
272*e0c4386eSCy Schubert
setup_tests(void)273*e0c4386eSCy Schubert int setup_tests(void)
274*e0c4386eSCy Schubert {
275*e0c4386eSCy Schubert OPTION_CHOICE o;
276*e0c4386eSCy Schubert
277*e0c4386eSCy Schubert while ((o = opt_next()) != OPT_EOF) {
278*e0c4386eSCy Schubert switch (o) {
279*e0c4386eSCy Schubert case OPT_PRINT:
280*e0c4386eSCy Schubert justprint = 1;
281*e0c4386eSCy Schubert break;
282*e0c4386eSCy Schubert case OPT_TEST_CASES:
283*e0c4386eSCy Schubert break;
284*e0c4386eSCy Schubert default:
285*e0c4386eSCy Schubert return 0;
286*e0c4386eSCy Schubert }
287*e0c4386eSCy Schubert }
288*e0c4386eSCy Schubert
289*e0c4386eSCy Schubert ADD_TEST(test_big);
290*e0c4386eSCy Schubert ADD_ALL_TESTS(test_fp, nelem(pw_params));
291*e0c4386eSCy Schubert ADD_ALL_TESTS(test_zu, nelem(zu_data));
292*e0c4386eSCy Schubert ADD_ALL_TESTS(test_j, nelem(jf_data));
293*e0c4386eSCy Schubert return 1;
294*e0c4386eSCy Schubert }
295*e0c4386eSCy Schubert
296*e0c4386eSCy Schubert /*
297*e0c4386eSCy Schubert * Replace testutil output routines. We do this to eliminate possible sources
298*e0c4386eSCy Schubert * of BIO error
299*e0c4386eSCy Schubert */
300*e0c4386eSCy Schubert BIO *bio_out = NULL;
301*e0c4386eSCy Schubert BIO *bio_err = NULL;
302*e0c4386eSCy Schubert
303*e0c4386eSCy Schubert static int tap_level = 0;
304*e0c4386eSCy Schubert
test_open_streams(void)305*e0c4386eSCy Schubert void test_open_streams(void)
306*e0c4386eSCy Schubert {
307*e0c4386eSCy Schubert }
308*e0c4386eSCy Schubert
test_adjust_streams_tap_level(int level)309*e0c4386eSCy Schubert void test_adjust_streams_tap_level(int level)
310*e0c4386eSCy Schubert {
311*e0c4386eSCy Schubert tap_level = level;
312*e0c4386eSCy Schubert }
313*e0c4386eSCy Schubert
test_close_streams(void)314*e0c4386eSCy Schubert void test_close_streams(void)
315*e0c4386eSCy Schubert {
316*e0c4386eSCy Schubert }
317*e0c4386eSCy Schubert
318*e0c4386eSCy Schubert /*
319*e0c4386eSCy Schubert * This works out as long as caller doesn't use any "fancy" formats.
320*e0c4386eSCy Schubert * But we are caller's caller, and test_str_eq is the only one called,
321*e0c4386eSCy Schubert * and it uses only "%s", which is not "fancy"...
322*e0c4386eSCy Schubert */
test_vprintf_stdout(const char * fmt,va_list ap)323*e0c4386eSCy Schubert int test_vprintf_stdout(const char *fmt, va_list ap)
324*e0c4386eSCy Schubert {
325*e0c4386eSCy Schubert return fprintf(stdout, "%*s# ", tap_level, "") + vfprintf(stdout, fmt, ap);
326*e0c4386eSCy Schubert }
327*e0c4386eSCy Schubert
test_vprintf_stderr(const char * fmt,va_list ap)328*e0c4386eSCy Schubert int test_vprintf_stderr(const char *fmt, va_list ap)
329*e0c4386eSCy Schubert {
330*e0c4386eSCy Schubert return fprintf(stderr, "%*s# ", tap_level, "") + vfprintf(stderr, fmt, ap);
331*e0c4386eSCy Schubert }
332*e0c4386eSCy Schubert
test_flush_stdout(void)333*e0c4386eSCy Schubert int test_flush_stdout(void)
334*e0c4386eSCy Schubert {
335*e0c4386eSCy Schubert return fflush(stdout);
336*e0c4386eSCy Schubert }
337*e0c4386eSCy Schubert
test_flush_stderr(void)338*e0c4386eSCy Schubert int test_flush_stderr(void)
339*e0c4386eSCy Schubert {
340*e0c4386eSCy Schubert return fflush(stderr);
341*e0c4386eSCy Schubert }
342*e0c4386eSCy Schubert
test_vprintf_tapout(const char * fmt,va_list ap)343*e0c4386eSCy Schubert int test_vprintf_tapout(const char *fmt, va_list ap)
344*e0c4386eSCy Schubert {
345*e0c4386eSCy Schubert return fprintf(stdout, "%*s", tap_level, "") + vfprintf(stdout, fmt, ap);
346*e0c4386eSCy Schubert }
347*e0c4386eSCy Schubert
test_vprintf_taperr(const char * fmt,va_list ap)348*e0c4386eSCy Schubert int test_vprintf_taperr(const char *fmt, va_list ap)
349*e0c4386eSCy Schubert {
350*e0c4386eSCy Schubert return fprintf(stderr, "%*s", tap_level, "") + vfprintf(stderr, fmt, ap);
351*e0c4386eSCy Schubert }
352*e0c4386eSCy Schubert
test_flush_tapout(void)353*e0c4386eSCy Schubert int test_flush_tapout(void)
354*e0c4386eSCy Schubert {
355*e0c4386eSCy Schubert return fflush(stdout);
356*e0c4386eSCy Schubert }
357*e0c4386eSCy Schubert
test_flush_taperr(void)358*e0c4386eSCy Schubert int test_flush_taperr(void)
359*e0c4386eSCy Schubert {
360*e0c4386eSCy Schubert return fflush(stderr);
361*e0c4386eSCy Schubert }
362*e0c4386eSCy Schubert
363