]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/cintltst/cstrtest.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cstrtest.c
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (C) 1998-2003, 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
21static void TestAPI(void);
22void addCStringTest(TestNode** root);
23
24void addCStringTest(TestNode** root) {
25
26 addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI");
27
28}
29
30static void TestAPI(void)
31{
32 int32_t intValue=0;
33 char src[30]="HELLO THERE", dest[30];
34 static const char *const abc="abcdefghijklmnopqrstuvwxyz", *const ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
35 const char *temp;
36 int32_t i;
37
38 log_verbose("Testing uprv_tolower() and uprv_toupper()\n");
39 for(i=0; i<=26; ++i) {
40 dest[i]=uprv_tolower(abc[i]);
41 }
42 if(0!=strcmp(abc, dest)) {
43 log_err("uprv_tolower(abc) failed\n");
44 }
45
46 for(i=0; i<=26; ++i) {
47 dest[i]=uprv_tolower(ABC[i]);
48 }
49 if(0!=strcmp(abc, dest)) {
50 log_err("uprv_tolower(ABC) failed\n");
51 }
52
53 for(i=0; i<=26; ++i) {
54 dest[i]=uprv_toupper(abc[i]);
55 }
56 if(0!=strcmp(ABC, dest)) {
57 log_err("uprv_toupper(abc) failed\n");
58 }
59
60 for(i=0; i<=26; ++i) {
61 dest[i]=uprv_toupper(ABC[i]);
62 }
63 if(0!=strcmp(ABC, dest)) {
64 log_err("uprv_toupper(ABC) failed\n");
65 }
66
67 log_verbose("Testing the API in cstring\n");
68 T_CString_toLowerCase(src);
69 if(uprv_strcmp(src, "hello there") != 0){
70 log_err("FAIL: *** T_CString_toLowerCase() failed. Expected: \"hello there\", Got: \"%s\"\n", src);
71 }
72 T_CString_toUpperCase(src);
73 if(uprv_strcmp(src, "HELLO THERE") != 0){
74 log_err("FAIL: *** T_CString_toUpperCase() failed. Expected: \"HELLO THERE\", Got: \"%s\"\n", src);
75 }
76
77 intValue=T_CString_stringToInteger("34556", 10);
78 if(intValue != 34556){
79 log_err("FAIL: ****T_CString_stringToInteger(\"34556\", 10) failed. Expected: 34556, Got: %d\n", intValue);
80 }
81 intValue=T_CString_stringToInteger("100", 16);
82 if(intValue != 256){
83 log_err("FAIL: ****T_CString_stringToInteger(\"100\", 16) failed. Expected: 256, Got: %d\n", intValue);
84 }
85 i = T_CString_integerToString(src, 34556, 10);
86 if(uprv_strcmp(src, "34556") != 0 || i != 5){
87 log_err("FAIL: ****integerToString(src, 34566, 10); failed. Expected: \"34556\", Got: %s\n", src);
88 }
89 i = T_CString_integerToString(src, 431, 16);
90 if(uprv_stricmp(src, "1AF") != 0 || i != 3){
91 log_err("FAIL: ****integerToString(src, 431, 16); failed. Expected: \"1AF\", Got: %s\n", src);
92 }
93
94 uprv_strcpy(src, "this is lower case");
95 if(T_CString_stricmp(src, "THIS is lower CASE") != 0){
96 log_err("FAIL: *****T_CString_stricmp() failed.");
97 }
98 if((intValue=T_CString_stricmp(NULL, "first string is null") )!= -1){
99 log_err("FAIL: T_CString_stricmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
100 }
101 if((intValue=T_CString_stricmp("second string is null", NULL)) != 1){
102 log_err("FAIL: T_CString_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
103 }
104 if((intValue=T_CString_stricmp(NULL, NULL)) != 0){
105 log_err("FAIL: T_CString_stricmp(NULL, NULL) failed. Expected: 0, returned %d\n", intValue);;
106 }
107 if((intValue=T_CString_stricmp("", "")) != 0){
108 log_err("FAIL: T_CString_stricmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);;
109 }
110 if((intValue=T_CString_stricmp("", "abc")) != -1){
111 log_err("FAIL: T_CString_stricmp(\"\", \"abc\") failed. Expected: -1, returned %d\n", intValue);
112 }
113 if((intValue=T_CString_stricmp("abc", "")) != 1){
114 log_err("FAIL: T_CString_stricmp(\"abc\", \"\") failed. Expected: 1, returned %d\n", intValue);
115 }
116
117 temp=uprv_strdup("strdup");
118 if(uprv_strcmp(temp, "strdup") !=0 ){
119 log_err("FAIL: uprv_strdup() failed. Expected: \"strdup\", Got: %s\n", temp);
120 }
121 uprv_free((char *)temp);
122
123 uprv_strcpy(src, "this is lower case");
124 if(T_CString_strnicmp(src, "THIS", 4 ) != 0){
125 log_err("FAIL: *****T_CString_strnicmp() failed.");
126 }
127 if((intValue=T_CString_strnicmp(NULL, "first string is null", 10) )!= -1){
128 log_err("FAIL: T_CString_strnicmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
129 }
130 if((intValue=T_CString_strnicmp("second string is null", NULL, 10)) != 1){
131 log_err("FAIL: T_CString_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
132 }
133 if((intValue=T_CString_strnicmp(NULL, NULL, 10)) != 0){
134 log_err("FAIL: T_CString_strnicmp(NULL, NULL, 10) failed. Expected: 0, returned %d\n", intValue);;
135 }
136 if((intValue=T_CString_strnicmp("", "", 10)) != 0){
137 log_err("FAIL: T_CString_strnicmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);;
138 }
139 if((intValue=T_CString_strnicmp("", "abc", 10)) != -1){
140 log_err("FAIL: T_CString_stricmp(\"\", \"abc\", 10) failed. Expected: -1, returned %d\n", intValue);
141 }
142 if((intValue=T_CString_strnicmp("abc", "", 10)) != 1){
143 log_err("FAIL: T_CString_strnicmp(\"abc\", \"\", 10) failed. Expected: 1, returned %d\n", intValue);
144 }
145
146}