4 #include <winpr/tchar.h>
5 #include <winpr/print.h>
18 #define _printf printf
20 static BOOL test_bin_tohex_string(
void)
24 const BYTE binbuffer[33] = { 0 };
25 const char empty[33] = { 0 };
26 char strbuffer[33] = { 0 };
29 winpr_BinToHexStringBuffer(NULL,
sizeof(binbuffer), strbuffer,
sizeof(strbuffer), TRUE);
32 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
34 len = winpr_BinToHexStringBuffer(binbuffer, 0, strbuffer,
sizeof(strbuffer), TRUE);
37 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
40 winpr_BinToHexStringBuffer(binbuffer,
sizeof(binbuffer), NULL,
sizeof(strbuffer), TRUE);
43 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
45 len = winpr_BinToHexStringBuffer(binbuffer,
sizeof(binbuffer), strbuffer, 0, TRUE);
48 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
50 len = winpr_BinToHexStringBuffer(binbuffer, 0, strbuffer, 0, TRUE);
53 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
55 len = winpr_BinToHexStringBuffer(binbuffer,
sizeof(binbuffer), NULL, 0, TRUE);
58 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
60 len = winpr_BinToHexStringBuffer(NULL,
sizeof(binbuffer), strbuffer, 0, TRUE);
63 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
66 len = winpr_BinToHexStringBuffer(binbuffer, 0, NULL, 0, TRUE);
69 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
71 len = winpr_BinToHexStringBuffer(NULL, 0, NULL, 0, TRUE);
74 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
76 len = winpr_BinToHexStringBuffer(binbuffer, 0, NULL, 0, FALSE);
79 if (memcmp(strbuffer, empty,
sizeof(strbuffer)) != 0)
83 const BYTE binbuffer1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
84 const char strbuffer1[] =
"0102030405060708090A0B0C0D0E0F1011";
85 const char strbuffer1_space[] =
"01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11";
87 char buffer[1024] = { 0 };
88 size_t len = winpr_BinToHexStringBuffer(binbuffer1,
sizeof(binbuffer1), buffer,
89 sizeof(buffer), FALSE);
90 if (len != strnlen(strbuffer1,
sizeof(strbuffer1)))
92 if (memcmp(strbuffer1, buffer,
sizeof(strbuffer1)) != 0)
94 len = winpr_BinToHexStringBuffer(binbuffer1,
sizeof(binbuffer1), buffer,
sizeof(buffer),
96 if (len != strnlen(strbuffer1_space,
sizeof(strbuffer1_space)))
98 if (memcmp(strbuffer1_space, buffer,
sizeof(strbuffer1_space)) != 0)
102 const BYTE binbuffer1[] = { 0xF1, 0xe2, 0xD3, 0xc4, 0xB5, 0xA6, 0x97, 0x88, 0x79,
103 0x6A, 0x5b, 0x4C, 0x3d, 0x2E, 0x1f, 0x00, 0xfF };
104 const char strbuffer1[] =
"F1E2D3C4B5A69788796A5B4C3D2E1F00FF";
105 const char strbuffer1_space[] =
"F1 E2 D3 C4 B5 A6 97 88 79 6A 5B 4C 3D 2E 1F 00 FF";
106 char buffer[1024] = { 0 };
107 size_t len = winpr_BinToHexStringBuffer(binbuffer1,
sizeof(binbuffer1), buffer,
108 sizeof(buffer), FALSE);
109 if (len != strnlen(strbuffer1,
sizeof(strbuffer1)))
111 if (memcmp(strbuffer1, buffer,
sizeof(strbuffer1)) != 0)
113 len = winpr_BinToHexStringBuffer(binbuffer1,
sizeof(binbuffer1), buffer,
sizeof(buffer),
115 if (len != strnlen(strbuffer1_space,
sizeof(strbuffer1_space)))
117 if (memcmp(strbuffer1_space, buffer,
sizeof(strbuffer1_space)) != 0)
127 static BOOL test_bin_tohex_string_alloc(
void)
132 const BYTE binbuffer[33] = { 0 };
134 str = winpr_BinToHexString(NULL,
sizeof(binbuffer), TRUE);
137 str = winpr_BinToHexString(binbuffer, 0, TRUE);
140 str = winpr_BinToHexString(binbuffer, 0, FALSE);
143 str = winpr_BinToHexString(NULL,
sizeof(binbuffer), FALSE);
148 const BYTE binbuffer1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
149 const char strbuffer1[] =
"0102030405060708090A0B0C0D0E0F1011";
150 const char strbuffer1_space[] =
"01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11";
152 str = winpr_BinToHexString(binbuffer1,
sizeof(binbuffer1), FALSE);
155 if (memcmp(strbuffer1, str,
sizeof(strbuffer1)) != 0)
158 str = winpr_BinToHexString(binbuffer1,
sizeof(binbuffer1), TRUE);
161 if (memcmp(strbuffer1_space, str,
sizeof(strbuffer1_space)) != 0)
167 const BYTE binbuffer1[] = { 0xF1, 0xe2, 0xD3, 0xc4, 0xB5, 0xA6, 0x97, 0x88, 0x79,
168 0x6A, 0x5b, 0x4C, 0x3d, 0x2E, 0x1f, 0x00, 0xfF };
169 const char strbuffer1[] =
"F1E2D3C4B5A69788796A5B4C3D2E1F00FF";
170 const char strbuffer1_space[] =
"F1 E2 D3 C4 B5 A6 97 88 79 6A 5B 4C 3D 2E 1F 00 FF";
171 str = winpr_BinToHexString(binbuffer1,
sizeof(binbuffer1), FALSE);
174 if (memcmp(strbuffer1, str,
sizeof(strbuffer1)) != 0)
178 str = winpr_BinToHexString(binbuffer1,
sizeof(binbuffer1), TRUE);
181 if (memcmp(strbuffer1_space, str,
sizeof(strbuffer1_space)) != 0)
192 static BOOL test_hex_string_to_bin(
void)
196 const char stringbuffer[] =
"123456789ABCDEFabcdef";
197 const BYTE empty[1024] = { 0 };
198 BYTE buffer[1024] = { 0 };
199 size_t len = winpr_HexStringToBinBuffer(NULL, 0, NULL, 0);
202 if (memcmp(buffer, empty,
sizeof(buffer)) != 0)
204 len = winpr_HexStringToBinBuffer(NULL,
sizeof(stringbuffer), buffer,
sizeof(buffer));
207 if (memcmp(buffer, empty,
sizeof(buffer)) != 0)
209 len = winpr_HexStringToBinBuffer(stringbuffer, 0, buffer,
sizeof(buffer));
212 if (memcmp(buffer, empty,
sizeof(buffer)) != 0)
214 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), NULL,
sizeof(buffer));
217 if (memcmp(buffer, empty,
sizeof(buffer)) != 0)
219 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer, 0);
222 if (memcmp(buffer, empty,
sizeof(buffer)) != 0)
226 const char stringbuffer[] =
"123456789ABCDEF1abcdef";
227 const BYTE expected[] = {
228 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf1, 0xab, 0xcd, 0xef
230 BYTE buffer[32] = { 0 };
232 winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
sizeof(buffer));
233 if (len !=
sizeof(expected))
235 if (memcmp(buffer, expected,
sizeof(expected)) != 0)
237 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
238 sizeof(expected) / 2);
239 if (len !=
sizeof(expected) / 2)
241 if (memcmp(buffer, expected,
sizeof(expected) / 2) != 0)
245 const char stringbuffer[] =
"12 34 56 78 9A BC DE F1 ab cd ef";
246 const BYTE expected[] = {
247 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf1, 0xab, 0xcd, 0xef
249 BYTE buffer[1024] = { 0 };
251 winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
sizeof(buffer));
252 if (len !=
sizeof(expected))
254 if (memcmp(buffer, expected,
sizeof(expected)) != 0)
256 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
257 sizeof(expected) / 2);
258 if (len !=
sizeof(expected) / 2)
260 if (memcmp(buffer, expected,
sizeof(expected) / 2) != 0)
264 const char stringbuffer[] =
"123456789ABCDEF1abcdef9";
265 const BYTE expected[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc,
266 0xde, 0xf1, 0xab, 0xcd, 0xef, 0x09 };
267 BYTE buffer[1024] = { 0 };
269 winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
sizeof(buffer));
270 if (len !=
sizeof(expected))
272 if (memcmp(buffer, expected,
sizeof(expected)) != 0)
274 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
275 sizeof(expected) / 2);
276 if (len !=
sizeof(expected) / 2)
278 if (memcmp(buffer, expected,
sizeof(expected) / 2) != 0)
282 const char stringbuffer[] =
"12 34 56 78 9A BC DE F1 ab cd ef 9";
283 const BYTE expected[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc,
284 0xde, 0xf1, 0xab, 0xcd, 0xef, 0x09 };
285 BYTE buffer[1024] = { 0 };
287 winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
sizeof(buffer));
288 if (len !=
sizeof(expected))
290 if (memcmp(buffer, expected,
sizeof(expected)) != 0)
292 len = winpr_HexStringToBinBuffer(stringbuffer,
sizeof(stringbuffer), buffer,
293 sizeof(expected) / 2);
294 if (len !=
sizeof(expected) / 2)
296 if (memcmp(buffer, expected,
sizeof(expected) / 2) != 0)
304 int TestPrint(
int argc,
char* argv[])
325 _printf(
"%03d\n", b);
328 _printf(
"%3.2f\n", d);
349 for (
int a = 0; a <= 300; a = a + 20)
350 _printf(
"%3d %06.3f\n", a, (5.0 / 9.0) * (a - 32));
364 _printf(
"The color: %s\n",
"blue");
365 _printf(
"First number: %d\n", 12345);
366 _printf(
"Second number: %04d\n", 25);
367 _printf(
"Third number: %i\n", 1234);
368 _printf(
"Float number: %3.2f\n", 3.14159);
369 _printf(
"Hexadecimal: %x/%X\n", 255, 255);
370 _printf(
"Octal: %o\n", 255);
371 _printf(
"Unsigned value: %u\n", 150);
372 _printf(
"Just print the percentage sign %%\n");
385 _printf(
":%s:\n",
"Hello, world!");
386 _printf(
":%15s:\n",
"Hello, world!");
387 _printf(
":%.10s:\n",
"Hello, world!");
388 _printf(
":%-10s:\n",
"Hello, world!");
389 _printf(
":%-15s:\n",
"Hello, world!");
390 _printf(
":%.15s:\n",
"Hello, world!");
391 _printf(
":%15.10s:\n",
"Hello, world!");
392 _printf(
":%-15.10s:\n",
"Hello, world!");
394 if (!test_bin_tohex_string())
396 if (!test_bin_tohex_string_alloc())
398 if (!test_hex_string_to_bin())