2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2009-04-10 07:47:09 +00:00
|
|
|
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CMSGTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
2000-08-09 23:34:41 +00:00
|
|
|
* Name Description
|
1999-08-16 21:50:52 +00:00
|
|
|
* Madhu Katragadda Creation
|
|
|
|
*********************************************************************************
|
|
|
|
*/
|
|
|
|
/* C API TEST FOR MESSAGE FORMAT */
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-09-20 17:54:45 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
2003-04-24 22:38:45 +00:00
|
|
|
#include <stdlib.h>
|
2003-04-23 05:49:02 +00:00
|
|
|
#include <string.h>
|
2004-04-01 23:04:47 +00:00
|
|
|
#include <stdarg.h>
|
2002-09-20 17:54:45 +00:00
|
|
|
#include "unicode/uloc.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/umsg.h"
|
|
|
|
#include "unicode/udat.h"
|
|
|
|
#include "unicode/umsg.h"
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
|
|
|
#include "cmsgtst.h"
|
|
|
|
#include "cformtst.h"
|
|
|
|
|
2002-04-11 21:41:44 +00:00
|
|
|
static const char* const txt_testCasePatterns[] = {
|
1999-08-16 21:50:52 +00:00
|
|
|
"Quotes '', '{', a {0,number,integer} '{'0}",
|
|
|
|
"Quotes '', '{', a {0,number,integer} '{'0}",
|
|
|
|
"You deposited {0,number,integer} times an amount of {1,number,currency} on {2,date,short}",
|
2001-08-16 00:58:53 +00:00
|
|
|
"'{'2,time,full}, for {1, number }, {0,number,integer} is {2,time,full} and full date is {2,date,full}",
|
1999-08-16 21:50:52 +00:00
|
|
|
"'{'1,number,percent} for {0,number,integer} is {1,number,percent}",
|
|
|
|
};
|
|
|
|
|
2002-04-11 21:41:44 +00:00
|
|
|
static const char* const txt_testResultStrings[] = {
|
1999-08-16 21:50:52 +00:00
|
|
|
"Quotes ', {, a 1 {0}",
|
|
|
|
"Quotes ', {, a 1 {0}",
|
2002-04-11 23:29:14 +00:00
|
|
|
"You deposited 1 times an amount of $3,456.00 on 1/12/70",
|
2009-04-10 07:47:09 +00:00
|
|
|
"{2,time,full}, for 3,456, 1 is 5:46:40 AM Pacific Standard Time and full date is Monday, January 12, 1970",
|
1999-08-16 21:50:52 +00:00
|
|
|
"{1,number,percent} for 1 is 345,600%"
|
|
|
|
};
|
|
|
|
|
|
|
|
const int32_t cnt_testCases = 5;
|
|
|
|
static UChar* testCasePatterns[5];
|
|
|
|
|
|
|
|
static UChar* testResultStrings[5];
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool strings_initialized = FALSE;
|
2001-03-08 23:39:57 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* function used to create the test patterns for testing Message formatting */
|
|
|
|
static void InitStrings( void )
|
|
|
|
{
|
|
|
|
int32_t i;
|
2001-03-08 23:39:57 +00:00
|
|
|
if (strings_initialized)
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
for (i=0; i < cnt_testCases; i++ ) {
|
2004-11-04 23:43:46 +00:00
|
|
|
uint32_t strSize = (uint32_t)strlen(txt_testCasePatterns[i]) + 1;
|
2002-07-27 00:22:01 +00:00
|
|
|
testCasePatterns[i]=(UChar*)malloc(sizeof(UChar) * strSize);
|
|
|
|
u_uastrncpy(testCasePatterns[i], txt_testCasePatterns[i], strSize);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
for (i=0; i < cnt_testCases; i++ ) {
|
2004-11-04 23:43:46 +00:00
|
|
|
uint32_t strSize = (uint32_t)strlen(txt_testResultStrings[i]) + 1;
|
2002-07-27 00:22:01 +00:00
|
|
|
testResultStrings[i] = (UChar*)malloc(sizeof(UChar) * strSize);
|
|
|
|
u_uastrncpy(testResultStrings[i], txt_testResultStrings[i], strSize);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-08 23:39:57 +00:00
|
|
|
|
|
|
|
strings_initialized = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FreeStrings( void )
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
if (!strings_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i=0; i < cnt_testCases; i++ ) {
|
|
|
|
free(testCasePatterns[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i < cnt_testCases; i++ ) {
|
|
|
|
free(testResultStrings[i]);
|
|
|
|
}
|
|
|
|
strings_initialized = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
2004-04-01 23:04:47 +00:00
|
|
|
/* Platform dependent test to detect if this type will return NULL when interpreted as a pointer. */
|
|
|
|
static UBool returnsNullForType(int firstParam, ...) {
|
|
|
|
UBool isNULL;
|
|
|
|
va_list marker;
|
|
|
|
va_start(marker, firstParam);
|
|
|
|
isNULL = (UBool)(va_arg(marker, void*) == NULL);
|
|
|
|
va_end(marker);
|
|
|
|
return isNULL;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Test u_formatMessage() with various test patterns() */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void MessageFormatTest( void )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UChar *str;
|
|
|
|
UChar* result;
|
|
|
|
int32_t resultLengthOut,resultlength,i, patternlength;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UDate d1=1000000000.0;
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
str=(UChar*)malloc(sizeof(UChar) * 7);
|
2002-07-27 00:22:01 +00:00
|
|
|
u_uastrncpy(str, "MyDisk", 7);
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * 1);
|
2004-04-01 23:04:47 +00:00
|
|
|
log_verbose("Testing u_formatMessage()\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
InitStrings();
|
|
|
|
for (i = 0; i < cnt_testCases; i++) {
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
patternlength=u_strlen(testCasePatterns[i]);
|
|
|
|
resultLengthOut=u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
|
|
|
|
&status, 1, 3456.00, d1);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status== U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-08 23:39:57 +00:00
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result,sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
|
|
|
|
&status, 1, 3456.00, d1);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) );
|
2008-02-19 05:05:51 +00:00
|
|
|
continue;
|
2001-03-08 23:39:57 +00:00
|
|
|
}
|
|
|
|
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]) );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
free(result);
|
2002-07-27 00:22:01 +00:00
|
|
|
result = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
free(str);
|
2002-04-03 03:36:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
for (i = 0; i < cnt_testCases; i++) {
|
|
|
|
UParseError parseError;
|
2002-04-03 19:01:59 +00:00
|
|
|
status=U_ZERO_ERROR;
|
2002-04-03 03:36:17 +00:00
|
|
|
patternlength=u_strlen(testCasePatterns[i]);
|
|
|
|
resultlength=0;
|
|
|
|
resultLengthOut=u_formatMessageWithError( "en_US",testCasePatterns[i], patternlength, result, resultlength,
|
|
|
|
&parseError,&status, 1, 3456.00, d1);
|
|
|
|
if(status== U_BUFFER_OVERFLOW_ERROR)
|
|
|
|
{
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
2002-07-29 21:04:18 +00:00
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
2002-04-03 03:36:17 +00:00
|
|
|
u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
|
|
|
|
&status, 1, 3456.00, d1);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) );
|
2002-04-06 00:13:05 +00:00
|
|
|
continue;
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
|
|
|
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]) );
|
|
|
|
}
|
2002-07-29 21:04:18 +00:00
|
|
|
free(result);
|
2002-04-03 03:36:17 +00:00
|
|
|
result=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
int32_t patternLength = u_strlen(testCasePatterns[0]);
|
|
|
|
|
|
|
|
UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec);
|
2002-04-03 19:01:59 +00:00
|
|
|
|
2002-04-03 03:36:17 +00:00
|
|
|
if(U_FAILURE(ec)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("umsg_open() failed for testCasePattens[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec));
|
2002-04-03 03:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-03 19:01:59 +00:00
|
|
|
for(i = 0;i<cnt_testCases; i++){
|
2002-04-03 03:36:17 +00:00
|
|
|
UParseError parseError;
|
|
|
|
int32_t resultLength =0,count=0;
|
|
|
|
int32_t one=0;
|
|
|
|
int32_t two=0;
|
2002-04-06 00:13:05 +00:00
|
|
|
UDate d2=0;
|
2002-04-03 03:36:17 +00:00
|
|
|
|
2002-04-03 19:01:59 +00:00
|
|
|
result=NULL;
|
2002-04-03 03:36:17 +00:00
|
|
|
patternLength = u_strlen(testCasePatterns[i]);
|
|
|
|
|
|
|
|
umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec);
|
|
|
|
if(U_FAILURE(ec)){
|
|
|
|
log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* pre-flight */
|
|
|
|
resultLength = umsg_format(formatter,result,resultLength,&ec,1,3456.00,d1);
|
|
|
|
if(ec==U_BUFFER_OVERFLOW_ERROR){
|
|
|
|
ec=U_ZERO_ERROR;
|
2002-07-29 21:04:18 +00:00
|
|
|
result = (UChar*) malloc(U_SIZEOF_UCHAR*resultLength+2);
|
2002-04-03 03:36:17 +00:00
|
|
|
resultLength = umsg_format(formatter,result,resultLength+2,&ec,1,3456.00,d1);
|
|
|
|
if(U_FAILURE(ec)){
|
|
|
|
log_err("ERROR: failure in message format on testcase %d: %s\n", i, u_errorName(status) );
|
2002-07-29 21:04:18 +00:00
|
|
|
free(result);
|
2002-04-03 03:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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]) );
|
|
|
|
}
|
2002-04-06 00:13:05 +00:00
|
|
|
|
2004-04-01 23:04:47 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
This relies upon "undefined" behavior, as indicated by C99 7.15.1.1 paragraph 2
|
|
|
|
*/
|
|
|
|
umsg_parse(formatter,result,resultLength,&count,&ec,one,two,d2);
|
|
|
|
if(ec!=U_ILLEGAL_ARGUMENT_ERROR){
|
|
|
|
log_err("FAIL: Did not get expected error for umsg_parse(). Expected: U_ILLEGAL_ARGUMENT_ERROR Got: %s \n",u_errorName(ec));
|
|
|
|
}else{
|
|
|
|
ec = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_verbose("Warning: Returning NULL for a mismatched va_arg type isn't supported on this platform.\n", i);
|
2002-04-03 18:21:53 +00:00
|
|
|
}
|
2002-04-06 00:13:05 +00:00
|
|
|
|
|
|
|
umsg_parse(formatter,result,resultLength,&count,&ec,&one,&two,&d2);
|
2002-04-03 03:36:17 +00:00
|
|
|
if(U_FAILURE(ec)){
|
|
|
|
log_err("umsg_parse could not parse the pattern. Error: %s.\n",u_errorName(ec));
|
|
|
|
}
|
2002-07-29 21:04:18 +00:00
|
|
|
free(result);
|
2002-04-03 03:36:17 +00:00
|
|
|
}else{
|
|
|
|
log_err("FAIL: Expected U_BUFFER_OVERFLOW error while preflighting got: %s for testCasePatterns[%d]",u_errorName(ec),i);
|
|
|
|
}
|
|
|
|
}
|
2002-07-27 00:22:01 +00:00
|
|
|
umsg_close(formatter);
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
2001-03-08 23:39:57 +00:00
|
|
|
FreeStrings();
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_resetTimeZone();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*test u_formatMessage() with sample patterns */
|
2005-10-14 03:30:45 +00:00
|
|
|
static void TestSampleMessageFormat(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-08 23:39:57 +00:00
|
|
|
UChar *str;
|
|
|
|
UChar *result;
|
|
|
|
UChar pattern[100], expected[100];
|
|
|
|
int32_t resultLengthOut, resultlength;
|
|
|
|
UDate d = 837039928046.0;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2003-10-07 23:49:04 +00:00
|
|
|
|
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
2001-03-08 23:39:57 +00:00
|
|
|
str=(UChar*)malloc(sizeof(UChar) * 15);
|
|
|
|
u_uastrcpy(str, "abc");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-08 23:39:57 +00:00
|
|
|
u_uastrcpy(pattern, "There are {0} files on {1,date}");
|
|
|
|
u_uastrcpy(expected, "There are abc files on Jul 10, 1996");
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * 1);
|
|
|
|
log_verbose("\nTesting a sample for Message format test#1\n");
|
|
|
|
resultlength=1;
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, d);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-08 23:39:57 +00:00
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, d);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("Error: failure in message format on test#1: %s (Are you missing data?)\n", myErrorName(status));
|
2001-03-08 23:39:57 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, expected)==0)
|
2001-03-08 23:39:57 +00:00
|
|
|
log_verbose("PASS: MessagFormat successful on test#1\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#1 \n GOT: %s EXPECTED: %s\n",
|
|
|
|
austrdup(result), austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log_verbose("\nTesting message format with another pattern test#2\n");
|
|
|
|
u_uastrcpy(pattern, "The disk \"{0}\" contains {1,number,integer} file(s)");
|
|
|
|
u_uastrcpy(expected, "The disk \"MyDisk\" contains 23 file(s)");
|
|
|
|
u_uastrcpy(str, "MyDisk");
|
|
|
|
|
|
|
|
resultLengthOut=u_formatMessage( "en_US",
|
|
|
|
pattern,
|
|
|
|
u_strlen(pattern),
|
|
|
|
result,
|
|
|
|
resultlength,
|
|
|
|
&status,
|
|
|
|
str,
|
|
|
|
235);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-08 23:39:57 +00:00
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * (resultlength+1));
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 23);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("Error: failure in message format on test#2 : %s (Are you missing data?)\n", myErrorName(status));
|
2001-03-08 23:39:57 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, expected)==0)
|
2001-03-08 23:39:57 +00:00
|
|
|
log_verbose("PASS: MessagFormat successful on test#2\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#2\n GOT: %s EXPECTED: %s\n",
|
|
|
|
austrdup(result), austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_verbose("\nTesting message format with another pattern test#3\n");
|
|
|
|
u_uastrcpy(pattern, "You made a {0} of {1,number,currency}");
|
|
|
|
u_uastrcpy(expected, "You made a deposit of $500.00");
|
|
|
|
u_uastrcpy(str, "deposit");
|
|
|
|
resultlength=0;
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, str, 500.00);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-08 23:39:57 +00:00
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 500.00);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("Error: failure in message format on test#3 : %s (Are you missing data?)\n", myErrorName(status));
|
2001-03-08 23:39:57 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, expected)==0)
|
2001-03-08 23:39:57 +00:00
|
|
|
log_verbose("PASS: MessagFormat successful on test#3\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#3\n GOT: %s EXPECTED %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-08 23:39:57 +00:00
|
|
|
free(result);
|
|
|
|
free(str);
|
2003-10-07 23:49:04 +00:00
|
|
|
|
|
|
|
ctest_resetTimeZone();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
2002-04-03 03:36:17 +00:00
|
|
|
/* Test umsg_format() and umsg_parse() , format and parse sequence and round trip */
|
|
|
|
static void TestNewFormatAndParseAPI(void)
|
|
|
|
{
|
|
|
|
|
2008-02-19 05:05:51 +00:00
|
|
|
UChar *result, tzID[4], str[25];
|
2002-04-03 03:36:17 +00:00
|
|
|
UChar pattern[100];
|
|
|
|
UChar expected[100];
|
|
|
|
int32_t resultLengthOut, resultlength;
|
|
|
|
UCalendar *cal;
|
|
|
|
UDate d1,d;
|
|
|
|
UDateFormat *def1;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2005-07-18 20:22:31 +00:00
|
|
|
int32_t value = 0;
|
2002-04-03 03:36:17 +00:00
|
|
|
UChar ret[30];
|
|
|
|
UParseError parseError;
|
|
|
|
UMessageFormat* fmt = NULL;
|
|
|
|
int32_t count=0;
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
2002-04-03 03:36:17 +00:00
|
|
|
log_verbose("Testing format and parse with parse error\n");
|
|
|
|
|
|
|
|
u_uastrcpy(str, "disturbance in force");
|
|
|
|
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) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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_verbose("\nTesting with pattern test#4");
|
|
|
|
u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
|
|
|
|
u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
|
|
|
|
resultlength=1;
|
|
|
|
fmt = umsg_open(pattern,u_strlen(pattern),"en_US",&parseError,&status);
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("error in umsg_open : %s (Are you missing data?)\n", u_errorName(status) );
|
2002-04-03 03:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
|
|
|
|
resultLengthOut=umsg_format(fmt ,result, resultlength,&status, d1, str, 7);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
|
|
|
{
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
|
|
|
|
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: failure in message format test#4: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if(u_strcmp(result, expected)==0)
|
|
|
|
log_verbose("PASS: MessagFormat successful on test#4\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*try to parse this and check*/
|
|
|
|
log_verbose("\nTesting the parse Message test#5\n");
|
|
|
|
|
|
|
|
umsg_parse(fmt, result, u_strlen(result),&count,&status, &d, ret, &value);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: error in parsing: test#5: %s\n", myErrorName(status));
|
|
|
|
}
|
2005-07-18 20:22:31 +00:00
|
|
|
if(value!=7 && u_strcmp(str,ret)!=0)
|
2002-04-03 03:36:17 +00:00
|
|
|
log_err("FAIL: Error in parseMessage on test#5 \n");
|
|
|
|
else
|
|
|
|
log_verbose("PASS: parseMessage successful 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));
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
|
|
|
|
log_verbose("PASS: parseMessage successful test#5\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
|
|
|
|
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
|
|
|
|
}
|
|
|
|
}
|
2002-07-27 00:22:01 +00:00
|
|
|
umsg_close(fmt);
|
2002-04-03 03:36:17 +00:00
|
|
|
udat_close(def1);
|
|
|
|
ucal_close(cal);
|
|
|
|
|
|
|
|
free(result);
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_resetTimeZone();
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test u_formatMessageWithError() and u_parseMessageWithError() , format and parse sequence and round trip */
|
|
|
|
static void TestSampleFormatAndParseWithError(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
UChar *result, *tzID, *str;
|
|
|
|
UChar pattern[100];
|
2002-11-28 08:53:37 +00:00
|
|
|
|
2002-04-03 03:36:17 +00:00
|
|
|
UChar expected[100];
|
|
|
|
int32_t resultLengthOut, resultlength;
|
|
|
|
UCalendar *cal;
|
|
|
|
UDate d1,d;
|
|
|
|
UDateFormat *def1;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2005-07-18 20:22:31 +00:00
|
|
|
int32_t value = 0;
|
2002-04-03 03:36:17 +00:00
|
|
|
UChar ret[30];
|
|
|
|
UParseError parseError;
|
|
|
|
|
2003-10-07 21:52:15 +00:00
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
2002-04-03 03:36:17 +00:00
|
|
|
log_verbose("Testing format and parse with parse error\n");
|
|
|
|
|
|
|
|
str=(UChar*)malloc(sizeof(UChar) * 25);
|
|
|
|
u_uastrcpy(str, "disturbance in force");
|
|
|
|
tzID=(UChar*)malloc(sizeof(UChar) * 4);
|
|
|
|
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) );
|
|
|
|
}
|
|
|
|
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_verbose("\nTesting with pattern test#4");
|
|
|
|
u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
|
|
|
|
u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
|
|
|
|
resultlength=1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
resultLengthOut=u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
|
|
|
{
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
|
|
|
|
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, expected)==0)
|
2002-04-03 03:36:17 +00:00
|
|
|
log_verbose("PASS: MessagFormat successful on test#4\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*try to parse this and check*/
|
|
|
|
log_verbose("\nTesting the parse Message test#5\n");
|
|
|
|
|
|
|
|
u_parseMessageWithError("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &parseError,&status, &d, ret, &value);
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(value!=7 && u_strcmp(str,ret)!=0)
|
2002-04-03 03:36:17 +00:00
|
|
|
log_err("FAIL: Error in parseMessage on test#5 \n");
|
|
|
|
else
|
|
|
|
log_verbose("PASS: parseMessage successful on test#5\n");
|
|
|
|
|
|
|
|
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
|
2002-04-03 03:36:17 +00:00
|
|
|
}else{
|
|
|
|
|
|
|
|
if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
|
|
|
|
log_verbose("PASS: parseMessage successful test#5\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
|
|
|
|
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
udat_close(def1);
|
|
|
|
ucal_close(cal);
|
|
|
|
|
|
|
|
free(result);
|
|
|
|
free(str);
|
|
|
|
free(tzID);
|
|
|
|
|
2003-10-07 21:52:15 +00:00
|
|
|
ctest_resetTimeZone();
|
2002-04-03 03:36:17 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Test u_formatMessage() and u_parseMessage() , format and parse sequence and round trip */
|
2005-10-14 03:30:45 +00:00
|
|
|
static void TestSampleFormatAndParse(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
UChar *result, *tzID, *str;
|
|
|
|
UChar pattern[100];
|
|
|
|
UChar expected[100];
|
|
|
|
int32_t resultLengthOut, resultlength;
|
|
|
|
UCalendar *cal;
|
|
|
|
UDate d1,d;
|
|
|
|
UDateFormat *def1;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2005-07-18 20:22:31 +00:00
|
|
|
int32_t value = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar ret[30];
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing format and parse\n");
|
|
|
|
|
|
|
|
str=(UChar*)malloc(sizeof(UChar) * 25);
|
|
|
|
u_uastrcpy(str, "disturbance in force");
|
|
|
|
tzID=(UChar*)malloc(sizeof(UChar) * 4);
|
|
|
|
u_uastrcpy(tzID, "PST");
|
|
|
|
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("error in ucal_open caldef : %s\n", myErrorName(status) );
|
|
|
|
}
|
|
|
|
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
|
|
|
|
d1=ucal_getMillis(cal, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: failure in get millis: %s\n", myErrorName(status) );
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("\nTesting with pattern test#4");
|
|
|
|
u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
|
|
|
|
u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
|
|
|
|
resultlength=1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
|
|
|
|
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, expected)==0)
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("PASS: MessagFormat successful on test#4\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*try to parse this and check*/
|
|
|
|
log_verbose("\nTesting the parse Message test#5\n");
|
2001-08-16 00:58:53 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_parseMessage("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &status, &d, ret, &value);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(value!=7 && u_strcmp(str,ret)!=0)
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("FAIL: Error in parseMessage on test#5 \n");
|
|
|
|
else
|
|
|
|
log_verbose("PASS: parseMessage successful on test#5\n");
|
|
|
|
|
2001-08-16 00:58:53 +00:00
|
|
|
def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
|
2001-08-16 00:58:53 +00:00
|
|
|
}else{
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-08-16 00:58:53 +00:00
|
|
|
if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
|
|
|
|
log_verbose("PASS: parseMessage successful test#5\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
|
|
|
|
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
udat_close(def1);
|
|
|
|
ucal_close(cal);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
free(result);
|
|
|
|
free(str);
|
2000-07-06 23:01:50 +00:00
|
|
|
free(tzID);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-10-07 21:52:15 +00:00
|
|
|
ctest_resetTimeZone();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* test message format with a choice option */
|
2005-10-14 03:30:45 +00:00
|
|
|
static void TestMsgFormatChoice(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UChar* str;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar *result;
|
|
|
|
UChar pattern[100];
|
|
|
|
UChar expected[100];
|
|
|
|
int32_t resultlength,resultLengthOut;
|
|
|
|
|
|
|
|
str=(UChar*)malloc(sizeof(UChar) * 25);
|
|
|
|
u_uastrcpy(str, "MyDisk");
|
|
|
|
log_verbose("Testing message format with choice test #6\n:");
|
|
|
|
/*There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.*/
|
|
|
|
u_uastrcpy(pattern, "The disk {1} contains {0,choice,0#no files|1#one file|1<{0,number,integer} files}");
|
|
|
|
u_uastrcpy(expected, "The disk MyDisk contains 100 files");
|
|
|
|
resultlength=0;
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 100., str);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 100., str);
|
2000-08-09 23:34:41 +00:00
|
|
|
if(u_strcmp(result, expected)==0)
|
|
|
|
log_verbose("PASS: MessagFormat successful on test#6\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#6\n GOT %s EXPECTED %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on test#6 : %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("Testing message format with choice test #7\n:");
|
|
|
|
u_uastrcpy(expected, "The disk MyDisk contains no files");
|
|
|
|
resultlength=0;
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 0., str);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 0., str);
|
2000-08-09 23:34:41 +00:00
|
|
|
|
|
|
|
if(u_strcmp(result, expected)==0)
|
|
|
|
log_verbose("PASS: MessagFormat successful on test#7\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#7\n GOT: %s EXPECTED %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on test#7 : %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("Testing message format with choice test #8\n:");
|
|
|
|
u_uastrcpy(expected, "The disk MyDisk contains one file");
|
|
|
|
resultlength=0;
|
|
|
|
resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 1., str);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultLengthOut+1;
|
|
|
|
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
|
|
|
u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 1., str);
|
2000-08-09 23:34:41 +00:00
|
|
|
|
|
|
|
if(u_strcmp(result, expected)==0)
|
|
|
|
log_verbose("PASS: MessagFormat successful on test#8\n");
|
|
|
|
else{
|
|
|
|
log_err("FAIL: Error in MessageFormat on test#8\n GOT %s EXPECTED: %s\n", austrdup(result),
|
|
|
|
austrdup(expected) );
|
|
|
|
}
|
|
|
|
|
|
|
|
free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on test#8 : %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
|
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*test u_parseMessage() with various test patterns */
|
2005-10-14 03:30:45 +00:00
|
|
|
static void TestParseMessage(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UChar pattern[100];
|
|
|
|
UChar source[100];
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-03 03:36:17 +00:00
|
|
|
int32_t value;
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar str[10];
|
|
|
|
UChar res[10];
|
|
|
|
|
|
|
|
log_verbose("\nTesting a sample for parse Message test#9\n");
|
|
|
|
|
|
|
|
u_uastrcpy(source, "You deposited an amount of $500.00");
|
|
|
|
u_uastrcpy(pattern, "You {0} an amount of {1,number,currency}");
|
|
|
|
u_uastrcpy(res,"deposited");
|
|
|
|
|
|
|
|
u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(value==500.00 && u_strcmp(str,res)==0)
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("PASS: parseMessage successful on test#9\n");
|
|
|
|
else
|
|
|
|
log_err("FAIL: Error in parseMessage on test#9 \n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_verbose("\nTesting a sample for parse Message test#10\n");
|
|
|
|
|
|
|
|
u_uastrcpy(source, "There are 123 files on MyDisk created");
|
|
|
|
u_uastrcpy(pattern, "There are {0,number,integer} files on {1} created");
|
|
|
|
u_uastrcpy(res,"MyDisk");
|
|
|
|
|
|
|
|
u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(value==123.00 && u_strcmp(str,res)==0)
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("PASS: parseMessage successful on test#10\n");
|
|
|
|
else
|
|
|
|
log_err("FAIL: Error in parseMessage on test#10 \n");
|
|
|
|
}
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static int32_t CallFormatMessage(const char* locale, UChar* testCasePattern, int32_t patternLength,
|
2000-04-18 22:18:05 +00:00
|
|
|
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. */
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestMessageFormatWithValist( void )
|
2000-04-18 22:18:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
UChar *str;
|
|
|
|
UChar* result;
|
|
|
|
int32_t resultLengthOut,resultlength,i, patternlength;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UDate d1=1000000000.0;
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
2000-04-18 22:18:05 +00:00
|
|
|
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);
|
2002-01-30 06:16:26 +00:00
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in message format on testcase %d: %s (Are you missing data?)\n", i, myErrorName(status) );
|
2002-01-30 06:16:26 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(u_strcmp(result, testResultStrings[i])==0){
|
2002-01-30 06:16:26 +00:00
|
|
|
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]) );
|
|
|
|
}
|
2000-04-18 22:18:05 +00:00
|
|
|
}
|
|
|
|
free(result);
|
|
|
|
free(str);
|
2001-03-08 23:39:57 +00:00
|
|
|
FreeStrings();
|
2003-10-07 21:52:15 +00:00
|
|
|
|
|
|
|
ctest_resetTimeZone();
|
2000-04-18 22:18:05 +00:00
|
|
|
}
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void CallParseMessage(const char* locale, UChar* pattern, int32_t patternLength,
|
2000-04-18 22:24:00 +00:00
|
|
|
UChar* source, int32_t sourceLength, UErrorCode *status, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, status);
|
|
|
|
u_vparseMessage(locale, pattern, patternLength, source, sourceLength, ap, status);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
/*test u_vparseMessage() with various test patterns */
|
2002-03-28 18:26:25 +00:00
|
|
|
static void TestParseMessageWithValist(void)
|
2000-04-18 22:24:00 +00:00
|
|
|
{
|
|
|
|
UChar pattern[100];
|
|
|
|
UChar source[100];
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-03 03:36:17 +00:00
|
|
|
int32_t value;
|
2000-04-18 22:24:00 +00:00
|
|
|
UChar str[10];
|
|
|
|
UChar res[10];
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
log_verbose("\nTesting a sample for parse Message test#9\n");
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
u_uastrcpy(source, "You deposited an amount of $500.00");
|
|
|
|
u_uastrcpy(pattern, "You {0} an amount of {1,number,currency}");
|
|
|
|
u_uastrcpy(res,"deposited");
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
|
2000-04-18 22:24:00 +00:00
|
|
|
}
|
2009-06-09 21:28:13 +00:00
|
|
|
else if(value==500.00 && u_strcmp(str,res)==0)
|
2000-04-18 22:24:00 +00:00
|
|
|
log_verbose("PASS: parseMessage successful on test#9\n");
|
|
|
|
else
|
2009-06-09 21:28:13 +00:00
|
|
|
log_err("FAIL: Error in parseMessage on test#9\n");
|
2000-04-18 22:24:00 +00:00
|
|
|
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
log_verbose("\nTesting a sample for parse Message test#10\n");
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
u_uastrcpy(source, "There are 123 files on MyDisk created");
|
|
|
|
u_uastrcpy(pattern, "There are {0,number,integer} files on {1} created");
|
|
|
|
u_uastrcpy(res,"MyDisk");
|
2001-03-29 01:08:13 +00:00
|
|
|
|
2000-04-18 22:24:00 +00:00
|
|
|
CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
|
|
|
|
if(U_FAILURE(status)){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
|
2000-04-18 22:24:00 +00:00
|
|
|
}
|
2008-02-19 05:05:51 +00:00
|
|
|
else if(value==123.00 && u_strcmp(str,res)==0)
|
2000-04-18 22:24:00 +00:00
|
|
|
log_verbose("PASS: parseMessage successful on test#10\n");
|
|
|
|
else
|
|
|
|
log_err("FAIL: Error in parseMessage on test#10 \n");
|
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
2001-03-23 19:08:53 +00:00
|
|
|
/**
|
|
|
|
* Regression test for ICU4C Jitterbug 904
|
|
|
|
*/
|
2001-03-29 01:08:13 +00:00
|
|
|
static void TestJ904(void) {
|
2001-03-23 19:08:53 +00:00
|
|
|
UChar pattern[256];
|
|
|
|
UChar result[256];
|
|
|
|
UChar string[16];
|
|
|
|
char cresult[256];
|
|
|
|
int32_t length;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
|
|
|
|
const char* EXP = "Number 0,143, String foo, Date 12:34:56.789";
|
|
|
|
|
2003-10-07 23:49:04 +00:00
|
|
|
ctest_setTimeZone(NULL, &status);
|
|
|
|
|
2001-03-23 19:08:53 +00:00
|
|
|
u_uastrcpy(string, "foo");
|
|
|
|
/* Slight hack here -- instead of date pattern HH:mm:ss.SSS, use
|
|
|
|
* 12:mm:ss.SSS. Why? So this test generates the same output --
|
|
|
|
* "12:34:56.789" -- regardless of time zone (as long as we aren't
|
|
|
|
* in one of the 30 minute offset zones!). */
|
|
|
|
u_uastrcpy(pattern, PAT);
|
|
|
|
length = u_formatMessage("nl", pattern, u_strlen(pattern),
|
|
|
|
result, 256, &status,
|
|
|
|
string, 1/7.0,
|
|
|
|
789.0+1000*(56+60*(34+60*12)));
|
|
|
|
|
2002-07-27 00:22:01 +00:00
|
|
|
u_austrncpy(cresult, result, sizeof(cresult));
|
2001-03-23 19:08:53 +00:00
|
|
|
|
|
|
|
/* This test passes if it DOESN'T CRASH. However, we test the
|
|
|
|
* output anyway. If the string doesn't match in the date part,
|
|
|
|
* check to see that the machine doesn't have an unusual time zone
|
|
|
|
* offset, that is, one with a non-zero minutes/seconds offset
|
|
|
|
* from GMT -- see above. */
|
2003-04-23 05:49:02 +00:00
|
|
|
if (strcmp(cresult, EXP) == 0) {
|
2001-03-23 19:08:53 +00:00
|
|
|
log_verbose("Ok: \"%s\"\n", cresult);
|
|
|
|
} else {
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("FAIL: got \"%s\", expected \"%s\" -> %s (Are you missing data?)\n", cresult, EXP, u_errorName(status));
|
2001-03-23 19:08:53 +00:00
|
|
|
}
|
2003-10-07 23:49:04 +00:00
|
|
|
|
|
|
|
ctest_resetTimeZone();
|
2001-03-23 19:08:53 +00:00
|
|
|
}
|
2001-08-17 17:34:37 +00:00
|
|
|
|
|
|
|
static void OpenMessageFormatTest(void)
|
2001-08-16 00:58:53 +00:00
|
|
|
{
|
|
|
|
UMessageFormat *f1, *f2, *f3;
|
|
|
|
UChar pattern[256];
|
|
|
|
UChar result[256];
|
|
|
|
char cresult[256];
|
|
|
|
UParseError parseError;
|
2001-08-17 17:34:37 +00:00
|
|
|
const char* locale = "hi_IN";
|
2001-08-16 00:58:53 +00:00
|
|
|
char* retLoc;
|
2001-08-17 17:34:37 +00:00
|
|
|
const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
|
2001-08-16 00:58:53 +00:00
|
|
|
int32_t length=0;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2002-07-27 00:22:01 +00:00
|
|
|
u_uastrncpy(pattern, PAT, sizeof(pattern)/sizeof(pattern[0]));
|
2001-08-16 00:58:53 +00:00
|
|
|
|
|
|
|
/* Test umsg_open */
|
|
|
|
f1 = umsg_open(pattern,length,NULL,NULL,&status);
|
|
|
|
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("umsg_open failed with pattern %s. Error: \n", PAT, u_errorName(status));
|
2002-01-30 06:16:26 +00:00
|
|
|
return;
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test umsg_open with parse error */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
f2 = umsg_open(pattern,length,NULL,&parseError,&status);
|
|
|
|
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("umsg_open with parseError failed with pattern %s. Error: %s\n", PAT, u_errorName(status));
|
2002-01-30 06:16:26 +00:00
|
|
|
return;
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test umsg_clone */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
f3 = umsg_clone(f1,&status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("umsg_clone failed. Error %s \n", u_errorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test umsg_setLocale */
|
|
|
|
umsg_setLocale(f1,locale);
|
|
|
|
/* Test umsg_getLocale */
|
|
|
|
retLoc = (char*)umsg_getLocale(f1);
|
|
|
|
if(strcmp(retLoc,locale)!=0)
|
|
|
|
{
|
|
|
|
log_err("umsg_setLocale and umsg_getLocale methods failed. Expected:%s Got: %s \n", locale, retLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test umsg_applyPattern */
|
|
|
|
status = U_ZERO_ERROR;
|
2002-05-24 17:22:53 +00:00
|
|
|
umsg_applyPattern(f1,pattern,(int32_t)strlen(PAT),NULL,&status);
|
2001-08-16 00:58:53 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("umsg_applyPattern failed. Error %s (Are you missing data?)\n",u_errorName(status));
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test umsg_toPattern */
|
|
|
|
umsg_toPattern(f1,result,256,&status);
|
|
|
|
if(U_FAILURE(status) ){
|
2009-06-09 21:28:13 +00:00
|
|
|
log_data_err("umsg_toPattern method failed. Error: %s (Are you missing data?)\n",u_errorName(status));
|
2004-12-16 02:54:23 +00:00
|
|
|
} else {
|
|
|
|
if(u_strcmp(result,pattern)!=0){
|
|
|
|
u_UCharsToChars(result,cresult,256);
|
|
|
|
log_err("umsg_toPattern method failed. Expected: %s Got: %s \n",PAT,cresult);
|
|
|
|
}
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
|
|
|
/* umsg_format umsg_parse */
|
|
|
|
|
2001-08-31 02:21:34 +00:00
|
|
|
umsg_close(f1);
|
|
|
|
umsg_close(f2);
|
|
|
|
umsg_close(f3);
|
2001-08-16 00:58:53 +00:00
|
|
|
}
|
2001-03-23 19:08:53 +00:00
|
|
|
|
2004-07-18 09:41:16 +00:00
|
|
|
static void MessageLength(void)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const char patChars[] = {"123{0}456{0}"};
|
|
|
|
const char expectedChars[] = {"123abc"};
|
|
|
|
UChar pattern[sizeof(patChars)];
|
|
|
|
UChar arg[] = {0x61,0x62,0x63,0};
|
|
|
|
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_formatMessage("en_US", pattern, 6, result, sizeof(result)/sizeof(result[0]), &status, arg);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("u_formatMessage method failed. Error: %s \n",u_errorName(status));
|
|
|
|
}
|
|
|
|
if (u_strcmp(result, expected) != 0) {
|
|
|
|
log_err("u_formatMessage didn't return expected result\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-24 23:43:25 +00:00
|
|
|
static void TestErrorChaining(void) {
|
|
|
|
UErrorCode status = U_USELESS_COLLATOR_ERROR;
|
|
|
|
|
|
|
|
umsg_open(NULL, 0, NULL, NULL, &status);
|
|
|
|
umsg_applyPattern(NULL, NULL, 0, NULL, &status);
|
2006-11-16 20:10:22 +00:00
|
|
|
umsg_toPattern(NULL, NULL, 0, &status);
|
2006-03-24 23:43:25 +00:00
|
|
|
umsg_clone(NULL, &status);
|
2006-11-16 20:10:22 +00:00
|
|
|
umsg_format(NULL, NULL, 0, &status);
|
|
|
|
umsg_parse(NULL, NULL, 0, NULL, &status);
|
2006-03-24 23:43:25 +00:00
|
|
|
umsg_close(NULL);
|
|
|
|
|
|
|
|
/* All of this code should have done nothing. */
|
|
|
|
if (status != U_USELESS_COLLATOR_ERROR) {
|
|
|
|
log_err("Status got changed to %s\n", u_errorName(status));
|
|
|
|
}
|
2006-11-16 20:10:22 +00:00
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
umsg_open(NULL, 0, NULL, NULL, &status);
|
|
|
|
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
|
|
|
|
log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
umsg_applyPattern(NULL, NULL, 0, NULL, &status);
|
|
|
|
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
|
|
|
|
log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
umsg_toPattern(NULL, NULL, 0, &status);
|
|
|
|
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
|
|
|
|
log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
umsg_clone(NULL, &status);
|
|
|
|
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
|
|
|
|
log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
|
|
|
|
}
|
2006-03-24 23:43:25 +00:00
|
|
|
}
|
2002-04-03 03:36:17 +00:00
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
void addMsgForTest(TestNode** root);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void addMsgForTest(TestNode** root)
|
|
|
|
{
|
2001-08-17 17:34:37 +00:00
|
|
|
addTest(root, &OpenMessageFormatTest, "tsformat/cmsgtst/OpenMessageFormatTest");
|
1999-08-16 21:50:52 +00:00
|
|
|
addTest(root, &MessageFormatTest, "tsformat/cmsgtst/MessageFormatTest");
|
|
|
|
addTest(root, &TestSampleMessageFormat, "tsformat/cmsgtst/TestSampleMessageFormat");
|
|
|
|
addTest(root, &TestSampleFormatAndParse, "tsformat/cmsgtst/TestSampleFormatAndParse");
|
2002-04-03 03:36:17 +00:00
|
|
|
addTest(root, &TestSampleFormatAndParseWithError, "tsformat/cmsgtst/TestSampleFormatAndParseWithError");
|
|
|
|
addTest(root, &TestNewFormatAndParseAPI, "tsformat/cmsgtst/TestNewFormatAndParseAPI");
|
1999-08-16 21:50:52 +00:00
|
|
|
addTest(root, &TestMsgFormatChoice, "tsformat/cmsgtst/TestMsgFormatChoice");
|
|
|
|
addTest(root, &TestParseMessage, "tsformat/cmsgtst/TestParseMessage");
|
2000-04-18 22:18:05 +00:00
|
|
|
addTest(root, &TestMessageFormatWithValist, "tsformat/cmsgtst/TestMessageFormatWithValist");
|
2000-04-18 22:24:00 +00:00
|
|
|
addTest(root, &TestParseMessageWithValist, "tsformat/cmsgtst/TestParseMessageWithValist");
|
2001-03-23 19:08:53 +00:00
|
|
|
addTest(root, &TestJ904, "tsformat/cmsgtst/TestJ904");
|
2004-07-18 09:41:16 +00:00
|
|
|
addTest(root, &MessageLength, "tsformat/cmsgtst/MessageLength");
|
2006-03-24 23:43:25 +00:00
|
|
|
addTest(root, &TestErrorChaining, "tsformat/cmsgtst/TestErrorChaining");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-09-20 17:54:45 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|