VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp@ 73705

Last change on this file since 73705 was 69833, checked in by vboxsync, 7 years ago

iprt/string.h: Adding %Rhcb + %Rhci for human readable size formatting (first is using binary prefix, latter is SI units), and adding %Rhub + %RThui for human readable non-size formatting.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 35.1 KB
Line 
1/* $Id: tstRTStrFormat.cpp 69833 2017-11-26 04:22:58Z vboxsync $ */
2/** @file
3 * IPRT Testcase - String formatting.
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/string.h>
32
33#include <iprt/initterm.h>
34#include <iprt/net.h>
35#include <iprt/stream.h>
36#include <iprt/test.h>
37#include <iprt/uuid.h>
38
39
40/** See FNRTSTRFORMATTYPE. */
41static DECLCALLBACK(size_t) TstType(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
42 const char *pszType, void const *pvValue,
43 int cchWidth, int cchPrecision, unsigned fFlags,
44 void *pvUser)
45{
46 /* validate */
47 if (strncmp(pszType, "type", 4))
48 RTTestIFailed("pszType=%s expected 'typeN'\n", pszType);
49
50 int iType = pszType[4] - '0';
51 if ((uintptr_t)pvUser != (uintptr_t)TstType + iType)
52 RTTestIFailed("pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType));
53
54 /* format */
55 size_t cch = pfnOutput(pvArgOutput, pszType, 5);
56 cch += pfnOutput(pvArgOutput, "=", 1);
57 char szNum[64];
58 size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 10, cchWidth, cchPrecision, fFlags);
59 cch += pfnOutput(pvArgOutput, szNum, cchNum);
60 return cch;
61}
62
63
64static void testNested(int iLine, const char *pszExpect, const char *pszFormat, ...)
65{
66 size_t cchExpect = strlen(pszExpect);
67 char szBuf[512];
68
69 va_list va;
70 va_start(va, pszFormat);
71 size_t cch = RTStrPrintf(szBuf, sizeof(szBuf), "%N", pszFormat, &va);
72 va_end(va);
73 if (strcmp(szBuf, pszExpect))
74 RTTestIFailed("at line %d: nested format '%s'\n"
75 " output: '%s'\n"
76 " wanted: '%s'\n",
77 iLine, pszFormat, szBuf, pszExpect);
78 else if (cch != cchExpect)
79 RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n",
80 iLine, cch, cchExpect);
81
82 va_start(va, pszFormat);
83 cch = RTStrPrintf(szBuf, sizeof(szBuf), "%uxxx%Nyyy%u", 43, pszFormat, &va, 43);
84 va_end(va);
85 if ( strncmp(szBuf, "43xxx", 5)
86 || strncmp(szBuf + 5, pszExpect, cchExpect)
87 || strcmp( szBuf + 5 + cchExpect, "yyy43") )
88 RTTestIFailed("at line %d: nested format '%s'\n"
89 " output: '%s'\n"
90 " wanted: '43xxx%syyy43'\n",
91 iLine, pszFormat, szBuf, pszExpect);
92 else if (cch != 5 + cchExpect + 5)
93 RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n",
94 iLine, cch, 5 + cchExpect + 5);
95}
96
97
98int main()
99{
100 RTTEST hTest;
101 int rc = RTTestInitAndCreate("tstRTStrFormat", &hTest);
102 if (rc)
103 return rc;
104 RTTestBanner(hTest);
105
106 uint32_t u32 = 0x010;
107 uint64_t u64 = 0x100;
108#define BUF_SIZE 120
109 char *pszBuf = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE);
110 char *pszBuf2 = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE);
111
112 RTTestSub(hTest, "Basics");
113
114 /* simple */
115 static const char s_szSimpleExpect[] = "u32=16 u64=256 u64=0x100";
116 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64);
117 if (strcmp(pszBuf, s_szSimpleExpect))
118 RTTestIFailed("error: '%s'\n"
119 "wanted '%s'\n", pszBuf, s_szSimpleExpect);
120 else if (cch != sizeof(s_szSimpleExpect) - 1)
121 RTTestIFailed("error: got %zd, expected %zd (#1)\n", cch, sizeof(s_szSimpleExpect) - 1);
122
123 ssize_t cch2 = RTStrPrintf2(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64);
124 if (strcmp(pszBuf, "u32=16 u64=256 u64=0x100"))
125 RTTestIFailed("error: '%s' (#2)\n"
126 "wanted '%s' (#2)\n", pszBuf, s_szSimpleExpect);
127 else if (cch2 != sizeof(s_szSimpleExpect) - 1)
128 RTTestIFailed("error: got %zd, expected %zd (#2)\n", cch2, sizeof(s_szSimpleExpect) - 1);
129
130 /* just big. */
131 u64 = UINT64_C(0x7070605040302010);
132 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
133 if (strcmp(pszBuf, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42"))
134 {
135 RTTestIFailed("error: '%s'\n"
136 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", pszBuf);
137 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));
138 }
139
140 /* huge and negative. */
141 u64 = UINT64_C(0x8070605040302010);
142 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42);
143 /* Not sure if this is the correct decimal representation... But both */
144 if (strcmp(pszBuf, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42"))
145 {
146 RTTestIFailed("error: '%s'\n"
147 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", pszBuf);
148 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));
149 }
150
151 /* 64-bit value bug. */
152 u64 = 0xa0000000;
153 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
154 if (strcmp(pszBuf, "u64=0xa0000000 42=42 u64=2684354560 42=42"))
155 RTTestIFailed("error: '%s'\n"
156 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", pszBuf);
157
158 /* uuid */
159 RTUUID Uuid;
160 RTUuidCreate(&Uuid);
161 char szCorrect[RTUUID_STR_LENGTH];
162 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));
163 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);
164 if (strcmp(pszBuf, szCorrect))
165 RTTestIFailed("error: '%s'\n"
166 "expected: '%s'\n",
167 pszBuf, szCorrect);
168
169 /*
170 * Nested
171 */
172 RTTestSub(hTest, "Nested (%N)");
173 testNested(__LINE__, "42 2684354560 42 asdf 42", "42 %u 42 %s 42", 2684354560U, "asdf");
174 testNested(__LINE__, "", "");
175
176 /*
177 * allocation
178 */
179 RTTestSub(hTest, "RTStrAPrintf");
180 char *psz = (char *)~0;
181 int cch3 = RTStrAPrintf(&psz, "Hey there! %s%s", "This is a test", "!");
182 if (cch3 < 0)
183 RTTestIFailed("RTStrAPrintf failed, cch3=%d\n", cch3);
184 else if (strcmp(psz, "Hey there! This is a test!"))
185 RTTestIFailed("RTStrAPrintf failed\n"
186 "got : '%s'\n"
187 "wanted: 'Hey there! This is a test!'\n",
188 psz);
189 else if ((int)strlen(psz) != cch3)
190 RTTestIFailed("RTStrAPrintf failed, cch3 == %d expected %u\n", cch3, strlen(psz));
191 RTStrFree(psz);
192
193/* This used to be very simple, but is not doing overflow handling checks and two APIs. */
194#define CHECK42(fmt, arg, out) \
195 do { \
196 static const char g_szCheck42Fmt[] = fmt " 42=%d " fmt " 42=%d" ; \
197 static const char g_szCheck42Expect[] = out " 42=42 " out " 42=42" ; \
198 \
199 cch = RTStrPrintf(pszBuf, BUF_SIZE, g_szCheck42Fmt, arg, 42, arg, 42); \
200 if (memcmp(pszBuf, g_szCheck42Expect, sizeof(g_szCheck42Expect)) != 0) \
201 RTTestIFailed("at line %d: format '%s'\n" \
202 " output: '%s'\n" \
203 " wanted: '%s'\n", \
204 __LINE__, fmt, pszBuf, g_szCheck42Expect); \
205 else if (cch != sizeof(g_szCheck42Expect) - 1) \
206 RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n", \
207 __LINE__, cch, sizeof(g_szCheck42Expect) - 1); \
208 \
209 RTTestIDisableAssertions(); \
210 for (size_t cbBuf = 0; cbBuf <= BUF_SIZE; cbBuf++) \
211 { \
212 memset(pszBuf, 0xcc, BUF_SIZE); \
213 const char chAfter = cbBuf != 0 ? '\0' : 0xcc; \
214 const size_t cchCompare = cbBuf >= sizeof(g_szCheck42Expect) ? sizeof(g_szCheck42Expect) - 1 \
215 : cbBuf > 0 ? cbBuf - 1 : 0; \
216 size_t cch1Expect = cchCompare; \
217 ssize_t cch2Expect = cbBuf >= sizeof(g_szCheck42Expect) \
218 ? sizeof(g_szCheck42Expect) - 1 : -(ssize_t)sizeof(g_szCheck42Expect); \
219 \
220 cch = RTStrPrintf(pszBuf, cbBuf, g_szCheck42Fmt, arg, 42, arg, 42);\
221 if ( memcmp(pszBuf, g_szCheck42Expect, cchCompare) != 0 \
222 || pszBuf[cchCompare] != chAfter) \
223 RTTestIFailed("at line %d: format '%s' (#1, cbBuf=%zu)\n" \
224 " output: '%s'\n" \
225 " wanted: '%s'\n", \
226 __LINE__, fmt, cbBuf, cbBuf ? pszBuf : "", g_szCheck42Expect); \
227 if (cch != cch1Expect) \
228 RTTestIFailed("at line %d: Invalid length %d returned for cbBuf=%zu, expected %zd! (#1)\n", \
229 __LINE__, cch, cbBuf, cch1Expect); \
230 \
231 cch2 = RTStrPrintf2(pszBuf, cbBuf, g_szCheck42Fmt, arg, 42, arg, 42);\
232 if ( memcmp(pszBuf, g_szCheck42Expect, cchCompare) != 0 \
233 || pszBuf[cchCompare] != chAfter) \
234 RTTestIFailed("at line %d: format '%s' (#2, cbBuf=%zu)\n" \
235 " output: '%s'\n" \
236 " wanted: '%s'\n", \
237 __LINE__, fmt, cbBuf, cbBuf ? pszBuf : "", g_szCheck42Expect); \
238 if (cch2 != cch2Expect) \
239 RTTestIFailed("at line %d: Invalid length %d returned for cbBuf=%zu, expected %zd! (#2)\n", \
240 __LINE__, cch2, cbBuf, cch2Expect); \
241 } \
242 RTTestIRestoreAssertions(); \
243 } while (0)
244
245#define CHECKSTR(Correct) \
246 if (strcmp(pszBuf, Correct)) \
247 RTTestIFailed("error: '%s'\n" \
248 "expected: '%s'\n", pszBuf, Correct);
249
250 /*
251 * Test the waters.
252 */
253 CHECK42("%d", 127, "127");
254 CHECK42("%s", "721", "721");
255
256 /*
257 * Runtime extensions.
258 */
259 RTTestSub(hTest, "Runtime format types (%R*)");
260 CHECK42("%RGi", (RTGCINT)127, "127");
261 CHECK42("%RGi", (RTGCINT)-586589, "-586589");
262
263 CHECK42("%RGp", (RTGCPHYS)0x0000000044505045, "0000000044505045");
264 CHECK42("%RGp", ~(RTGCPHYS)0, "ffffffffffffffff");
265
266 CHECK42("%RGu", (RTGCUINT)586589, "586589");
267 CHECK42("%RGu", (RTGCUINT)1, "1");
268 CHECK42("%RGu", (RTGCUINT)3000000000U, "3000000000");
269
270#if GC_ARCH_BITS == 32
271 CHECK42("%RGv", (RTGCUINTPTR)0, "00000000");
272 CHECK42("%RGv", ~(RTGCUINTPTR)0, "ffffffff");
273 CHECK42("%RGv", (RTGCUINTPTR)0x84342134, "84342134");
274#else
275 CHECK42("%RGv", (RTGCUINTPTR)0, "0000000000000000");
276 CHECK42("%RGv", ~(RTGCUINTPTR)0, "ffffffffffffffff");
277 CHECK42("%RGv", (RTGCUINTPTR)0x84342134, "0000000084342134");
278#endif
279
280 CHECK42("%RGx", (RTGCUINT)0x234, "234");
281 CHECK42("%RGx", (RTGCUINT)0xffffffff, "ffffffff");
282
283 CHECK42("%RRv", (RTRCUINTPTR)0, "00000000");
284 CHECK42("%RRv", ~(RTRCUINTPTR)0, "ffffffff");
285 CHECK42("%RRv", (RTRCUINTPTR)0x84342134, "84342134");
286
287 CHECK42("%RHi", (RTHCINT)127, "127");
288 CHECK42("%RHi", (RTHCINT)-586589, "-586589");
289
290 CHECK42("%RHp", (RTHCPHYS)0x0000000044505045, "0000000044505045");
291 CHECK42("%RHp", ~(RTHCPHYS)0, "ffffffffffffffff");
292
293 CHECK42("%RHu", (RTHCUINT)586589, "586589");
294 CHECK42("%RHu", (RTHCUINT)1, "1");
295 CHECK42("%RHu", (RTHCUINT)3000000000U, "3000000000");
296
297 if (sizeof(void*) == 8)
298 {
299 CHECK42("%RHv", (RTHCUINTPTR)0, "0000000000000000");
300 CHECK42("%RHv", ~(RTHCUINTPTR)0, "ffffffffffffffff");
301 CHECK42("%RHv", (RTHCUINTPTR)0x84342134, "0000000084342134");
302 }
303 else
304 {
305 CHECK42("%RHv", (RTHCUINTPTR)0, "00000000");
306 CHECK42("%RHv", ~(RTHCUINTPTR)0, "ffffffff");
307 CHECK42("%RHv", (RTHCUINTPTR)0x84342134, "84342134");
308 }
309
310 CHECK42("%RHx", (RTHCUINT)0x234, "234");
311 CHECK42("%RHx", (RTHCUINT)0xffffffff, "ffffffff");
312
313 CHECK42("%RI16", (int16_t)1, "1");
314 CHECK42("%RI16", (int16_t)-16384, "-16384");
315
316 CHECK42("%RI32", (int32_t)1123, "1123");
317 CHECK42("%RI32", (int32_t)-86596, "-86596");
318
319 CHECK42("%RI64", (int64_t)112345987345LL, "112345987345");
320 CHECK42("%RI64", (int64_t)-8659643985723459LL, "-8659643985723459");
321
322 CHECK42("%RI8", (int8_t)1, "1");
323 CHECK42("%RI8", (int8_t)-128, "-128");
324
325 CHECK42("%Rbn", "file.c", "file.c");
326 CHECK42("%Rbn", "foo/file.c", "file.c");
327 CHECK42("%Rbn", "/foo/file.c", "file.c");
328 CHECK42("%Rbn", "/dir/subdir/", "subdir/");
329
330 CHECK42("%Rfn", "function", "function");
331 CHECK42("%Rfn", "void function(void)", "function");
332
333 CHECK42("%RTfile", (RTFILE)127, "127");
334 CHECK42("%RTfile", (RTFILE)12341234, "12341234");
335
336 CHECK42("%RTfmode", (RTFMODE)0x123403, "00123403");
337
338 CHECK42("%RTfoff", (RTFOFF)12342312, "12342312");
339 CHECK42("%RTfoff", (RTFOFF)-123123123, "-123123123");
340 CHECK42("%RTfoff", (RTFOFF)858694596874568LL, "858694596874568");
341
342 RTFAR16 fp16;
343 fp16.off = 0x34ff;
344 fp16.sel = 0x0160;
345 CHECK42("%RTfp16", fp16, "0160:34ff");
346
347 RTFAR32 fp32;
348 fp32.off = 0xff094030;
349 fp32.sel = 0x0168;
350 CHECK42("%RTfp32", fp32, "0168:ff094030");
351
352 RTFAR64 fp64;
353 fp64.off = 0xffff003401293487ULL;
354 fp64.sel = 0x0ff8;
355 CHECK42("%RTfp64", fp64, "0ff8:ffff003401293487");
356 fp64.off = 0x0;
357 fp64.sel = 0x0;
358 CHECK42("%RTfp64", fp64, "0000:0000000000000000");
359
360 CHECK42("%RTgid", (RTGID)-1, "-1");
361 CHECK42("%RTgid", (RTGID)1004, "1004");
362
363 CHECK42("%RTino", (RTINODE)0, "0000000000000000");
364 CHECK42("%RTino", (RTINODE)0x123412341324ULL, "0000123412341324");
365
366 CHECK42("%RTint", (RTINT)127, "127");
367 CHECK42("%RTint", (RTINT)-586589, "-586589");
368 CHECK42("%RTint", (RTINT)-23498723, "-23498723");
369
370 CHECK42("%RTiop", (RTIOPORT)0x3c4, "03c4");
371 CHECK42("%RTiop", (RTIOPORT)0xffff, "ffff");
372
373 RTMAC Mac;
374 Mac.au8[0] = 0;
375 Mac.au8[1] = 0x1b;
376 Mac.au8[2] = 0x21;
377 Mac.au8[3] = 0x0a;
378 Mac.au8[4] = 0x1d;
379 Mac.au8[5] = 0xd9;
380 CHECK42("%RTmac", &Mac, "00:1b:21:0a:1d:d9");
381 Mac.au16[0] = 0xffff;
382 Mac.au16[1] = 0xffff;
383 Mac.au16[2] = 0xffff;
384 CHECK42("%RTmac", &Mac, "ff:ff:ff:ff:ff:ff");
385
386 RTNETADDRIPV4 Ipv4Addr;
387 Ipv4Addr.u = RT_H2N_U32_C(0xf040d003);
388 CHECK42("%RTnaipv4", Ipv4Addr.u, "240.64.208.3");
389 Ipv4Addr.u = RT_H2N_U32_C(0xffffffff);
390 CHECK42("%RTnaipv4", Ipv4Addr.u, "255.255.255.255");
391
392 RTNETADDRIPV6 Ipv6Addr;
393
394 /* any */
395 memset(&Ipv6Addr, 0, sizeof(Ipv6Addr));
396 CHECK42("%RTnaipv6", &Ipv6Addr, "::");
397
398 /* loopback */
399 Ipv6Addr.au8[15] = 1;
400 CHECK42("%RTnaipv6", &Ipv6Addr, "::1");
401
402 /* IPv4-compatible */
403 Ipv6Addr.au8[12] = 1;
404 Ipv6Addr.au8[13] = 1;
405 Ipv6Addr.au8[14] = 1;
406 Ipv6Addr.au8[15] = 1;
407 CHECK42("%RTnaipv6", &Ipv6Addr, "::1.1.1.1");
408
409 /* IPv4-mapped */
410 Ipv6Addr.au16[5] = RT_H2N_U16_C(0xffff);
411 CHECK42("%RTnaipv6", &Ipv6Addr, "::ffff:1.1.1.1");
412
413 /* IPv4-translated */
414 Ipv6Addr.au16[4] = RT_H2N_U16_C(0xffff);
415 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
416 CHECK42("%RTnaipv6", &Ipv6Addr, "::ffff:0:1.1.1.1");
417
418 /* single zero word is not abbreviated, leading zeroes are not printed */
419 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0000);
420 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0001);
421 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
422 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
423 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
424 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0001);
425 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
426 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
427 CHECK42("%RTnaipv6", &Ipv6Addr, "0:1:0:1:0:1:0:1");
428
429 /* longest run is abbreviated (here: at the beginning) */
430 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0000);
431 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
432 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
433 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
434 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
435 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
436 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0001);
437 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0000);
438 CHECK42("%RTnaipv6", &Ipv6Addr, "::1:0:0:1:0");
439
440 /* longest run is abbreviated (here: first) */
441 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
442 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
443 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
444 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
445 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0001);
446 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
447 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
448 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
449 CHECK42("%RTnaipv6", &Ipv6Addr, "1::1:0:0:1");
450
451 /* longest run is abbreviated (here: second) */
452 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
453 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
454 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
455 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
456 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
457 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
458 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
459 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
460 CHECK42("%RTnaipv6", &Ipv6Addr, "1:0:0:1::1");
461
462 /* longest run is abbreviated (here: at the end) */
463 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
464 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
465 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
466 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
467 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
468 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
469 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
470 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0000);
471 CHECK42("%RTnaipv6", &Ipv6Addr, "1:0:0:1::");
472
473 /* first of the two runs of equal length is abbreviated */
474 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x2001);
475 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0db8);
476 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
477 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
478 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0001);
479 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
480 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
481 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
482 CHECK42("%RTnaipv6", &Ipv6Addr, "2001:db8::1:0:0:1");
483
484 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x2001);
485 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0db8);
486 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x85a3);
487 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
488 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
489 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x8a2e);
490 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0370);
491 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x7334);
492 CHECK42("%RTnaipv6", &Ipv6Addr, "2001:db8:85a3::8a2e:370:7334");
493
494 Ipv6Addr.au64[0] = UINT64_MAX;
495 Ipv6Addr.au64[1] = UINT64_MAX;
496 CHECK42("%RTnaipv6", &Ipv6Addr, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
497
498 RTNETADDR NetAddr;
499 memset(&NetAddr, 0, sizeof(NetAddr));
500
501 /* plain IPv6 address if port is not specified */
502 NetAddr.enmType = RTNETADDRTYPE_IPV6;
503 NetAddr.uAddr.au16[0] = RT_H2N_U16_C(0x0001);
504 NetAddr.uAddr.au16[7] = RT_H2N_U16_C(0x0001);
505 NetAddr.uPort = RTNETADDR_PORT_NA;
506 CHECK42("%RTnaddr", &NetAddr, "1::1");
507
508 /* square brackets around IPv6 address if port is specified */
509 NetAddr.uPort = 1;
510 CHECK42("%RTnaddr", &NetAddr, "[1::1]:1");
511
512 CHECK42("%RTproc", (RTPROCESS)0xffffff, "00ffffff");
513 CHECK42("%RTproc", (RTPROCESS)0x43455443, "43455443");
514
515#if (HC_ARCH_BITS == 64 || GC_ARCH_BITS == 64)
516 CHECK42("%RTptr", (RTUINTPTR)0, "0000000000000000");
517 CHECK42("%RTptr", ~(RTUINTPTR)0, "ffffffffffffffff");
518 CHECK42("%RTptr", (RTUINTPTR)(uintptr_t)0x84342134, "0000000084342134");
519#else
520 CHECK42("%RTptr", (RTUINTPTR)0, "00000000");
521 CHECK42("%RTptr", ~(RTUINTPTR)0, "ffffffff");
522 CHECK42("%RTptr", (RTUINTPTR)(uintptr_t)0x84342134, "84342134");
523#endif
524
525#if ARCH_BITS == 64
526 AssertCompileSize(RTCCUINTREG, 8);
527 CHECK42("%RTreg", (RTCCUINTREG)0, "0000000000000000");
528 CHECK42("%RTreg", ~(RTCCUINTREG)0, "ffffffffffffffff");
529 CHECK42("%RTreg", (RTCCUINTREG)0x84342134, "0000000084342134");
530 CHECK42("%RTreg", (RTCCUINTREG)0x23484342134ULL, "0000023484342134");
531#elif ARCH_BITS == 32
532 AssertCompileSize(RTCCUINTREG, 4);
533 CHECK42("%RTreg", (RTCCUINTREG)0, "00000000");
534 CHECK42("%RTreg", ~(RTCCUINTREG)0, "ffffffff");
535 CHECK42("%RTreg", (RTCCUINTREG)0x84342134, "84342134");
536#else
537# error ARCH_BITS
538#endif
539
540 CHECK42("%RTsel", (RTSEL)0x543, "0543");
541 CHECK42("%RTsel", (RTSEL)0xf8f8, "f8f8");
542
543#if ARCH_BITS == 64
544 CHECK42("%RTsem", (RTSEMEVENT)0, "0000000000000000");
545 CHECK42("%RTsem", (RTSEMEVENT)(uintptr_t)0x23484342134ULL, "0000023484342134");
546#else
547 CHECK42("%RTsem", (RTSEMEVENT)0, "00000000");
548 CHECK42("%RTsem", (RTSEMEVENT)(uintptr_t)0x84342134, "84342134");
549#endif
550
551 CHECK42("%RTsock", (RTSOCKET)(uintptr_t)12234, "12234");
552 CHECK42("%RTsock", (RTSOCKET)(uintptr_t)584854543, "584854543");
553
554#if ARCH_BITS == 64
555 CHECK42("%RTthrd", (RTTHREAD)0, "0000000000000000");
556 CHECK42("%RTthrd", (RTTHREAD)~(uintptr_t)0, "ffffffffffffffff");
557 CHECK42("%RTthrd", (RTTHREAD)(uintptr_t)0x63484342134ULL, "0000063484342134");
558#else
559 CHECK42("%RTthrd", (RTTHREAD)0, "00000000");
560 CHECK42("%RTthrd", (RTTHREAD)~(uintptr_t)0, "ffffffff");
561 CHECK42("%RTthrd", (RTTHREAD)(uintptr_t)0x54342134, "54342134");
562#endif
563
564 CHECK42("%RTuid", (RTUID)-2, "-2");
565 CHECK42("%RTuid", (RTUID)90344, "90344");
566
567 CHECK42("%RTuint", (RTUINT)584589, "584589");
568 CHECK42("%RTuint", (RTUINT)3, "3");
569 CHECK42("%RTuint", (RTUINT)2400000000U, "2400000000");
570
571 RTUuidCreate(&Uuid);
572 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));
573 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);
574 if (strcmp(pszBuf, szCorrect))
575 RTTestIFailed("error: '%s'\n"
576 "expected: '%s'\n",
577 pszBuf, szCorrect);
578
579 CHECK42("%RTxint", (RTUINT)0x2345, "2345");
580 CHECK42("%RTxint", (RTUINT)0xffff8fff, "ffff8fff");
581
582 CHECK42("%RU16", (uint16_t)7, "7");
583 CHECK42("%RU16", (uint16_t)46384, "46384");
584
585 CHECK42("%RU32", (uint32_t)1123, "1123");
586 CHECK42("%RU32", (uint32_t)86596, "86596");
587 CHECK42("%4RU32", (uint32_t)42, " 42");
588 CHECK42("%04RU32", (uint32_t)42, "0042");
589 CHECK42("%.4RU32", (uint32_t)42, "0042");
590
591 CHECK42("%RU64", (uint64_t)112345987345ULL, "112345987345");
592 CHECK42("%RU64", (uint64_t)8659643985723459ULL, "8659643985723459");
593 CHECK42("%14RU64", (uint64_t)4, " 4");
594 CHECK42("%014RU64", (uint64_t)4, "00000000000004");
595 CHECK42("%.14RU64", (uint64_t)4, "00000000000004");
596
597 CHECK42("%RU8", (uint8_t)1, "1");
598 CHECK42("%RU8", (uint8_t)254, "254");
599 CHECK42("%RU8", 256, "0");
600
601 CHECK42("%RX16", (uint16_t)0x7, "7");
602 CHECK42("%RX16", 0x46384, "6384");
603
604 CHECK42("%RX32", (uint32_t)0x1123, "1123");
605 CHECK42("%RX32", (uint32_t)0x49939493, "49939493");
606
607 CHECK42("%RX64", UINT64_C(0x348734), "348734");
608 CHECK42("%RX64", UINT64_C(0x12312312312343f), "12312312312343f");
609 CHECK42("%5RX64", UINT64_C(0x42), " 42");
610 CHECK42("%05RX64", UINT64_C(0x42), "00042");
611 CHECK42("%.5RX64", UINT64_C(0x42), "00042");
612 CHECK42("%.05RX64", UINT64_C(0x42), "00042"); /* '0' is ignored */
613
614 CHECK42("%RX8", (uint8_t)1, "1");
615 CHECK42("%RX8", (uint8_t)0xff, "ff");
616 CHECK42("%RX8", 0x100, "0");
617
618 /*
619 * Thousand separators.
620 */
621 RTTestSub(hTest, "Thousand Separators (%'*)");
622
623 RTStrFormatNumber(pszBuf, 1, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1"); memset(pszBuf, '!', BUF_SIZE);
624 RTStrFormatNumber(pszBuf, 10, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10"); memset(pszBuf, '!', BUF_SIZE);
625 RTStrFormatNumber(pszBuf, 100, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100"); memset(pszBuf, '!', BUF_SIZE);
626 RTStrFormatNumber(pszBuf, 1000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000"); memset(pszBuf, '!', BUF_SIZE);
627 RTStrFormatNumber(pszBuf, 10000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10 000"); memset(pszBuf, '!', BUF_SIZE);
628 RTStrFormatNumber(pszBuf, 100000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100 000"); memset(pszBuf, '!', BUF_SIZE);
629 RTStrFormatNumber(pszBuf, 1000000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000 000"); memset(pszBuf, '!', BUF_SIZE);
630
631 CHECK42("%'u", 1, "1");
632 CHECK42("%'u", 10, "10");
633 CHECK42("%'u", 100, "100");
634 CHECK42("%'u", 1000, "1 000");
635 CHECK42("%'u", 10000, "10 000");
636 CHECK42("%'u", 100000, "100 000");
637 CHECK42("%'u", 1000000, "1 000 000");
638 CHECK42("%'RU64", _1T, "1 099 511 627 776");
639 CHECK42("%'RU64", _1E, "1 152 921 504 606 846 976");
640
641 /*
642 * String formatting.
643 */
644 RTTestSub(hTest, "String formatting (%s)");
645
646// 0 1 2 3 4 5 6 7
647// 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
648 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description");
649 CHECKSTR("cmd args description");
650
651 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "", "description");
652 CHECKSTR("cmd description");
653
654
655 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%*s", 0, "");
656 CHECKSTR("");
657
658 /* automatic conversions. */
659 static RTUNICP s_usz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii.
660 static RTUTF16 s_wsz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii.
661
662 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz1);
663 CHECKSTR("hello world");
664 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz1);
665 CHECKSTR("hello world");
666
667 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5ls", s_wsz1);
668 CHECKSTR("hello");
669 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5Ls", s_usz1);
670 CHECKSTR("hello");
671
672 /*
673 * Unicode string formatting.
674 */
675 RTTestSub(hTest, "Unicode string formatting (%ls)");
676 static RTUTF16 s_wszEmpty[] = { 0 }; //assumes ascii.
677 static RTUTF16 s_wszCmd[] = { 'c', 'm', 'd', 0 }; //assumes ascii.
678 static RTUTF16 s_wszArgs[] = { 'a', 'r', 'g', 's', 0 }; //assumes ascii.
679 static RTUTF16 s_wszDesc[] = { 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n', 0 }; //assumes ascii.
680
681// 0 1 2 3 4 5 6 7
682// 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
683 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);
684 CHECKSTR("cmd args description");
685
686 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc);
687 CHECKSTR("cmd description");
688
689
690#if 0
691 static RTUNICP s_usz2[] = { 0xc5, 0xc6, 0xf8, 0 };
692 static RTUTF16 s_wsz2[] = { 0xc5, 0xc6, 0xf8, 0 };
693 static char s_sz2[] = { 0xc5, 0xc6, 0xf8, 0 };/// @todo multibyte tests.
694
695 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz2);
696 CHECKSTR(s_sz2);
697 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz2);
698 CHECKSTR(s_sz2);
699#endif
700
701 /*
702 * Hex formatting.
703 */
704 RTTestSub(hTest, "Hex dump formatting (%Rhx*)");
705 static uint8_t const s_abHex1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
706 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.1Rhxs", s_abHex1);
707 CHECKSTR("00");
708 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.2Rhxs", s_abHex1);
709 CHECKSTR("00 01");
710 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhxs", s_abHex1);
711 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f");
712 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxs", sizeof(s_abHex1), s_abHex1);
713 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
714 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.*Rhxs", sizeof(s_abHex1), s_abHex1);
715 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
716 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%1.*Rhxs", sizeof(s_abHex1), s_abHex1);
717 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
718 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*Rhxs", sizeof(s_abHex1), s_abHex1);
719 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
720
721 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.8Rhxd", s_abHex1);
722 RTStrPrintf(pszBuf2, BUF_SIZE,
723 "%p 0000: 00 01 02 03 ....\n"
724 "%p 0004: 04 05 06 07 ....",
725 &s_abHex1[0], &s_abHex1[4]);
726 CHECKSTR(pszBuf2);
727
728 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.6Rhxd", s_abHex1);
729 RTStrPrintf(pszBuf2, BUF_SIZE,
730 "%p 0000: 00 01 02 03 ....\n"
731 "%p 0004: 04 05 ..",
732 &s_abHex1[0], &s_abHex1[4]);
733 CHECKSTR(pszBuf2);
734
735 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxd", sizeof(s_abHex1), s_abHex1);
736 RTStrPrintf(pszBuf2, BUF_SIZE,
737 "%p 0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
738 "%p 0010: 10 11 12 13 14 ....."
739 ,
740 &s_abHex1[0], &s_abHex1[0x10]);
741 CHECKSTR(pszBuf2);
742
743 /*
744 * human readable sizes and numbers.
745 */
746 RTTestSub(hTest, "Human readable (%Rhc?, %Rhn?)");
747 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(1235467), 42);
748 CHECKSTR("1.1MiB42");
749 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(999), 42);
750 CHECKSTR("999B42");
751 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(8), 42);
752 CHECKSTR("8B42");
753 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(0), 42);
754 CHECKSTR("0B42");
755 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.2Rhcb%u", UINT64_C(129957349834756374), 42);
756 CHECKSTR("115.42PiB42");
757 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.3Rhcb%u", UINT64_C(1957349834756374), 42);
758 CHECKSTR("1.738PiB42");
759 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.0Rhcb%u", UINT64_C(1957349834756374), 42);
760 CHECKSTR("1780TiB42");
761 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhcb%u", UINT64_C(6678345), 42);
762 CHECKSTR(" 6.3MiB42");
763
764 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhub%u", UINT64_C(6678345), 42);
765 CHECKSTR(" 6.3Mi42");
766
767 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhci%u", UINT64_C(6678345), 42);
768 CHECKSTR(" 6.7MB42"); /* rounded, unlike the binary variant.*/
769
770
771 /*
772 * x86 register formatting.
773 */
774 RTTestSub(hTest, "x86 register format types (%RAx86[*])");
775 CHECK42("%RAx86[cr0]", UINT64_C(0x80000011), "80000011{PE,ET,PG}");
776 CHECK42("%RAx86[cr0]", UINT64_C(0x80000001), "80000001{PE,PG}");
777 CHECK42("%RAx86[cr0]", UINT64_C(0x00000001), "00000001{PE}");
778 CHECK42("%RAx86[cr0]", UINT64_C(0x80000000), "80000000{PG}");
779 CHECK42("%RAx86[cr4]", UINT64_C(0x80000001), "80000001{VME,unkn=80000000}");
780 CHECK42("%#RAx86[cr4]", UINT64_C(0x80000001), "0x80000001{VME,unkn=0x80000000}");
781
782 /*
783 * Custom types.
784 */
785 RTTestSub(hTest, "Custom format types (%R[*])");
786 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
787 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
788 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1);
789 CHECKSTR("type3=1");
790
791 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
792 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
793 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2);
794 CHECKSTR("type3=1 type1=2");
795
796 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
797 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
798 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3);
799 CHECKSTR("type3=1 type1=2 type4=3");
800
801 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
802 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
803 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4);
804 CHECKSTR("type3=1 type1=2 type4=3 type2=4");
805
806 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
807 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
808 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)1, (void *)2, (void *)3, (void *)4, (void *)5);
809 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5");
810
811 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
812 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
813 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
814 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
815 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
816
817 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40, (void *)50);
818 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50");
819
820 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS);
821 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40);
822 CHECKSTR("type3=10 type1=20 type4=30 type5=40");
823
824 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS);
825 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30);
826 CHECKSTR("type3=10 type1=20 type4=30");
827
828 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS);
829 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20);
830 CHECKSTR("type3=10 type1=20");
831
832 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS);
833 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10);
834 CHECKSTR("type3=10");
835
836 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS);
837
838 /*
839 * Summarize and exit.
840 */
841 return RTTestSummaryAndDestroy(hTest);
842}
843
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette