Example #1
0
static void TestAPI(void)
{
    int32_t intValue=0;
    char src[30]="HELLO THERE", dest[30];
    static const char *const abc="abcdefghijklmnopqrstuvwxyz", *const ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const char *temp;
    int32_t i;

    log_verbose("Testing uprv_tolower() and uprv_toupper()\n");
    for(i=0; i<=26; ++i) {
        dest[i]=uprv_tolower(abc[i]);
    }
    if(0!=strcmp(abc, dest)) {
        log_err("uprv_tolower(abc) failed\n");
    }

    for(i=0; i<=26; ++i) {
        dest[i]=uprv_tolower(ABC[i]);
    }
    if(0!=strcmp(abc, dest)) {
        log_err("uprv_tolower(ABC) failed\n");
    }

    for(i=0; i<=26; ++i) {
        dest[i]=uprv_toupper(abc[i]);
    }
    if(0!=strcmp(ABC, dest)) {
        log_err("uprv_toupper(abc) failed\n");
    }

    for(i=0; i<=26; ++i) {
        dest[i]=uprv_toupper(ABC[i]);
    }
    if(0!=strcmp(ABC, dest)) {
        log_err("uprv_toupper(ABC) failed\n");
    }

    log_verbose("Testing the API in cstring\n");
    T_CString_toLowerCase(src);
    if(uprv_strcmp(src, "hello there") != 0){
        log_err("FAIL: *** T_CString_toLowerCase() failed. Expected: \"hello there\", Got: \"%s\"\n", src);
    }
    T_CString_toUpperCase(src);
    if(uprv_strcmp(src, "HELLO THERE") != 0){
        log_err("FAIL: *** T_CString_toUpperCase() failed. Expected: \"HELLO THERE\", Got: \"%s\"\n", src);
    }
     
    intValue=T_CString_stringToInteger("34556", 10);
    if(intValue != 34556){
        log_err("FAIL: ****T_CString_stringToInteger(\"34556\", 10) failed. Expected: 34556, Got: %d\n", intValue);
    }
    intValue=T_CString_stringToInteger("100", 16);
    if(intValue != 256){
        log_err("FAIL: ****T_CString_stringToInteger(\"100\", 16) failed. Expected: 256, Got: %d\n", intValue);
    }
    i = T_CString_integerToString(src, 34556, 10);
    if(uprv_strcmp(src, "34556") != 0 || i != 5){
        log_err("FAIL: ****integerToString(src, 34566, 10); failed. Expected: \"34556\", Got: %s\n", src);
    }
    i = T_CString_integerToString(src, 431, 16);
    if(uprv_stricmp(src, "1AF") != 0 || i != 3){
        log_err("FAIL: ****integerToString(src, 431, 16); failed. Expected: \"1AF\", Got: %s\n", src);
    }
    i = T_CString_int64ToString(src, U_INT64_MAX, 10);
    if(uprv_strcmp(src,  "9223372036854775807") != 0 || i != 19){
        log_err("FAIL: ****integerToString(src, 9223372036854775807, 10); failed. Got: %s\n", src);
    }
    i = T_CString_int64ToString(src, U_INT64_MAX, 16);
    if(uprv_stricmp(src, "7FFFFFFFFFFFFFFF") != 0 || i != 16){
        log_err("FAIL: ****integerToString(src, 7FFFFFFFFFFFFFFF, 16); failed. Got: %s\n", src);
    }

    uprv_strcpy(src, "this is lower case");
    if(T_CString_stricmp(src, "THIS is lower CASE") != 0){
        log_err("FAIL: *****T_CString_stricmp() failed.");
    }
    if((intValue=T_CString_stricmp(NULL, "first string is null") )!= -1){
        log_err("FAIL: T_CString_stricmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
    }
    if((intValue=T_CString_stricmp("second string is null", NULL)) != 1){
        log_err("FAIL: T_CString_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
    }
    if((intValue=T_CString_stricmp(NULL, NULL)) != 0){
        log_err("FAIL: T_CString_stricmp(NULL, NULL) failed.  Expected:  0, returned %d\n", intValue);
    }
    if((intValue=T_CString_stricmp("", "")) != 0){
        log_err("FAIL: T_CString_stricmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);
    }
    if((intValue=T_CString_stricmp("", "abc")) != -1){
        log_err("FAIL: T_CString_stricmp(\"\", \"abc\") failed.  Expected: -1, returned %d\n", intValue);
    }
    if((intValue=T_CString_stricmp("abc", "")) != 1){
        log_err("FAIL: T_CString_stricmp(\"abc\", \"\") failed.  Expected: 1, returned %d\n", intValue);
    }

    temp=uprv_strdup("strdup");
    if(uprv_strcmp(temp, "strdup") !=0 ){
        log_err("FAIL: uprv_strdup() failed. Expected: \"strdup\", Got: %s\n", temp);
    }
    uprv_free((char *)temp);
  
    uprv_strcpy(src, "this is lower case");
    if(T_CString_strnicmp(src, "THIS", 4 ) != 0){
        log_err("FAIL: *****T_CString_strnicmp() failed.");
    }
    if((intValue=T_CString_strnicmp(NULL, "first string is null", 10) )!= -1){
        log_err("FAIL: T_CString_strnicmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
    }
    if((intValue=T_CString_strnicmp("second string is null", NULL, 10)) != 1){
        log_err("FAIL: T_CString_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
    }
    if((intValue=T_CString_strnicmp(NULL, NULL, 10)) != 0){
        log_err("FAIL: T_CString_strnicmp(NULL, NULL, 10) failed.  Expected:  0, returned %d\n", intValue);
    }
    if((intValue=T_CString_strnicmp("", "", 10)) != 0){
        log_err("FAIL: T_CString_strnicmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);
    }
    if((intValue=T_CString_strnicmp("", "abc", 10)) != -1){
        log_err("FAIL: T_CString_stricmp(\"\", \"abc\", 10) failed.  Expected: -1, returned %d\n", intValue);
    }
    if((intValue=T_CString_strnicmp("abc", "", 10)) != 1){
        log_err("FAIL: T_CString_strnicmp(\"abc\", \"\", 10) failed.  Expected: 1, returned %d\n", intValue);
    }
    
}
Example #2
0
void TestMessageCatalog(void) {

    UErrorCode ec = U_ZERO_ERROR;
    u_nl_catd catd;
    const char* DATA[] = {
        /* set_num, msg_num, expected string result, expected error code */
        "1", "4", "Good morning.", "U_ZERO_ERROR",
        "1", "5", "Good afternoon.", "U_ZERO_ERROR",
        "1", "6", "FAIL", "U_MISSING_RESOURCE_ERROR",
        "1", "7", "Good evening.", "U_ZERO_ERROR",
        "1", "8", "Good night.", "U_ZERO_ERROR",
        "1", "9", "FAIL", "U_MISSING_RESOURCE_ERROR",
        "3", "1", "FAIL", "U_MISSING_RESOURCE_ERROR",
        "4", "14", "Please ", "U_ZERO_ERROR",
        "4", "15", "FAIL", "U_MISSING_RESOURCE_ERROR",
        "4", "19", "Thank you.", "U_ZERO_ERROR",
        "4", "20", "Sincerely,", "U_ZERO_ERROR",
        NULL
    };
    const UChar FAIL[] = {0x46, 0x41, 0x49, 0x4C, 0x00}; /* "FAIL" */
    int32_t i;
    const char *path = loadTestData(&ec);
 
    if (U_FAILURE(ec)) {
        log_data_err("FAIL: loadTestData => %s\n", u_errorName(ec));
        return;
    }

    catd = u_catopen(path, "mc", &ec);
    if (U_FAILURE(ec)) {
        log_data_err("FAIL: u_catopen => %s\n", u_errorName(ec));
        return;
    }

    for (i=0; DATA[i]!=NULL; i+=4) {
        int32_t set_num = T_CString_stringToInteger(DATA[i], 10);
        int32_t msg_num = T_CString_stringToInteger(DATA[i+1], 10);
        UChar exp[128];
        int32_t len = -1;
        const char* err;
        char str[128];
        const UChar* ustr;

        u_uastrcpy(exp, DATA[i+2]);

        ec = U_ZERO_ERROR;
        ustr = u_catgets(catd, set_num, msg_num, FAIL, &len, &ec);
        u_austrcpy(str, ustr);
        err = u_errorName(ec);
        
        log_verbose("u_catgets(%d, %d) => \"%s\", len=%d, %s\n",
                    set_num, msg_num, str, len, err);

        if (u_strcmp(ustr, exp) != 0) {
            log_err("FAIL: u_catgets => \"%s\", exp. \"%s\"\n",
                    str, DATA[i+2]);
        }

        if (len != (int32_t) uprv_strlen(DATA[i+2])) {
            log_err("FAIL: u_catgets => len=%d, exp. %d\n",
                    len, uprv_strlen(DATA[i+2]));
        }

        if (uprv_strcmp(err, DATA[i+3]) != 0) {
            log_err("FAIL: u_catgets => %s, exp. %s\n",
                    err, DATA[i+3]);
        }
    }

    u_catclose(catd);
}