/*
**********************************************************************
-* Copyright (C) 1998-2004, International Business Machines Corporation
+* Copyright (C) 1998-2014, International Business Machines Corporation
* and others. All Rights Reserved.
**********************************************************************
*
#include "cintltst.h"
#include "cmemory.h"
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
static void TestAPI(void);
void addCStringTest(TestNode** root);
static void TestInvariant(void);
+static void TestCompareInvEbcdicAsAscii(void);
void addCStringTest(TestNode** root) {
addTest(root, &TestAPI, "tsutil/cstrtest/TestAPI");
addTest(root, &TestInvariant, "tsutil/cstrtest/TestInvariant");
+ addTest(root, &TestCompareInvEbcdicAsAscii, "tsutil/cstrtest/TestCompareInvEbcdicAsAscii");
}
static void TestAPI(void)
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(uprv_stricmp(src, "THIS is lower CASE") != 0){
+ log_err("FAIL: *****uprv_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=uprv_stricmp(NULL, "first string is null") )!= -1){
+ log_err("FAIL: uprv_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=uprv_stricmp("second string is null", NULL)) != 1){
+ log_err("FAIL: uprv_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=uprv_stricmp(NULL, NULL)) != 0){
+ log_err("FAIL: uprv_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=uprv_stricmp("", "")) != 0){
+ log_err("FAIL: uprv_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=uprv_stricmp("", "abc")) != -1){
+ log_err("FAIL: uprv_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);
+ if((intValue=uprv_stricmp("abc", "")) != 1){
+ log_err("FAIL: uprv_stricmp(\"abc\", \"\") failed. Expected: 1, returned %d\n", intValue);
}
temp=uprv_strdup("strdup");
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(uprv_strnicmp(src, "THIS", 4 ) != 0){
+ log_err("FAIL: *****uprv_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=uprv_strnicmp(NULL, "first string is null", 10) )!= -1){
+ log_err("FAIL: uprv_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=uprv_strnicmp("second string is null", NULL, 10)) != 1){
+ log_err("FAIL: uprv_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=uprv_strnicmp(NULL, NULL, 10)) != 0){
+ log_err("FAIL: uprv_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=uprv_strnicmp("", "", 10)) != 0){
+ log_err("FAIL: uprv_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=uprv_strnicmp("", "abc", 10)) != -1){
+ log_err("FAIL: uprv_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);
+ if((intValue=uprv_strnicmp("abc", "", 10)) != 1){
+ log_err("FAIL: uprv_strnicmp(\"abc\", \"\", 10) failed. Expected: 1, returned %d\n", intValue);
}
}
}
errorCode=U_ZERO_ERROR;
- length=ucnv_toUChars(cnv, us, LENGTHOF(us), invariantChars, -1, &errorCode);
+ length=ucnv_toUChars(cnv, us, UPRV_LENGTHOF(us), invariantChars, -1, &errorCode);
if(U_FAILURE(errorCode)) {
log_err("ucnv_toUChars(invariantChars) failed - %s\n", u_errorName(errorCode));
- } else if(length!=LENGTHOF(invariantUChars)-1 || u_strcmp(us, invariantUChars)!=0) {
+ } else if(length!=UPRV_LENGTHOF(invariantUChars)-1 || u_strcmp(us, invariantUChars)!=0) {
log_err("ucnv_toUChars(invariantChars) failed\n");
}
if(!uprv_isInvariantUString(invariantUChars, -1)) {
log_err("uprv_isInvariantUString(invariantUChars) failed\n");
}
+ if(!uprv_isInvariantString(invariantChars+strlen(invariantChars), 1)) {
+ log_err("uprv_isInvariantString(\"\\0\") failed\n");
+ }
for(i=0; i<(sizeof(variantChars)-1); ++i) {
if(uprv_isInvariantString(variantChars+i, 1)) {
}
}
- for(i=0; i<LENGTHOF(nonASCIIUChars); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(nonASCIIUChars); ++i) {
if(uprv_isInvariantUString(nonASCIIUChars+i, 1)) {
log_err("uprv_isInvariantUString(nonASCIIUChars[%d]) failed\n", i);
}
}
}
+
+static int32_t getSign(int32_t n) {
+ if(n<0) {
+ return -1;
+ } else if(n==0) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+static void
+TestCompareInvEbcdicAsAscii() {
+ static const char *const invStrings[][2]={
+ /* invariant-character strings in ascending ASCII order */
+ /* EBCDIC native */
+ { "", "" },
+ { "\x6c", "%" },
+ { "\xf0", "0" },
+ { "\xf0\xf0", "00" },
+ { "\xf0\xf0\x81", "00a" },
+ { "\x7e", "=" },
+ { "\xc1", "A" },
+ { "\xc1\xf0\xf0", "A00" },
+ { "\xc1\xf0\xf0", "A00" },
+ { "\xc1\xc1", "AA" },
+ { "\xc1\xc1\xf0", "AA0" },
+ { "\x6d", "_" },
+ { "\x81", "a" },
+ { "\x81\xf0\xf0", "a00" },
+ { "\x81\xf0\xf0", "a00" },
+ { "\x81\x81", "aa" },
+ { "\x81\x81\xf0", "aa0" },
+ { "\x81\x81\x81", "aaa" },
+ { "\x81\x81\x82", "aab" }
+ };
+ int32_t i;
+ for(i=1; i<UPRV_LENGTHOF(invStrings); ++i) {
+ int32_t diff1, diff2;
+ /* compare previous vs. current */
+ diff1=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i-1][0], invStrings[i][0]));
+ if(diff1>0 || (diff1==0 && 0!=uprv_strcmp(invStrings[i-1][0], invStrings[i][0]))) {
+ log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n",
+ invStrings[i-1][1], invStrings[i][1], (short)diff1);
+ }
+ /* compare current vs. previous, should be inverse diff */
+ diff2=getSign(uprv_compareInvEbcdicAsAscii(invStrings[i][0], invStrings[i-1][0]));
+ if(diff2!=-diff1) {
+ log_err("uprv_compareInvEbcdicAsAscii(%s, %s)=%hd is wrong\n",
+ invStrings[i][1], invStrings[i-1][1], (short)diff2);
+ }
+ }
+}