ICU-432 Fixed a very odd leak with cloctest, cucdtst and crestst

X-SVN-Rev: 3245
This commit is contained in:
George Rhoten 2000-12-15 19:16:43 +00:00
parent 92123b144f
commit 994d196cbb
7 changed files with 258 additions and 285 deletions

View file

@ -8,7 +8,7 @@
* File CINTLTST.C
*
* Modification History:
* Name Description
* Name Description
* Madhu Katragadda Creation
*********************************************************************************
*/
@ -21,9 +21,6 @@
#include "unicode/utypes.h"
#include "cintltst.h"
U_CDECL_BEGIN
#include "cucdtst.h"
U_CDECL_END
#include "unicode/uchar.h"
#include "unicode/ustring.h"
@ -95,7 +92,6 @@ int main(int argc, const char* const argv[])
addAllTests(&root);
nerrors = processArgs(root, argc, argv);
cleanUpTestTree(root);
cleanUpDataTable();
#ifdef CTST_LEAK_CHECK
ctst_freeAll();
@ -112,35 +108,30 @@ int main(int argc, const char* const argv[])
void
ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath )
{
char mainDirBuffer[200];
char mainDirBuffer[1024];
char* mainDir = NULL;
const char *dataDirectory = u_getDataDirectory();
const char inpSepChar = '|';
char* tmp;
int32_t lenMainDir;
int32_t lenRelPath ;
int32_t lenRelPath;
#if defined(_WIN32) || defined(WIN32) || defined(__OS2__) || defined(OS2)
/* This should always be u_getDataDirectory().
*/
mainDir= u_getDataDirectory();
if(mainDir!=NULL) {
strcpy(mainDirBuffer, mainDir);
strcat(mainDirBuffer, "..");
} else {
mainDirBuffer[0]='\0';
}
mainDir=mainDirBuffer;
#elif defined(XP_MAC)
Str255 volName;
int16_t volNum;
OSErr err = GetVol( volName, &volNum );
if (err != noErr) volName[0] = 0;
mainDir = (char*) &(volName[1]);
mainDir[volName[0]] = 0;
#ifdef XP_MAC
Str255 volName;
int16_t volNum;
OSErr err = GetVol( volName, &volNum );
if (err != noErr)
volName[0] = 0;
mainDir = (char*) &(volName[1]);
mainDir[volName[0]] = 0;
#else
strcpy(mainDirBuffer, u_getDataDirectory());
if (dataDirectory != NULL) {
strcpy(mainDirBuffer, dataDirectory);
strcat(mainDirBuffer, ".." U_FILE_SEP_STRING);
mainDir = mainDirBuffer;
} else {
mainDirBuffer[0]='\0';
}
mainDir = mainDirBuffer;
#endif
lenMainDir = strlen( mainDir );
@ -149,9 +140,13 @@ ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath )
mainDir[lenMainDir] = 0;
}
if (relPath[0] == '|') relPath++;
if (relPath[0] == '|')
relPath++;
lenRelPath = strlen( relPath );
if (maxsize < lenMainDir + lenRelPath + 2) { fullname[0] = 0; return; }
if (maxsize < lenMainDir + lenRelPath + 2) {
fullname[0] = 0;
return;
}
strcpy( fullname, mainDir );
/*strcat( fullname, U_FILE_SEP_STRING );*/
strcat( fullname, relPath );
@ -193,7 +188,7 @@ char *austrdup(const UChar* unichars)
length = u_strlen ( unichars );
/*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */
newString = (char*)ctst_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
if ( newString == NULL )
return NULL;

View file

