/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2010, 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"
"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%"
};
&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){
&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){
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[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec));
return;
}
for(i = 0;i<cnt_testCases; i++){
austrdup(result), austrdup(testResultStrings[i]) );
}
+#if defined (U_DARWIN) /* add platforms here .. */
+ log_verbose("Skipping potentially crashing test for mismatched varargs.\n");
+#else
+ log_verbose("Note: the next is a platform dependent test. If it crashes, add an exclusion for your platform near %s:%d\n", __FILE__, __LINE__);
+
if (returnsNullForType(1, (double)2.0)) {
/* HP/UX and possibly other platforms don't properly check for this case.
We pass in a UDate, but the function expects a UDate *. When va_arg is used,
most compilers will return NULL, but HP-UX won't do that and will return 2
- in this case. This is a platform dependent test.
+ in this case. This is a platform dependent test. It crashes on some systems.
+
+ If you get a crash here, see the definition of returnsNullForType.
This relies upon "undefined" behavior, as indicated by C99 7.15.1.1 paragraph 2
*/
else {
log_verbose("Warning: Returning NULL for a mismatched va_arg type isn't supported on this platform.\n", i);
}
+#endif
umsg_parse(formatter,result,resultLength,&count,&ec,&one,&two,&d2);
if(U_FAILURE(ec)){
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, d);
}
if(U_FAILURE(status)){
- log_err("Error: failure in message format on test#1: %s\n", myErrorName(status));
+ log_data_err("Error: failure in message format on test#1: %s (Are you missing data?)\n", myErrorName(status));
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#1\n");
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 23);
}
if(U_FAILURE(status)){
- log_err("Error: failure in message format on test#2 : %s\n", myErrorName(status));
+ log_data_err("Error: failure in message format on test#2 : %s (Are you missing data?)\n", myErrorName(status));
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#2\n");
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 500.00);
}
if(U_FAILURE(status)){
- log_err("Error: failure in message format on test#3 : %s\n", myErrorName(status));
+ log_data_err("Error: failure in message format on test#3 : %s (Are you missing data?)\n", myErrorName(status));
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#3\n");
u_uastrcpy(tzID, "PST");
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
- log_err("error in ucal_open caldef : %s\n", myErrorName(status) );
+ log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
return;
}
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
resultlength=1;
fmt = umsg_open(pattern,u_strlen(pattern),"en_US",&parseError,&status);
if(U_FAILURE(status)){
- log_err("error in umsg_open : %s\n", u_errorName(status) );
+ log_data_err("error in umsg_open : %s (Are you missing data?)\n", u_errorName(status) );
return;
}
result=(UChar*)malloc(sizeof(UChar) * resultlength);
u_uastrcpy(tzID, "PST");
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
- log_err("error in ucal_open caldef : %s\n", myErrorName(status) );
+ log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
}
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
d1=ucal_getMillis(cal, &status);
if(U_FAILURE(status)){
- log_err("Error: failure in get millis: %s\n", myErrorName(status) );
+ log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
}
log_verbose("\nTesting with pattern test#4");
}
if(U_FAILURE(status)){
- log_err("ERROR: failure in message format test#4: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#4\n");
u_parseMessageWithError("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &parseError,&status, &d, ret, &value);
if(U_FAILURE(status)){
- log_err("ERROR: error in parsing: test#5: %s\n", myErrorName(status));
+ log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
}
else if(value!=7 && u_strcmp(str,ret)!=0)
log_err("FAIL: Error in parseMessage on test#5 \n");
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
if(U_FAILURE(status))
{
- log_err("error in creating the dateformat using short date and time style:\n %s\n", myErrorName(status));
+ log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
}else{
if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
u_uastrcpy(tzID, "PST");
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
- log_err("error in ucal_open caldef : %s\n", myErrorName(status) );
+ log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
}
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
d1=ucal_getMillis(cal, &status);
if(U_FAILURE(status)){
- log_err("Error: failure in get millis: %s\n", myErrorName(status) );
+ log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
}
log_verbose("\nTesting with pattern test#4");
}
if(U_FAILURE(status)){
- log_err("ERROR: failure in message format test#4: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#4\n");
u_parseMessage("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &status, &d, ret, &value);
if(U_FAILURE(status)){
- log_err("ERROR: error in parsing: test#5: %s\n", myErrorName(status));
+ log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
}
else if(value!=7 && u_strcmp(str,ret)!=0)
log_err("FAIL: Error in parseMessage on test#5 \n");
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
if(U_FAILURE(status))
{
- log_err("error in creating the dateformat using short date and time style:\n %s\n", myErrorName(status));
+ log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
}else{
if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
ctest_resetTimeZone();
}
+/* Test message format with a Select option */
+static void TestMsgFormatSelect(void)
+{
+ UChar* str;
+ UChar* str1;
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *result;
+ UChar pattern[100];
+ UChar expected[100];
+ int32_t resultlength,resultLengthOut;
+
+ str=(UChar*)malloc(sizeof(UChar) * 25);
+ u_uastrcpy(str, "Kirti");
+ str1=(UChar*)malloc(sizeof(UChar) * 25);
+ u_uastrcpy(str1, "female");
+ log_verbose("Testing message format with Select test #1\n:");
+ u_uastrcpy(pattern, "{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
+ u_uastrcpy(expected, "Kirti est all\\u00E9e \\u00E0 Paris.");
+ resultlength=0;
+ resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1);
+ if(status==U_BUFFER_OVERFLOW_ERROR)
+ {
+ status=U_ZERO_ERROR;
+ resultlength=resultLengthOut+1;
+ result=(UChar*)malloc(sizeof(UChar) * resultlength);
+ u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
+ if(u_strcmp(result, expected)==0)
+ log_verbose("PASS: MessagFormat successful on Select test#1\n");
+ else{
+ log_err("FAIL: Error in MessageFormat on Select test#1\n GOT %s EXPECTED %s\n", austrdup(result),
+ austrdup(expected) );
+ }
+ free(result);
+ }
+ if(U_FAILURE(status)){
+ log_data_err("ERROR: failure in message format on Select test#1 : %s \n", myErrorName(status));
+ }
+ free(str);
+ free(str1);
+
+ /*Test a nested pattern*/
+ str=(UChar*)malloc(sizeof(UChar) * 25);
+ u_uastrcpy(str, "Noname");
+ str1=(UChar*)malloc(sizeof(UChar) * 25);
+ u_uastrcpy(str1, "other");
+ log_verbose("Testing message format with Select test #2\n:");
+ u_uastrcpy(pattern, "{0} est {1, select, female {{2,number,integer} all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
+ u_uastrcpy(expected, "Noname est all\\u00E9 \\u00E0 Paris.");
+ resultlength=0;
+ resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1,6);
+ if(status==U_BUFFER_OVERFLOW_ERROR)
+ {
+ status=U_ZERO_ERROR;
+ resultlength=resultLengthOut+1;
+ result=(UChar*)malloc(sizeof(UChar) * resultlength);
+ u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
+ if(u_strcmp(result, expected)==0)
+ log_verbose("PASS: MessagFormat successful on Select test#2\n");
+ else{
+ log_err("FAIL: Error in MessageFormat on Select test#2\n GOT %s EXPECTED %s\n", austrdup(result),
+ austrdup(expected) );
+ }
+ free(result);
+ }
+ if(U_FAILURE(status)){
+ log_data_err("ERROR: failure in message format on Select test#2 : %s \n", myErrorName(status));
+ }
+ free(str);
+ free(str1);
+}
+
/* test message format with a choice option */
static void TestMsgFormatChoice(void)
{
free(result);
}
if(U_FAILURE(status)){
- log_err("ERROR: failure in message format on test#6 : %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in message format on test#6 : %s (Are you missing data?)\n", myErrorName(status));
}
log_verbose("Testing message format with choice test #7\n:");
free(result);
}
if(U_FAILURE(status)){
- log_err("ERROR: failure in message format on test#7 : %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in message format on test#7 : %s (Are you missing data?)\n", myErrorName(status));
}
log_verbose("Testing message format with choice test #8\n:");
free(result);
}
if(U_FAILURE(status)){
- log_err("ERROR: failure in message format on test#8 : %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in message format on test#8 : %s (Are you missing data?)\n", myErrorName(status));
}
free(str);
u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
if(U_FAILURE(status)){
- log_err("ERROR: failure in parse Message on test#9: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
}
else if(value==500.00 && u_strcmp(str,res)==0)
log_verbose("PASS: parseMessage successful on test#9\n");
u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
if(U_FAILURE(status)){
- log_err("ERROR: failure in parse Message on test#10: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
}
else if(value==123.00 && u_strcmp(str,res)==0)
log_verbose("PASS: parseMessage successful on test#10\n");
else
log_err("FAIL: Error in parseMessage on test#10 \n");
-
-
-
}
static int32_t CallFormatMessage(const char* locale, UChar* testCasePattern, int32_t patternLength,
&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) );
}
else if(u_strcmp(result, testResultStrings[i])==0){
log_verbose("PASS: MessagFormat successful on testcase : %d\n", i);
CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
if(U_FAILURE(status)){
- log_err("ERROR: failure in parse Message on test#9: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
}
- if(value==500.00 && u_strcmp(str,res)==0)
+ else if(value==500.00 && u_strcmp(str,res)==0)
log_verbose("PASS: parseMessage successful on test#9\n");
else
- log_err("FAIL: Error in parseMessage on test#9 \n");
+ log_err("FAIL: Error in parseMessage on test#9\n");
log_verbose("\nTesting a sample for parse Message test#10\n");
CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
if(U_FAILURE(status)){
- log_err("ERROR: failure in parse Message on test#10: %s\n", myErrorName(status));
+ log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
}
else if(value==123.00 && u_strcmp(str,res)==0)
log_verbose("PASS: parseMessage successful on test#10\n");
if (strcmp(cresult, EXP) == 0) {
log_verbose("Ok: \"%s\"\n", cresult);
} else {
- log_err("FAIL: got \"%s\", expected \"%s\"\n", cresult, EXP);
+ log_data_err("FAIL: got \"%s\", expected \"%s\" -> %s (Are you missing data?)\n", cresult, EXP, u_errorName(status));
}
ctest_resetTimeZone();
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);
addTest(root, &TestJ904, "tsformat/cmsgtst/TestJ904");
addTest(root, &MessageLength, "tsformat/cmsgtst/MessageLength");
addTest(root, &TestErrorChaining, "tsformat/cmsgtst/TestErrorChaining");
+ addTest(root, &TestMsgFormatSelect, "tsformat/cmsgtst/TestMsgFormatSelect");
}
#endif /* #if !UCONFIG_NO_FORMATTING */