Changeset 86335 in vbox
- Timestamp:
- Sep 28, 2020 9:23:50 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp
r83838 r86335 146 146 147 147 148 int main() 149 { 150 RTTEST hTest; 151 int rc = RTTestInitAndCreate("tstRTStrFormat", &hTest); 152 if (rc) 153 return rc; 154 RTTestBanner(hTest); 155 156 uint32_t u32 = 0x010; 157 uint64_t u64 = 0x100; 148 149 150 /* 151 * This next portion used to all be in main() but gcc cannot handle 152 * that in asan + -O2 mode. 153 */ 154 155 156 158 157 #define BUF_SIZE 120 159 char *pszBuf = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE);160 char *pszBuf2 = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE);161 162 RTTestSub(hTest, "Basics");163 164 /* simple */165 static const char s_szSimpleExpect[] = "u32=16 u64=256 u64=0x100";166 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64);167 if (strcmp(pszBuf, s_szSimpleExpect))168 RTTestIFailed("error: '%s'\n"169 "wanted '%s'\n", pszBuf, s_szSimpleExpect);170 else if (cch != sizeof(s_szSimpleExpect) - 1)171 RTTestIFailed("error: got %zd, expected %zd (#1)\n", cch, sizeof(s_szSimpleExpect) - 1);172 173 ssize_t cch2 = RTStrPrintf2(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64);174 if (strcmp(pszBuf, "u32=16 u64=256 u64=0x100"))175 RTTestIFailed("error: '%s' (#2)\n"176 "wanted '%s' (#2)\n", pszBuf, s_szSimpleExpect);177 else if (cch2 != sizeof(s_szSimpleExpect) - 1)178 RTTestIFailed("error: got %zd, expected %zd (#2)\n", cch2, sizeof(s_szSimpleExpect) - 1);179 180 /* just big. */181 u64 = UINT64_C(0x7070605040302010);182 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);183 if (strcmp(pszBuf, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42"))184 {185 RTTestIFailed("error: '%s'\n"186 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", pszBuf);187 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));188 }189 190 /* huge and negative. */191 u64 = UINT64_C(0x8070605040302010);192 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42);193 /* Not sure if this is the correct decimal representation... But both */194 if (strcmp(pszBuf, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42"))195 {196 RTTestIFailed("error: '%s'\n"197 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", pszBuf);198 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));199 }200 201 /* 64-bit value bug. */202 u64 = 0xa0000000;203 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);204 if (strcmp(pszBuf, "u64=0xa0000000 42=42 u64=2684354560 42=42"))205 RTTestIFailed("error: '%s'\n"206 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", pszBuf);207 208 /* uuid */209 RTUUID Uuid;210 RTUuidCreate(&Uuid);211 char szCorrect[RTUUID_STR_LENGTH];212 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));213 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);214 if (strcmp(pszBuf, szCorrect))215 RTTestIFailed("error: '%s'\n"216 "expected: '%s'\n",217 pszBuf, szCorrect);218 219 /*220 * Nested221 */222 RTTestSub(hTest, "Nested (%N)");223 testNested(__LINE__, "42 2684354560 42 asdf 42", "42 %u 42 %s 42", 2684354560U, "asdf");224 testNested(__LINE__, "", "");225 226 /*227 * allocation228 */229 RTTestSub(hTest, "RTStrAPrintf");230 char *psz = (char *)~0;231 int cch3 = RTStrAPrintf(&psz, "Hey there! %s%s", "This is a test", "!");232 if (cch3 < 0)233 RTTestIFailed("RTStrAPrintf failed, cch3=%d\n", cch3);234 else if (strcmp(psz, "Hey there! This is a test!"))235 RTTestIFailed("RTStrAPrintf failed\n"236 "got : '%s'\n"237 "wanted: 'Hey there! This is a test!'\n",238 psz);239 else if ((int)strlen(psz) != cch3)240 RTTestIFailed("RTStrAPrintf failed, cch3 == %d expected %u\n", cch3, strlen(psz));241 RTStrFree(psz);242 158 243 159 /* This used to be very simple, but is not doing overflow handling checks and two APIs. */ … … 247 163 static const char g_szCheck42Expect[] = out " 42=42 " out " 42=42" ; \ 248 164 \ 249 cch = RTStrPrintf(pszBuf, BUF_SIZE, g_szCheck42Fmt, arg, 42, arg, 42); \165 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, g_szCheck42Fmt, arg, 42, arg, 42); \ 250 166 if (memcmp(pszBuf, g_szCheck42Expect, sizeof(g_szCheck42Expect)) != 0) \ 251 167 RTTestIFailed("at line %d: format '%s'\n" \ … … 279 195 __LINE__, cch, cbBuf, cch1Expect); \ 280 196 \ 281 cch2 = RTStrPrintf2(pszBuf, cbBuf, g_szCheck42Fmt, arg, 42, arg, 42);\197 ssize_t cch2 = RTStrPrintf2(pszBuf, cbBuf, g_szCheck42Fmt, arg, 42, arg, 42);\ 282 198 if ( memcmp(pszBuf, g_szCheck42Expect, cchCompare) != 0 \ 283 199 || pszBuf[cchCompare] != chAfter) \ … … 298 214 "expected: '%s'\n", pszBuf, Correct); 299 215 300 /* 301 * Test the waters. 302 */ 303 CHECK42("%d", 127, "127"); 304 CHECK42("%s", "721", "721"); 305 306 /* 307 * Runtime extensions. 308 */ 216 static void testBasics(RTTEST hTest, char *pszBuf) 217 { 218 RTTestSub(hTest, "Basics"); 219 220 uint32_t u32 = 0x010; 221 uint64_t u64 = 0x100; 222 223 /* simple */ 224 static const char s_szSimpleExpect[] = "u32=16 u64=256 u64=0x100"; 225 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64); 226 if (strcmp(pszBuf, s_szSimpleExpect)) 227 RTTestIFailed("error: '%s'\n" 228 "wanted '%s'\n", pszBuf, s_szSimpleExpect); 229 else if (cch != sizeof(s_szSimpleExpect) - 1) 230 RTTestIFailed("error: got %zd, expected %zd (#1)\n", cch, sizeof(s_szSimpleExpect) - 1); 231 232 ssize_t cch2 = RTStrPrintf2(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64); 233 if (strcmp(pszBuf, "u32=16 u64=256 u64=0x100")) 234 RTTestIFailed("error: '%s' (#2)\n" 235 "wanted '%s' (#2)\n", pszBuf, s_szSimpleExpect); 236 else if (cch2 != sizeof(s_szSimpleExpect) - 1) 237 RTTestIFailed("error: got %zd, expected %zd (#2)\n", cch2, sizeof(s_szSimpleExpect) - 1); 238 239 /* just big. */ 240 u64 = UINT64_C(0x7070605040302010); 241 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 242 if (strcmp(pszBuf, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42")) 243 { 244 RTTestIFailed("error: '%s'\n" 245 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", pszBuf); 246 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10)); 247 } 248 249 /* huge and negative. */ 250 u64 = UINT64_C(0x8070605040302010); 251 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42); 252 /* Not sure if this is the correct decimal representation... But both */ 253 if (strcmp(pszBuf, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42")) 254 { 255 RTTestIFailed("error: '%s'\n" 256 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", pszBuf); 257 RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10)); 258 } 259 260 /* 64-bit value bug. */ 261 u64 = 0xa0000000; 262 cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42); 263 if (strcmp(pszBuf, "u64=0xa0000000 42=42 u64=2684354560 42=42")) 264 RTTestIFailed("error: '%s'\n" 265 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", pszBuf); 266 267 /* uuid */ 268 RTUUID Uuid; 269 RTUuidCreate(&Uuid); 270 char szCorrect[RTUUID_STR_LENGTH]; 271 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect)); 272 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid); 273 if (strcmp(pszBuf, szCorrect)) 274 RTTestIFailed("error: '%s'\n" 275 "expected: '%s'\n", 276 pszBuf, szCorrect); 277 } 278 279 280 static void testRuntimeExtensions(RTTEST hTest, char *pszBuf) 281 { 309 282 RTTestSub(hTest, "Runtime format types (%R*)"); 310 283 CHECK42("%RGi", (RTGCINT)127, "127"); … … 629 602 CHECK42("%RTuint", (RTUINT)2400000000U, "2400000000"); 630 603 604 RTUUID Uuid; 605 char szCorrect[RTUUID_STR_LENGTH]; 631 606 RTUuidCreate(&Uuid); 632 607 RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect)); 633 cch =RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);608 RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid); 634 609 if (strcmp(pszBuf, szCorrect)) 635 610 RTTestIFailed("error: '%s'\n" … … 680 655 CHECK42("%RX8", 0x100, "0"); 681 656 682 /* 683 * Thousand separators. 684 */ 657 } 658 659 static void testThousandSeparators(RTTEST hTest, char *pszBuf) 660 { 685 661 RTTestSub(hTest, "Thousand Separators (%'*)"); 686 662 … … 702 678 CHECK42("%'RU64", _1T, "1 099 511 627 776"); 703 679 CHECK42("%'RU64", _1E, "1 152 921 504 606 846 976"); 704 705 /* 706 * String formatting. 707 */ 680 } 681 682 static void testStringFormatter(RTTEST hTest, char *pszBuf) 683 { 708 684 RTTestSub(hTest, "String formatting (%s)"); 709 685 710 686 // 0 1 2 3 4 5 6 7 711 687 // 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0 712 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description");688 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description"); 713 689 CHECKSTR("cmd args description"); 714 690 … … 733 709 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5Ls", s_usz1); 734 710 CHECKSTR("hello"); 735 736 /* 737 * Unicode string formatting. 738 */ 711 } 712 713 static void testUnicodeStringFormatter(RTTEST hTest, char *pszBuf) 714 { 739 715 RTTestSub(hTest, "Unicode string formatting (%ls)"); 740 716 static RTUTF16 s_wszEmpty[] = { 0 }; //assumes ascii. … … 745 721 // 0 1 2 3 4 5 6 7 746 722 // 0....5....0....5....0....5....0....5....0....5....0....5....0....5....0 747 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);723 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc); 748 724 CHECKSTR("cmd args description"); 749 725 … … 762 738 CHECKSTR(s_sz2); 763 739 #endif 764 765 /* 766 * Hex formatting. 767 */ 740 } 741 742 static void testHexFormatter(RTTEST hTest, char *pszBuf, char *pszBuf2) 743 { 768 744 RTTestSub(hTest, "Hex dump formatting (%Rhx*)"); 769 745 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 }; 770 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.1Rhxs", s_abHex1);746 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.1Rhxs", s_abHex1); 771 747 CHECKSTR("00"); 772 748 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.2Rhxs", s_abHex1); … … 820 796 "0123456789abcdff/0010: 10 11 12 13 14 ....."); 821 797 CHECKSTR(pszBuf2); 822 823 /* 824 * human readable sizes and numbers. 825 */ 798 } 799 800 static void testHumanReadableNumbers(RTTEST hTest, char *pszBuf) 801 { 826 802 RTTestSub(hTest, "Human readable (%Rhc?, %Rhn?)"); 827 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(1235467), 42);803 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(1235467), 42); 828 804 CHECKSTR("1.1MiB42"); 829 805 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Rhcb%u", UINT64_C(999), 42); … … 857 833 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhci%u", UINT64_C(6678345), 42); 858 834 CHECKSTR(" 6.7MB42"); /* rounded, unlike the binary variant.*/ 859 835 } 836 837 static void testCustomTypes(RTTEST hTest, char *pszBuf) 838 { 839 RTTestSub(hTest, "Custom format types (%R[*])"); 840 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 841 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 842 size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1); 843 CHECKSTR("type3=1"); 844 845 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 846 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 847 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2); 848 CHECKSTR("type3=1 type1=2"); 849 850 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 851 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 852 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3); 853 CHECKSTR("type3=1 type1=2 type4=3"); 854 855 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 856 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 857 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4); 858 CHECKSTR("type3=1 type1=2 type4=3 type2=4"); 859 860 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 861 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 862 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); 863 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5"); 864 865 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 866 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 867 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 868 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 869 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 870 871 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); 872 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50"); 873 874 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS); 875 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40); 876 CHECKSTR("type3=10 type1=20 type4=30 type5=40"); 877 878 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS); 879 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30); 880 CHECKSTR("type3=10 type1=20 type4=30"); 881 882 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS); 883 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20); 884 CHECKSTR("type3=10 type1=20"); 885 886 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS); 887 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10); 888 CHECKSTR("type3=10"); 889 890 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS); 891 } 892 893 894 int main() 895 { 896 RTTEST hTest; 897 int rc = RTTestInitAndCreate("tstRTStrFormat", &hTest); 898 if (rc) 899 return rc; 900 RTTestBanner(hTest); 901 902 char *pszBuf = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE); 903 char *pszBuf2 = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE); 904 905 /* 906 * Do the basics. 907 */ 908 testBasics(hTest, pszBuf); 909 910 /* 911 * Nested 912 */ 913 RTTestSub(hTest, "Nested (%N)"); 914 testNested(__LINE__, "42 2684354560 42 asdf 42", "42 %u 42 %s 42", 2684354560U, "asdf"); 915 testNested(__LINE__, "", ""); 916 917 /* 918 * allocation 919 */ 920 RTTestSub(hTest, "RTStrAPrintf"); 921 char *psz = (char *)~0; 922 int cch3 = RTStrAPrintf(&psz, "Hey there! %s%s", "This is a test", "!"); 923 if (cch3 < 0) 924 RTTestIFailed("RTStrAPrintf failed, cch3=%d\n", cch3); 925 else if (strcmp(psz, "Hey there! This is a test!")) 926 RTTestIFailed("RTStrAPrintf failed\n" 927 "got : '%s'\n" 928 "wanted: 'Hey there! This is a test!'\n", 929 psz); 930 else if ((int)strlen(psz) != cch3) 931 RTTestIFailed("RTStrAPrintf failed, cch3 == %d expected %u\n", cch3, strlen(psz)); 932 RTStrFree(psz); 933 934 /* 935 * Test the waters. 936 */ 937 CHECK42("%d", 127, "127"); 938 CHECK42("%s", "721", "721"); 939 940 /* 941 * Runtime extensions. 942 */ 943 testRuntimeExtensions(hTest, psz); 944 945 /* 946 * Thousand separators. 947 */ 948 testThousandSeparators(hTest, pszBuf); 949 950 /* 951 * String formatting. 952 */ 953 testStringFormatter(hTest, pszBuf); 954 955 /* 956 * Unicode string formatting. 957 */ 958 testUnicodeStringFormatter(hTest, pszBuf); 959 960 /* 961 * Hex formatting. 962 */ 963 testHexFormatter(hTest, pszBuf, pszBuf2); 964 965 /* 966 * human readable sizes and numbers. 967 */ 968 testHumanReadableNumbers(hTest, pszBuf); 860 969 861 970 /* … … 873 982 * Custom types. 874 983 */ 875 RTTestSub(hTest, "Custom format types (%R[*])"); 876 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 877 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 878 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1); 879 CHECKSTR("type3=1"); 880 881 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 882 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 883 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2); 884 CHECKSTR("type3=1 type1=2"); 885 886 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 887 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 888 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3); 889 CHECKSTR("type3=1 type1=2 type4=3"); 890 891 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 892 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 893 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4); 894 CHECKSTR("type3=1 type1=2 type4=3 type2=4"); 895 896 RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS); 897 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 898 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); 899 CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5"); 900 901 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1", (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS); 902 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2", (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS); 903 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3", (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS); 904 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4", (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS); 905 RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5", (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS); 906 907 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); 908 CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50"); 909 910 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS); 911 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40); 912 CHECKSTR("type3=10 type1=20 type4=30 type5=40"); 913 914 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS); 915 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30); 916 CHECKSTR("type3=10 type1=20 type4=30"); 917 918 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS); 919 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20); 920 CHECKSTR("type3=10 type1=20"); 921 922 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS); 923 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10); 924 CHECKSTR("type3=10"); 925 926 RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS); 927 984 testCustomTypes(hTest, pszBuf); 928 985 929 986 testUtf16Printf(hTest);
Note:
See TracChangeset
for help on using the changeset viewer.