ICU-738 Eliminate call to system sprintf in reordering test.

X-SVN-Rev: 22897
This commit is contained in:
Michael Ow 2007-11-07 00:30:22 +00:00
parent 1f872827e3
commit f87c360920

View File

@ -377,7 +377,8 @@ static void TestSprintfFormat(void) {
#if !UCONFIG_NO_FORMATTING
static const UChar abcUChars[] = {0x61,0x62,0x63,0};
static const char abcChars[] = "abc";
const char *format = "%2$d==>%1$-10.10s %4$-10.10s %3$#x\n%5$d"; /* reordering test*/
const char *reorderFormat = "%2$d==>%1$-10.10s %4$-10.10s %3$#x((%5$d"; /* reordering test*/
const char *reorderResult = "99==>truncateif 1234567890 0xf1b93((10";
UChar uBuffer[256];
char buffer[256];
char compBuffer[256];
@ -490,25 +491,13 @@ static void TestSprintfFormat(void) {
TestSPrintFormat("%3f", 1.234, "%3f", 1.234);
TestSPrintFormat("%3f", -1.234, "%3f", -1.234);
/* Test reordering format */
/* Reinitialize the buffer to verify null termination works. */
u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
cNumPrinted = sprintf(buffer, format,"truncateiftoolong", 99, 990099, "12345678901234567890", 10);
uNumPrinted = u_sprintf(uBuffer, format,"truncateiftoolong", 99, 990099, "12345678901234567890", 10);
/* Test reordering format */
u_sprintf(uBuffer, reorderFormat,"truncateiftoolong", 99, 990099, "12345678901234567890", 10);
u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));
if (strcmp(buffer, compBuffer) != 0) {
log_err("%s Got: \"%s\", Expected: \"%s\"\n", format, compBuffer, buffer);
}
if (cNumPrinted != uNumPrinted) {
log_err("%s number printed Got: %d, Expected: %d\n", format, uNumPrinted, cNumPrinted);\
}
if (buffer[uNumPrinted+1] != '*') {
log_err("%s too much stored\n", format);
}
if (strcmp(compBuffer, reorderResult) != 0) {
log_err("%s Got: \"%s\", Expected: \"%s\"\n", reorderFormat, compBuffer, buffer);
}
#endif
}