-
- u_sprintf(myUString, NULL, "This is a long test123456789012345678901234567890123456789012345678901234567890");
- u_austrncpy(myString, myUString, sizeof(myString)/sizeof(*myString));
- if (strcmp(myString, "This is a long test123456789012345678901234567890123456789012345678901234567890")) {
- log_err("%%U Got: %s, Expected: My String\n", myString);
- }
-
-
-// u_sscanf(uStringBuf, NULL, "Pointer %%p: %p\n", myFile);
-}
-
-#define Test_u_snprintf(limit, format, value, expectedSize, expectedStr) \
- u_uastrncpy(testStr, "xxxxxxxxxxxxxx", sizeof(testStr)/sizeof(testStr[0]));\
- size = u_snprintf(testStr, limit, "en_US_POSIX", format, value);\
- u_austrncpy(cTestResult, testStr, sizeof(cTestResult)/sizeof(cTestResult[0]));\
- if (size != expectedSize || strcmp(cTestResult, expectedStr) != 0) {\
- log_err("Unexpected formatting. size=%d expectedSize=%d cTestResult=%s expectedStr=%s\n",\
- size, expectedSize, cTestResult, expectedStr);\
- }\
- else {\
- log_verbose("Got: %s\n", cTestResult);\
- }\
-
-
-static void TestSnprintf() {
- UChar testStr[256];
- char cTestResult[256];
- int32_t size;
-
- Test_u_snprintf(0, "%d", 123, 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(2, "%d", 123, 2, "12xxxxxxxxxxxx");
- Test_u_snprintf(3, "%d", 123, 3, "123xxxxxxxxxxx");
- Test_u_snprintf(4, "%d", 123, 3, "123");
-
- Test_u_snprintf(0, "%s", "abcd", 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(3, "%s", "abcd", 3, "abcxxxxxxxxxxx");
- Test_u_snprintf(4, "%s", "abcd", 4, "abcdxxxxxxxxxx");
- Test_u_snprintf(5, "%s", "abcd", 4, "abcd");
-
- Test_u_snprintf(0, "%e", 12.34, 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(1, "%e", 12.34, 1, "1xxxxxxxxxxxxx");
- Test_u_snprintf(2, "%e", 12.34, 2, "1.xxxxxxxxxxxx");
- Test_u_snprintf(3, "%e", 12.34, 3, "1.2xxxxxxxxxxx");
- Test_u_snprintf(5, "%e", 12.34, 5, "1.234xxxxxxxxx");
- Test_u_snprintf(6, "%e", 12.34, 6, "1.2340xxxxxxxx");
- Test_u_snprintf(8, "%e", 12.34, 8, "1.234000xxxxxx");
- Test_u_snprintf(9, "%e", 12.34, 9, "1.234000exxxxx");
- Test_u_snprintf(10, "%e", 12.34, 10, "1.234000e+xxxx");
- Test_u_snprintf(11, "%e", 12.34, 11, "1.234000e+0xxx");
- Test_u_snprintf(13, "%e", 12.34, 13, "1.234000e+001x");
- Test_u_snprintf(14, "%e", 12.34, 13, "1.234000e+001");
-}
-
-#define TestSPrintFormat(uFormat, uValue, cFormat, cValue) \
- /* Reinitialize the buffer to verify null termination works. */\
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
- memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));\
- \
- uNumPrinted = u_sprintf(uBuffer, "en_US_POSIX", uFormat, uValue);\
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));\
- cNumPrinted = sprintf(buffer, cFormat, cValue);\
- if (strcmp(buffer, compBuffer) != 0) {\
- log_err("%" uFormat " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
- }\
- if (cNumPrinted != uNumPrinted) {\
- log_err("%" uFormat " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
- }\
- if (buffer[uNumPrinted+1] != 0x2a) {\
- log_err("%" uFormat " too much stored\n");\
- }\
-
-#define TestSPrintFormat2(format, precision, value) \
- /* Reinitialize the buffer to verify null termination works. */\
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
- memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));\
- \
- uNumPrinted = u_sprintf(uBuffer, "en_US_POSIX", format, precision, value);\
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));\
- cNumPrinted = sprintf(buffer, format, precision, value);\
- if (strcmp(buffer, compBuffer) != 0) {\
- log_err("%" format " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
- }\
- if (cNumPrinted != uNumPrinted) {\
- log_err("%" format " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
- }\
-
-static void TestSprintfFormat() {
- static const UChar abcUChars[] = {0x61,0x62,0x63,0};
- static const char abcChars[] = "abc";
- UChar uBuffer[256];
- char buffer[256];
- char compBuffer[256];
- int32_t uNumPrinted;
- int32_t cNumPrinted;
-
- TestSPrintFormat("%8U", abcUChars, "%8s", abcChars);
- TestSPrintFormat("%-8U", abcUChars, "%-8s", abcChars);
-
- TestSPrintFormat("%8s", abcChars, "%8s", abcChars);
- TestSPrintFormat("%-8s", abcChars, "%-8s", abcChars);
-
- TestSPrintFormat("%8c", 0x65, "%8c", 0x65);
- TestSPrintFormat("%-8c", 0x65, "%-8c", 0x65);
-
- TestSPrintFormat("%8K", (UChar)0x65, "%8c", (char)0x65);
- TestSPrintFormat("%-8K", (UChar)0x65, "%-8c", (char)0x65);
-
- TestSPrintFormat("%10f", 1.23456789, "%10f", 1.23456789);
- TestSPrintFormat("%-10f", 1.23456789, "%-10f", 1.23456789);
- TestSPrintFormat("%10f", 123.456789, "%10f", 123.456789);
- TestSPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
-
- TestSPrintFormat("%e", 1234567.89, "%e", 1234567.89);
- TestSPrintFormat("%E", 1234567.89, "%E", 1234567.89);
- TestSPrintFormat("%10e", 1.23456789, "%10e", 1.23456789);
- TestSPrintFormat("%-10e", 1.23456789, "%-10e", 1.23456789);
- TestSPrintFormat("%10e", 123.456789, "%10e", 123.456789);
- TestSPrintFormat("%-10e", 123.456789, "%-10e", 123.456789);
-
- TestSPrintFormat("%g", 123456.789, "%g", 123456.789);
- TestSPrintFormat("%g", 1234567.89, "%g", 1234567.89);
- TestSPrintFormat("%G", 1234567.89, "%G", 1234567.89);
- TestSPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
- TestSPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
- TestSPrintFormat("%10g", 123.456789, "%10g", 123.456789);
- TestSPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
-
- TestSPrintFormat("%8x", 123456, "%8x", 123456);
- TestSPrintFormat("%-8x", 123456, "%-8x", 123456);
-
- TestSPrintFormat("%8X", 123456, "%8X", 123456);
- TestSPrintFormat("%-8X", 123456, "%-8X", 123456);
- TestSPrintFormat("%#x", 123456, "%#x", 123456);
- TestSPrintFormat("%#x", -123456, "%#x", -123456);
-
- TestSPrintFormat("%8o", 123456, "%8o", 123456);
- TestSPrintFormat("%-8o", 123456, "%-8o", 123456);
- TestSPrintFormat("%#o", 123, "%#o", 123);
- TestSPrintFormat("%#o", -123, "%#o", -123);
-
- TestSPrintFormat("%8u", 123456, "%8u", 123456);
- TestSPrintFormat("%-8u", 123456, "%-8u", 123456);
- TestSPrintFormat("%8u", -123456, "%8u", -123456);
- TestSPrintFormat("%-8u", -123456, "%-8u", -123456);
-
- TestSPrintFormat("%8d", 123456, "%8d", 123456);
- TestSPrintFormat("%-8d", 123456, "%-8d", 123456);
- TestSPrintFormat("% d", 123456, "% d", 123456);
- TestSPrintFormat("% d", -123456, "% d", -123456);
-
- TestSPrintFormat("%8i", 123456, "%8i", 123456);
- TestSPrintFormat("%-8i", 123456, "%-8i", 123456);
-
- TestSPrintFormat2("%+1.*e", 4, 1.2345678);
- TestSPrintFormat2("%+2.*e", 6, 1.2345678);
-
- log_verbose("Get really crazy with the formatting.\n");
-
- TestSPrintFormat("%-#12x", 123, "%-#12x", 123);
- TestSPrintFormat("%-#12x", -123, "%-#12x", -123);
- TestSPrintFormat("%#12x", 123, "%#12x", 123);
- TestSPrintFormat("%#12x", -123, "%#12x", -123);
-
- TestSPrintFormat("%-+12d", 123, "%-+12d", 123);
- TestSPrintFormat("%-+12d", -123, "%-+12d", -123);
- TestSPrintFormat("%- 12d", 123, "%- 12d", 123);
- TestSPrintFormat("%- 12d", -123, "%- 12d", -123);
- TestSPrintFormat("%+12d", 123, "%+12d", 123);
- TestSPrintFormat("%+12d", -123, "%+12d", -123);
- TestSPrintFormat("% 12d", 123, "% 12d", 123);
- TestSPrintFormat("% 12d", -123, "% 12d", -123);
- TestSPrintFormat("%12d", 123, "%12d", 123);
- TestSPrintFormat("%12d", -123, "%12d", -123);
-
- TestSPrintFormat("%-+12.1e", 1.234, "%-+12.1e", 1.234);
- TestSPrintFormat("%-+12.1e", -1.234, "%-+12.1e", -1.234);
- TestSPrintFormat("%- 12.1e", 1.234, "%- 12.1e", 1.234);
- TestSPrintFormat("%- 12.1e", -1.234, "%- 12.1e", -1.234);
- TestSPrintFormat("%+12.1e", 1.234, "%+12.1e", 1.234);
- TestSPrintFormat("%+12.1e", -1.234, "%+12.1e", -1.234);
- TestSPrintFormat("% 12.1e", 1.234, "% 12.1e", 1.234);
- TestSPrintFormat("% 12.1e", -1.234, "% 12.1e", -1.234);
- TestSPrintFormat("%12.1e", 1.234, "%12.1e", 1.234);
- TestSPrintFormat("%12.1e", -1.234, "%12.1e", -1.234);
- TestSPrintFormat("%.2e", 1.234, "%.2e", 1.234);
- TestSPrintFormat("%.2e", -1.234, "%.2e", -1.234);
- TestSPrintFormat("%3e", 1.234, "%3e", 1.234);
- TestSPrintFormat("%3e", -1.234, "%3e", -1.234);
-
- TestSPrintFormat("%-+12.1f", 1.234, "%-+12.1f", 1.234);
- TestSPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
- TestSPrintFormat("%- 12.1f", 1.234, "%- 12.1f", 1.234);
- TestSPrintFormat("%- 12.1f", -1.234, "%- 12.1f", -1.234);
- TestSPrintFormat("%+12.1f", 1.234, "%+12.1f", 1.234);
- TestSPrintFormat("%+12.1f", -1.234, "%+12.1f", -1.234);
- TestSPrintFormat("% 12.1f", 1.234, "% 12.1f", 1.234);
- TestSPrintFormat("% 12.1f", -1.234, "% 12.1f", -1.234);
- TestSPrintFormat("%12.1f", 1.234, "%12.1f", 1.234);
- TestSPrintFormat("%12.1f", -1.234, "%12.1f", -1.234);
- TestSPrintFormat("%.2f", 1.234, "%.2f", 1.234);
- TestSPrintFormat("%.2f", -1.234, "%.2f", -1.234);
- TestSPrintFormat("%3f", 1.234, "%3f", 1.234);
- TestSPrintFormat("%3f", -1.234, "%3f", -1.234);
-