- Timestamp:
- May 23, 2009 3:42:57 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47644
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/xml/Settings.cpp
r16560 r19942 246 246 247 247 stdx::char_auto_ptr result (new char [len]); 248 if (aBase == 0) 249 aBase = 10; 248 250 int vrc = RTStrFormatNumber (result.get(), aValue, aBase, 0, 0, flags); 249 251 if (RT_SUCCESS (vrc)) -
trunk/src/VBox/Runtime/common/string/strformat.cpp
r14066 r19942 170 170 static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags) 171 171 { 172 const char *pachDigits = "0123456789abcdef";173 char *pszStart = psz;172 const char *pachDigits = "0123456789abcdef"; 173 char *pszStart = psz; 174 174 int cchValue; 175 175 unsigned long ul; 176 #if 0177 unsigned long ullow;178 #endif179 176 int i; 180 177 int j; 181 178 182 /** @todo Formatting of 64 bit numbers is broken, fix it! */183 184 179 /* 185 * Validate and ad djust input...180 * Validate and adjust input... 186 181 */ 187 /** @todo r=bird: Dmitry, who is calling this code with uiBase == 0? */ 188 if (uiBase == 0) 189 uiBase = 10; 190 kASSERT((uiBase >= 2 || uiBase <= 16)); 182 Assert(uiBase >= 2 || uiBase <= 16); 191 183 if (fFlags & RTSTR_F_CAPITAL) 192 184 pachDigits = "0123456789ABCDEF"; 193 185 if (fFlags & RTSTR_F_LEFT) 194 186 fFlags &= ~RTSTR_F_ZEROPAD; 187 if ( (fFlags & RTSTR_F_THOUSAND_SEP) 188 && ( uiBase != 10 189 || (fFlags & RTSTR_F_ZEROPAD))) /** @todo implement RTSTR_F_ZEROPAD + RTSTR_F_THOUSAND_SEP. */ 190 fFlags &= ~RTSTR_F_THOUSAND_SEP; 195 191 196 192 /* … … 218 214 } while (ul); 219 215 } 216 if (fFlags & RTSTR_F_THOUSAND_SEP) 217 { 218 if (cchValue <= 3) 219 fFlags &= ~RTSTR_F_THOUSAND_SEP; 220 else 221 cchValue += cchValue / 3 - (cchValue % 3 == 0); 222 } 220 223 221 224 /* … … 281 284 { 282 285 uint64_t u64 = *(uint64_t *)(void *)&ullValue; 283 do 284 { 285 psz[i--] = pachDigits[u64 % uiBase]; 286 u64 /= uiBase; 287 } while (u64); 286 if (fFlags & RTSTR_F_THOUSAND_SEP) 287 { 288 do 289 { 290 if ((-i - 1) % 4 == 3) 291 psz[i--] = ' '; 292 psz[i--] = pachDigits[u64 % uiBase]; 293 u64 /= uiBase; 294 } while (u64); 295 } 296 else 297 { 298 do 299 { 300 psz[i--] = pachDigits[u64 % uiBase]; 301 u64 /= uiBase; 302 } while (u64); 303 } 288 304 } 289 305 else 290 306 { 291 307 ul = (fFlags & RTSTR_F_VALSIGNED) && (ullValue.ulLo & 0x80000000) ? -(int32_t)ullValue.ulLo : ullValue.ulLo; 292 do308 if (fFlags & RTSTR_F_THOUSAND_SEP) 293 309 { 294 psz[i--] = pachDigits[ul % uiBase]; 295 ul /= uiBase; 296 } while (ul); 310 do 311 { 312 if ((-i - 1) % 4 == 3) 313 psz[i--] = ' '; 314 psz[i--] = pachDigits[ul % uiBase]; 315 ul /= uiBase; 316 } while (ul); 317 } 318 else 319 { 320 do 321 { 322 psz[i--] = pachDigits[ul % uiBase]; 323 ul /= uiBase; 324 } while (ul); 325 } 297 326 } 298 299 327 300 328 /* … … 358 386 switch (*pszFormat++) 359 387 { 360 case '#': fFlags |= RTSTR_F_SPECIAL; continue; 361 case '-': fFlags |= RTSTR_F_LEFT; continue; 362 case '+': fFlags |= RTSTR_F_PLUS; continue; 363 case ' ': fFlags |= RTSTR_F_BLANK; continue; 364 case '0': fFlags |= RTSTR_F_ZEROPAD; continue; 388 case '#': fFlags |= RTSTR_F_SPECIAL; continue; 389 case '-': fFlags |= RTSTR_F_LEFT; continue; 390 case '+': fFlags |= RTSTR_F_PLUS; continue; 391 case ' ': fFlags |= RTSTR_F_BLANK; continue; 392 case '0': fFlags |= RTSTR_F_ZEROPAD; continue; 393 case '\'': fFlags |= RTSTR_F_THOUSAND_SEP; continue; 365 394 } 366 395 pszFormat--; -
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r13837 r19942 414 414 case RTSF_FP16: 415 415 { 416 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );416 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 417 417 cch = RTStrFormatNumber(&szBuf[0], u.fp16.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 418 418 Assert(cch == 4); … … 425 425 case RTSF_FP32: 426 426 { 427 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );427 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 428 428 cch = RTStrFormatNumber(&szBuf[0], u.fp32.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 429 429 Assert(cch == 4); … … 436 436 case RTSF_FP64: 437 437 { 438 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );438 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 439 439 cch = RTStrFormatNumber(&szBuf[0], u.fp64.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 440 440 Assert(cch == 4); -
trunk/src/VBox/Runtime/testcase/tstStrFormat.cpp
r14831 r19942 33 33 *******************************************************************************/ 34 34 #include <iprt/string.h> 35 35 36 #include <iprt/initterm.h> 37 #include <iprt/stream.h> 38 #include <iprt/test.h> 36 39 #include <iprt/uuid.h> 37 #include <iprt/string.h>38 #include <iprt/stream.h>39 40 /*******************************************************************************41 * Global Variables *42 *******************************************************************************/43 static int g_cErrors = 0;44 40 45 41 … … 52 48 /* validate */ 53 49 if (strncmp(pszType, "type", 4)) 54 { 55 RTPrintf("tstStrFormat: pszType=%s expected 'typeN'\n", pszType); 56 g_cErrors++; 57 } 50 RTTestIFailed("pszType=%s expected 'typeN'\n", pszType); 58 51 59 52 int iType = pszType[4] - '0'; 60 53 if ((uintptr_t)pvUser != (uintptr_t)TstType + iType) 61 { 62 RTPrintf("tstStrFormat: pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType)); 63 g_cErrors++; 64 } 54 RTTestIFailed("pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType)); 65 55 66 56 /* format */ … … 68 58 cch += pfnOutput(pvArgOutput, "=", 1); 69 59 char szNum[64]; 70 size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 0, cchWidth, cchPrecision, fFlags);60 size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 10, cchWidth, cchPrecision, fFlags); 71 61 cch += pfnOutput(pvArgOutput, szNum, cchNum); 72 62 return cch; … … 76 66 int main() 77 67 { 78 RTR3Init(); 68 int rc = RTR3Init(); 69 if (RT_FAILURE(rc)) 70 return 1; 71 RTTEST hTest; 72 rc = RTTestCreate("tstStrFormat", &hTest); 73 if (RT_FAILURE(rc)) 74 return 1; 75 RTTestBanner(hTest); 79 76 80 77 uint32_t u32 = 0x010; 81 78 uint64_t u64 = 0x100; 82 char szStr[120]; 79 #define BUF_SIZE 120 80 char *pszBuf = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE); 81 82 RTTestSub(hTest, "Basics"); 83 83 84 84 /* simple */ 85 size_t cch = RTStrPrintf(szStr, sizeof(szStr), "u32=%d u64=%lld u64=%#llx", u32, u64, u64); 86 if (strcmp(szStr, "u32=16 u64=256 u64=0x100")) 87 { 88 RTPrintf("error: '%s'\n" 89 "wanted 'u32=16 u64=256 u64=0x100'\n", szStr); 90 g_cErrors++; 85 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64); 86 if (strcmp(pszBuf, "u32=16 u64=256 u64=0x100")) 87 { 88 RTTestIFailed("error: '%s'\n" 89 "wanted 'u32=16 u64=256 u64=0x100'\n", pszBuf); 91 90 } 92 91 93 92 /* just big. */ 94 93 u64 = UINT64_C(0x7070605040302010); 95 cch = RTStrPrintf(szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 96 if (strcmp(szStr, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42")) 97 { 98 RTPrintf("error: '%s'\n" 99 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", szStr); 100 RTPrintf("%d\n", (int)(u64 % 10)); 101 g_cErrors++; 94 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 95 if (strcmp(pszBuf, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42")) 96 { 97 RTTestIFailed("error: '%s'\n" 98 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", pszBuf); 99 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10)); 102 100 } 103 101 104 102 /* huge and negative. */ 105 103 u64 = UINT64_C(0x8070605040302010); 106 cch = RTStrPrintf( szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42);104 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42); 107 105 /* Not sure if this is the correct decimal representation... But both */ 108 if (strcmp(szStr, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42")) 109 { 110 RTPrintf("error: '%s'\n" 111 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", szStr); 112 RTPrintf("%d\n", (int)(u64 % 10)); 113 g_cErrors++; 106 if (strcmp(pszBuf, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42")) 107 { 108 RTTestIFailed("error: '%s'\n" 109 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", pszBuf); 110 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10)); 114 111 } 115 112 116 113 /* 64-bit value bug. */ 117 114 u64 = 0xa0000000; 118 cch = RTStrPrintf(szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 119 if (strcmp(szStr, "u64=0xa0000000 42=42 u64=2684354560 42=42")) 120 { 121 RTPrintf("error: '%s'\n" 122 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", szStr); 123 g_cErrors++; 124 } 115 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 116 if (strcmp(pszBuf, "u64=0xa0000000 42=42 u64=2684354560 42=42")) 117 RTTestIFailed("error: '%s'\n" 118 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", pszBuf); 125 119 126 120 /* uuid */ … … 129 123 char szCorrect[RTUUID_STR_LENGTH]; 130 124 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect)); 131 cch = RTStrPrintf( szStr, sizeof(szStr), "%Vuuid", &Uuid);132 if (strcmp( szStr, szCorrect))133 {134 RTPrintf("error: '%s'\n"135 "expected: '%s'\n",136 szStr, szCorrect); 137 g_cErrors++;138 }139 140 /* allocation */125 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Vuuid", &Uuid); 126 if (strcmp(pszBuf, szCorrect)) 127 RTTestIFailed("error: '%s'\n" 128 "expected: '%s'\n", 129 pszBuf, szCorrect); 130 131 /* 132 * allocation 133 */ 134 RTTestSub(hTest, "RTStrAPrintf"); 141 135 char *psz = (char *)~0; 142 136 int cch2 = RTStrAPrintf(&psz, "Hey there! %s%s", "This is a test", "!"); 143 137 if (cch2 < 0) 144 { 145 RTPrintf("error: RTStrAPrintf failed, cch2=%d\n", cch2); 146 g_cErrors++; 147 } 138 RTTestIFailed("RTStrAPrintf failed, cch2=%d\n", cch2); 148 139 else if (strcmp(psz, "Hey there! This is a test!")) 149 { 150 RTPrintf("error: RTStrAPrintf failed\n" 151 "got : '%s'\n" 152 "wanted: 'Hey there! This is a test!'\n", 153 psz); 154 g_cErrors++; 155 } 140 RTTestIFailed("RTStrAPrintf failed\n" 141 "got : '%s'\n" 142 "wanted: 'Hey there! This is a test!'\n", 143 psz); 156 144 else if ((int)strlen(psz) != cch2) 157 { 158 RTPrintf("error: RTStrAPrintf failed, cch2 == %d expected %u\n", cch2, strlen(psz)); 159 g_cErrors++; 160 } 145 RTTestIFailed("RTStrAPrintf failed, cch2 == %d expected %u\n", cch2, strlen(psz)); 161 146 RTStrFree(psz); 162 147 163 148 #define CHECK42(fmt, arg, out) \ 164 149 do { \ 165 cch = RTStrPrintf(szStr, sizeof(szStr), fmt " 42=%d " fmt " 42=%d", arg, 42, arg, 42); \ 166 if (strcmp(szStr, out " 42=42 " out " 42=42")) \ 167 { \ 168 RTPrintf("error(%d): format '%s'\n" \ 169 " output: '%s'\n" \ 170 " wanted: '%s'\n", \ 171 __LINE__, fmt, szStr, out " 42=42 " out " 42=42"); \ 172 g_cErrors++; \ 173 } \ 150 cch = RTStrPrintf(pszBuf, BUF_SIZE, fmt " 42=%d " fmt " 42=%d", arg, 42, arg, 42); \ 151 if (strcmp(pszBuf, out " 42=42 " out " 42=42")) \ 152 RTTestIFailed("at line %d: format '%s'\n" \ 153 " output: '%s'\n" \ 154 " wanted: '%s'\n", \ 155 __LINE__, fmt, pszBuf, out " 42=42 " out " 42=42"); \ 174 156 else if (cch != sizeof(out " 42=42 " out " 42=42") - 1) \ 175 { \ 176 RTPrintf("error(%d): Invalid length %d returned, expected %u!\n", \ 177 __LINE__, cch, sizeof(out " 42=42 " out " 42=42") - 1); \ 178 g_cErrors++; \ 179 } \ 157 RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n", \ 158 __LINE__, cch, sizeof(out " 42=42 " out " 42=42") - 1); \ 180 159 } while (0) 160 161 #define CHECKSTR(Correct) \ 162 if (strcmp(pszBuf, Correct)) \ 163 RTTestIFailed("error: '%s'\n" \ 164 "expected: '%s'\n", pszBuf, Correct); \ 181 165 182 166 /* 183 167 * Runtime extensions. 184 168 */ 169 RTTestSub(hTest, "Runtime format types (%R*)"); 185 170 CHECK42("%RGi", (RTGCINT)127, "127"); 186 171 CHECK42("%RGi", (RTGCINT)-586589, "-586589"); … … 357 342 RTUuidCreate(&Uuid); 358 343 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect)); 359 cch = RTStrPrintf(szStr, sizeof(szStr), "%RTuuid", &Uuid); 360 if (strcmp(szStr, szCorrect)) 361 { 362 RTPrintf("error: '%s'\n" 363 "expected: '%s'\n", 364 szStr, szCorrect); 365 g_cErrors++; 366 } 344 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid); 345 if (strcmp(pszBuf, szCorrect)) 346 RTTestIFailed("error: '%s'\n" 347 "expected: '%s'\n", 348 pszBuf, szCorrect); 367 349 368 350 CHECK42("%RTxint", (RTGCUINT)0x2345, "2345"); … … 395 377 CHECK42("%RX8", 0x100, "0"); 396 378 397 #define CHECKSTR(Correct) \ 398 if (strcmp(szStr, Correct)) \ 399 { \ 400 RTPrintf("error: '%s'\n" \ 401 "expected: '%s'\n", szStr, Correct); \ 402 g_cErrors++; \ 403 } 379 /* 380 * Thousand separators. 381 */ 382 RTTestSub(hTest, "Thousand Separators (%'*)"); 383 384 RTStrFormatNumber(pszBuf, 1, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1"); memset(pszBuf, '!', BUF_SIZE); 385 RTStrFormatNumber(pszBuf, 10, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10"); memset(pszBuf, '!', BUF_SIZE); 386 RTStrFormatNumber(pszBuf, 100, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100"); memset(pszBuf, '!', BUF_SIZE); 387 RTStrFormatNumber(pszBuf, 1000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000"); memset(pszBuf, '!', BUF_SIZE); 388 RTStrFormatNumber(pszBuf, 10000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10 000"); memset(pszBuf, '!', BUF_SIZE); 389 RTStrFormatNumber(pszBuf, 100000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100 000"); memset(pszBuf, '!', BUF_SIZE); 390 RTStrFormatNumber(pszBuf, 1000000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000 000"); memset(pszBuf, '!', BUF_SIZE); 391 392 CHECK42("%'u", 1, "1"); 393 CHECK42("%'u", 10, "10"); 394 CHECK42("%'u", 100, "100"); 395 CHECK42("%'u", 1000, "1 000"); 396 CHECK42("%'u", 10000, "10 000"); 397 CHECK42("%'u", 100000, "100 000"); 398 CHECK42("%'u", 1000000, "1 000 000"); 399 CHECK42("%'RU64", _1T, "1 099 511 627 776"); 400 CHECK42("%'RU64", _1E, "1 152 921 504 606 846 976"); 404 401 405 402 /* 406 403 * String formatting. 407 404 */ 405 RTTestSub(hTest, "String formatting (%s)"); 406 408 407 // 0 1 2 3 4 5 6 7 409 408 // 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0 410 cch = RTStrPrintf( szStr, sizeof(szStr), "%-10s %-30s %s", "cmd", "args", "description");409 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description"); 411 410 CHECKSTR("cmd args description"); 412 411 413 cch = RTStrPrintf( szStr, sizeof(szStr), "%-10s %-30s %s", "cmd", "", "description");412 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "", "description"); 414 413 CHECKSTR("cmd description"); 415 414 416 415 417 cch = RTStrPrintf( szStr, sizeof(szStr), "%*s", 0, "");416 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%*s", 0, ""); 418 417 CHECKSTR(""); 419 418 … … 422 421 static RTUTF16 s_wsz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii. 423 422 424 cch = RTStrPrintf( szStr, sizeof(szStr), "%ls", s_wsz1);423 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz1); 425 424 CHECKSTR("hello world"); 426 cch = RTStrPrintf( szStr, sizeof(szStr), "%Ls", s_usz1);425 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz1); 427 426 CHECKSTR("hello world"); 428 427 429 cch = RTStrPrintf( szStr, sizeof(szStr), "%.5ls", s_wsz1);428 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5ls", s_wsz1); 430 429 CHECKSTR("hello"); 431 cch = RTStrPrintf( szStr, sizeof(szStr), "%.5Ls", s_usz1);430 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5Ls", s_usz1); 432 431 CHECKSTR("hello"); 433 432 … … 435 434 * Unicode string formatting. 436 435 */ 436 RTTestSub(hTest, "Unicode string formatting (%ls)"); 437 437 static RTUTF16 s_wszEmpty[] = { 0 }; //assumes ascii. 438 438 static RTUTF16 s_wszCmd[] = { 'c', 'm', 'd', 0 }; //assumes ascii. … … 442 442 // 0 1 2 3 4 5 6 7 443 443 // 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0 444 cch = RTStrPrintf( szStr, sizeof(szStr), "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);444 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc); 445 445 CHECKSTR("cmd args description"); 446 446 447 cch = RTStrPrintf( szStr, sizeof(szStr), "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc);447 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc); 448 448 CHECKSTR("cmd description"); 449 449 … … 454 454 static char s_sz2[] = { 0xc5, 0xc6, 0xf8, 0 };///@todo multibyte tests. 455 455 456 cch = RTStrPrintf( szStr, sizeof(szStr), "%ls", s_wsz2);456 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz2); 457 457 CHECKSTR(s_sz2); 458 cch = RTStrPrintf( szStr, sizeof(szStr), "%Ls", s_usz2);458 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz2); 459 459 CHECKSTR(s_sz2); 460 460 #endif … … 463 463 * Custom types. 464 464 */ 465 #define CHECK(expr) do { if (!(expr)) { RTPrintf("tstEnv: error line %d: %s\n", __LINE__, #expr); g_cErrors++; } } while (0) 466 #define CHECK_RC(expr, rc) do { int rc2 = expr; if (rc2 != (rc)) { RTPrintf("tstEnv: error line %d: %s -> %Rrc expected %Rrc\n", __LINE__, #expr, rc2, rc); g_cErrors++; } } while (0) 467 468 CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 469 CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 470 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3]", (void *)1); 465 RTTestSub(hTest, "Custom format types (%R[*])"); 466 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 467 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 468 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1); 471 469 CHECKSTR("type3=1"); 472 470 473 CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);474 CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);475 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)1, (void *)2);471 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 472 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 473 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2); 476 474 CHECKSTR("type3=1 type1=2"); 477 475 478 CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);479 CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);480 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3);476 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 477 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 478 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3); 481 479 CHECKSTR("type3=1 type1=2 type4=3"); 482 480 483 CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);484 CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);485 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4);481 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 482 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 483 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4); 486 484 CHECKSTR("type3=1 type1=2 type4=3 type2=4"); 487 485 488 CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);489 CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);490 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)1, (void *)2, (void *)3, (void *)4, (void *)5);486 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 487 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 488 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); 491 489 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5"); 492 490 493 CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);494 CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);495 CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);496 CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);497 CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);498 499 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40, (void *)50);491 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 492 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 493 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 494 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 495 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 496 497 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); 500 498 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50"); 501 499 502 CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS);503 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40);500 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS); 501 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40); 504 502 CHECKSTR("type3=10 type1=20 type4=30 type5=40"); 505 503 506 CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS);507 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30);504 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS); 505 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30); 508 506 CHECKSTR("type3=10 type1=20 type4=30"); 509 507 510 CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS);511 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)10, (void *)20);508 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS); 509 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20); 512 510 CHECKSTR("type3=10 type1=20"); 513 511 514 CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS);515 cch = RTStrPrintf( szStr, sizeof(szStr), "%R[type3]", (void *)10);512 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS); 513 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10); 516 514 CHECKSTR("type3=10"); 517 515 518 CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS);516 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS); 519 517 520 518 /* 521 519 * Summarize and exit. 522 520 */ 523 if (!g_cErrors) 524 RTPrintf("tstStrFormat: SUCCESS\n"); 525 else 526 RTPrintf("tstStrFormat: FAILED - %d errors\n", g_cErrors); 527 return !!g_cErrors; 521 return RTTestSummaryAndDestroy(hTest); 528 522 } 529 523
Note:
See TracChangeset
for help on using the changeset viewer.