~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/test/cintltst/cstrtest.c

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
**********************************************************************
 
3
* Copyright (C) 1998-2001, International Business Machines Corporation 
 
4
* and others.  All Rights Reserved.
 
5
**********************************************************************
 
6
*
 
7
* File cstrtest.c
 
8
*
 
9
* Modification History:
 
10
*
 
11
*   Date        Name        Description
 
12
*   07/13/2000  Madhu         created
 
13
*******************************************************************************
 
14
*/
 
15
 
 
16
 
 
17
#include "cstring.h"
 
18
#include "cintltst.h"
 
19
#include "cmemory.h"
 
20
 
 
21
static void TestAPI(void);
 
22
void addCStringTest(TestNode** root);
 
23
 
 
24
void addCStringTest(TestNode** root) {
 
25
   
 
26
    addTest(root, &TestAPI,   "tsutil/cstrtest/TestAPI");
 
27
  
 
28
}
 
29
 
 
30
static void TestAPI(void)
 
31
{
 
32
 
 
33
    int32_t intValue=0;
 
34
    char src[30]="HELLO THERE";
 
35
    const char *temp;
 
36
    
 
37
    log_verbose("Testing the API in cstring\n");
 
38
    T_CString_toLowerCase(src);
 
39
    if(uprv_strcmp(src, "hello there") != 0){
 
40
        log_err("FAIL: *** T_CString_toLowerCase() failed. Expected: \"hello there\", Got: \"%s\"\n", src);
 
41
    }
 
42
    T_CString_toUpperCase(src);
 
43
    if(uprv_strcmp(src, "HELLO THERE") != 0){
 
44
        log_err("FAIL: *** T_CString_toUpperCase() failed. Expected: \"HELLO THERE\", Got: \"%s\"\n", src);
 
45
    }
 
46
     
 
47
    intValue=T_CString_stringToInteger("34556", 10);
 
48
    if(intValue != 34556){
 
49
        log_err("FAIL: ****T_CString_stringToInteger(\"34556\", 10) failed. Expected: 34556, Got: %d\n", intValue);
 
50
    }
 
51
    intValue=T_CString_stringToInteger("100", 16);
 
52
    if(intValue != 256){
 
53
        log_err("FAIL: ****T_CString_stringToInteger(\"100\", 16) failed. Expected: 256, Got: %d\n", intValue);
 
54
    }
 
55
    T_CString_integerToString(src, 34556, 10);
 
56
    if(uprv_strcmp(src, "34556") != 0){
 
57
        log_err("FAIL: ****integerToString(src, 34566, 10); failed. Expected: \"34556\", Got: %s\n", src);
 
58
    }
 
59
    T_CString_integerToString(src, 256, 16);
 
60
    if(uprv_strcmp(src, "100") != 0){
 
61
        log_err("FAIL: ****integerToString(src, 256, 16); failed. Expected: \"100\", Got: %s\n", src);
 
62
    }
 
63
 
 
64
    uprv_strcpy(src, "this is lower case");
 
65
    if(T_CString_stricmp(src, "THIS is lower CASE") != 0){
 
66
        log_err("FAIL: *****T_CString_stricmp() failed.");
 
67
    }
 
68
    if((intValue=T_CString_stricmp(NULL, "first string is null") )!= -1){
 
69
        log_err("FAIL: T_CString_stricmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
 
70
    }
 
71
    if((intValue=T_CString_stricmp("second string is null", NULL)) != 1){
 
72
        log_err("FAIL: T_CString_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
 
73
    }
 
74
    if((intValue=T_CString_stricmp(NULL, NULL)) != 0){
 
75
        log_err("FAIL: T_CString_stricmp(NULL, NULL) failed.  Expected:  0, returned %d\n", intValue);;
 
76
    }
 
77
    if((intValue=T_CString_stricmp("", "")) != 0){
 
78
        log_err("FAIL: T_CString_stricmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
 
79
    }
 
80
    if((intValue=T_CString_stricmp("", "abc")) != -1){
 
81
        log_err("FAIL: T_CString_stricmp(\"\", \"abc\") failed.  Expected: -1, returned %d\n", intValue);
 
82
    }
 
83
    if((intValue=T_CString_stricmp("abc", "")) != 1){
 
84
        log_err("FAIL: T_CString_stricmp(\"abc\", \"\") failed.  Expected: 1, returned %d\n", intValue);
 
85
    }
 
86
 
 
87
    temp=uprv_strdup("strdup");
 
88
    if(uprv_strcmp(temp, "strdup") !=0 ){
 
89
        log_err("FAIL: uprv_strdup() failed. Expected: \"strdup\", Got: %s\n", temp);
 
90
    }
 
91
    uprv_free((char *)temp);
 
92
  
 
93
    uprv_strcpy(src, "this is lower case");
 
94
    if(T_CString_strnicmp(src, "THIS", 4 ) != 0){
 
95
        log_err("FAIL: *****T_CString_strnicmp() failed.");
 
96
    }
 
97
    if((intValue=T_CString_strnicmp(NULL, "first string is null", 10) )!= -1){
 
98
        log_err("FAIL: T_CString_strnicmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
 
99
    }
 
100
    if((intValue=T_CString_strnicmp("second string is null", NULL, 10)) != 1){
 
101
        log_err("FAIL: T_CString_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
 
102
    }
 
103
    if((intValue=T_CString_strnicmp(NULL, NULL, 10)) != 0){
 
104
        log_err("FAIL: T_CString_strnicmp(NULL, NULL, 10) failed.  Expected:  0, returned %d\n", intValue);;
 
105
    }
 
106
    if((intValue=T_CString_strnicmp("", "", 10)) != 0){
 
107
        log_err("FAIL: T_CString_strnicmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
 
108
    }
 
109
    if((intValue=T_CString_strnicmp("", "abc", 10)) != -1){
 
110
        log_err("FAIL: T_CString_stricmp(\"\", \"abc\", 10) failed.  Expected: -1, returned %d\n", intValue);
 
111
    }
 
112
    if((intValue=T_CString_strnicmp("abc", "", 10)) != 1){
 
113
        log_err("FAIL: T_CString_strnicmp(\"abc\", \"\", 10) failed.  Expected: 1, returned %d\n", intValue);
 
114
    }
 
115
    
 
116
}