Changeset 7183 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Feb 27, 2008 5:41:30 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 28483
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstStrFormat.cpp
r5999 r7183 34 34 #include <iprt/stream.h> 35 35 36 /******************************************************************************* 37 * Global Variables * 38 *******************************************************************************/ 39 static int g_cErrors = 0; 40 41 42 /** See FNRTSTRFORMATTYPE. */ 43 static DECLCALLBACK(size_t) TstType(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, 44 const char *pszType, void const *pvValue, 45 int cchWidth, int cchPrecision, unsigned fFlags, 46 void *pvUser) 47 { 48 /* validate */ 49 if (strncmp(pszType, "type", 4)) 50 { 51 RTPrintf("tstStrFormat: pszType=%s expected 'typeN'\n", pszType); 52 g_cErrors++; 53 } 54 55 int iType = pszType[4] - '0'; 56 if ((uintptr_t)pvUser != (uintptr_t)TstType + iType) 57 { 58 RTPrintf("tstStrFormat: pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType)); 59 g_cErrors++; 60 } 61 62 /* format */ 63 size_t cch = pfnOutput(pvArgOutput, pszType, 5); 64 cch += pfnOutput(pvArgOutput, "=", 1); 65 char szNum[64]; 66 size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 0, cchWidth, cchPrecision, fFlags); 67 cch += pfnOutput(pvArgOutput, szNum, cchNum); 68 return cch; 69 } 70 71 36 72 int main() 37 73 { 38 74 RTR3Init(); 39 75 40 int cErrors = 0;41 76 uint32_t u32 = 0x010; 42 77 uint64_t u64 = 0x100; … … 49 84 RTPrintf("error: '%s'\n" 50 85 "wanted 'u32=16 u64=256 u64=0x100'\n", szStr); 51 cErrors++;86 g_cErrors++; 52 87 } 53 88 … … 60 95 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", szStr); 61 96 RTPrintf("%d\n", (int)(u64 % 10)); 62 cErrors++;97 g_cErrors++; 63 98 } 64 99 … … 72 107 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", szStr); 73 108 RTPrintf("%d\n", (int)(u64 % 10)); 74 cErrors++;109 g_cErrors++; 75 110 } 76 111 … … 82 117 RTPrintf("error: '%s'\n" 83 118 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", szStr); 84 cErrors++;119 g_cErrors++; 85 120 } 86 121 … … 96 131 "expected: '%s'\n", 97 132 szStr, szCorrect); 98 cErrors++;133 g_cErrors++; 99 134 } 100 135 … … 105 140 { 106 141 RTPrintf("error: RTStrAPrintf failed, cch2=%d\n", cch2); 107 cErrors++;142 g_cErrors++; 108 143 } 109 144 else if (strcmp(psz, "Hey there! This is a test!")) … … 113 148 "wanted: 'Hey there! This is a test!'\n", 114 149 psz); 115 cErrors++;150 g_cErrors++; 116 151 } 117 152 else if ((int)strlen(psz) != cch2) 118 153 { 119 154 RTPrintf("error: RTStrAPrintf failed, cch2 == %d expected %u\n", cch2, strlen(psz)); 120 cErrors++;155 g_cErrors++; 121 156 } 122 157 RTStrFree(psz); … … 131 166 " wanted: '%s'\n", \ 132 167 __LINE__, fmt, szStr, out " 42=42 " out " 42=42"); \ 133 cErrors++; \168 g_cErrors++; \ 134 169 } \ 135 170 else if (cch != sizeof(out " 42=42 " out " 42=42") - 1) \ … … 137 172 RTPrintf("error(%d): Invalid length %d returned, expected %u!\n", \ 138 173 __LINE__, cch, sizeof(out " 42=42 " out " 42=42") - 1); \ 139 cErrors++; \174 g_cErrors++; \ 140 175 } \ 141 176 } while (0) … … 314 349 "expected: '%s'\n", 315 350 szStr, szCorrect); 316 cErrors++;351 g_cErrors++; 317 352 } 318 353 … … 351 386 RTPrintf("error: '%s'\n" \ 352 387 "expected: '%s'\n", szStr, Correct); \ 353 cErrors++; \388 g_cErrors++; \ 354 389 } 355 390 … … 394 429 #endif 395 430 431 /* 432 * Custom types. 433 */ 434 #define CHECK(expr) do { if (!(expr)) { RTPrintf("tstEnv: error line %d: %s\n", __LINE__, #expr); g_cErrors++; } } while (0) 435 #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) 436 437 CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 438 CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 439 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3]", (void *)1); 440 CHECKSTR("type3=1"); 441 442 CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 443 CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 444 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)1, (void *)2); 445 CHECKSTR("type3=1 type1=2"); 446 447 CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 448 CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 449 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3); 450 CHECKSTR("type3=1 type1=2 type4=3"); 451 452 CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 453 CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 454 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4); 455 CHECKSTR("type3=1 type1=2 type4=3 type2=4"); 456 457 CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 458 CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 459 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); 460 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5"); 461 462 CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 463 CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 464 CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 465 CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 466 CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 467 468 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); 469 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50"); 470 471 CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS); 472 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40); 473 CHECKSTR("type3=10 type1=20 type4=30 type5=40"); 474 475 CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS); 476 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30); 477 CHECKSTR("type3=10 type1=20 type4=30"); 478 479 CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS); 480 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)10, (void *)20); 481 CHECKSTR("type3=10 type1=20"); 482 483 CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS); 484 cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3]", (void *)10); 485 CHECKSTR("type3=10"); 486 487 CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS); 396 488 397 489 /* 398 490 * Summarize and exit. 399 491 */ 400 if (! cErrors)492 if (!g_cErrors) 401 493 RTPrintf("tstStrFormat: SUCCESS\n"); 402 494 else 403 RTPrintf("tstStrFormat: FAILED - %d errors\n", cErrors);404 return !! cErrors;495 RTPrintf("tstStrFormat: FAILED - %d errors\n", g_cErrors); 496 return !!g_cErrors; 405 497 } 406 498
Note:
See TracChangeset
for help on using the changeset viewer.