diff --git a/icu4c/source/test/cintltst/cmsgtst.c b/icu4c/source/test/cintltst/cmsgtst.c index 9bd283fe2d..347a318aa0 100644 --- a/icu4c/source/test/cintltst/cmsgtst.c +++ b/icu4c/source/test/cintltst/cmsgtst.c @@ -417,6 +417,60 @@ void TestParseMessage() } +int32_t CallFormatMessage(const char* locale, UChar* testCasePattern, int32_t patternLength, + UChar* result, int32_t resultLength, UErrorCode *status, ...) +{ + int32_t len = 0; + va_list ap; + va_start(ap, status); + len = u_vformatMessage(locale, testCasePattern, patternLength, result, resultLength, ap, status); + va_end(ap); + return len; +} + +/* Test u_vformatMessage() with various test patterns. */ +void TestMessageFormatWithValist( void ) +{ + + UChar *str; + UChar* result; + int32_t resultLengthOut,resultlength,i, patternlength; + UErrorCode status = U_ZERO_ERROR; + UDate d1=1000000000.0; + str=(UChar*)malloc(sizeof(UChar) * 7); + u_uastrcpy(str, "MyDisk"); + resultlength=1; + result=(UChar*)malloc(sizeof(UChar) * 1); + log_verbose("Testing u_formatMessage90\n"); + InitStrings(); + for (i = 0; i < cnt_testCases; i++) { + status=U_ZERO_ERROR; + patternlength=u_strlen(testCasePatterns[i]); + resultLengthOut=CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, + &status, 1, 3456.00, d1); + if(status== U_BUFFER_OVERFLOW_ERROR) + { + status=U_ZERO_ERROR; + resultlength=resultLengthOut+1; + result=(UChar*)realloc(result,sizeof(UChar) * resultlength); + CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength, + &status, 1, 3456.00, d1); + } + if(U_FAILURE(status)){ + log_err("ERROR: failure in message format on testcase %d: %s\n", i, myErrorName(status) ); + } + if(u_strcmp(result, testResultStrings[i])==0){ + log_verbose("PASS: MessagFormat successful on testcase : %d\n", i); + } + else{ + log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i, + austrdup(result), austrdup(testResultStrings[i]) ); + } + } + free(result); + free(str); +} + void addMsgForTest(TestNode** root) { addTest(root, &MessageFormatTest, "tsformat/cmsgtst/MessageFormatTest"); @@ -424,5 +478,6 @@ void addMsgForTest(TestNode** root) addTest(root, &TestSampleFormatAndParse, "tsformat/cmsgtst/TestSampleFormatAndParse"); addTest(root, &TestMsgFormatChoice, "tsformat/cmsgtst/TestMsgFormatChoice"); addTest(root, &TestParseMessage, "tsformat/cmsgtst/TestParseMessage"); + addTest(root, &TestMessageFormatWithValist, "tsformat/cmsgtst/TestMessageFormatWithValist"); }