Home | History | Annotate | Download | only in cintltst
      1 /********************************************************************
      2  * COPYRIGHT:
      3  * Copyright (c) 1997-2010, International Business Machines Corporation and
      4  * others. All Rights Reserved.
      5  ********************************************************************
      6  *
      7  * File CMSGTST.C
      8  *
      9  * Modification History:
     10  *        Name                     Description
     11  *     Madhu Katragadda              Creation
     12  ********************************************************************/
     13 /* C API TEST FOR MESSAGE FORMAT */
     14 
     15 #include "unicode/utypes.h"
     16 
     17 #if !UCONFIG_NO_FORMATTING
     18 
     19 #include <stdlib.h>
     20 #include <string.h>
     21 #include <stdarg.h>
     22 #include "unicode/uloc.h"
     23 #include "unicode/umsg.h"
     24 #include "unicode/udat.h"
     25 #include "unicode/umsg.h"
     26 #include "unicode/ustring.h"
     27 #include "cintltst.h"
     28 #include "cmsgtst.h"
     29 #include "cformtst.h"
     30 
     31 static const char* const txt_testCasePatterns[] = {
     32    "Quotes '', '{', a {0,number,integer} '{'0}",
     33    "Quotes '', '{', a {0,number,integer} '{'0}",
     34    "You deposited {0,number,integer} times an amount of {1,number,currency} on {2,date,short}",
     35     "'{'2,time,full}, for {1, number }, {0,number,integer} is {2,time,full} and full date is {2,date,full}",
     36    "'{'1,number,percent} for {0,number,integer} is {1,number,percent}",
     37 };
     38 
     39 static const char* const txt_testResultStrings[] = {
     40     "Quotes ', {, a 1 {0}",
     41     "Quotes ', {, a 1 {0}",
     42     "You deposited 1 times an amount of $3,456.00 on 1/12/70",
     43     "{2,time,full}, for 3,456, 1 is 5:46:40 AM Pacific Standard Time and full date is Monday, January 12, 1970",
     44     "{1,number,percent} for 1 is 345,600%"
     45 };
     46 
     47 const int32_t cnt_testCases = 5;
     48 static UChar* testCasePatterns[5];
     49 
     50 static UChar* testResultStrings[5];
     51 
     52 static UBool strings_initialized = FALSE;
     53 
     54 /* function used to create the test patterns for testing Message formatting */
     55 static void InitStrings( void )
     56 {
     57     int32_t i;
     58     if (strings_initialized)
     59         return;
     60 
     61     for (i=0; i < cnt_testCases; i++ ) {
     62         uint32_t strSize = (uint32_t)strlen(txt_testCasePatterns[i]) + 1;
     63         testCasePatterns[i]=(UChar*)malloc(sizeof(UChar) * strSize);
     64         u_uastrncpy(testCasePatterns[i], txt_testCasePatterns[i], strSize);
     65     }
     66     for (i=0; i < cnt_testCases; i++ ) {
     67         uint32_t strSize = (uint32_t)strlen(txt_testResultStrings[i]) + 1;
     68         testResultStrings[i] = (UChar*)malloc(sizeof(UChar) * strSize);
     69         u_uastrncpy(testResultStrings[i], txt_testResultStrings[i], strSize);
     70     }
     71 
     72     strings_initialized = TRUE;
     73 }
     74 
     75 static void FreeStrings( void )
     76 {
     77     int32_t i;
     78     if (!strings_initialized)
     79         return;
     80 
     81     for (i=0; i < cnt_testCases; i++ ) {
     82         free(testCasePatterns[i]);
     83     }
     84     for (i=0; i < cnt_testCases; i++ ) {
     85         free(testResultStrings[i]);
     86     }
     87     strings_initialized = FALSE;
     88 }
     89 
     90 /* Platform dependent test to detect if this type will return NULL when interpreted as a pointer. */
     91 static UBool returnsNullForType(int firstParam, ...) {
     92     UBool isNULL;
     93     va_list marker;
     94     va_start(marker, firstParam);
     95     isNULL = (UBool)(va_arg(marker, void*) == NULL);
     96     va_end(marker);
     97     return isNULL;
     98 }
     99 
    100 /* Test u_formatMessage() with various test patterns() */
    101 static void MessageFormatTest( void )
    102 {
    103     UChar *str;
    104     UChar* result;
    105     int32_t resultLengthOut,resultlength,i, patternlength;
    106     UErrorCode status = U_ZERO_ERROR;
    107     UDate d1=1000000000.0;
    108 
    109     ctest_setTimeZone(NULL, &status);
    110 
    111     str=(UChar*)malloc(sizeof(UChar) * 7);
    112     u_uastrncpy(str, "MyDisk", 7);
    113     resultlength=1;
    114     result=(UChar*)malloc(sizeof(UChar) * 1);
    115     log_verbose("Testing u_formatMessage()\n");
    116     InitStrings();
    117     for (i = 0; i < cnt_testCases; i++) {
    118         status=U_ZERO_ERROR;
    119         patternlength=u_strlen(testCasePatterns[i]);
    120         resultLengthOut=u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    121             &status, 1, 3456.00, d1);
    122         if(status== U_BUFFER_OVERFLOW_ERROR)
    123         {
    124             status=U_ZERO_ERROR;
    125             resultlength=resultLengthOut+1;
    126             result=(UChar*)realloc(result,sizeof(UChar) * resultlength);
    127             u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    128                 &status, 1, 3456.00, d1);
    129         }
    130         if(U_FAILURE(status)){
    131             log_data_err("ERROR: failure in message format on testcase %d:  %s (Are you missing data?)\n", i, myErrorName(status) );
    132             continue;
    133         }
    134         if(u_strcmp(result, testResultStrings[i])==0){
    135             log_verbose("PASS: MessagFormat successful on testcase : %d\n", i);
    136         }
    137         else{
    138             log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i,
    139                 austrdup(result), austrdup(testResultStrings[i]) );
    140         }
    141     }
    142     free(result);
    143     result = NULL;
    144     free(str);
    145     {
    146 
    147          for (i = 0; i < cnt_testCases; i++) {
    148             UParseError parseError;
    149             status=U_ZERO_ERROR;
    150             patternlength=u_strlen(testCasePatterns[i]);
    151             resultlength=0;
    152             resultLengthOut=u_formatMessageWithError( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    153                 &parseError,&status, 1, 3456.00, d1);
    154             if(status== U_BUFFER_OVERFLOW_ERROR)
    155             {
    156                 status=U_ZERO_ERROR;
    157                 resultlength=resultLengthOut+1;
    158                 result=(UChar*)malloc(sizeof(UChar) * resultlength);
    159                 u_formatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    160                     &status, 1, 3456.00, d1);
    161             }
    162             if(U_FAILURE(status)){
    163                 log_data_err("ERROR: failure in message format on testcase %d:  %s (Are you missing data?)\n", i, myErrorName(status) );
    164                 continue;
    165             }
    166             if(u_strcmp(result, testResultStrings[i])==0){
    167                 log_verbose("PASS: MessagFormat successful on testcase : %d\n", i);
    168             }
    169             else{
    170                 log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i,
    171                     austrdup(result), austrdup(testResultStrings[i]) );
    172             }
    173             free(result);
    174             result=NULL;
    175         }
    176     }
    177     {
    178         UErrorCode ec = U_ZERO_ERROR;
    179         int32_t patternLength = u_strlen(testCasePatterns[0]);
    180 
    181         UMessageFormat formatter = umsg_open(testCasePatterns[0],patternLength,"en_US",NULL,&ec);
    182 
    183         if(U_FAILURE(ec)){
    184             log_data_err("umsg_open() failed for testCasePattens[%d]. -> %s (Are you missing data?)\n",i, u_errorName(ec));
    185             return;
    186         }
    187         for(i = 0;i<cnt_testCases; i++){
    188             UParseError parseError;
    189             int32_t resultLength =0,count=0;
    190             int32_t one=0;
    191             int32_t two=0;
    192             UDate d2=0;
    193 
    194             result=NULL;
    195             patternLength = u_strlen(testCasePatterns[i]);
    196 
    197             umsg_applyPattern(formatter,testCasePatterns[i],patternLength,&parseError,&ec);
    198             if(U_FAILURE(ec)){
    199                 log_err("umsg_applyPattern() failed for testCasePattens[%d].\n",i);
    200                 return;
    201             }
    202             /* pre-flight */
    203             resultLength = umsg_format(formatter,result,resultLength,&ec,1,3456.00,d1);
    204             if(ec==U_BUFFER_OVERFLOW_ERROR){
    205                 ec=U_ZERO_ERROR;
    206                 result = (UChar*) malloc(U_SIZEOF_UCHAR*resultLength+2);
    207                 resultLength =  umsg_format(formatter,result,resultLength+2,&ec,1,3456.00,d1);
    208                 if(U_FAILURE(ec)){
    209                       log_err("ERROR: failure in message format on testcase %d:  %s\n", i, u_errorName(status) );
    210                       free(result);
    211                       return;
    212                 }
    213 
    214                 if(u_strcmp(result, testResultStrings[i])==0){
    215                     log_verbose("PASS: MessagFormat successful on testcase : %d\n", i);
    216                 }
    217                 else{
    218                     log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i,
    219                         austrdup(result), austrdup(testResultStrings[i]) );
    220                 }
    221 
    222                 if (returnsNullForType(1, (double)2.0)) {
    223                     /* HP/UX and possibly other platforms don't properly check for this case.
    224                     We pass in a UDate, but the function expects a UDate *.  When va_arg is used,
    225                     most compilers will return NULL, but HP-UX won't do that and will return 2
    226                     in this case.  This is a platform dependent test.
    227 
    228                     This relies upon "undefined" behavior, as indicated by C99 7.15.1.1 paragraph 2
    229                     */
    230                     umsg_parse(formatter,result,resultLength,&count,&ec,one,two,d2);
    231                     if(ec!=U_ILLEGAL_ARGUMENT_ERROR){
    232                         log_err("FAIL: Did not get expected error for umsg_parse(). Expected: U_ILLEGAL_ARGUMENT_ERROR Got: %s \n",u_errorName(ec));
    233                     }else{
    234                         ec = U_ZERO_ERROR;
    235                     }
    236                 }
    237                 else {
    238                     log_verbose("Warning: Returning NULL for a mismatched va_arg type isn't supported on this platform.\n", i);
    239                 }
    240 
    241                 umsg_parse(formatter,result,resultLength,&count,&ec,&one,&two,&d2);
    242                 if(U_FAILURE(ec)){
    243                     log_err("umsg_parse could not parse the pattern. Error: %s.\n",u_errorName(ec));
    244                 }
    245                 free(result);
    246             }else{
    247                 log_err("FAIL: Expected U_BUFFER_OVERFLOW error while preflighting got: %s for testCasePatterns[%d]",u_errorName(ec),i);
    248             }
    249         }
    250         umsg_close(formatter);
    251     }
    252     FreeStrings();
    253 
    254     ctest_resetTimeZone();
    255 }
    256 
    257 
    258 /*test u_formatMessage() with sample patterns */
    259 static void TestSampleMessageFormat(void)
    260 {
    261     UChar *str;
    262     UChar *result;
    263     UChar pattern[100], expected[100];
    264     int32_t resultLengthOut, resultlength;
    265     UDate d = 837039928046.0;
    266     UErrorCode status = U_ZERO_ERROR;
    267 
    268     ctest_setTimeZone(NULL, &status);
    269 
    270     str=(UChar*)malloc(sizeof(UChar) * 15);
    271     u_uastrcpy(str, "abc");
    272 
    273     u_uastrcpy(pattern, "There are {0} files on {1,date}");
    274     u_uastrcpy(expected, "There are abc files on Jul 10, 1996");
    275     result=(UChar*)malloc(sizeof(UChar) * 1);
    276     log_verbose("\nTesting a sample for Message format test#1\n");
    277     resultlength=1;
    278     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, d);
    279     if(status==U_BUFFER_OVERFLOW_ERROR)
    280     {
    281         status=U_ZERO_ERROR;
    282         resultlength=resultLengthOut+1;
    283         result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
    284         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, d);
    285     }
    286     if(U_FAILURE(status)){
    287         log_data_err("Error: failure in message format on test#1: %s (Are you missing data?)\n", myErrorName(status));
    288     }
    289     else if(u_strcmp(result, expected)==0)
    290         log_verbose("PASS: MessagFormat successful on test#1\n");
    291     else{
    292         log_err("FAIL: Error in MessageFormat on test#1 \n GOT: %s EXPECTED: %s\n",
    293             austrdup(result), austrdup(expected) );
    294     }
    295 
    296 
    297     log_verbose("\nTesting message format with another pattern test#2\n");
    298     u_uastrcpy(pattern, "The disk \"{0}\" contains {1,number,integer} file(s)");
    299     u_uastrcpy(expected, "The disk \"MyDisk\" contains 23 file(s)");
    300     u_uastrcpy(str, "MyDisk");
    301 
    302     resultLengthOut=u_formatMessage( "en_US",
    303         pattern,
    304         u_strlen(pattern),
    305         result,
    306         resultlength,
    307         &status,
    308         str,
    309         235);
    310     if(status==U_BUFFER_OVERFLOW_ERROR)
    311     {
    312         status=U_ZERO_ERROR;
    313         resultlength=resultLengthOut+1;
    314         result=(UChar*)realloc(result, sizeof(UChar) * (resultlength+1));
    315         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 23);
    316     }
    317     if(U_FAILURE(status)){
    318         log_data_err("Error: failure in message format on test#2 : %s (Are you missing data?)\n", myErrorName(status));
    319     }
    320     else if(u_strcmp(result, expected)==0)
    321         log_verbose("PASS: MessagFormat successful on test#2\n");
    322     else{
    323         log_err("FAIL: Error in MessageFormat on test#2\n GOT: %s EXPECTED: %s\n",
    324             austrdup(result), austrdup(expected) );
    325     }
    326 
    327 
    328 
    329     log_verbose("\nTesting message format with another pattern test#3\n");
    330     u_uastrcpy(pattern, "You made a {0} of {1,number,currency}");
    331     u_uastrcpy(expected, "You made a deposit of $500.00");
    332     u_uastrcpy(str, "deposit");
    333     resultlength=0;
    334     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, str, 500.00);
    335     if(status==U_BUFFER_OVERFLOW_ERROR)
    336     {
    337         status=U_ZERO_ERROR;
    338         resultlength=resultLengthOut+1;
    339         result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
    340         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, str, 500.00);
    341     }
    342     if(U_FAILURE(status)){
    343         log_data_err("Error: failure in message format on test#3 : %s (Are you missing data?)\n", myErrorName(status));
    344     }
    345     else if(u_strcmp(result, expected)==0)
    346         log_verbose("PASS: MessagFormat successful on test#3\n");
    347     else{
    348         log_err("FAIL: Error in MessageFormat on test#3\n GOT: %s EXPECTED %s\n", austrdup(result),
    349             austrdup(expected) );
    350     }
    351 
    352     free(result);
    353     free(str);
    354 
    355     ctest_resetTimeZone();
    356 }
    357 
    358 /* Test umsg_format() and umsg_parse() , format and parse sequence and round trip */
    359 static void TestNewFormatAndParseAPI(void)
    360 {
    361 
    362     UChar *result, tzID[4], str[25];
    363     UChar pattern[100];
    364     UChar expected[100];
    365     int32_t resultLengthOut, resultlength;
    366     UCalendar *cal;
    367     UDate d1,d;
    368     UDateFormat *def1;
    369     UErrorCode status = U_ZERO_ERROR;
    370     int32_t value = 0;
    371     UChar ret[30];
    372     UParseError parseError;
    373     UMessageFormat* fmt = NULL;
    374     int32_t count=0;
    375 
    376     ctest_setTimeZone(NULL, &status);
    377 
    378     log_verbose("Testing format and parse with parse error\n");
    379 
    380     u_uastrcpy(str, "disturbance in force");
    381     u_uastrcpy(tzID, "PST");
    382     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
    383     if(U_FAILURE(status)){
    384         log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
    385         return;
    386     }
    387     ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
    388     d1=ucal_getMillis(cal, &status);
    389     if(U_FAILURE(status)){
    390             log_err("Error: failure in get millis: %s\n", myErrorName(status) );
    391             return;
    392     }
    393 
    394     log_verbose("\nTesting with pattern test#4");
    395     u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
    396     u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
    397     resultlength=1;
    398     fmt = umsg_open(pattern,u_strlen(pattern),"en_US",&parseError,&status);
    399     if(U_FAILURE(status)){
    400         log_data_err("error in umsg_open  : %s (Are you missing data?)\n", u_errorName(status) );
    401         return;
    402     }
    403     result=(UChar*)malloc(sizeof(UChar) * resultlength);
    404 
    405     resultLengthOut=umsg_format(fmt ,result, resultlength,&status, d1, str, 7);
    406     if(status==U_BUFFER_OVERFLOW_ERROR)
    407     {
    408         status=U_ZERO_ERROR;
    409         resultlength=resultLengthOut+1;
    410         result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
    411         u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
    412 
    413     }
    414     if(U_FAILURE(status)){
    415         log_err("ERROR: failure in message format test#4: %s\n", myErrorName(status));
    416     }
    417     if(u_strcmp(result, expected)==0)
    418         log_verbose("PASS: MessagFormat successful on test#4\n");
    419     else{
    420         log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
    421             austrdup(expected) );
    422     }
    423 
    424 
    425     /*try to parse this and check*/
    426     log_verbose("\nTesting the parse Message test#5\n");
    427 
    428     umsg_parse(fmt, result, u_strlen(result),&count,&status, &d, ret, &value);
    429     if(U_FAILURE(status)){
    430         log_err("ERROR: error in parsing: test#5: %s\n", myErrorName(status));
    431     }
    432     if(value!=7 && u_strcmp(str,ret)!=0)
    433         log_err("FAIL: Error in parseMessage on test#5 \n");
    434     else
    435         log_verbose("PASS: parseMessage successful on test#5\n");
    436 
    437     def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
    438     if(U_FAILURE(status))
    439     {
    440         log_err("error in creating the dateformat using short date and time style:\n %s\n", myErrorName(status));
    441     }else{
    442 
    443         if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
    444             log_verbose("PASS: parseMessage successful test#5\n");
    445         else{
    446             log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
    447                 austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
    448         }
    449     }
    450     umsg_close(fmt);
    451     udat_close(def1);
    452     ucal_close(cal);
    453 
    454     free(result);
    455 
    456     ctest_resetTimeZone();
    457 }
    458 
    459 /* Test u_formatMessageWithError() and u_parseMessageWithError() , format and parse sequence and round trip */
    460 static void TestSampleFormatAndParseWithError(void)
    461 {
    462 
    463     UChar *result, *tzID, *str;
    464     UChar pattern[100];
    465 
    466     UChar expected[100];
    467     int32_t resultLengthOut, resultlength;
    468     UCalendar *cal;
    469     UDate d1,d;
    470     UDateFormat *def1;
    471     UErrorCode status = U_ZERO_ERROR;
    472     int32_t value = 0;
    473     UChar ret[30];
    474     UParseError parseError;
    475 
    476     ctest_setTimeZone(NULL, &status);
    477 
    478     log_verbose("Testing format and parse with parse error\n");
    479 
    480     str=(UChar*)malloc(sizeof(UChar) * 25);
    481     u_uastrcpy(str, "disturbance in force");
    482     tzID=(UChar*)malloc(sizeof(UChar) * 4);
    483     u_uastrcpy(tzID, "PST");
    484     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
    485     if(U_FAILURE(status)){
    486         log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
    487     }
    488     ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
    489     d1=ucal_getMillis(cal, &status);
    490     if(U_FAILURE(status)){
    491             log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
    492     }
    493 
    494     log_verbose("\nTesting with pattern test#4");
    495     u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
    496     u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
    497     resultlength=1;
    498     result=(UChar*)malloc(sizeof(UChar) * resultlength);
    499     resultLengthOut=u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
    500     if(status==U_BUFFER_OVERFLOW_ERROR)
    501     {
    502         status=U_ZERO_ERROR;
    503         resultlength=resultLengthOut+1;
    504         result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
    505         u_formatMessageWithError( "en_US", pattern, u_strlen(pattern), result, resultlength,&parseError, &status, d1, str, 7);
    506 
    507     }
    508     if(U_FAILURE(status)){
    509         log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
    510     }
    511     else if(u_strcmp(result, expected)==0)
    512         log_verbose("PASS: MessagFormat successful on test#4\n");
    513     else{
    514         log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
    515             austrdup(expected) );
    516     }
    517 
    518 
    519     /*try to parse this and check*/
    520     log_verbose("\nTesting the parse Message test#5\n");
    521 
    522     u_parseMessageWithError("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &parseError,&status, &d, ret, &value);
    523     if(U_FAILURE(status)){
    524         log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
    525     }
    526     else if(value!=7 && u_strcmp(str,ret)!=0)
    527         log_err("FAIL: Error in parseMessage on test#5 \n");
    528     else
    529         log_verbose("PASS: parseMessage successful on test#5\n");
    530 
    531     def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
    532     if(U_FAILURE(status))
    533     {
    534         log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
    535     }else{
    536 
    537         if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
    538             log_verbose("PASS: parseMessage successful test#5\n");
    539         else{
    540             log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
    541                 austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
    542         }
    543     }
    544     udat_close(def1);
    545     ucal_close(cal);
    546 
    547     free(result);
    548     free(str);
    549     free(tzID);
    550 
    551     ctest_resetTimeZone();
    552 }
    553 
    554 /* Test u_formatMessage() and u_parseMessage() , format and parse sequence and round trip */
    555 static void TestSampleFormatAndParse(void)
    556 {
    557 
    558     UChar *result, *tzID, *str;
    559     UChar pattern[100];
    560     UChar expected[100];
    561     int32_t resultLengthOut, resultlength;
    562     UCalendar *cal;
    563     UDate d1,d;
    564     UDateFormat *def1;
    565     UErrorCode status = U_ZERO_ERROR;
    566     int32_t value = 0;
    567     UChar ret[30];
    568 
    569     ctest_setTimeZone(NULL, &status);
    570 
    571     log_verbose("Testing format and parse\n");
    572 
    573     str=(UChar*)malloc(sizeof(UChar) * 25);
    574     u_uastrcpy(str, "disturbance in force");
    575     tzID=(UChar*)malloc(sizeof(UChar) * 4);
    576     u_uastrcpy(tzID, "PST");
    577     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
    578     if(U_FAILURE(status)){
    579         log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
    580     }
    581     ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
    582     d1=ucal_getMillis(cal, &status);
    583     if(U_FAILURE(status)){
    584             log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
    585     }
    586 
    587     log_verbose("\nTesting with pattern test#4");
    588     u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
    589     u_uastrcpy(expected, "On March 18, 1999, there was a disturbance in force on planet 7");
    590     resultlength=1;
    591     result=(UChar*)malloc(sizeof(UChar) * resultlength);
    592     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
    593     if(status==U_BUFFER_OVERFLOW_ERROR)
    594     {
    595         status=U_ZERO_ERROR;
    596         resultlength=resultLengthOut+1;
    597         result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
    598         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
    599 
    600     }
    601     if(U_FAILURE(status)){
    602         log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
    603     }
    604     else if(u_strcmp(result, expected)==0)
    605         log_verbose("PASS: MessagFormat successful on test#4\n");
    606     else{
    607         log_err("FAIL: Error in MessageFormat on test#4\n GOT: %s EXPECTED: %s\n", austrdup(result),
    608             austrdup(expected) );
    609     }
    610 
    611 
    612     /*try to parse this and check*/
    613     log_verbose("\nTesting the parse Message test#5\n");
    614 
    615     u_parseMessage("en_US", pattern, u_strlen(pattern), result, u_strlen(result), &status, &d, ret, &value);
    616     if(U_FAILURE(status)){
    617         log_data_err("ERROR: error in parsing: test#5: %s (Are you missing data?)\n", myErrorName(status));
    618     }
    619     else if(value!=7 && u_strcmp(str,ret)!=0)
    620         log_err("FAIL: Error in parseMessage on test#5 \n");
    621     else
    622         log_verbose("PASS: parseMessage successful on test#5\n");
    623 
    624     def1 = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, NULL,0,&status);
    625     if(U_FAILURE(status))
    626     {
    627         log_data_err("error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status));
    628     }else{
    629 
    630         if(u_strcmp(myDateFormat(def1, d), myDateFormat(def1, d1))==0)
    631             log_verbose("PASS: parseMessage successful test#5\n");
    632         else{
    633             log_err("FAIL: parseMessage didn't parse the date successfully\n GOT: %s EXPECTED %s\n",
    634                 austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
    635         }
    636     }
    637     udat_close(def1);
    638     ucal_close(cal);
    639 
    640     free(result);
    641     free(str);
    642     free(tzID);
    643 
    644     ctest_resetTimeZone();
    645 }
    646 
    647 /* Test message format with a Select option */
    648 static void TestMsgFormatSelect(void)
    649 {
    650     UChar* str;
    651     UChar* str1;
    652     UErrorCode status = U_ZERO_ERROR;
    653     UChar *result;
    654     UChar pattern[100];
    655     UChar expected[100];
    656     int32_t resultlength,resultLengthOut;
    657 
    658     str=(UChar*)malloc(sizeof(UChar) * 25);
    659     u_uastrcpy(str, "Kirti");
    660     str1=(UChar*)malloc(sizeof(UChar) * 25);
    661     u_uastrcpy(str1, "female");
    662     log_verbose("Testing message format with Select test #1\n:");
    663     u_uastrcpy(pattern, "{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
    664     u_uastrcpy(expected, "Kirti est all\\u00E9e \\u00E0 Paris.");
    665     resultlength=0;
    666     resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1);
    667     if(status==U_BUFFER_OVERFLOW_ERROR)
    668     {
    669         status=U_ZERO_ERROR;
    670         resultlength=resultLengthOut+1;
    671         result=(UChar*)malloc(sizeof(UChar) * resultlength);
    672         u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
    673         if(u_strcmp(result, expected)==0)
    674             log_verbose("PASS: MessagFormat successful on Select test#1\n");
    675         else{
    676             log_err("FAIL: Error in MessageFormat on Select test#1\n GOT %s EXPECTED %s\n", austrdup(result),
    677                 austrdup(expected) );
    678         }
    679         free(result);
    680     }
    681     if(U_FAILURE(status)){
    682         log_data_err("ERROR: failure in message format on Select test#1 : %s \n", myErrorName(status));
    683     }
    684     free(str);
    685     free(str1);
    686 
    687     /*Test a nested pattern*/
    688     str=(UChar*)malloc(sizeof(UChar) * 25);
    689     u_uastrcpy(str, "Noname");
    690     str1=(UChar*)malloc(sizeof(UChar) * 25);
    691     u_uastrcpy(str1, "other");
    692     log_verbose("Testing message format with Select test #2\n:");
    693     u_uastrcpy(pattern, "{0} est {1, select, female {{2,number,integer} all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
    694     u_uastrcpy(expected, "Noname est all\\u00E9 \\u00E0 Paris.");
    695     resultlength=0;
    696     resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1,6);
    697     if(status==U_BUFFER_OVERFLOW_ERROR)
    698     {
    699         status=U_ZERO_ERROR;
    700         resultlength=resultLengthOut+1;
    701         result=(UChar*)malloc(sizeof(UChar) * resultlength);
    702         u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
    703         if(u_strcmp(result, expected)==0)
    704             log_verbose("PASS: MessagFormat successful on Select test#2\n");
    705         else{
    706             log_err("FAIL: Error in MessageFormat on Select test#2\n GOT %s EXPECTED %s\n", austrdup(result),
    707                 austrdup(expected) );
    708         }
    709         free(result);
    710     }
    711     if(U_FAILURE(status)){
    712         log_data_err("ERROR: failure in message format on Select test#2 : %s \n", myErrorName(status));
    713     }
    714     free(str);
    715     free(str1);
    716 }
    717 
    718 /* test message format with a choice option */
    719 static void TestMsgFormatChoice(void)
    720 {
    721     UChar* str;
    722     UErrorCode status = U_ZERO_ERROR;
    723     UChar *result;
    724     UChar pattern[100];
    725     UChar expected[100];
    726     int32_t resultlength,resultLengthOut;
    727 
    728     str=(UChar*)malloc(sizeof(UChar) * 25);
    729     u_uastrcpy(str, "MyDisk");
    730     log_verbose("Testing message format with choice test #6\n:");
    731     /*There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.*/
    732     u_uastrcpy(pattern, "The disk {1} contains {0,choice,0#no files|1#one file|1<{0,number,integer} files}");
    733     u_uastrcpy(expected, "The disk MyDisk contains 100 files");
    734     resultlength=0;
    735     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 100., str);
    736     if(status==U_BUFFER_OVERFLOW_ERROR)
    737     {
    738         status=U_ZERO_ERROR;
    739         resultlength=resultLengthOut+1;
    740         result=(UChar*)malloc(sizeof(UChar) * resultlength);
    741         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 100., str);
    742         if(u_strcmp(result, expected)==0)
    743             log_verbose("PASS: MessagFormat successful on test#6\n");
    744         else{
    745             log_err("FAIL: Error in MessageFormat on test#6\n GOT %s EXPECTED %s\n", austrdup(result),
    746                 austrdup(expected) );
    747         }
    748         free(result);
    749     }
    750     if(U_FAILURE(status)){
    751         log_data_err("ERROR: failure in message format on test#6 : %s (Are you missing data?)\n", myErrorName(status));
    752     }
    753 
    754     log_verbose("Testing message format with choice test #7\n:");
    755     u_uastrcpy(expected, "The disk MyDisk contains no files");
    756     resultlength=0;
    757     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 0., str);
    758     if(status==U_BUFFER_OVERFLOW_ERROR)
    759     {
    760         status=U_ZERO_ERROR;
    761         resultlength=resultLengthOut+1;
    762         result=(UChar*)malloc(sizeof(UChar) * resultlength);
    763         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 0., str);
    764 
    765         if(u_strcmp(result, expected)==0)
    766             log_verbose("PASS: MessagFormat successful on test#7\n");
    767         else{
    768             log_err("FAIL: Error in MessageFormat on test#7\n GOT: %s EXPECTED %s\n", austrdup(result),
    769                 austrdup(expected) );
    770         }
    771         free(result);
    772     }
    773     if(U_FAILURE(status)){
    774         log_data_err("ERROR: failure in message format on test#7 : %s (Are you missing data?)\n", myErrorName(status));
    775     }
    776 
    777     log_verbose("Testing message format with choice test #8\n:");
    778     u_uastrcpy(expected, "The disk MyDisk contains one file");
    779     resultlength=0;
    780     resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, 1., str);
    781     if(status==U_BUFFER_OVERFLOW_ERROR)
    782     {
    783         status=U_ZERO_ERROR;
    784         resultlength=resultLengthOut+1;
    785         result=(UChar*)malloc(sizeof(UChar) * resultlength);
    786         u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, 1., str);
    787 
    788         if(u_strcmp(result, expected)==0)
    789             log_verbose("PASS: MessagFormat successful on test#8\n");
    790         else{
    791             log_err("FAIL: Error in MessageFormat on test#8\n GOT %s EXPECTED: %s\n", austrdup(result),
    792                 austrdup(expected) );
    793         }
    794 
    795         free(result);
    796     }
    797     if(U_FAILURE(status)){
    798         log_data_err("ERROR: failure in message format on test#8 : %s (Are you missing data?)\n", myErrorName(status));
    799     }
    800 
    801     free(str);
    802 
    803 }
    804 
    805 /*test u_parseMessage() with various test patterns */
    806 static void TestParseMessage(void)
    807 {
    808     UChar pattern[100];
    809     UChar source[100];
    810     UErrorCode status = U_ZERO_ERROR;
    811     int32_t value;
    812     UChar str[10];
    813     UChar res[10];
    814 
    815     log_verbose("\nTesting a sample for parse Message test#9\n");
    816 
    817     u_uastrcpy(source, "You deposited an amount of $500.00");
    818     u_uastrcpy(pattern, "You {0} an amount of {1,number,currency}");
    819     u_uastrcpy(res,"deposited");
    820 
    821     u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
    822     if(U_FAILURE(status)){
    823         log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
    824     }
    825     else if(value==500.00  && u_strcmp(str,res)==0)
    826         log_verbose("PASS: parseMessage successful on test#9\n");
    827     else
    828         log_err("FAIL: Error in parseMessage on test#9 \n");
    829 
    830 
    831 
    832     log_verbose("\nTesting a sample for parse Message test#10\n");
    833 
    834     u_uastrcpy(source, "There are 123 files on MyDisk created");
    835     u_uastrcpy(pattern, "There are {0,number,integer} files on {1} created");
    836     u_uastrcpy(res,"MyDisk");
    837 
    838     u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
    839     if(U_FAILURE(status)){
    840         log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
    841     }
    842     else if(value==123.00 && u_strcmp(str,res)==0)
    843         log_verbose("PASS: parseMessage successful on test#10\n");
    844     else
    845         log_err("FAIL: Error in parseMessage on test#10 \n");
    846 }
    847 
    848 static int32_t CallFormatMessage(const char* locale, UChar* testCasePattern, int32_t patternLength,
    849                        UChar* result, int32_t resultLength, UErrorCode *status, ...)
    850 {
    851     int32_t len = 0;
    852     va_list ap;
    853     va_start(ap, status);
    854     len = u_vformatMessage(locale, testCasePattern, patternLength, result, resultLength, ap, status);
    855     va_end(ap);
    856     return len;
    857 }
    858 
    859 /* Test u_vformatMessage() with various test patterns. */
    860 static void TestMessageFormatWithValist( void )
    861 {
    862 
    863     UChar *str;
    864     UChar* result;
    865     int32_t resultLengthOut,resultlength,i, patternlength;
    866     UErrorCode status = U_ZERO_ERROR;
    867     UDate d1=1000000000.0;
    868 
    869     ctest_setTimeZone(NULL, &status);
    870 
    871     str=(UChar*)malloc(sizeof(UChar) * 7);
    872     u_uastrcpy(str, "MyDisk");
    873     resultlength=1;
    874     result=(UChar*)malloc(sizeof(UChar) * 1);
    875     log_verbose("Testing u_formatMessage90\n");
    876     InitStrings();
    877     for (i = 0; i < cnt_testCases; i++) {
    878         status=U_ZERO_ERROR;
    879         patternlength=u_strlen(testCasePatterns[i]);
    880         resultLengthOut=CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    881             &status, 1, 3456.00, d1);
    882         if(status== U_BUFFER_OVERFLOW_ERROR)
    883         {
    884             status=U_ZERO_ERROR;
    885             resultlength=resultLengthOut+1;
    886             result=(UChar*)realloc(result,sizeof(UChar) * resultlength);
    887             CallFormatMessage( "en_US",testCasePatterns[i], patternlength, result, resultlength,
    888                 &status, 1, 3456.00, d1);
    889         }
    890         if(U_FAILURE(status)){
    891             log_data_err("ERROR: failure in message format on testcase %d:  %s (Are you missing data?)\n", i, myErrorName(status) );
    892         }
    893         else if(u_strcmp(result, testResultStrings[i])==0){
    894             log_verbose("PASS: MessagFormat successful on testcase : %d\n", i);
    895         }
    896         else{
    897             log_err("FAIL: Error in MessageFormat on testcase : %d\n GOT %s EXPECTED %s\n", i,
    898                 austrdup(result), austrdup(testResultStrings[i]) );
    899         }
    900     }
    901     free(result);
    902     free(str);
    903     FreeStrings();
    904 
    905     ctest_resetTimeZone();
    906 }
    907 
    908 static void CallParseMessage(const char* locale, UChar* pattern, int32_t patternLength,
    909                        UChar* source, int32_t sourceLength, UErrorCode *status, ...)
    910 {
    911     va_list ap;
    912     va_start(ap, status);
    913     u_vparseMessage(locale, pattern, patternLength, source, sourceLength, ap, status);
    914     va_end(ap);
    915 }
    916 
    917 /*test u_vparseMessage() with various test patterns */
    918 static void TestParseMessageWithValist(void)
    919 {
    920     UChar pattern[100];
    921     UChar source[100];
    922     UErrorCode status = U_ZERO_ERROR;
    923     int32_t value;
    924     UChar str[10];
    925     UChar res[10];
    926 
    927     log_verbose("\nTesting a sample for parse Message test#9\n");
    928 
    929     u_uastrcpy(source, "You deposited an amount of $500.00");
    930     u_uastrcpy(pattern, "You {0} an amount of {1,number,currency}");
    931     u_uastrcpy(res,"deposited");
    932 
    933     CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value);
    934     if(U_FAILURE(status)){
    935         log_data_err("ERROR: failure in parse Message on test#9: %s (Are you missing data?)\n", myErrorName(status));
    936     }
    937     else if(value==500.00  && u_strcmp(str,res)==0)
    938         log_verbose("PASS: parseMessage successful on test#9\n");
    939     else
    940         log_err("FAIL: Error in parseMessage on test#9\n");
    941 
    942 
    943     log_verbose("\nTesting a sample for parse Message test#10\n");
    944 
    945     u_uastrcpy(source, "There are 123 files on MyDisk created");
    946     u_uastrcpy(pattern, "There are {0,number,integer} files on {1} created");
    947     u_uastrcpy(res,"MyDisk");
    948 
    949     CallParseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str);
    950     if(U_FAILURE(status)){
    951         log_data_err("ERROR: failure in parse Message on test#10: %s (Are you missing data?)\n", myErrorName(status));
    952     }
    953     else if(value==123.00 && u_strcmp(str,res)==0)
    954         log_verbose("PASS: parseMessage successful on test#10\n");
    955     else
    956         log_err("FAIL: Error in parseMessage on test#10 \n");
    957 }
    958 
    959 /**
    960  * Regression test for ICU4C Jitterbug 904
    961  */
    962 static void TestJ904(void) {
    963     UChar pattern[256];
    964     UChar result[256];
    965     UChar string[16];
    966     char cresult[256];
    967     int32_t length;
    968     UErrorCode status = U_ZERO_ERROR;
    969     const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
    970     const char* EXP = "Number 0,143, String foo, Date 12:34:56.789";
    971 
    972     ctest_setTimeZone(NULL, &status);
    973 
    974     u_uastrcpy(string, "foo");
    975     /* Slight hack here -- instead of date pattern HH:mm:ss.SSS, use
    976      * 12:mm:ss.SSS.  Why?  So this test generates the same output --
    977      * "12:34:56.789" -- regardless of time zone (as long as we aren't
    978      * in one of the 30 minute offset zones!). */
    979     u_uastrcpy(pattern, PAT);
    980     length = u_formatMessage("nl", pattern, u_strlen(pattern),
    981                              result, 256, &status,
    982                              string, 1/7.0,
    983                              789.0+1000*(56+60*(34+60*12)));
    984 
    985     u_austrncpy(cresult, result, sizeof(cresult));
    986 
    987     /* This test passes if it DOESN'T CRASH.  However, we test the
    988      * output anyway.  If the string doesn't match in the date part,
    989      * check to see that the machine doesn't have an unusual time zone
    990      * offset, that is, one with a non-zero minutes/seconds offset
    991      * from GMT -- see above. */
    992     if (strcmp(cresult, EXP) == 0) {
    993         log_verbose("Ok: \"%s\"\n", cresult);
    994     } else {
    995         log_data_err("FAIL: got \"%s\", expected \"%s\" -> %s (Are you missing data?)\n", cresult, EXP, u_errorName(status));
    996     }
    997 
    998     ctest_resetTimeZone();
    999 }
   1000 
   1001 static void OpenMessageFormatTest(void)
   1002 {
   1003     UMessageFormat *f1, *f2, *f3;
   1004     UChar pattern[256];
   1005     UChar result[256];
   1006     char cresult[256];
   1007     UParseError parseError;
   1008     const char* locale = "hi_IN";
   1009     char* retLoc;
   1010     const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
   1011     int32_t length=0;
   1012     UErrorCode status = U_ZERO_ERROR;
   1013 
   1014     u_uastrncpy(pattern, PAT, sizeof(pattern)/sizeof(pattern[0]));
   1015 
   1016     /* Test umsg_open                   */
   1017     f1 = umsg_open(pattern,length,NULL,NULL,&status);
   1018 
   1019     if(U_FAILURE(status))
   1020     {
   1021         log_err("umsg_open failed with pattern %s. Error: \n", PAT, u_errorName(status));
   1022         return;
   1023     }
   1024 
   1025     /* Test umsg_open with parse error  */
   1026     status = U_ZERO_ERROR;
   1027     f2 = umsg_open(pattern,length,NULL,&parseError,&status);
   1028 
   1029     if(U_FAILURE(status))
   1030     {
   1031         log_err("umsg_open with parseError failed with pattern %s. Error: %s\n", PAT, u_errorName(status));
   1032         return;
   1033     }
   1034 
   1035     /* Test umsg_clone                  */
   1036     status = U_ZERO_ERROR;
   1037     f3 = umsg_clone(f1,&status);
   1038     if(U_FAILURE(status))
   1039     {
   1040         log_err("umsg_clone failed. Error %s \n", u_errorName(status));
   1041     }
   1042 
   1043     /* Test umsg_setLocale              */
   1044     umsg_setLocale(f1,locale);
   1045     /* Test umsg_getLocale              */
   1046     retLoc = (char*)umsg_getLocale(f1);
   1047     if(strcmp(retLoc,locale)!=0)
   1048     {
   1049         log_err("umsg_setLocale and umsg_getLocale methods failed. Expected:%s Got: %s \n", locale, retLoc);
   1050     }
   1051 
   1052     /* Test umsg_applyPattern           */
   1053     status = U_ZERO_ERROR;
   1054     umsg_applyPattern(f1,pattern,(int32_t)strlen(PAT),NULL,&status);
   1055     if(U_FAILURE(status))
   1056     {
   1057         log_data_err("umsg_applyPattern failed. Error %s (Are you missing data?)\n",u_errorName(status));
   1058     }
   1059 
   1060     /* Test umsg_toPattern              */
   1061     umsg_toPattern(f1,result,256,&status);
   1062     if(U_FAILURE(status) ){
   1063         log_data_err("umsg_toPattern method failed. Error: %s (Are you missing data?)\n",u_errorName(status));
   1064     } else {
   1065         if(u_strcmp(result,pattern)!=0){
   1066             u_UCharsToChars(result,cresult,256);
   1067             log_err("umsg_toPattern method failed. Expected: %s Got: %s \n",PAT,cresult);
   1068         }
   1069     }
   1070     /* umsg_format umsg_parse */
   1071 
   1072     umsg_close(f1);
   1073     umsg_close(f2);
   1074     umsg_close(f3);
   1075 }
   1076 
   1077 static void MessageLength(void)
   1078 {
   1079     UErrorCode status = U_ZERO_ERROR;
   1080     const char patChars[] = {"123{0}456{0}"};
   1081     const char expectedChars[] = {"123abc"};
   1082     UChar pattern[sizeof(patChars)];
   1083     UChar arg[] = {0x61,0x62,0x63,0};
   1084     UChar result[128] = {0};
   1085     UChar expected[sizeof(expectedChars)];
   1086 
   1087     u_uastrncpy(pattern, patChars, sizeof(pattern)/sizeof(pattern[0]));
   1088     u_uastrncpy(expected, expectedChars, sizeof(expected)/sizeof(expected[0]));
   1089 
   1090     u_formatMessage("en_US", pattern, 6, result, sizeof(result)/sizeof(result[0]), &status, arg);
   1091     if (U_FAILURE(status)) {
   1092         log_err("u_formatMessage method failed. Error: %s \n",u_errorName(status));
   1093     }
   1094     if (u_strcmp(result, expected) != 0) {
   1095         log_err("u_formatMessage didn't return expected result\n");
   1096     }
   1097 }
   1098 
   1099 static void TestErrorChaining(void) {
   1100     UErrorCode status = U_USELESS_COLLATOR_ERROR;
   1101 
   1102     umsg_open(NULL, 0, NULL, NULL, &status);
   1103     umsg_applyPattern(NULL, NULL, 0, NULL, &status);
   1104     umsg_toPattern(NULL, NULL, 0, &status);
   1105     umsg_clone(NULL, &status);
   1106     umsg_format(NULL, NULL, 0, &status);
   1107     umsg_parse(NULL, NULL, 0, NULL, &status);
   1108     umsg_close(NULL);
   1109 
   1110     /* All of this code should have done nothing. */
   1111     if (status != U_USELESS_COLLATOR_ERROR) {
   1112         log_err("Status got changed to %s\n", u_errorName(status));
   1113     }
   1114 
   1115     status = U_ZERO_ERROR;
   1116     umsg_open(NULL, 0, NULL, NULL, &status);
   1117     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
   1118         log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
   1119     }
   1120     status = U_ZERO_ERROR;
   1121     umsg_applyPattern(NULL, NULL, 0, NULL, &status);
   1122     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
   1123         log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
   1124     }
   1125     status = U_ZERO_ERROR;
   1126     umsg_toPattern(NULL, NULL, 0, &status);
   1127     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
   1128         log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
   1129     }
   1130     status = U_ZERO_ERROR;
   1131     umsg_clone(NULL, &status);
   1132     if (status != U_ILLEGAL_ARGUMENT_ERROR) {
   1133         log_err("Status should be U_ILLEGAL_ARGUMENT_ERROR instead of %s\n", u_errorName(status));
   1134     }
   1135 }
   1136 
   1137 void addMsgForTest(TestNode** root);
   1138 
   1139 void addMsgForTest(TestNode** root)
   1140 {
   1141     addTest(root, &OpenMessageFormatTest, "tsformat/cmsgtst/OpenMessageFormatTest");
   1142     addTest(root, &MessageFormatTest, "tsformat/cmsgtst/MessageFormatTest");
   1143     addTest(root, &TestSampleMessageFormat, "tsformat/cmsgtst/TestSampleMessageFormat");
   1144     addTest(root, &TestSampleFormatAndParse, "tsformat/cmsgtst/TestSampleFormatAndParse");
   1145     addTest(root, &TestSampleFormatAndParseWithError, "tsformat/cmsgtst/TestSampleFormatAndParseWithError");
   1146     addTest(root, &TestNewFormatAndParseAPI, "tsformat/cmsgtst/TestNewFormatAndParseAPI");
   1147     addTest(root, &TestMsgFormatChoice, "tsformat/cmsgtst/TestMsgFormatChoice");
   1148     addTest(root, &TestParseMessage, "tsformat/cmsgtst/TestParseMessage");
   1149     addTest(root, &TestMessageFormatWithValist, "tsformat/cmsgtst/TestMessageFormatWithValist");
   1150     addTest(root, &TestParseMessageWithValist, "tsformat/cmsgtst/TestParseMessageWithValist");
   1151     addTest(root, &TestJ904, "tsformat/cmsgtst/TestJ904");
   1152     addTest(root, &MessageLength, "tsformat/cmsgtst/MessageLength");
   1153     addTest(root, &TestErrorChaining, "tsformat/cmsgtst/TestErrorChaining");
   1154     addTest(root, &TestMsgFormatSelect, "tsformat/cmsgtst/TestMsgFormatSelect");
   1155 }
   1156 
   1157 #endif /* #if !UCONFIG_NO_FORMATTING */
   1158