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