@ -28,9 +28,10 @@ void PrintDataTable();
/*---------------------------------------------------
table of valid data
--------------------------------------------------- */
#define LOCALE_SIZE 5
#define LOCALE_INFO_SIZE 23
static const char* rawData2[23][5] = {
static const char* rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = {
/* language code */
{ "en", "fr", "hr", "el", "no" },
/* country code */
@ -65,22 +66,22 @@ static const char* rawData2[23][5] = {
{ "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "croate (Croatie)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, Nynorsk)" },
/* display langage (Croatian) */
{ "", "", "hrvatski", "", "" },
/* display country (Croatian) */
{ "", "", "Hrvatska", "", "" },
{ "", "", "hrvatski", "", "" },
/* display country (Croatian) */
{ "", "", "Hrvatska", "", "" },
/* display variant (Croatian) */
{ "", "", "", "", "" },
{ "", "", "", "", "" },
/* display name (Croatian) */
{ "", "", "hrvatski (Hrvatska)", "", "" },
/* display langage (Greek) [actual values listed below] */
{ "", "", "", "", "" },
/* display country (Greek) [actual values listed below] */
{ "", "", "", "", "" },
/* display langage (Greek) */
{ "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac", "" },
/* display country (Greek) */
{ "", "", "", "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1", "" },
/* display variant (Greek) */
{ "", "", "", "", "" },
/* display name (Greek) [actual values listed below] */
{ "", "", "", "", "" }
{ "", "", "", "", "" },
/* display name (Greek) */
{ "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)", "" }
};
static UChar*** dataTable=0;
@ -122,8 +123,6 @@ enum {
void addLocaleTest(TestNode** root)
{
setUpDataTable();
addTest(root, &TestBasicGetters, "tsutil/cloctst/TestBasicGetters");
addTest(root, &TestSimpleResourceInfo, "tsutil/cloctst/TestSimpleResourceInfo");
addTest(root, &TestDisplayNames, "tsutil/cloctst/TestDisplayNames");
@ -134,9 +133,8 @@ void addLocaleTest(TestNode** root)
addTest(root, &TestUninstalledISO3Names, "tsutil/cloctst/TestUninstalledISO3Names");
addTest(root, &TestSimpleDisplayNames, "tsutil/cloctst/TestSimpleDisplayNames");
addTest(root, &TestVariantParsing, "tsutil/cloctst/TestVariantParsing");
}
/* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */
static void TestBasicGetters() {
@ -189,12 +187,9 @@ static void TestBasicGetters() {
log_err("ERROR: in uloc_getVariant %s\n", myErrorName(status));
}
if (0 != strcmp(temp, rawData2[VAR][i])) {
log_err("Variant code mismatch: %s versus %s\n", temp, rawData2[VAR][i]);
}
}
cap=uloc_getName(testLocale, NULL, 0, &status);
if(status==U_BUFFER_OVERFLOW_ERROR){
status=U_ZERO_ERROR;
@ -212,14 +207,12 @@ static void TestBasicGetters() {
free(temp);
free(name);
free(testLocale);
free(testLocale);
}
}
/* testing uloc_getISO3Language(), uloc_getISO3Country(), */
static void TestSimpleResourceInfo() {
int32_t i;
char* testLocale = 0;
UChar* expected = 0;
@ -229,38 +222,40 @@ static void TestSimpleResourceInfo() {
testLocale=(char*)malloc(sizeof(char) * 1);
expected=(UChar*)malloc(sizeof(UChar) * 1);
setUpDataTable();
log_verbose("Testing getISO3Language and getISO3Country\n");
for (i = 0; i <= MAX_LOCALES; i++) {
testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
u_austrcpy(testLocale, dataTable[NAME][i]);
log_verbose("Testing %s ......\n", testLocale);
temp=uloc_getISO3Language(testLocale);
expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
u_uastrcpy(expected,temp);
if (0 != u_strcmp(expected, dataTable[LANG3][i])) {
log_err(" ISO-3 language code mismatch: %s versus %s\n", austrdup(expected),
austrdup(dataTable[LANG3][i]));
}
}
temp=uloc_getISO3Country(testLocale);
expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
u_uastrcpy(expected,temp);
if (0 != u_strcmp(expected, dataTable[CTRY3][i])) {
log_err(" ISO-3 Country code mismatch: %s versus %s\n", austrdup(expected),
austrdup(dataTable[CTRY3][i]));
}
}
sprintf(temp2, "%x", uloc_getLCID(testLocale));
if (strcmp(temp2, rawData2[LCID][i]) != 0) {
log_err("LCID mismatch: %ld versus %s\n", (int32_t)uloc_getLCID(testLocale) , rawData2[LCID][i]);
}
}
free(expected);
free(testLocale);
cleanUpDataTable();
}
static void TestDisplayNames()
@ -272,9 +267,9 @@ static void TestDisplayNames()
*/
const char *saveDefault;
char *defaultLocale;
UErrorCode err = U_ZERO_ERROR;
saveDefault = uloc_getDefault();
defaultLocale = (char*) malloc(strlen(saveDefault) + 1);
@ -289,11 +284,11 @@ static void TestDisplayNames()
log_err("uloc_setDefault returned error code ");
return;
}
log_verbose("Testing getDisplayName for different locales\n");
log_verbose("With default = en_US...\n");
log_verbose(" In default locale...\n");
doTestDisplayNames(" ", DLANG_EN, FALSE);
log_verbose(" In locale = en_US...\n");
@ -310,9 +305,9 @@ static void TestDisplayNames()
log_err("Locale::setDefault returned error code %s\n", myErrorName(err));
return;
}
log_verbose("With default = fr_FR...\n");
log_verbose(" In default locale...\n");
doTestDisplayNames(" ", DLANG_FR, TRUE);
log_verbose(" In locale = en_US...\n");
@ -341,23 +336,22 @@ static void TestGetAvailableLocales()
const char *locList;
int32_t locCount,i;
log_verbose("Testing the no of avialable locales\n");
locCount=uloc_countAvailable();
if (locCount == 0)
log_err("countAvailable() returned an empty list!\n");
/* use something sensible w/o hardcoding the count */
else if(locCount < 0){
log_err("countAvailable() returned a wrong value!= %d\n", locCount);
}
else{
log_info("Number of locales returned = %d\n", locCount);
}
for(i=0;i<locCount;i++){
locList=uloc_getAvailable(i);
log_verbose(" %s\n", locList);
}
}
@ -379,7 +373,6 @@ static void TestDataDirectory()
if (0 != strcmp(testValue1,"eng")){
log_err("Initial check of ISO3 language failed: expected \"eng\", got %s \n", testValue1);
}
/*defining the path for DataDirectory */
@ -389,18 +382,17 @@ static void TestDataDirectory()
log_verbose("setDataDirectory working fine\n");
else
log_err("Error in setDataDirectory. Directory not set correctly - came back as [%s], expected [%s]\n", u_getDataDirectory(), path);
testValue2=uloc_getISO3Language("en_US");
log_verbose("second fetch of language retrieved %s \n", testValue2);
u_setDataDirectory(oldDirectory);
testValue3=uloc_getISO3Language("en_US");
log_verbose("third fetch of language retrieved %s \n", testValue3);
if (0 != strcmp(testValue3,"eng")) {
log_err("get/setDataDirectory() failed: expected \"eng\", got \" %s \" \n", testValue3);
}
}
}
@ -414,15 +406,15 @@ static void doTestDisplayNames(const char* inLocale,
UErrorCode status = U_ZERO_ERROR;
int32_t i;
int32_t maxresultsize;
char* testLocale;
UChar *testLang = 0;
UChar *testCtry = 0;
UChar *testVar = 0;
UChar *testName = 0;
UChar* expectedLang = 0;
UChar* expectedCtry = 0;
@ -430,33 +422,31 @@ static void doTestDisplayNames(const char* inLocale,
UChar* expectedName = 0;
char temp[5];
const char* defaultDefaultLocale=" ";
setUpDataTable();
uloc_getLanguage(uloc_getDefault(), temp, 5, &status);
if(U_FAILURE(status)){
log_err("ERROR: in getDefault %s \n", myErrorName(status));
}
if (defaultIsFrench && 0 != strcmp(temp, "fr")) {
log_err("Default locale should be French, but it's really %s\n", temp);
}
else if (!defaultIsFrench && 0 != strcmp(temp, "en")){
log_err("Default locale should be English, but it's really %s\n", temp);
}
testLocale = (char*)malloc(sizeof(char) * 1);
for(i=0;i<MAX_LOCALES; ++i)
{
testLocale = (char*)malloc(sizeof(char) * 1);
for(i=0;i<MAX_LOCALES; ++i)
{
testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
u_austrcpy(testLocale,dataTable[NAME][i]);
log_verbose("Testing..... %s\n", testLocale);
if (strcmp(inLocale, defaultDefaultLocale)==0) {
maxresultsize=0;
maxresultsize=uloc_getDisplayLanguage(testLocale, NULL, NULL, maxresultsize, &status);
@ -465,12 +455,10 @@ static void doTestDisplayNames(const char* inLocale,
status=U_ZERO_ERROR;
testLang=(UChar*)malloc(sizeof(UChar) * (maxresultsize + 1));
uloc_getDisplayLanguage(testLocale, NULL, testLang, maxresultsize, &status);
}
if(U_FAILURE(status)){
log_err("Error in getDisplayLanguage() %s\n", myErrorName(status));
}
maxresultsize=0;
maxresultsize=uloc_getDisplayCountry(testLocale, NULL, NULL, maxresultsize, &status);
@ -482,9 +470,8 @@ static void doTestDisplayNames(const char* inLocale,
}
if(U_FAILURE(status)){
log_err("Error in getDisplayCountry() %s\n", myErrorName(status));
}
maxresultsize=0;
maxresultsize=uloc_getDisplayVariant(testLocale, NULL, NULL, maxresultsize, &status);
if(status==U_BUFFER_OVERFLOW_ERROR)
@ -495,7 +482,6 @@ static void doTestDisplayNames(const char* inLocale,
}
if(U_FAILURE(status)){
log_err("Error in getDisplayVariant() %s\n", myErrorName(status));
}
maxresultsize=0;
maxresultsize=uloc_getDisplayName(testLocale, NULL, NULL, maxresultsize, &status);
@ -561,53 +547,50 @@ static void doTestDisplayNames(const char* inLocale,
}
}
expectedLang=dataTable[compareIndex][i];
if(u_strlen(expectedLang) == 0 && defaultIsFrench)
if(u_strlen(expectedLang) == 0 && defaultIsFrench)
expectedLang=dataTable[DLANG_FR][i];
if(u_strlen(expectedLang)== 0)
expectedLang=dataTable[DLANG_EN][i];
expectedCtry=dataTable[compareIndex + 1][i];
if(u_strlen(expectedCtry) == 0 && defaultIsFrench)
expectedCtry=dataTable[DCTRY_FR][i];
if(u_strlen(expectedCtry)== 0)
expectedCtry=dataTable[DCTRY_EN][i];
expectedCtry=dataTable[DCTRY_EN][i];
expectedVar=dataTable[compareIndex + 2][i];
if(u_strlen(expectedVar) == 0 && defaultIsFrench)
expectedVar=dataTable[DVAR_FR][i];
if(u_strlen(expectedCtry)== 0)
expectedVar=dataTable[DVAR_EN][i];
expectedName=dataTable[compareIndex + 3][i];
if(u_strlen(expectedName) ==0 && defaultIsFrench)
expectedName=dataTable[DNAME_FR][i];
if(u_strlen(expectedName) == 0)
expectedName=dataTable[DNAME_EN][i];
if (0 !=u_strcmp(testLang,expectedLang)) {
if (0 !=u_strcmp(testLang,expectedLang)) {
log_err(" Display Language mismatch: %s versus %s\n", austrdup(testLang), austrdup(expectedLang));
}
}
if (0 != u_strcmp(testCtry,expectedCtry)) {
log_err(" Display Country mismatch: %s versus %s\n", austrdup(testCtry), austrdup(expectedCtry));
}
}
if (0 != u_strcmp(testVar,expectedVar)) {
log_err(" Display Variant mismatch: %s versus %s\n", austrdup(testVar), austrdup(expectedVar));
}
}
if(0 != u_strcmp(testName, expectedName)) {
log_err(" Display Name mismatch: %s versus %s\n", austrdup(testName), austrdup(expectedName));
}
free(testName);
free(testLang);
free(testCtry);
@ -615,81 +598,76 @@ static void doTestDisplayNames(const char* inLocale,
}
free(testLocale);
cleanUpDataTable();
}
/* test for uloc_getISOLanguages, uloc_getISOCountries */
static void TestISOFunctions()
{
int32_t count = 0;
UBool done = FALSE;
const char* const* str=uloc_getISOLanguages();
const char* const* str1=uloc_getISOCountries();
int32_t count = 0;
UBool done = FALSE;
/* test getISOLanguages*/
count = 0;
done = FALSE;
/*str=uloc_getISOLanguages(); */
log_verbose("Testing ISO Languages: \n");
while(!done){
while(!done)
{
if(*(str+count++) == 0)
{
done = TRUE;
}
}
count--;
if(count!=142)
if(count!=142) {
log_err("There is an error in getISOLanguages %d\n", count);
}
log_verbose("Testing ISO Countries");
count=0;
done=FALSE;
while(!done)
{
if(*(str1 + count++)==0)
{
done=TRUE;
}
}
count--;
if(count!=239)
{
log_err("There is an error in getISOCountries %d \n", count);
}
}
static UChar greekDisplayLanguage[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0 };
static UChar greekDisplayCountry[] = { 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0 };
static UChar greekDisplayName[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba,
0x03ac, 0x20, 0x28, 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0x29, 0 };
static void setUpDataTable()
{
int32_t i,j;
dataTable = (UChar***)(calloc(sizeof(UChar**),23));
dataTable = (UChar***)(calloc(sizeof(UChar**),LOCALE_INFO_SIZE));
for (i = 0; i < 23; i++) {
dataTable[i] = (UChar**)(calloc(sizeof(UChar*),5));
dataTable[i] = (UChar**)(calloc(sizeof(UChar*),LOCALE_SIZE));
for (j = 0; j < 5; j++){
dataTable[i][j] = CharsToUChars(rawData2[i][j]);
}
}
dataTable[DLANG_EL][GREEKS]=(UChar*)realloc(dataTable[DLANG_EL][GREEKS],sizeof(UChar)*(u_strlen(greekDisplayLanguage)+1));
u_strncpy(dataTable[DLANG_EL][GREEKS],greekDisplayLanguage,8);
dataTable[DCTRY_EL][GREEKS]=(UChar*)realloc(dataTable[DCTRY_EL][GREEKS],sizeof(UChar)*(u_strlen(greekDisplayCountry)+1));
u_strncpy(dataTable[DCTRY_EL][GREEKS],greekDisplayCountry,6);
dataTable[DNAME_EL][GREEKS]=(UChar*)realloc(dataTable[DNAME_EL][GREEKS],sizeof(UChar)*(u_strlen(greekDisplayName)+1));
u_strncpy(dataTable[DNAME_EL][GREEKS],greekDisplayName,17);
}
static void cleanUpDataTable()
{
int32_t i,j;
if(dataTable != NULL) {
for (i=0; i<LOCALE_INFO_SIZE; i++) {
for(j = 0; j < LOCALE_SIZE; j++) {
free(dataTable[i][j]);
}
free(dataTable[i]);
}
free(dataTable);
}
dataTable = NULL;
}
/**

View file

@ -59,14 +59,16 @@ static void TestDisplayNames(void);
**/
static void TestVariantParsing(void);
/*
/**
* routine to perform subtests, used by TestDisplayNames
**/
*/
static void doTestDisplayNames(const char* inLocale, int32_t compareIndex, int32_t defaultIsFrench);
/**
* additional intialization for datatables storing expected values
**/
*/
static void setUpDataTable(void);
static void cleanUpDataTable(void);
void displayDataTable(void);
#endif

View file

@ -97,8 +97,7 @@ static struct
E_Where where;
UBool like[e_Where_count];
UBool inherits[e_Where_count];
}
param[] =
} param[] =
{
/* "te" means test */
/* "IN" means inherits */
@ -122,14 +121,11 @@ static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
void addResourceBundleTest(TestNode** root)
{
setUpDataTable();
addTest(root, &TestConstruction1, "tsutil/crestst/TestConstruction1");
addTest(root, &TestConstruction2, "tsutil/crestst/TestConstruction2");
addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundle");
addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
addTest(root, &TestAliasConflict, "tsutil/crestst/TestAlias");
addTest(root, &TestConstruction1, "tsutil/crestst/TestConstruction1");
addTest(root, &TestConstruction2, "tsutil/crestst/TestConstruction2");
addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundle");
addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
addTest(root, &TestAliasConflict, "tsutil/crestst/TestAlias");
}
@ -139,7 +135,7 @@ void TestAliasConflict(void) {
UResourceBundle *he = NULL;
UResourceBundle *iw = NULL;
const UChar *result = NULL;
he = ures_open(NULL, "he", &status);
iw = ures_open(NULL, "iw", &status);
if(U_FAILURE(status)) {
@ -156,18 +152,16 @@ void TestAliasConflict(void) {
void TestResourceBundles()
{
testTag("only_in_Root", TRUE, FALSE, FALSE);
testTag("in_Root_te", TRUE, TRUE, FALSE);
testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
testTag("only_in_te", FALSE, TRUE, FALSE);
testTag("only_in_te_IN", FALSE, FALSE, TRUE);
testTag("in_te_te_IN", FALSE, TRUE, TRUE);
testTag("nonexistent", FALSE, FALSE, FALSE);
testTag("only_in_Root", TRUE, FALSE, FALSE);
testTag("in_Root_te", TRUE, TRUE, FALSE);
testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
testTag("only_in_te", FALSE, TRUE, FALSE);
testTag("only_in_te_IN", FALSE, FALSE, TRUE);
testTag("in_te_te_IN", FALSE, TRUE, TRUE);
testTag("nonexistent", FALSE, FALSE, FALSE);
log_verbose("Passed:= %d Failed= %d \n", pass, fail);
log_verbose("Passed:= %d Failed= %d \n", pass, fail);
}

View file

@ -22,13 +22,13 @@
void addTestResourceBundleTest(TestNode**);
/**
*Perform several extensive tests using the subtest routine testTag
*/
/**
* Perform several extensive tests using the subtest routine testTag
*/
void TestResourceBundles(void);
/**
* Test construction of ResourceBundle accessing a custom test resource-file
**/
*/
void TestConstruction1(void);
void TestConstruction2(void);
@ -37,14 +37,13 @@
/**
* extensive subtests called by TestResourceBundles
**/
void setUpDataTable(void);
UBool testTag(const char* frag, UBool in_Root, UBool in_te, UBool in_te_IN);
void record_pass(void);
void record_fail(void);
int32_t pass;
int32_t fail;

View file

@ -38,9 +38,11 @@ static void
TestUnescape();
/* test data ---------------------------------------------------------------- */
#ifndef MIN
#define MIN(a,b) (a < b ? a : b)
#endif
UChar*** dataTable = 0;
UChar*** dataTable = NULL;
const UChar LAST_CHAR_CODE_IN_FILE = 0xFFFD;
const char tagStrings[] = "MnMcMeNdNlNoZsZlZpCcCfCsCoCnLuLlLtLmLoPcPdPsPePoSmScSkSoPiPf";
const int32_t tagValues[] =
@ -102,7 +104,6 @@ const char dirStrings[][5] = {
void addUnicodeTest(TestNode** root)
{
setUpDataTable();
addTest(root, &TestUpperLower, "tsutil/cucdtst/TestUpperLower");
addTest(root, &TestLetterNumber, "tsutil/cucdtst/TestLetterNumber");
addTest(root, &TestMisc, "tsutil/cucdtst/TestMisc");
@ -129,7 +130,7 @@ static void TestUpperLower()
U_STRING_INIT(upperTest, "abcdefg123hij.?:klmno", 21);
U_STRING_INIT(lowerTest, "ABCDEFG123HIJ.?:KLMNO", 21);
for(i=0; i < u_strlen(upper); i++){
if(u_tolower(upper[i]) != lower[i]){
log_err("FAILED u_tolower() for %lx Expected %lx Got %lx\n", upper[i], lower[i], u_tolower(upper[i]));
@ -607,8 +608,8 @@ static const char* raw[3][4] = {
/* Concatenated string */
{ "English_United States", "French_France", "Croatian_Croatia", "English_United States"}
};
U_CFUNC void setUpDataTable()
static void setUpDataTable()
{
int32_t i,j;
if(dataTable == NULL) {
@ -622,10 +623,9 @@ U_CFUNC void setUpDataTable()
}
}
}
}
U_CFUNC void cleanUpDataTable()
static void cleanUpDataTable()
{
int32_t i,j;
if(dataTable != NULL) {
@ -643,28 +643,31 @@ U_CFUNC void cleanUpDataTable()
/*Tests for u_strcat(),u_strcmp(), u_strlen(), u_strcpy(),u_strncat(),u_strncmp(),u_strncpy, u_uastrcpy(),u_austrcpy(), u_uastrncpy(); */
static void TestStringFunctions()
{
int32_t i,j,k;
UChar temp[40];
char test[40];
setUpDataTable();
log_verbose("Testing u_strlen()\n");
if( u_strlen(dataTable[0][0])!= u_strlen(dataTable[0][3]) || u_strlen(dataTable[0][0]) == u_strlen(dataTable[0][2]))
log_err("There is an error in u_strlen()");
log_verbose("Testing u_strcpy() and u_strcmp)\n");
for(i=0;i<3;++i){
for(i=0;i<3;++i)
{
for(j=0;j<4;++j)
{
log_verbose("Testing %s \n", austrdup(dataTable[i][j]));
u_uastrcpy(temp, "");
u_strcpy(temp,dataTable[i][j]);
log_verbose("Testing %s \n", austrdup(dataTable[i][j]));
u_uastrcpy(temp, "");
u_strcpy(temp,dataTable[i][j]);
if(u_strcmp(temp,dataTable[i][j])!=0)
log_err("something threw an error in u_strcpy() or u_strcmp()\n");
if(u_strcmp(temp,dataTable[i][j])!=0)
log_err("something threw an error in u_strcpy() or u_strcmp()\n");
}
}
log_verbose("testing u_strcat()\n");
i=0;
for(j=0; j<2;++j)
@ -674,7 +677,7 @@ static void TestStringFunctions()
u_strcat(temp,dataTable[i+1][j]);
if(u_strcmp(temp,dataTable[i+2][j])!=0)
log_err("something threw an error in u_strcat()\n");
}
log_verbose("Testing u_strncmp()\n");
for(i=0,j=0;j<4; ++j)
@ -683,18 +686,18 @@ static void TestStringFunctions()
if(u_strncmp(dataTable[i][j],dataTable[i+2][j],k)!=0)
log_err("Something threw an error in u_strncmp\n");
}
log_verbose("Testing u_strncat \n");
for(i=0,j=0;j<4; ++j)
{
{
k=u_strlen(dataTable[i][j]);
u_uastrcpy(temp,"");
if(u_strcmp(u_strncat(temp,dataTable[i+2][j],k),dataTable[i][j])!=0)
log_err("something threw an error in u_strncat or u_uastrcpy()\n");
}
log_verbose("Testing u_strncpy()\n");
@ -707,9 +710,9 @@ static void TestStringFunctions()
if(u_strcmp(temp,dataTable[i][j])!=0)
log_err("something threw an error in u_strncpy()\n");
}
log_verbose("Testing if u_strchr() works fine\n");
for(i=2,j=0;j<4;j++)
{
UChar *findPtr = u_strchr(dataTable[i][j],'_');
@ -734,74 +737,76 @@ static void TestStringFunctions()
log_verbose("Testing u_uastrncpy() and u_uastrcpy()");
{
UChar *result=0;
UChar subString[5];
UChar uchars[]={0x61, 0x62, 0x63, 0x00};
u_uastrcpy(temp, "abc");
if(u_strcmp(temp, uchars) != 0){
log_err("There is an error in u_uastrcpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
UChar *result=0;
UChar subString[5];
UChar uchars[]={0x61, 0x62, 0x63, 0x00};
u_uastrcpy(temp, "abc");
if(u_strcmp(temp, uchars) != 0) {
log_err("There is an error in u_uastrcpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
}
temp[0] = 0xFB; /* load garbage into it */
temp[1] = 0xFB;
temp[2] = 0xFB;
temp[3] = 0xFB;
u_uastrncpy(temp, "abcabcabc", 3);
if(u_strncmp(uchars, temp, 3) != 0){
log_err("There is an error in u_uastrncpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
}
if(temp[3] != 0xFB) {
log_err("u_austrncpy wrote past it's bounds. Expected undisturbed byte at 3\n");
}
/*Testing u_strchr()*/
log_verbose("Testing u_strchr\n");
temp[0]=0x42;
temp[1]=0x62;
temp[2]=0x62;
temp[3]=0x63;
temp[4]=0xd841;
temp[5]=0xd841;
temp[6]=0xdc02;
temp[7]=0;
result=u_strchr(temp, (UChar)0x62);
if(result != temp+1){
log_err("There is an error in u_strchr() Expected match at position 1 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
/*Testing u_strstr()*/
log_verbose("Testing u_strstr\n");
subString[0]=0x62;
subString[1]=0x63;
subString[2]=0;
result=u_strstr(temp, subString);
if(result != temp+2){
log_err("There is an error in u_strstr() Expected match at position 2 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strstr(temp, subString+2); /* subString+2 is an empty string */
if(result != temp){
log_err("There is an error in u_strstr() Expected match at position 0 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strstr(subString, temp);
if(result != NULL){
log_err("There is an error in u_strstr() Expected NULL \"not found\" Got non-NULL \"found\" result\n");
}
/*Testing u_strchr32*/
log_verbose("Testing u_strchr32\n");
result=u_strchr32(temp, (UChar32)0x62);
if(result != temp+1){
log_err("There is an error in u_strchr32() Expected match at position 1 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strchr32(temp, (UChar32)0xfb);
if(result != NULL){
log_err("There is an error in u_strchr32() Expected NULL \"not found\" Got non-NULL \"found\" result\n");
}
result=u_strchr32(temp, (UChar32)0x20402);
if(result != temp+5){
log_err("There is an error in u_strchr32() Expected match at position 5 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
}
temp[0] = 0xFB; /* load garbage into it */
temp[1] = 0xFB;
temp[2] = 0xFB;
temp[3] = 0xFB;
u_uastrncpy(temp, "abcabcabc", 3);
if(u_strncmp(uchars, temp, 3) != 0){
log_err("There is an error in u_uastrncpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
}
if(temp[3] != 0xFB) {
log_err("u_austrncpy wrote past it's bounds. Expected undisturbed byte at 3\n");
}
/*Testing u_strchr()*/
log_verbose("Testing u_strchr\n");
temp[0]=0x42;
temp[1]=0x62;
temp[2]=0x62;
temp[3]=0x63;
temp[4]=0xd841;
temp[5]=0xd841;
temp[6]=0xdc02;
temp[7]=0;
result=u_strchr(temp, (UChar)0x62);
if(result != temp+1){
log_err("There is an error in u_strchr() Expected match at position 1 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
/*Testing u_strstr()*/
log_verbose("Testing u_strstr\n");
subString[0]=0x62;
subString[1]=0x63;
subString[2]=0;
result=u_strstr(temp, subString);
if(result != temp+2){
log_err("There is an error in u_strstr() Expected match at position 2 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strstr(temp, subString+2); /* subString+2 is an empty string */
if(result != temp){
log_err("There is an error in u_strstr() Expected match at position 0 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strstr(subString, temp);
if(result != NULL){
log_err("There is an error in u_strstr() Expected NULL \"not found\" Got non-NULL \"found\" result\n");
}
/*Testing u_strchr32*/
log_verbose("Testing u_strchr32\n");
result=u_strchr32(temp, (UChar32)0x62);
if(result != temp+1){
log_err("There is an error in u_strchr32() Expected match at position 1 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
result=u_strchr32(temp, (UChar32)0xfb);
if(result != NULL){
log_err("There is an error in u_strchr32() Expected NULL \"not found\" Got non-NULL \"found\" result\n");
}
result=u_strchr32(temp, (UChar32)0x20402);
if(result != temp+5){
log_err("There is an error in u_strchr32() Expected match at position 5 Got %ld (pointer 0x%lx)\n", result-temp, result);
}
}
cleanUpDataTable();
}
/* test u_charName() -------------------------------------------------------- */

View file

@ -18,8 +18,8 @@
#define _CUNDTST
U_CFUNC void setUpDataTable(void);
U_CFUNC void cleanUpDataTable(void);
static void setUpDataTable(void);
static void cleanUpDataTable(void);
static void TestUpperLower(void);
static void TestLetterNumber(void);