VirtualBox

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

Last change on this file since 64340 was 64340, checked in by vboxsync, 9 years ago

IPRT: Introducing RTStrPrintf2, RTStrPrintf2V, RTStrPrintf2Ex, and RTStrPrintf2ExV. The existing RTStrPrintf* interfaces are deprecated and unwanted in new code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 33.9 KB
Line 
1/* $Id: tstRTStrFormat.cpp 64340 2016-10-20 18:38:21Z vboxsync $ */
2/** @file
3 * IPRT Testcase - String formatting.
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 cch2 = 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) - code is buggy */ \
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 * Runtime extensions.
252 */
253 RTTestSub(hTest, "Runtime format types (%R*)");
254 CHECK42("%RGi", (RTGCINT)127, "127");
255 CHECK42("%RGi", (RTGCINT)-586589, "-586589");
256
257 CHECK42("%RGp", (RTGCPHYS)0x0000000044505045, "0000000044505045");
258 CHECK42("%RGp", ~(RTGCPHYS)0, "ffffffffffffffff");
259
260 CHECK42("%RGu", (RTGCUINT)586589, "586589");
261 CHECK42("%RGu", (RTGCUINT)1, "1");
262 CHECK42("%RGu", (RTGCUINT)3000000000U, "3000000000");
263
264#if GC_ARCH_BITS == 32
265 CHECK42("%RGv", (RTGCUINTPTR)0, "00000000");
266 CHECK42("%RGv", ~(RTGCUINTPTR)0, "ffffffff");
267 CHECK42("%RGv", (RTGCUINTPTR)0x84342134, "84342134");
268#else
269 CHECK42("%RGv", (RTGCUINTPTR)0, "0000000000000000");
270 CHECK42("%RGv", ~(RTGCUINTPTR)0, "ffffffffffffffff");
271 CHECK42("%RGv", (RTGCUINTPTR)0x84342134, "0000000084342134");
272#endif
273
274 CHECK42("%RGx", (RTGCUINT)0x234, "234");
275 CHECK42("%RGx", (RTGCUINT)0xffffffff, "ffffffff");
276
277 CHECK42("%RRv", (RTRCUINTPTR)0, "00000000");
278 CHECK42("%RRv", ~(RTRCUINTPTR)0, "ffffffff");
279 CHECK42("%RRv", (RTRCUINTPTR)0x84342134, "84342134");
280
281 CHECK42("%RHi", (RTHCINT)127, "127");
282 CHECK42("%RHi", (RTHCINT)-586589, "-586589");
283
284 CHECK42("%RHp", (RTHCPHYS)0x0000000044505045, "0000000044505045");
285 CHECK42("%RHp", ~(RTHCPHYS)0, "ffffffffffffffff");
286
287 CHECK42("%RHu", (RTHCUINT)586589, "586589");
288 CHECK42("%RHu", (RTHCUINT)1, "1");
289 CHECK42("%RHu", (RTHCUINT)3000000000U, "3000000000");
290
291 if (sizeof(void*) == 8)
292 {
293 CHECK42("%RHv", (RTHCUINTPTR)0, "0000000000000000");
294 CHECK42("%RHv", ~(RTHCUINTPTR)0, "ffffffffffffffff");
295 CHECK42("%RHv", (RTHCUINTPTR)0x84342134, "0000000084342134");
296 }
297 else
298 {
299 CHECK42("%RHv", (RTHCUINTPTR)0, "00000000");
300 CHECK42("%RHv", ~(RTHCUINTPTR)0, "ffffffff");
301 CHECK42("%RHv", (RTHCUINTPTR)0x84342134, "84342134");
302 }
303
304 CHECK42("%RHx", (RTHCUINT)0x234, "234");
305 CHECK42("%RHx", (RTHCUINT)0xffffffff, "ffffffff");
306
307 CHECK42("%RI16", (int16_t)1, "1");
308 CHECK42("%RI16", (int16_t)-16384, "-16384");
309
310 CHECK42("%RI32", (int32_t)1123, "1123");
311 CHECK42("%RI32", (int32_t)-86596, "-86596");
312
313 CHECK42("%RI64", (int64_t)112345987345LL, "112345987345");
314 CHECK42("%RI64", (int64_t)-8659643985723459LL, "-8659643985723459");
315
316 CHECK42("%RI8", (int8_t)1, "1");
317 CHECK42("%RI8", (int8_t)-128, "-128");
318
319 CHECK42("%Rbn", "file.c", "file.c");
320 CHECK42("%Rbn", "foo/file.c", "file.c");
321 CHECK42("%Rbn", "/foo/file.c", "file.c");
322 CHECK42("%Rbn", "/dir/subdir/", "subdir/");
323
324 CHECK42("%Rfn", "function", "function");
325 CHECK42("%Rfn", "void function(void)", "function");
326
327 CHECK42("%RTfile", (RTFILE)127, "127");
328 CHECK42("%RTfile", (RTFILE)12341234, "12341234");
329
330 CHECK42("%RTfmode", (RTFMODE)0x123403, "00123403");
331
332 CHECK42("%RTfoff", (RTFOFF)12342312, "12342312");
333 CHECK42("%RTfoff", (RTFOFF)-123123123, "-123123123");
334 CHECK42("%RTfoff", (RTFOFF)858694596874568LL, "858694596874568");
335
336 RTFAR16 fp16;
337 fp16.off = 0x34ff;
338 fp16.sel = 0x0160;
339 CHECK42("%RTfp16", fp16, "0160:34ff");
340
341 RTFAR32 fp32;
342 fp32.off = 0xff094030;
343 fp32.sel = 0x0168;
344 CHECK42("%RTfp32", fp32, "0168:ff094030");
345
346 RTFAR64 fp64;
347 fp64.off = 0xffff003401293487ULL;
348 fp64.sel = 0x0ff8;
349 CHECK42("%RTfp64", fp64, "0ff8:ffff003401293487");
350 fp64.off = 0x0;
351 fp64.sel = 0x0;
352 CHECK42("%RTfp64", fp64, "0000:0000000000000000");
353
354 CHECK42("%RTgid", (RTGID)-1, "-1");
355 CHECK42("%RTgid", (RTGID)1004, "1004");
356
357 CHECK42("%RTino", (RTINODE)0, "0000000000000000");
358 CHECK42("%RTino", (RTINODE)0x123412341324ULL, "0000123412341324");
359
360 CHECK42("%RTint", (RTINT)127, "127");
361 CHECK42("%RTint", (RTINT)-586589, "-586589");
362 CHECK42("%RTint", (RTINT)-23498723, "-23498723");
363
364 CHECK42("%RTiop", (RTIOPORT)0x3c4, "03c4");
365 CHECK42("%RTiop", (RTIOPORT)0xffff, "ffff");
366
367 RTMAC Mac;
368 Mac.au8[0] = 0;
369 Mac.au8[1] = 0x1b;
370 Mac.au8[2] = 0x21;
371 Mac.au8[3] = 0x0a;
372 Mac.au8[4] = 0x1d;
373 Mac.au8[5] = 0xd9;
374 CHECK42("%RTmac", &Mac, "00:1b:21:0a:1d:d9");
375 Mac.au16[0] = 0xffff;
376 Mac.au16[1] = 0xffff;
377 Mac.au16[2] = 0xffff;
378 CHECK42("%RTmac", &Mac, "ff:ff:ff:ff:ff:ff");
379
380 RTNETADDRIPV4 Ipv4Addr;
381 Ipv4Addr.u = RT_H2N_U32_C(0xf040d003);
382 CHECK42("%RTnaipv4", Ipv4Addr.u, "240.64.208.3");
383 Ipv4Addr.u = RT_H2N_U32_C(0xffffffff);
384 CHECK42("%RTnaipv4", Ipv4Addr.u, "255.255.255.255");
385
386 RTNETADDRIPV6 Ipv6Addr;
387
388 /* any */
389 memset(&Ipv6Addr, 0, sizeof(Ipv6Addr));
390 CHECK42("%RTnaipv6", &Ipv6Addr, "::");
391
392 /* loopback */
393 Ipv6Addr.au8[15] = 1;
394 CHECK42("%RTnaipv6", &Ipv6Addr, "::1");
395
396 /* IPv4-compatible */
397 Ipv6Addr.au8[12] = 1;
398 Ipv6Addr.au8[13] = 1;
399 Ipv6Addr.au8[14] = 1;
400 Ipv6Addr.au8[15] = 1;
401 CHECK42("%RTnaipv6", &Ipv6Addr, "::1.1.1.1");
402
403 /* IPv4-mapped */
404 Ipv6Addr.au16[5] = RT_H2N_U16_C(0xffff);
405 CHECK42("%RTnaipv6", &Ipv6Addr, "::ffff:1.1.1.1");
406
407 /* IPv4-translated */
408 Ipv6Addr.au16[4] = RT_H2N_U16_C(0xffff);
409 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
410 CHECK42("%RTnaipv6", &Ipv6Addr, "::ffff:0:1.1.1.1");
411
412 /* single zero word is not abbreviated, leading zeroes are not printed */
413 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0000);
414 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0001);
415 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
416 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
417 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
418 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0001);
419 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
420 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
421 CHECK42("%RTnaipv6", &Ipv6Addr, "0:1:0:1:0:1:0:1");
422
423 /* longest run is abbreviated (here: at the beginning) */
424 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0000);
425 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
426 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
427 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
428 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
429 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
430 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0001);
431 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0000);
432 CHECK42("%RTnaipv6", &Ipv6Addr, "::1:0:0:1:0");
433
434 /* longest run is abbreviated (here: first) */
435 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
436 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
437 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
438 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
439 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0001);
440 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
441 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
442 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
443 CHECK42("%RTnaipv6", &Ipv6Addr, "1::1:0:0:1");
444
445 /* longest run is abbreviated (here: second) */
446 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
447 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
448 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
449 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
450 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
451 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
452 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
453 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
454 CHECK42("%RTnaipv6", &Ipv6Addr, "1:0:0:1::1");
455
456 /* longest run is abbreviated (here: at the end) */
457 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x0001);
458 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0000);
459 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
460 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0001);
461 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
462 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
463 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
464 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0000);
465 CHECK42("%RTnaipv6", &Ipv6Addr, "1:0:0:1::");
466
467 /* first of the two runs of equal length is abbreviated */
468 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x2001);
469 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0db8);
470 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x0000);
471 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
472 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0001);
473 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x0000);
474 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0000);
475 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x0001);
476 CHECK42("%RTnaipv6", &Ipv6Addr, "2001:db8::1:0:0:1");
477
478 Ipv6Addr.au16[0] = RT_H2N_U16_C(0x2001);
479 Ipv6Addr.au16[1] = RT_H2N_U16_C(0x0db8);
480 Ipv6Addr.au16[2] = RT_H2N_U16_C(0x85a3);
481 Ipv6Addr.au16[3] = RT_H2N_U16_C(0x0000);
482 Ipv6Addr.au16[4] = RT_H2N_U16_C(0x0000);
483 Ipv6Addr.au16[5] = RT_H2N_U16_C(0x8a2e);
484 Ipv6Addr.au16[6] = RT_H2N_U16_C(0x0370);
485 Ipv6Addr.au16[7] = RT_H2N_U16_C(0x7334);
486 CHECK42("%RTnaipv6", &Ipv6Addr, "2001:db8:85a3::8a2e:370:7334");
487
488 Ipv6Addr.au64[0] = UINT64_MAX;
489 Ipv6Addr.au64[1] = UINT64_MAX;
490 CHECK42("%RTnaipv6", &Ipv6Addr, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
491
492 RTNETADDR NetAddr;
493 memset(&NetAddr, 0, sizeof(NetAddr));
494
495 /* plain IPv6 address if port is not specified */
496 NetAddr.enmType = RTNETADDRTYPE_IPV6;
497 NetAddr.uAddr.au16[0] = RT_H2N_U16_C(0x0001);
498 NetAddr.uAddr.au16[7] = RT_H2N_U16_C(0x0001);
499 NetAddr.uPort = RTNETADDR_PORT_NA;
500 CHECK42("%RTnaddr", &NetAddr, "1::1");
501
502 /* square brackets around IPv6 address if port is specified */
503 NetAddr.uPort = 1;
504 CHECK42("%RTnaddr", &NetAddr, "[1::1]:1");
505
506 CHECK42("%RTproc", (RTPROCESS)0xffffff, "00ffffff");
507 CHECK42("%RTproc", (RTPROCESS)0x43455443, "43455443");
508
509 if (sizeof(RTUINTPTR) == 8)
510 {
511 CHECK42("%RTptr", (RTUINTPTR)0, "0000000000000000");
512 CHECK42("%RTptr", ~(RTUINTPTR)0, "ffffffffffffffff");
513 CHECK42("%RTptr", (RTUINTPTR)0x84342134, "0000000084342134");
514 }
515 else
516 {
517 CHECK42("%RTptr", (RTUINTPTR)0, "00000000");
518 CHECK42("%RTptr", ~(RTUINTPTR)0, "ffffffff");
519 CHECK42("%RTptr", (RTUINTPTR)0x84342134, "84342134");
520 }
521
522#if ARCH_BITS == 64
523 AssertCompileSize(RTCCUINTREG, 8);
524 CHECK42("%RTreg", (RTCCUINTREG)0, "0000000000000000");
525 CHECK42("%RTreg", ~(RTCCUINTREG)0, "ffffffffffffffff");
526 CHECK42("%RTreg", (RTCCUINTREG)0x84342134, "0000000084342134");
527 CHECK42("%RTreg", (RTCCUINTREG)0x23484342134ULL, "0000023484342134");
528#elif ARCH_BITS == 32
529 AssertCompileSize(RTCCUINTREG, 4);
530 CHECK42("%RTreg", (RTCCUINTREG)0, "00000000");
531 CHECK42("%RTreg", ~(RTCCUINTREG)0, "ffffffff");
532 CHECK42("%RTreg", (RTCCUINTREG)0x84342134, "84342134");
533#else
534# error ARCH_BITS
535#endif
536
537 CHECK42("%RTsel", (RTSEL)0x543, "0543");
538 CHECK42("%RTsel", (RTSEL)0xf8f8, "f8f8");
539
540 if (sizeof(RTSEMEVENT) == 8)
541 {
542 CHECK42("%RTsem", (RTSEMEVENT)0, "0000000000000000");
543 CHECK42("%RTsem", (RTSEMEVENT)0x23484342134ULL, "0000023484342134");
544 }
545 else
546 {
547 CHECK42("%RTsem", (RTSEMEVENT)0, "00000000");
548 CHECK42("%RTsem", (RTSEMEVENT)0x84342134, "84342134");
549 }
550
551 CHECK42("%RTsock", (RTSOCKET)12234, "12234");
552 CHECK42("%RTsock", (RTSOCKET)584854543, "584854543");
553
554 if (sizeof(RTTHREAD) == 8)
555 {
556 CHECK42("%RTthrd", (RTTHREAD)0, "0000000000000000");
557 CHECK42("%RTthrd", (RTTHREAD)~(uintptr_t)0, "ffffffffffffffff");
558 CHECK42("%RTthrd", (RTTHREAD)0x63484342134ULL, "0000063484342134");
559 }
560 else
561 {
562 CHECK42("%RTthrd", (RTTHREAD)0, "00000000");
563 CHECK42("%RTthrd", (RTTHREAD)~(uintptr_t)0, "ffffffff");
564 CHECK42("%RTthrd", (RTTHREAD)0x54342134, "54342134");
565 }
566
567 CHECK42("%RTuid", (RTUID)-2, "-2");
568 CHECK42("%RTuid", (RTUID)90344, "90344");
569
570 CHECK42("%RTuint", (RTUINT)584589, "584589");
571 CHECK42("%RTuint", (RTUINT)3, "3");
572 CHECK42("%RTuint", (RTUINT)2400000000U, "2400000000");
573
574 RTUuidCreate(&Uuid);
575 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));
576 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);
577 if (strcmp(pszBuf, szCorrect))
578 RTTestIFailed("error: '%s'\n"
579 "expected: '%s'\n",
580 pszBuf, szCorrect);
581
582 CHECK42("%RTxint", (RTUINT)0x2345, "2345");
583 CHECK42("%RTxint", (RTUINT)0xffff8fff, "ffff8fff");
584
585 CHECK42("%RU16", (uint16_t)7, "7");
586 CHECK42("%RU16", (uint16_t)46384, "46384");
587
588 CHECK42("%RU32", (uint32_t)1123, "1123");
589 CHECK42("%RU32", (uint32_t)86596, "86596");
590 CHECK42("%4RU32", (uint32_t)42, " 42");
591 CHECK42("%04RU32", (uint32_t)42, "0042");
592 CHECK42("%.4RU32", (uint32_t)42, "0042");
593
594 CHECK42("%RU64", (uint64_t)112345987345ULL, "112345987345");
595 CHECK42("%RU64", (uint64_t)8659643985723459ULL, "8659643985723459");
596 CHECK42("%14RU64", (uint64_t)4, " 4");
597 CHECK42("%014RU64", (uint64_t)4, "00000000000004");
598 CHECK42("%.14RU64", (uint64_t)4, "00000000000004");
599
600 CHECK42("%RU8", (uint8_t)1, "1");
601 CHECK42("%RU8", (uint8_t)254, "254");
602 CHECK42("%RU8", 256, "0");
603
604 CHECK42("%RX16", (uint16_t)0x7, "7");
605 CHECK42("%RX16", 0x46384, "6384");
606
607 CHECK42("%RX32", (uint32_t)0x1123, "1123");
608 CHECK42("%RX32", (uint32_t)0x49939493, "49939493");
609
610 CHECK42("%RX64", UINT64_C(0x348734), "348734");
611 CHECK42("%RX64", UINT64_C(0x12312312312343f), "12312312312343f");
612 CHECK42("%5RX64", UINT64_C(0x42), " 42");
613 CHECK42("%05RX64", UINT64_C(0x42), "00042");
614 CHECK42("%.5RX64", UINT64_C(0x42), "00042");
615 CHECK42("%.05RX64", UINT64_C(0x42), "00042"); /* '0' is ignored */
616
617 CHECK42("%RX8", (uint8_t)1, "1");
618 CHECK42("%RX8", (uint8_t)0xff, "ff");
619 CHECK42("%RX8", 0x100, "0");
620
621 /*
622 * Thousand separators.
623 */
624 RTTestSub(hTest, "Thousand Separators (%'*)");
625
626 RTStrFormatNumber(pszBuf, 1, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1"); memset(pszBuf, '!', BUF_SIZE);
627 RTStrFormatNumber(pszBuf, 10, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10"); memset(pszBuf, '!', BUF_SIZE);
628 RTStrFormatNumber(pszBuf, 100, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100"); memset(pszBuf, '!', BUF_SIZE);
629 RTStrFormatNumber(pszBuf, 1000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000"); memset(pszBuf, '!', BUF_SIZE);
630 RTStrFormatNumber(pszBuf, 10000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10 000"); memset(pszBuf, '!', BUF_SIZE);
631 RTStrFormatNumber(pszBuf, 100000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100 000"); memset(pszBuf, '!', BUF_SIZE);
632 RTStrFormatNumber(pszBuf, 1000000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000 000"); memset(pszBuf, '!', BUF_SIZE);
633
634 CHECK42("%'u", 1, "1");
635 CHECK42("%'u", 10, "10");
636 CHECK42("%'u", 100, "100");
637 CHECK42("%'u", 1000, "1 000");
638 CHECK42("%'u", 10000, "10 000");
639 CHECK42("%'u", 100000, "100 000");
640 CHECK42("%'u", 1000000, "1 000 000");
641 CHECK42("%'RU64", _1T, "1 099 511 627 776");
642 CHECK42("%'RU64", _1E, "1 152 921 504 606 846 976");
643
644 /*
645 * String formatting.
646 */
647 RTTestSub(hTest, "String formatting (%s)");
648
649// 0 1 2 3 4 5 6 7
650// 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
651 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description");
652 CHECKSTR("cmd args description");
653
654 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "", "description");
655 CHECKSTR("cmd description");
656
657
658 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%*s", 0, "");
659 CHECKSTR("");
660
661 /* automatic conversions. */
662 static RTUNICP s_usz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii.
663 static RTUTF16 s_wsz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii.
664
665 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz1);
666 CHECKSTR("hello world");
667 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz1);
668 CHECKSTR("hello world");
669
670 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5ls", s_wsz1);
671 CHECKSTR("hello");
672 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5Ls", s_usz1);
673 CHECKSTR("hello");
674
675 /*
676 * Unicode string formatting.
677 */
678 RTTestSub(hTest, "Unicode string formatting (%ls)");
679 static RTUTF16 s_wszEmpty[] = { 0 }; //assumes ascii.
680 static RTUTF16 s_wszCmd[] = { 'c', 'm', 'd', 0 }; //assumes ascii.
681 static RTUTF16 s_wszArgs[] = { 'a', 'r', 'g', 's', 0 }; //assumes ascii.
682 static RTUTF16 s_wszDesc[] = { 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n', 0 }; //assumes ascii.
683
684// 0 1 2 3 4 5 6 7
685// 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
686 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);
687 CHECKSTR("cmd args description");
688
689 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc);
690 CHECKSTR("cmd description");
691
692
693#if 0
694 static RTUNICP s_usz2[] = { 0xc5, 0xc6, 0xf8, 0 };
695 static RTUTF16 s_wsz2[] = { 0xc5, 0xc6, 0xf8, 0 };
696 static char s_sz2[] = { 0xc5, 0xc6, 0xf8, 0 };/// @todo multibyte tests.
697
698 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz2);
699 CHECKSTR(s_sz2);
700 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz2);
701 CHECKSTR(s_sz2);
702#endif
703
704 /*
705 * Hex formatting.
706 */
707 RTTestSub(hTest, "Hex dump formatting (%Rhx*)");
708 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 };
709 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.1Rhxs", s_abHex1);
710 CHECKSTR("00");
711 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.2Rhxs", s_abHex1);
712 CHECKSTR("00 01");
713 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhxs", s_abHex1);
714 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f");
715 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxs", sizeof(s_abHex1), s_abHex1);
716 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
717 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.*Rhxs", sizeof(s_abHex1), s_abHex1);
718 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
719 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%1.*Rhxs", sizeof(s_abHex1), s_abHex1);
720 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
721 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*Rhxs", sizeof(s_abHex1), s_abHex1);
722 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14");
723
724 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.8Rhxd", s_abHex1);
725 RTStrPrintf(pszBuf2, BUF_SIZE,
726 "%p 0000: 00 01 02 03 ....\n"
727 "%p 0004: 04 05 06 07 ....",
728 &s_abHex1[0], &s_abHex1[4]);
729 CHECKSTR(pszBuf2);
730
731 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.6Rhxd", s_abHex1);
732 RTStrPrintf(pszBuf2, BUF_SIZE,
733 "%p 0000: 00 01 02 03 ....\n"
734 "%p 0004: 04 05 ..",
735 &s_abHex1[0], &s_abHex1[4]);
736 CHECKSTR(pszBuf2);
737
738 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxd", sizeof(s_abHex1), s_abHex1);
739 RTStrPrintf(pszBuf2, BUF_SIZE,
740 "%p 0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
741 "%p 0010: 10 11 12 13 14 ....."
742 ,
743 &s_abHex1[0], &s_abHex1[0x10]);
744 CHECKSTR(pszBuf2);
745
746 /*
747 * x86 register formatting.
748 */
749 RTTestSub(hTest, "x86 register format types (%RAx86[*])");
750 CHECK42("%RAx86[cr0]", UINT64_C(0x80000011), "80000011{PE,ET,PG}");
751 CHECK42("%RAx86[cr0]", UINT64_C(0x80000001), "80000001{PE,PG}");
752 CHECK42("%RAx86[cr0]", UINT64_C(0x00000001), "00000001{PE}");
753 CHECK42("%RAx86[cr0]", UINT64_C(0x80000000), "80000000{PG}");
754 CHECK42("%RAx86[cr4]", UINT64_C(0x80000001), "80000001{VME,unkn=80000000}");
755 CHECK42("%#RAx86[cr4]", UINT64_C(0x80000001), "0x80000001{VME,unkn=0x80000000}");
756
757 /*
758 * Custom types.
759 */
760 RTTestSub(hTest, "Custom format types (%R[*])");
761 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
762 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
763 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1);
764 CHECKSTR("type3=1");
765
766 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
767 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
768 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2);
769 CHECKSTR("type3=1 type1=2");
770
771 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
772 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
773 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3);
774 CHECKSTR("type3=1 type1=2 type4=3");
775
776 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
777 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
778 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4);
779 CHECKSTR("type3=1 type1=2 type4=3 type2=4");
780
781 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
782 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
783 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);
784 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5");
785
786 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
787 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
788 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
789 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
790 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
791
792 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);
793 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50");
794
795 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS);
796 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40);
797 CHECKSTR("type3=10 type1=20 type4=30 type5=40");
798
799 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS);
800 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30);
801 CHECKSTR("type3=10 type1=20 type4=30");
802
803 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS);
804 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20);
805 CHECKSTR("type3=10 type1=20");
806
807 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS);
808 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10);
809 CHECKSTR("type3=10");
810
811 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS);
812
813 /*
814 * Summarize and exit.
815 */
816 return RTTestSummaryAndDestroy(hTest);
817}
818
Note: See TracBrowser for help on using the repository browser.

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