2
**********************************************************************
3
* Copyright (C) 1998-2001, International Business Machines Corporation
4
* and others. All Rights Reserved.
5
**********************************************************************
9
* Modification History:
11
* Date Name Description
12
* 07/13/2000 Madhu created
13
*******************************************************************************
21
static void TestAPI(void);
22
void addCStringTest(TestNode** root);
24
void addCStringTest(TestNode** root) {
26
addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI");
30
static void TestAPI(void)
34
char src[30]="HELLO THERE";
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);
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);
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);
51
intValue=T_CString_stringToInteger("100", 16);
53
log_err("FAIL: ****T_CString_stringToInteger(\"100\", 16) failed. Expected: 256, Got: %d\n", intValue);
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);
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);
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.");
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);
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);
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);;
77
if((intValue=T_CString_stricmp("", "")) != 0){
78
log_err("FAIL: T_CString_stricmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);;
80
if((intValue=T_CString_stricmp("", "abc")) != -1){
81
log_err("FAIL: T_CString_stricmp(\"\", \"abc\") failed. Expected: -1, returned %d\n", intValue);
83
if((intValue=T_CString_stricmp("abc", "")) != 1){
84
log_err("FAIL: T_CString_stricmp(\"abc\", \"\") failed. Expected: 1, returned %d\n", intValue);
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);
91
uprv_free((char *)temp);
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.");
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);
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);
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);;
106
if((intValue=T_CString_strnicmp("", "", 10)) != 0){
107
log_err("FAIL: T_CString_strnicmp(\"\", \"\") failed. Expected: 0, returned %d\n", intValue);;
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);
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);