1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================================ |
6 | ** |
7 | ** Source: vprintf.h |
8 | ** |
9 | ** Purpose: Containts common testing functions for vprintf |
10 | ** |
11 | ** |
12 | **==========================================================================*/ |
13 | |
14 | #ifndef __vprintf_H__ |
15 | #define __vprintf_H__ |
16 | |
17 | int DoVprintf(const char *format, ...) |
18 | { |
19 | int retVal; |
20 | va_list arglist; |
21 | |
22 | va_start(arglist, format); |
23 | retVal = vprintf(format, arglist); |
24 | va_end(arglist); |
25 | |
26 | return (retVal); |
27 | } |
28 | |
29 | void DoStrTest(const char *formatstr, char* param, const char *checkstr) |
30 | { |
31 | int ret; |
32 | |
33 | ret = DoVprintf(formatstr, param); |
34 | if (ret != strlen(checkstr)) |
35 | { |
36 | Fail("Expected vprintf to return %d, got %d.\n" , |
37 | strlen(checkstr), ret); |
38 | } |
39 | } |
40 | |
41 | void DoWStrTest(const char *formatstr, WCHAR* param, const char *checkstr) |
42 | { |
43 | int ret; |
44 | |
45 | ret = DoVprintf(formatstr, param); |
46 | if (ret != strlen(checkstr)) |
47 | { |
48 | Fail("Expected vprintf to return %d, got %d.\n" , |
49 | strlen(checkstr), ret); |
50 | } |
51 | } |
52 | |
53 | void DoPointerTest(const char *formatstr, void* param, char* paramstr, |
54 | const char *checkstr1) |
55 | { |
56 | int ret; |
57 | |
58 | ret = DoVprintf(formatstr, param); |
59 | if (ret != strlen(checkstr1)) |
60 | { |
61 | Fail("Expected vprintf to return %d, got %d.\n" , |
62 | strlen(checkstr1), ret); |
63 | } |
64 | } |
65 | |
66 | void DoCountTest(const char *formatstr, int param, const char *checkstr) |
67 | { |
68 | int ret; |
69 | int n = -1; |
70 | |
71 | ret = DoVprintf(formatstr, &n); |
72 | |
73 | if (n != param) |
74 | { |
75 | Fail("Expected count parameter to resolve to %d, got %d\n" , param, n); |
76 | } |
77 | |
78 | if (ret != strlen(checkstr)) |
79 | { |
80 | Fail("Expected vprintf to return %d, got %d.\n" , |
81 | strlen(checkstr), ret); |
82 | } |
83 | } |
84 | |
85 | void DoShortCountTest(const char *formatstr, int param, const char *checkstr) |
86 | { |
87 | int ret; |
88 | short int n = -1; |
89 | |
90 | ret = DoVprintf(formatstr, &n); |
91 | |
92 | if (n != param) |
93 | { |
94 | Fail("Expected count parameter to resolve to %d, got %d\n" , param, n); |
95 | } |
96 | |
97 | if (ret != strlen(checkstr)) |
98 | { |
99 | Fail("Expected vprintf to return %d, got %d.\n" , |
100 | strlen(checkstr), ret); |
101 | } |
102 | } |
103 | |
104 | |
105 | void DoCharTest(const char *formatstr, char param, const char *checkstr) |
106 | { |
107 | int ret; |
108 | |
109 | ret = DoVprintf(formatstr, param); |
110 | if (ret != strlen(checkstr)) |
111 | { |
112 | Fail("Expected vprintf to return %d, got %d.\n" , |
113 | strlen(checkstr), ret); |
114 | } |
115 | } |
116 | |
117 | void DoWCharTest(const char *formatstr, WCHAR param, const char *checkstr) |
118 | { |
119 | int ret; |
120 | |
121 | ret = DoVprintf(formatstr, param); |
122 | if (ret != strlen(checkstr)) |
123 | { |
124 | Fail("Expected vprintf to return %d, got %d.\n" , |
125 | strlen(checkstr), ret); |
126 | } |
127 | } |
128 | |
129 | void DoNumTest(const char *formatstr, int param, const char *checkstr) |
130 | { |
131 | int ret; |
132 | |
133 | ret = DoVprintf(formatstr, param); |
134 | if (ret != strlen(checkstr)) |
135 | { |
136 | Fail("Expected vprintf to return %d, got %d.\n" , |
137 | strlen(checkstr), ret); |
138 | } |
139 | } |
140 | |
141 | void DoI64Test(const char *formatstr, INT64 param, char *valuestr, const char *checkstr1) |
142 | { |
143 | int ret; |
144 | |
145 | ret = DoVprintf(formatstr, param); |
146 | if (ret != strlen(checkstr1)) |
147 | { |
148 | Fail("Expected vprintf to return %d, got %d.\n" , |
149 | strlen(checkstr1), ret); |
150 | } |
151 | } |
152 | |
153 | void DoDoubleTest(const char *formatstr, double param, const char *checkstr1, |
154 | const char *checkstr2) |
155 | { |
156 | int ret; |
157 | |
158 | ret = DoVprintf(formatstr, param); |
159 | if (ret != strlen(checkstr1) && ret != strlen(checkstr2)) |
160 | { |
161 | Fail("Expected vprintf to return %d or %d, got %d.\n" , |
162 | strlen(checkstr1), strlen(checkstr2), ret); |
163 | } |
164 | } |
165 | |
166 | void DoArgumentPrecTest(const char *formatstr, int precision, void *param, |
167 | char *paramstr, const char *checkstr1, const char *checkstr2) |
168 | { |
169 | int ret; |
170 | |
171 | ret = DoVprintf(formatstr, precision, param); |
172 | if (ret != strlen(checkstr1) && ret != strlen(checkstr2)) |
173 | { |
174 | Fail("Expected vprintf to return %d or %d, got %d.\n" , |
175 | strlen(checkstr1), strlen(checkstr2), ret); |
176 | } |
177 | } |
178 | |
179 | void DoArgumentPrecDoubleTest(const char *formatstr, int precision, double param, |
180 | const char *checkstr1, const char *checkstr2) |
181 | { |
182 | int ret; |
183 | |
184 | ret = DoVprintf(formatstr, precision, param); |
185 | if (ret != strlen(checkstr1) && ret != strlen(checkstr2)) |
186 | { |
187 | Fail("Expected vprintf to return %d or %d, got %d.\n" , |
188 | strlen(checkstr1), strlen(checkstr2), ret); |
189 | } |
190 | } |
191 | |
192 | #endif |
193 | |
194 | |