X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/test/cintltst/cmsgtst.c diff --git a/icuSources/test/cintltst/cmsgtst.c b/icuSources/test/cintltst/cmsgtst.c index c95f4d89..16730092 100644 --- a/icuSources/test/cintltst/cmsgtst.c +++ b/icuSources/test/cintltst/cmsgtst.c @@ -1,17 +1,17 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2008, International Business Machines Corporation and + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. + ******************************************************************** + * + * File CMSGTST.C + * + * Modification History: + * Name Description + * Madhu Katragadda Creation ********************************************************************/ -/******************************************************************************** -* -* File CMSGTST.C -* -* Modification History: -* Name Description -* Madhu Katragadda Creation -********************************************************************************* -*/ /* C API TEST FOR MESSAGE FORMAT */ #include "unicode/utypes.h" @@ -29,6 +29,7 @@ #include "cintltst.h" #include "cmsgtst.h" #include "cformtst.h" +#include "cmemory.h" static const char* const txt_testCasePatterns[] = { "Quotes '', '{', a {0,number,integer} '{'0}", @@ -42,7 +43,7 @@ static const char* const txt_testResultStrings[] = { "Quotes ', {, a 1 {0}", "Quotes ', {, a 1 {0}", "You deposited 1 times an amount of $3,456.00 on 1/12/70", - "{2,time,full}, for 3,456, 1 is 5:46:40 AM PT and full date is Monday, January 12, 1970", + "{2,time,full}, for 3,456, 1 is 5:46:40 AM Pacific Standard Time and full date is Monday, January 12, 1970", "{1,number,percent} for 1 is 345,600%" }; @@ -89,6 +90,9 @@ static void FreeStrings( void ) strings_initialized = FALSE; } +#if (U_PLATFORM == U_PF_LINUX) /* add platforms here .. */ +/* Keep the #if above in sync with the one below that has the same "add platforms here .." comment. */ +#else /* Platform dependent test to detect if this type will return NULL when interpreted as a pointer. */ static UBool returnsNullForType(int firstParam, ...) { UBool isNULL; @@ -98,6 +102,7 @@ static UBool returnsNullForType(int firstParam, ...) { va_end(marker); return isNULL; } +#endif /* Test u_formatMessage() with various test patterns() */ static void MessageFormatTest( void ) @@ -130,7 +135,7 @@ static void MessageFormatTest( void ) &status, 1, 3456.00, d1); } if(U_FAILURE(status)){ - log_err("ERROR: failure in message format on testcase %d: %s\n", i, myErrorName(status) ); + log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) ); continue; } if(u_strcmp(result, testResultStrings[i])==0){ @@ -162,7 +167,7 @@ static void MessageFormatTest( void ) &status, 1, 3456.00, d1); } if(U_FAILURE(status)){ - log_err("ERROR: failure in message format on testcase %d: %s\n", i, myErrorName(status) ); + log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) ); continue; } if(u_strcmp(result, testResultStrings[i])==0){ @@ -183,7 +188,7 @@ static void MessageFormatTest( void ) UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec); if(U_FAILURE(ec)){ - log_err("umsg_open() failed for testCasePattens[%d].\n",i); + log_data_err("umsg_open() failed for testCasePattens[0]. -> %s (Are you missing data?)\n", u_errorName(ec)); return; } for(i = 0;i %s (Are you missing data?)\n", cresult, EXP, u_errorName(status)); } ctest_resetTimeZone(); @@ -945,7 +1038,7 @@ static void OpenMessageFormatTest(void) int32_t length=0; UErrorCode status = U_ZERO_ERROR; - u_uastrncpy(pattern, PAT, sizeof(pattern)/sizeof(pattern[0])); + u_uastrncpy(pattern, PAT, UPRV_LENGTHOF(pattern)); /* Test umsg_open */ f1 = umsg_open(pattern,length,NULL,NULL,&status); @@ -988,13 +1081,13 @@ static void OpenMessageFormatTest(void) umsg_applyPattern(f1,pattern,(int32_t)strlen(PAT),NULL,&status); if(U_FAILURE(status)) { - log_err("umsg_applyPattern failed. Error %s \n",u_errorName(status)); + log_data_err("umsg_applyPattern failed. Error %s (Are you missing data?)\n",u_errorName(status)); } /* Test umsg_toPattern */ umsg_toPattern(f1,result,256,&status); if(U_FAILURE(status) ){ - log_err("umsg_toPattern method failed. Error: %s \n",u_errorName(status)); + log_data_err("umsg_toPattern method failed. Error: %s (Are you missing data?)\n",u_errorName(status)); } else { if(u_strcmp(result,pattern)!=0){ u_UCharsToChars(result,cresult,256); @@ -1018,10 +1111,10 @@ static void MessageLength(void) UChar result[128] = {0}; UChar expected[sizeof(expectedChars)]; - u_uastrncpy(pattern, patChars, sizeof(pattern)/sizeof(pattern[0])); - u_uastrncpy(expected, expectedChars, sizeof(expected)/sizeof(expected[0])); + u_uastrncpy(pattern, patChars, UPRV_LENGTHOF(pattern)); + u_uastrncpy(expected, expectedChars, UPRV_LENGTHOF(expected)); - u_formatMessage("en_US", pattern, 6, result, sizeof(result)/sizeof(result[0]), &status, arg); + u_formatMessage("en_US", pattern, 6, result, UPRV_LENGTHOF(result), &status, arg); if (U_FAILURE(status)) { log_err("u_formatMessage method failed. Error: %s \n",u_errorName(status)); } @@ -1030,6 +1123,24 @@ static void MessageLength(void) } } +static void TestMessageWithUnusedArgNumber(void) { + UErrorCode errorCode = U_ZERO_ERROR; + U_STRING_DECL(pattern, "abc {1} def", 11); + UChar x[2] = { 0x78, 0 }; // "x" + UChar y[2] = { 0x79, 0 }; // "y" + U_STRING_DECL(expected, "abc y def", 9); + UChar result[20]; + int32_t length; + + U_STRING_INIT(pattern, "abc {1} def", 11); + U_STRING_INIT(expected, "abc y def", 9); + length = u_formatMessage("en", pattern, -1, result, UPRV_LENGTHOF(result), &errorCode, x, y); + if (U_FAILURE(errorCode) || length != u_strlen(expected) || u_strcmp(result, expected) != 0) { + log_err("u_formatMessage(pattern with only {1}, 2 args) failed: result length %d, UErrorCode %s \n", + (int)length, u_errorName(errorCode)); + } +} + static void TestErrorChaining(void) { UErrorCode status = U_USELESS_COLLATOR_ERROR; @@ -1084,7 +1195,9 @@ void addMsgForTest(TestNode** root) addTest(root, &TestParseMessageWithValist, "tsformat/cmsgtst/TestParseMessageWithValist"); addTest(root, &TestJ904, "tsformat/cmsgtst/TestJ904"); addTest(root, &MessageLength, "tsformat/cmsgtst/MessageLength"); + addTest(root, &TestMessageWithUnusedArgNumber, "tsformat/cmsgtst/TestMessageWithUnusedArgNumber"); addTest(root, &TestErrorChaining, "tsformat/cmsgtst/TestErrorChaining"); + addTest(root, &TestMsgFormatSelect, "tsformat/cmsgtst/TestMsgFormatSelect"); } #endif /* #if !UCONFIG_NO_FORMATTING */