2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-1999, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CINTLTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
* Name Description
|
|
|
|
* Madhu Katragadda Creation
|
|
|
|
*********************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*The main root for C API tests*/
|
|
|
|
|
2000-08-28 21:43:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-08-15 02:39:18 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
2000-08-15 02:39:18 +00:00
|
|
|
U_CDECL_BEGIN
|
2000-07-06 23:01:50 +00:00
|
|
|
#include "cucdtst.h"
|
2000-08-15 02:39:18 +00:00
|
|
|
U_CDECL_END
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uchar.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/ucnv.h"
|
2000-03-29 21:48:44 +00:00
|
|
|
#include "unicode/ures.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-28 20:24:40 +00:00
|
|
|
#ifdef XP_MAC_CONSOLE
|
|
|
|
# include <console.h>
|
|
|
|
#endif
|
|
|
|
|
2000-08-14 23:14:23 +00:00
|
|
|
U_CAPI void U_EXPORT2 ucnv_orphanAllConverters();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static char* _testDirectory=NULL;
|
2000-09-21 18:41:55 +00:00
|
|
|
|
|
|
|
int main(int argc, const char* const argv[])
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-08-11 04:29:07 +00:00
|
|
|
int nerrors;
|
1999-12-08 00:15:46 +00:00
|
|
|
TestNode *root;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
/* initial check for the default converter */
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
2000-03-29 21:48:44 +00:00
|
|
|
UResourceBundle *rb;
|
2000-08-28 20:24:40 +00:00
|
|
|
UConverter *cnv;
|
2000-09-21 18:41:55 +00:00
|
|
|
|
2000-08-28 20:24:40 +00:00
|
|
|
#ifdef XP_MAC_CONSOLE
|
2000-09-21 18:41:55 +00:00
|
|
|
argc = ccommand((char***)&argv);
|
2000-08-28 20:24:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
cnv = ucnv_open(NULL, &errorCode);
|
1999-12-08 00:15:46 +00:00
|
|
|
if(cnv != NULL) {
|
1999-12-09 01:31:44 +00:00
|
|
|
/* ok */
|
1999-12-08 00:15:46 +00:00
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"*** Failure! The default converter cannot be opened.\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-29 21:48:44 +00:00
|
|
|
/* try more data */
|
|
|
|
cnv = ucnv_open("iso-8859-7", &errorCode);
|
|
|
|
if(cnv != 0) {
|
|
|
|
/* ok */
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"*** Failure! The converter for iso-8859-7 cannot be opened.\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
rb = ures_open(NULL, "en", &errorCode);
|
2000-03-29 21:48:44 +00:00
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* ok */
|
|
|
|
ures_close(rb);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"*** Failure! The \"en\" locale resource bundle cannot be opened.\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:05:21 +00:00
|
|
|
fprintf(stderr, "Default locale for this run is %s\n", uloc_getDefault());
|
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
root = NULL;
|
|
|
|
addAllTests(&root);
|
2000-09-21 18:41:55 +00:00
|
|
|
nerrors = processArgs(root, argc, argv);
|
2000-07-06 23:01:50 +00:00
|
|
|
cleanUpTestTree(root);
|
|
|
|
cleanUpDataTable();
|
2000-09-21 18:41:55 +00:00
|
|
|
#ifdef CTST_LEAK_CHECK
|
2000-07-06 23:01:50 +00:00
|
|
|
ctst_freeAll();
|
2000-08-11 04:29:07 +00:00
|
|
|
|
2000-08-14 23:14:23 +00:00
|
|
|
/* To check for leaks */
|
|
|
|
|
|
|
|
ucnv_flushCache();
|
|
|
|
ucnv_orphanAllConverters(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
|
|
|
|
/* above function must be enabled in ucnv_bld.c */
|
|
|
|
#endif
|
|
|
|
|
2000-08-11 04:29:07 +00:00
|
|
|
return nerrors ? 1 : 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath )
|
|
|
|
{
|
2000-03-22 01:57:16 +00:00
|
|
|
char mainDirBuffer[200];
|
2000-05-15 18:39:17 +00:00
|
|
|
char* mainDir = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
const char inpSepChar = '|';
|
|
|
|
char* tmp;
|
|
|
|
int32_t lenMainDir;
|
|
|
|
int32_t lenRelPath ;
|
|
|
|
|
1999-10-14 19:10:43 +00:00
|
|
|
#if defined(_WIN32) || defined(WIN32) || defined(__OS2__) || defined(OS2)
|
2000-11-28 02:11:23 +00:00
|
|
|
/* This should always be u_getDataDirectory().
|
|
|
|
* getenv should not be used
|
|
|
|
*/
|
|
|
|
/*mainDir = getenv("ICU_DATA");*/
|
|
|
|
mainDir= u_getDataDirectory();
|
|
|
|
if(mainDir!=NULL) {
|
1999-10-14 19:10:43 +00:00
|
|
|
strcpy(mainDirBuffer, mainDir);
|
2000-08-15 01:06:38 +00:00
|
|
|
strcat(mainDirBuffer, "..\\..");
|
1999-10-14 19:10:43 +00:00
|
|
|
} else {
|
|
|
|
mainDirBuffer[0]='\0';
|
|
|
|
}
|
|
|
|
mainDir=mainDirBuffer;
|
1999-08-16 21:50:52 +00:00
|
|
|
#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;
|
|
|
|
#else
|
2000-03-22 01:57:16 +00:00
|
|
|
strcpy(mainDirBuffer, u_getDataDirectory());
|
|
|
|
strcat(mainDirBuffer, ".." U_FILE_SEP_STRING);
|
|
|
|
mainDir = mainDirBuffer;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
lenMainDir = strlen( mainDir );
|
2000-03-22 01:57:16 +00:00
|
|
|
if(lenMainDir > 0 && mainDir[lenMainDir - 1] != U_FILE_SEP_CHAR) {
|
|
|
|
mainDir[lenMainDir++] = U_FILE_SEP_CHAR;
|
|
|
|
mainDir[lenMainDir] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (relPath[0] == '|') relPath++;
|
|
|
|
lenRelPath = strlen( relPath );
|
1999-08-16 21:50:52 +00:00
|
|
|
if (maxsize < lenMainDir + lenRelPath + 2) { fullname[0] = 0; return; }
|
|
|
|
strcpy( fullname, mainDir );
|
2000-08-15 00:17:10 +00:00
|
|
|
/*strcat( fullname, U_FILE_SEP_STRING );*/
|
1999-08-16 21:50:52 +00:00
|
|
|
strcat( fullname, relPath );
|
|
|
|
strchr( fullname, inpSepChar );
|
|
|
|
tmp = strchr(fullname, inpSepChar);
|
|
|
|
while (tmp) {
|
2000-03-22 01:57:16 +00:00
|
|
|
*tmp = U_FILE_SEP_CHAR;
|
1999-08-16 21:50:52 +00:00
|
|
|
tmp = strchr( tmp+1, inpSepChar );
|
|
|
|
}
|
|
|
|
}
|
2000-03-22 01:57:16 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const char*
|
|
|
|
ctest_getTestDirectory()
|
|
|
|
{
|
|
|
|
if (_testDirectory == NULL)
|
|
|
|
{
|
2000-06-30 21:35:03 +00:00
|
|
|
#if defined(_AIX) || defined(U_SOLARIS) || defined(U_LINUX) || defined(HPUX) || defined(POSIX) || defined(OS390)
|
2000-08-29 07:28:22 +00:00
|
|
|
ctest_setTestDirectory("test|testdata|");
|
2000-02-16 22:38:38 +00:00
|
|
|
#else
|
|
|
|
ctest_setTestDirectory("icu|source|test|testdata|");
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
return _testDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ctest_setTestDirectory(const char* newDir)
|
|
|
|
{
|
|
|
|
char newTestDir[256];
|
|
|
|
ctest_pathnameInContext(newTestDir, sizeof(newTestDir), newDir);
|
|
|
|
if(_testDirectory != NULL)
|
|
|
|
free(_testDirectory);
|
|
|
|
_testDirectory = (char*) malloc(sizeof(char*) * (strlen(newTestDir) + 1));
|
|
|
|
strcpy(_testDirectory, newTestDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *austrdup(const UChar* unichars)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
char *newString;
|
|
|
|
|
|
|
|
length = u_strlen ( unichars );
|
2000-07-06 23:01:50 +00:00
|
|
|
/*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */
|
|
|
|
newString = (char*)ctst_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if ( newString == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
u_austrcpy ( newString, unichars );
|
|
|
|
|
|
|
|
return newString;
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
|
|
|
|
#define CTST_MAX_ALLOC 10000
|
|
|
|
static void * ctst_allocated_stuff[CTST_MAX_ALLOC];
|
|
|
|
static int ctst_allocated = 0;
|
2000-09-21 18:41:55 +00:00
|
|
|
static UBool ctst_free = 0;
|
2000-07-06 23:01:50 +00:00
|
|
|
|
|
|
|
void *ctst_malloc(size_t size) {
|
|
|
|
ctst_allocated ++;
|
|
|
|
if(ctst_allocated == CTST_MAX_ALLOC) {
|
|
|
|
ctst_allocated = 0;
|
|
|
|
ctst_free = 1;
|
|
|
|
}
|
|
|
|
if(ctst_free == 1) {
|
|
|
|
free(ctst_allocated_stuff[ctst_allocated]);
|
|
|
|
}
|
|
|
|
ctst_allocated_stuff[ctst_allocated] = malloc(size);
|
|
|
|
return ctst_allocated_stuff[ctst_allocated];
|
|
|
|
}
|
|
|
|
|
2000-09-21 18:41:55 +00:00
|
|
|
#ifdef CTST_LEAK_CHECK
|
2000-07-06 23:01:50 +00:00
|
|
|
void ctst_freeAll() {
|
|
|
|
int i;
|
|
|
|
if(ctst_free == 0) {
|
|
|
|
for(i=0; i<ctst_allocated; i++) {
|
|
|
|
free(ctst_allocated_stuff[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i=0; i<CTST_MAX_ALLOC; i++) {
|
|
|
|
free(ctst_allocated_stuff[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-25 20:56:12 +00:00
|
|
|
#endif
|