Beispiel #1
0
static void OpenMessageFormatTest(void)
{
    UMessageFormat *f1, *f2, *f3;
    UChar pattern[256];
    UChar result[256];
    char cresult[256];
    UParseError parseError;
    const char* locale = "hi_IN";
    char* retLoc;
    const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
    int32_t length=0;
    UErrorCode status = U_ZERO_ERROR;

    u_uastrncpy(pattern, PAT, sizeof(pattern)/sizeof(pattern[0]));

    /* 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));
        return;
    }
   
    /* 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));
        return;
    }
    
    /* 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;
    umsg_applyPattern(f1,pattern,(int32_t)strlen(PAT),NULL,&status);
    if(U_FAILURE(status))
    {
        log_data_err("umsg_applyPattern failed. Error %s (Are you missing data?)\n",u_errorName(status));
    }

    /* Test umsg_toPattern              */
    umsg_toPattern(f1,result,256,&status);
    if(U_FAILURE(status) ){
        log_data_err("umsg_toPattern method failed. Error: %s (Are you missing data?)\n",u_errorName(status));
    } else {
        if(u_strcmp(result,pattern)!=0){
            u_UCharsToChars(result,cresult,256);
            log_err("umsg_toPattern method failed. Expected: %s Got: %s \n",PAT,cresult);
        }
    }
    /* umsg_format umsg_parse */

    umsg_close(f1);
    umsg_close(f2);
    umsg_close(f3);
}
Beispiel #2
0
static String HHVM_METHOD(MessageFormatter, getLocale) {
  FETCH_MFMT(data, this_);
  return String(umsg_getLocale(data->formatter()), CopyString);
}