+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2016, International Business Machines Corporation and
UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec);
if(U_FAILURE(ec)){
- log_data_err("umsg_open() failed for testCasePattens[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec));
+ log_data_err("umsg_open() failed for testCasePattens[0]. -> %s (Are you missing data?)\n", u_errorName(ec));
return;
}
for(i = 0;i<cnt_testCases; i++){
UDate d2=0;
result=NULL;
- patternLength = u_strlen(testCasePatterns[i]);
-
+ // Alternate between specifying the length and using NUL-termination.
+ patternLength = ((i & 1) == 0) ? u_strlen(testCasePatterns[i]) : -1;
+
umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec);
if(U_FAILURE(ec)){
log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);
static void TestNewFormatAndParseAPI(void)
{
- UChar *result, tzID[4], str[25];
+ UChar *result = NULL, tzID[4], str[25];
UChar pattern[100];
UChar expected[100];
int32_t resultLengthOut, resultlength;
UCalendar *cal;
UDate d1,d;
- UDateFormat *def1;
+ UDateFormat *def1 = NULL;
UErrorCode status = U_ZERO_ERROR;
int32_t value = 0;
UChar ret[30];
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
- return;
+ goto cleanup;
}
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) );
- return;
+ log_err("Error: failure in get millis: %s\n", myErrorName(status) );
}
log_verbose("\nTesting with pattern test#4");
fmt = umsg_open(pattern,u_strlen(pattern),"en_US",&parseError,&status);
if(U_FAILURE(status)){
log_data_err("error in umsg_open : %s (Are you missing data?)\n", u_errorName(status) );
- return;
+ goto cleanup;
}
result=(UChar*)malloc(sizeof(UChar) * resultlength);
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
}
}
+cleanup:
umsg_close(fmt);
udat_close(def1);
ucal_close(cal);
int32_t resultLengthOut, resultlength;
UCalendar *cal;
UDate d1,d;
- UDateFormat *def1;
+ UDateFormat *def1 = NULL;
UErrorCode status = U_ZERO_ERROR;
int32_t value = 0;
UChar ret[30];
}
if(U_FAILURE(status)){
log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
+ goto cleanup;
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#4\n");
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
}
}
+cleanup:
udat_close(def1);
ucal_close(cal);
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(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);
d1=ucal_getMillis(cal, &status);
if(U_FAILURE(status)){
- log_data_err("Error: failure in get millis: %s - (Are you missing data?)\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_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
+ return;
}
else if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on test#4\n");
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);
+ u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1, 6);
if(u_strcmp(result, expected)==0)
log_verbose("PASS: MessagFormat successful on Select test#2\n");
else{
}
}
-static void TestMessageWithUnusedArgNumber() {
+static void TestMessageWithUnusedArgNumber(void) {
UErrorCode errorCode = U_ZERO_ERROR;
U_STRING_DECL(pattern, "abc {1} def", 11);
UChar x[2] = { 0x78, 0 }; // "x"