2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2001-07-31 23:32:59 +00:00
|
|
|
* COPYRIGHT:
|
2007-12-14 00:46:21 +00:00
|
|
|
* Copyright (c) 1997-2007, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CINTLTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
2000-12-15 19:16:43 +00:00
|
|
|
* Name Description
|
1999-08-16 21:50:52 +00:00
|
|
|
* 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"
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
2004-04-28 05:31:02 +00:00
|
|
|
#include "cstring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
2001-08-24 02:49:04 +00:00
|
|
|
#include "umutex.h"
|
2004-04-28 05:31:02 +00:00
|
|
|
#include "uassert.h"
|
2005-03-31 00:19:21 +00:00
|
|
|
#include "cmemory.h"
|
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"
|
2001-08-24 02:49:04 +00:00
|
|
|
#include "unicode/uclean.h"
|
2003-09-22 18:48:31 +00:00
|
|
|
#include "unicode/ucal.h"
|
2003-09-20 01:21:23 +00:00
|
|
|
#include "uoptions.h"
|
2005-07-09 03:15:06 +00:00
|
|
|
#include "putilimp.h" /* for uprv_getUTCtime() */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-28 20:24:40 +00:00
|
|
|
#ifdef XP_MAC_CONSOLE
|
|
|
|
# include <console.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 01:06:41 +00:00
|
|
|
#define CTST_LEAK_CHECK 1
|
2001-08-24 02:49:04 +00:00
|
|
|
#ifdef CTST_LEAK_CHECK
|
2001-10-10 00:54:27 +00:00
|
|
|
U_CFUNC void ctst_freeAll(void);
|
2001-08-24 02:49:04 +00:00
|
|
|
#endif
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
static char* _testDataPath=NULL;
|
2000-09-21 18:41:55 +00:00
|
|
|
|
2001-07-31 17:29:43 +00:00
|
|
|
/*
|
|
|
|
* Forward Declarations
|
|
|
|
*/
|
2001-08-18 01:05:52 +00:00
|
|
|
void ctest_setICU_DATA(void);
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2002-04-25 21:49:16 +00:00
|
|
|
|
|
|
|
|
2002-09-20 18:03:18 +00:00
|
|
|
#if UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
# define TRY_CNV_1 "iso-8859-1"
|
|
|
|
# define TRY_CNV_2 "ibm-1208"
|
|
|
|
#else
|
|
|
|
# define TRY_CNV_1 "iso-8859-7"
|
|
|
|
# define TRY_CNV_2 "sjis"
|
|
|
|
#endif
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
static int gOrigArgc;
|
|
|
|
static const char* const * gOrigArgv;
|
2003-09-20 01:21:23 +00:00
|
|
|
|
2000-09-21 18:41:55 +00:00
|
|
|
int main(int argc, const char* const argv[])
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-02-20 17:36:11 +00:00
|
|
|
int nerrors = 0;
|
2004-10-11 21:23:12 +00:00
|
|
|
UBool defaultDataFound;
|
1999-12-08 00:15:46 +00:00
|
|
|
TestNode *root;
|
2002-09-24 18:58:56 +00:00
|
|
|
const char *warnOrErr = "Failure";
|
2005-03-16 00:33:39 +00:00
|
|
|
UDate startTime, endTime;
|
|
|
|
int32_t diffTime;
|
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
|
|
|
|
2003-09-20 01:21:23 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
2003-08-14 21:34:54 +00:00
|
|
|
|
2005-07-09 03:15:06 +00:00
|
|
|
startTime = uprv_getUTCtime();
|
2005-03-16 00:33:39 +00:00
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
gOrigArgc = argc;
|
|
|
|
gOrigArgv = argv;
|
|
|
|
if (!initArgs(argc, argv)) {
|
|
|
|
/* Error already displayed. */
|
|
|
|
return -1;
|
2003-09-22 18:48:31 +00:00
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
|
|
|
|
/* Check whether ICU will initialize without forcing the build data directory into
|
|
|
|
* the ICU_DATA path. Success here means either the data dll contains data, or that
|
|
|
|
* this test program was run with ICU_DATA set externally. Failure of this check
|
|
|
|
* is normal when ICU data is not packaged into a shared library.
|
|
|
|
*
|
|
|
|
* Whether or not this test succeeds, we want to cleanup and reinitialize
|
|
|
|
* with a data path so that data loading from individual files can be tested.
|
2003-09-20 01:21:23 +00:00
|
|
|
*/
|
2007-12-07 10:49:34 +00:00
|
|
|
defaultDataFound = TRUE;
|
|
|
|
u_init(&errorCode);
|
|
|
|
if (U_FAILURE(errorCode)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"#### Note: ICU Init without build-specific setDataDirectory() failed. %s\n", u_errorName(errorCode));
|
|
|
|
defaultDataFound = FALSE;
|
2002-09-24 18:58:56 +00:00
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
u_cleanup();
|
2003-09-22 18:48:31 +00:00
|
|
|
|
2003-09-20 01:21:23 +00:00
|
|
|
while (REPEAT_TESTS > 0) { /* Loop runs once per complete execution of the tests
|
|
|
|
* used for -r (repeat) test option. */
|
2007-12-07 10:49:34 +00:00
|
|
|
if (!initArgs(argc, argv)) {
|
|
|
|
/* Error already displayed. */
|
|
|
|
return -1;
|
2003-09-15 22:50:31 +00:00
|
|
|
}
|
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
|
2003-08-14 21:34:54 +00:00
|
|
|
/* Initialize ICU */
|
2004-10-11 21:23:12 +00:00
|
|
|
if (!defaultDataFound) {
|
|
|
|
ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */
|
|
|
|
}
|
2003-08-14 21:34:54 +00:00
|
|
|
u_init(&errorCode);
|
|
|
|
if (U_FAILURE(errorCode)) {
|
2002-03-20 18:36:17 +00:00
|
|
|
fprintf(stderr,
|
2003-08-16 02:17:56 +00:00
|
|
|
"#### ERROR! %s: u_init() failed with status = \"%s\".\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
|
2007-12-07 10:49:34 +00:00
|
|
|
if(!WARN_ON_MISSING_DATA) {
|
2003-08-14 21:34:54 +00:00
|
|
|
fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
|
|
|
u_cleanup();
|
|
|
|
return 1;
|
|
|
|
}
|
2002-03-20 18:36:17 +00:00
|
|
|
}
|
2003-08-16 02:17:56 +00:00
|
|
|
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2000-03-29 21:48:44 +00:00
|
|
|
|
2002-01-16 04:33:33 +00:00
|
|
|
/* try more data */
|
2002-09-20 18:03:18 +00:00
|
|
|
cnv = ucnv_open(TRY_CNV_2, &errorCode);
|
2002-01-16 04:33:33 +00:00
|
|
|
if(cnv != 0) {
|
|
|
|
/* ok */
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
2002-09-24 18:58:56 +00:00
|
|
|
"*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n"
|
2002-01-16 04:33:33 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
2002-09-24 18:58:56 +00:00
|
|
|
"*** check that the data files are present.\n", warnOrErr);
|
2007-12-07 10:49:34 +00:00
|
|
|
if(!WARN_ON_MISSING_DATA) {
|
2002-12-13 04:05:50 +00:00
|
|
|
fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
2003-08-14 21:34:54 +00:00
|
|
|
u_cleanup();
|
2002-12-13 04:05:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
}
|
2000-03-29 21:48:44 +00:00
|
|
|
|
2002-01-16 04:33:33 +00:00
|
|
|
rb = ures_open(NULL, "en", &errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* ok */
|
|
|
|
ures_close(rb);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
2002-09-24 18:58:56 +00:00
|
|
|
"*** %s! The \"en\" locale resource bundle cannot be opened.\n"
|
2002-01-16 04:33:33 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
2002-09-24 18:58:56 +00:00
|
|
|
"*** check that the data files are present.\n", warnOrErr);
|
2007-12-07 10:49:34 +00:00
|
|
|
if(!WARN_ON_MISSING_DATA) {
|
2002-12-13 04:05:50 +00:00
|
|
|
fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
2003-08-14 21:34:54 +00:00
|
|
|
u_cleanup();
|
2002-12-13 04:05:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
}
|
|
|
|
|
2006-11-07 18:52:45 +00:00
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
rb = ures_open(NULL, NULL, &errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* ok */
|
|
|
|
if (errorCode == U_USING_DEFAULT_WARNING || errorCode == U_USING_FALLBACK_WARNING) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"#### Note: The default locale %s is not available\n", uloc_getDefault());
|
|
|
|
}
|
|
|
|
ures_close(rb);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault());
|
2007-12-07 10:49:34 +00:00
|
|
|
if(!WARN_ON_MISSING_DATA) {
|
2006-11-07 18:52:45 +00:00
|
|
|
fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n"
|
|
|
|
"*** purposely removed, to continue test anyway.\n");
|
|
|
|
u_cleanup();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault());
|
2000-06-09 00:05:21 +00:00
|
|
|
|
2003-09-20 01:21:23 +00:00
|
|
|
/* Build a tree of all tests.
|
|
|
|
* Subsequently will be used to find / iterate the tests to run */
|
2002-01-16 04:33:33 +00:00
|
|
|
root = NULL;
|
|
|
|
addAllTests(&root);
|
2003-09-20 01:21:23 +00:00
|
|
|
|
|
|
|
/* Tests acutally run HERE. TODO: separate command line option parsing & setting from test execution!! */
|
2007-12-07 10:49:34 +00:00
|
|
|
nerrors = runTestRequest(root, argc, argv);
|
2003-09-20 01:21:23 +00:00
|
|
|
|
2002-01-16 04:33:33 +00:00
|
|
|
if (--REPEAT_TESTS > 0) {
|
|
|
|
printf("Repeating tests %d more time(s)\n", REPEAT_TESTS);
|
|
|
|
}
|
|
|
|
cleanUpTestTree(root);
|
2003-09-20 01:21:23 +00:00
|
|
|
|
2000-09-21 18:41:55 +00:00
|
|
|
#ifdef CTST_LEAK_CHECK
|
2002-01-16 04:33:33 +00:00
|
|
|
ctst_freeAll();
|
|
|
|
/* To check for leaks */
|
|
|
|
u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
|
2000-08-14 23:14:23 +00:00
|
|
|
#endif
|
2003-09-20 01:21:23 +00:00
|
|
|
|
|
|
|
} /* End of loop that repeats the entire test, if requested. (Normally doesn't loop) */
|
2000-08-14 23:14:23 +00:00
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
if (ALLOCATION_COUNT > 0) {
|
|
|
|
fprintf(stderr, "There were %d blocks leaked!\n", ALLOCATION_COUNT);
|
|
|
|
nerrors++;
|
|
|
|
}
|
2005-07-09 03:15:06 +00:00
|
|
|
endTime = uprv_getUTCtime();
|
2005-03-16 00:33:39 +00:00
|
|
|
diffTime = (int32_t)(endTime - startTime);
|
|
|
|
printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
|
2005-07-14 06:03:34 +00:00
|
|
|
(int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR),
|
|
|
|
(int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE),
|
|
|
|
(int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND),
|
|
|
|
(int)(diffTime%U_MILLIS_PER_SECOND));
|
2005-03-16 00:33:39 +00:00
|
|
|
|
2000-08-11 04:29:07 +00:00
|
|
|
return nerrors ? 1 : 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-08-28 15:55:37 +00:00
|
|
|
/*
|
2002-07-25 18:32:04 +00:00
|
|
|
static void ctest_appendToDataDirectory(const char *toAppend)
|
2002-07-17 03:56:50 +00:00
|
|
|
{
|
|
|
|
const char *oldPath ="";
|
|
|
|
char newBuf [1024];
|
|
|
|
char *newPath = newBuf;
|
|
|
|
int32_t oldLen;
|
|
|
|
int32_t newLen;
|
|
|
|
|
|
|
|
if((toAppend == NULL) || (*toAppend == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldPath = u_getDataDirectory();
|
|
|
|
if( (oldPath==NULL) || (*oldPath == 0)) {
|
|
|
|
u_setDataDirectory(toAppend);
|
|
|
|
} else {
|
|
|
|
oldLen = strlen(oldPath);
|
|
|
|
newLen = strlen(toAppend)+1+oldLen;
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(newLen > 1022)
|
|
|
|
{
|
2002-07-17 22:21:34 +00:00
|
|
|
newPath = (char *)ctst_malloc(newLen);
|
2002-07-17 03:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(newPath, oldPath);
|
|
|
|
strcpy(newPath+oldLen, U_PATH_SEP_STRING);
|
|
|
|
strcpy(newPath+oldLen+1, toAppend);
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
u_setDataDirectory(newPath);
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(newPath != newBuf)
|
|
|
|
{
|
|
|
|
free(newPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-28 15:55:37 +00:00
|
|
|
*/
|
2002-07-17 03:56:50 +00:00
|
|
|
|
2003-04-24 23:08:42 +00:00
|
|
|
/* returns the path to icu/source/data */
|
|
|
|
const char * ctest_dataSrcDir()
|
|
|
|
{
|
|
|
|
static const char *dataSrcDir = NULL;
|
|
|
|
|
2003-06-02 03:38:31 +00:00
|
|
|
if(dataSrcDir) {
|
2003-04-24 23:08:42 +00:00
|
|
|
return dataSrcDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst
|
|
|
|
// to point to the top of the build hierarchy, which may or
|
|
|
|
// may not be the same as the source directory, depending on
|
|
|
|
// the configure options used. At any rate,
|
|
|
|
// set the data path to the built data from this directory.
|
|
|
|
// The value is complete with quotes, so it can be used
|
|
|
|
// as-is as a string constant.
|
|
|
|
*/
|
|
|
|
#if defined (U_TOPSRCDIR)
|
|
|
|
{
|
|
|
|
dataSrcDir = U_TOPSRCDIR U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* On Windows, the file name obtained from __FILE__ includes a full path.
|
|
|
|
* This file is "wherever\icu\source\test\cintltst\cintltst.c"
|
|
|
|
* Change to "wherever\icu\source\data"
|
|
|
|
*/
|
|
|
|
{
|
2003-06-02 03:38:31 +00:00
|
|
|
static char p[sizeof(__FILE__) + 20];
|
2003-04-24 23:08:42 +00:00
|
|
|
char *pBackSlash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
strcpy(p, __FILE__);
|
|
|
|
/* We want to back over three '\' chars. */
|
|
|
|
/* Only Windows should end up here, so looking for '\' is safe. */
|
|
|
|
for (i=1; i<=3; i++) {
|
|
|
|
pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
|
|
|
|
if (pBackSlash != NULL) {
|
|
|
|
*pBackSlash = 0; /* Truncate the string at the '\' */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBackSlash != NULL) {
|
|
|
|
/* We found and truncated three names from the path.
|
|
|
|
* Now append "source\data" and set the environment
|
|
|
|
*/
|
|
|
|
strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING );
|
2004-03-16 23:52:07 +00:00
|
|
|
dataSrcDir = p;
|
2003-06-02 03:38:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* __FILE__ on MSVC7 does not contain the directory */
|
2004-05-26 18:28:09 +00:00
|
|
|
FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
|
|
|
|
if (file) {
|
|
|
|
fclose(file);
|
|
|
|
dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
|
|
|
}
|
2003-04-24 23:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return dataSrcDir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
/* returns the path to icu/source/data/out */
|
|
|
|
const char *ctest_dataOutDir()
|
|
|
|
{
|
2002-07-17 22:21:34 +00:00
|
|
|
static const char *dataOutDir = NULL;
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(dataOutDir) {
|
|
|
|
return dataOutDir;
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
/* U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst
|
2002-04-02 02:55:31 +00:00
|
|
|
// to point to the top of the build hierarchy, which may or
|
|
|
|
// may not be the same as the source directory, depending on
|
|
|
|
// the configure options used. At any rate,
|
|
|
|
// set the data path to the built data from this directory.
|
|
|
|
// The value is complete with quotes, so it can be used
|
|
|
|
// as-is as a string constant.
|
|
|
|
*/
|
2001-11-02 02:24:15 +00:00
|
|
|
#if defined (U_TOPBUILDDIR)
|
2001-07-31 17:29:43 +00:00
|
|
|
{
|
2003-09-23 00:51:49 +00:00
|
|
|
dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
2001-09-18 21:02:14 +00:00
|
|
|
#else
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
/* On Windows, the file name obtained from __FILE__ includes a full path.
|
|
|
|
* This file is "wherever\icu\source\test\cintltst\cintltst.c"
|
|
|
|
* Change to "wherever\icu\source\data"
|
2001-07-31 17:29:43 +00:00
|
|
|
*/
|
|
|
|
{
|
2003-06-02 03:38:31 +00:00
|
|
|
static char p[sizeof(__FILE__) + 20];
|
2001-07-31 17:29:43 +00:00
|
|
|
char *pBackSlash;
|
|
|
|
int i;
|
2001-07-31 23:32:59 +00:00
|
|
|
|
2001-08-20 23:48:50 +00:00
|
|
|
strcpy(p, __FILE__);
|
2001-07-31 17:29:43 +00:00
|
|
|
/* We want to back over three '\' chars. */
|
|
|
|
/* Only Windows should end up here, so looking for '\' is safe. */
|
|
|
|
for (i=1; i<=3; i++) {
|
2001-08-20 23:48:50 +00:00
|
|
|
pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
|
2001-07-31 17:29:43 +00:00
|
|
|
if (pBackSlash != NULL) {
|
|
|
|
*pBackSlash = 0; /* Truncate the string at the '\' */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBackSlash != NULL) {
|
2001-07-31 23:32:59 +00:00
|
|
|
/* We found and truncated three names from the path.
|
2001-07-31 17:29:43 +00:00
|
|
|
* Now append "source\data" and set the environment
|
|
|
|
*/
|
2002-02-19 02:07:41 +00:00
|
|
|
strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING);
|
2004-03-16 23:52:07 +00:00
|
|
|
dataOutDir = p;
|
2003-06-02 03:38:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* __FILE__ on MSVC7 does not contain the directory */
|
2004-05-26 18:28:09 +00:00
|
|
|
FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
|
|
|
|
if (file) {
|
|
|
|
fclose(file);
|
|
|
|
dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
|
|
|
|
}
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-18 21:02:14 +00:00
|
|
|
#endif
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
return dataOutDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ctest_setICU_DATA - if the ICU_DATA environment variable is not already
|
|
|
|
* set, try to deduce the directory in which ICU was built,
|
|
|
|
* and set ICU_DATA to "icu/source/data" in that location.
|
|
|
|
* The intent is to allow the tests to have a good chance
|
|
|
|
* of running without requiring that the user manually set
|
|
|
|
* ICU_DATA. Common data isn't a problem, since it is
|
|
|
|
* picked up via a static (build time) reference, but the
|
|
|
|
* tests dynamically load some data.
|
|
|
|
*/
|
|
|
|
void ctest_setICU_DATA() {
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2001-07-31 17:29:43 +00:00
|
|
|
/* No location for the data dir was identifiable.
|
|
|
|
* Add other fallbacks for the test data location here if the need arises
|
|
|
|
*/
|
2004-01-08 22:33:17 +00:00
|
|
|
if (getenv("ICU_DATA") == NULL) {
|
|
|
|
/* If ICU_DATA isn't set, set it to the usual location */
|
|
|
|
u_setDataDirectory(ctest_dataOutDir());
|
|
|
|
}
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
/* These tests do cleanup and reinitialize ICU in the course of their operation.
|
|
|
|
* The ICU data directory must be preserved across these operations.
|
|
|
|
* Here is a helper function to assist with that.
|
|
|
|
*/
|
|
|
|
static char *safeGetICUDataDirectory() {
|
|
|
|
const char *dataDir = u_getDataDirectory(); /* Returned string vanashes with u_cleanup */
|
|
|
|
char *retStr = NULL;
|
|
|
|
if (dataDir != NULL) {
|
|
|
|
retStr = (char *)malloc(strlen(dataDir)+1);
|
|
|
|
strcpy(retStr, dataDir);
|
|
|
|
}
|
|
|
|
return retStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool ctest_resetICU() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
char *dataDir = safeGetICUDataDirectory();
|
|
|
|
|
|
|
|
u_cleanup();
|
|
|
|
if (!initArgs(gOrigArgc, gOrigArgv)) {
|
|
|
|
/* Error already displayed. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
u_setDataDirectory(dataDir);
|
2007-12-14 00:46:21 +00:00
|
|
|
free(dataDir);
|
2007-12-07 10:49:34 +00:00
|
|
|
u_init(&status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("u_init failed with %s\n", u_errorName(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-09-20 17:54:45 +00:00
|
|
|
UChar* CharsToUChars(const char* str) {
|
|
|
|
/* Might be faster to just use uprv_strlen() as the preflight len - liu */
|
|
|
|
int32_t len = u_unescape(str, 0, 0); /* preflight */
|
|
|
|
/* Do NOT use malloc() - we are supposed to be acting like user code! */
|
|
|
|
UChar *buf = (UChar*) malloc(sizeof(UChar) * (len + 1));
|
|
|
|
u_unescape(str, buf, len + 1);
|
|
|
|
return buf;
|
|
|
|
}
|
2001-07-31 17:29:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
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 */
|
2000-12-15 19:16:43 +00:00
|
|
|
|
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
|
|
|
|
2002-04-02 03:36:54 +00:00
|
|
|
char *aescstrdup(const UChar* unichars,int32_t length){
|
2001-03-13 23:43:54 +00:00
|
|
|
char *newString,*targetLimit,*target;
|
|
|
|
UConverterFromUCallback cb;
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *p;
|
2001-03-13 23:43:54 +00:00
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
2002-05-14 20:52:36 +00:00
|
|
|
#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
|
|
|
|
# ifdef OS390
|
|
|
|
static const char convName[] = "ibm-1047";
|
|
|
|
# else
|
|
|
|
static const char convName[] = "ibm-37";
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
static const char convName[] = "US-ASCII";
|
|
|
|
#endif
|
|
|
|
UConverter* conv = ucnv_open(convName, &errorCode);
|
2002-04-02 03:36:54 +00:00
|
|
|
if(length==-1){
|
|
|
|
length = u_strlen( unichars);
|
|
|
|
}
|
2001-03-14 02:29:54 +00:00
|
|
|
newString = (char*)ctst_malloc ( sizeof(char) * 8 * (length +1));
|
2001-03-13 23:43:54 +00:00
|
|
|
target = newString;
|
2001-03-14 02:29:54 +00:00
|
|
|
targetLimit = newString+sizeof(char) * 8 * (length +1);
|
2001-03-15 00:43:12 +00:00
|
|
|
ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_JAVA, &cb, &p, &errorCode);
|
2001-03-13 23:43:54 +00:00
|
|
|
ucnv_fromUnicode(conv,&target,targetLimit, &unichars, (UChar*)(unichars+length),NULL,TRUE,&errorCode);
|
2001-03-16 02:03:24 +00:00
|
|
|
ucnv_close(conv);
|
2001-03-13 23:43:54 +00:00
|
|
|
*target = '\0';
|
|
|
|
return newString;
|
|
|
|
}
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
const char* loadTestData(UErrorCode* err){
|
|
|
|
if( _testDataPath == NULL){
|
2004-12-02 07:09:05 +00:00
|
|
|
const char* directory=NULL;
|
|
|
|
UResourceBundle* test =NULL;
|
|
|
|
char* tdpath=NULL;
|
|
|
|
const char* tdrelativepath;
|
|
|
|
#if defined (U_TOPBUILDDIR)
|
|
|
|
tdrelativepath = "test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
|
|
|
directory = U_TOPBUILDDIR;
|
|
|
|
#else
|
|
|
|
tdrelativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
2002-07-17 03:56:50 +00:00
|
|
|
directory= ctest_dataOutDir();
|
2004-12-02 07:09:05 +00:00
|
|
|
#endif
|
2002-07-17 03:56:50 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
tdpath = (char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
|
|
|
|
|
|
|
|
|
|
|
|
/* u_getDataDirectory shoul return \source\data ... set the
|
|
|
|
* directory to ..\source\data\..\test\testdata\out\testdata
|
|
|
|
*
|
|
|
|
* Fallback: When Memory mapped file is built
|
|
|
|
* ..\source\data\out\..\..\test\testdata\out\testdata
|
|
|
|
*/
|
|
|
|
strcpy(tdpath, directory);
|
|
|
|
strcat(tdpath, tdrelativepath);
|
|
|
|
strcat(tdpath,"testdata");
|
2001-03-13 23:43:54 +00:00
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
test=ures_open(tdpath, "testtypes", err);
|
2002-07-29 21:04:18 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
/* Fall back did not succeed either so return */
|
|
|
|
if(U_FAILURE(*err)){
|
|
|
|
*err = U_FILE_ACCESS_ERROR;
|
2002-09-20 19:07:19 +00:00
|
|
|
log_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(*err));
|
2002-07-17 03:56:50 +00:00
|
|
|
return "";
|
2002-01-29 04:01:49 +00:00
|
|
|
}
|
|
|
|
ures_close(test);
|
2002-02-07 19:37:34 +00:00
|
|
|
_testDataPath = tdpath;
|
|
|
|
return _testDataPath;
|
2002-01-29 04:01:49 +00:00
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
return _testDataPath;
|
2002-01-29 04:01:49 +00:00
|
|
|
}
|
2001-03-13 23:43:54 +00:00
|
|
|
|
2003-10-07 21:50:15 +00:00
|
|
|
#define CTEST_MAX_TIMEZONE_SIZE 256
|
|
|
|
static UChar gOriginalTimeZone[CTEST_MAX_TIMEZONE_SIZE] = {0};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value.
|
|
|
|
* @param optionalTimeZone Set this to a requested timezone.
|
|
|
|
* Set to NULL to use the standard test timezone (Pacific Time)
|
|
|
|
*/
|
|
|
|
U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) {
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
UChar zoneID[CTEST_MAX_TIMEZONE_SIZE];
|
|
|
|
|
|
|
|
if (optionalTimeZone == NULL) {
|
|
|
|
optionalTimeZone = "America/Los_Angeles";
|
|
|
|
}
|
|
|
|
if (gOriginalTimeZone[0]) {
|
|
|
|
log_err("*** Error: time zone saved twice. New value will be %s\n",
|
|
|
|
optionalTimeZone);
|
|
|
|
}
|
|
|
|
ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
log_err("*** Error: Failed to save default time zone: %s\n",
|
|
|
|
u_errorName(*status));
|
|
|
|
*status = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1);
|
|
|
|
zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0;
|
|
|
|
ucal_setDefaultTimeZone(zoneID, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
log_err("*** Error: Failed to set default time zone to \"%s\": %s\n",
|
|
|
|
optionalTimeZone, u_errorName(*status));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this once get back the original timezone
|
|
|
|
*/
|
|
|
|
U_CFUNC void ctest_resetTimeZone(void) {
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
ucal_setDefaultTimeZone(gOriginalTimeZone, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("*** Error: Failed to reset default time zone: %s\n",
|
|
|
|
u_errorName(status));
|
|
|
|
}
|
|
|
|
/* Set to an empty state */
|
|
|
|
gOriginalTimeZone[0] = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-29 03:37:37 +00:00
|
|
|
#define CTST_MAX_ALLOC 8192
|
2001-08-24 02:49:04 +00:00
|
|
|
/* Array used as a queue */
|
2003-10-10 20:58:22 +00:00
|
|
|
static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
|
2000-07-06 23:01:50 +00:00
|
|
|
static int ctst_allocated = 0;
|
2001-08-24 02:49:04 +00:00
|
|
|
static UBool ctst_free = FALSE;
|
|
|
|
|
2000-07-06 23:01:50 +00:00
|
|
|
void *ctst_malloc(size_t size) {
|
2001-08-24 02:49:04 +00:00
|
|
|
if(ctst_allocated >= CTST_MAX_ALLOC - 1) {
|
2000-07-06 23:01:50 +00:00
|
|
|
ctst_allocated = 0;
|
2001-08-24 02:49:04 +00:00
|
|
|
ctst_free = TRUE;
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
2001-08-24 02:49:04 +00:00
|
|
|
if(ctst_allocated_stuff[ctst_allocated]) {
|
2000-07-06 23:01:50 +00:00
|
|
|
free(ctst_allocated_stuff[ctst_allocated]);
|
|
|
|
}
|
2001-08-24 02:49:04 +00:00
|
|
|
return ctst_allocated_stuff[ctst_allocated++] = malloc(size);
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
|
|
|
|
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]);
|
2003-10-10 20:58:22 +00:00
|
|
|
ctst_allocated_stuff[i] = NULL;
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i=0; i<CTST_MAX_ALLOC; i++) {
|
|
|
|
free(ctst_allocated_stuff[i]);
|
2003-10-10 20:58:22 +00:00
|
|
|
ctst_allocated_stuff[i] = NULL;
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-10 20:58:22 +00:00
|
|
|
ctst_allocated = 0;
|
2002-02-07 19:37:34 +00:00
|
|
|
_testDataPath=NULL;
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
2004-04-28 05:31:02 +00:00
|
|
|
|
|
|
|
#define VERBOSE_ASSERTIONS
|
|
|
|
|
|
|
|
U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) {
|
|
|
|
U_ASSERT(ec!=NULL);
|
|
|
|
if (U_FAILURE(*ec)) {
|
|
|
|
log_err("FAIL: %s (%s)\n", msg, u_errorName(*ec));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-05-19 17:28:20 +00:00
|
|
|
/* if 'condition' is a UBool, the compiler complains bitterly about
|
|
|
|
expressions like 'a > 0' which it evaluates as int */
|
|
|
|
U_CFUNC UBool assertTrue(const char* msg, int /*not UBool*/ condition) {
|
2004-04-28 05:31:02 +00:00
|
|
|
if (!condition) {
|
|
|
|
log_err("FAIL: assertTrue() failed: %s\n", msg);
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
log_verbose("Ok: %s\n", msg);
|
|
|
|
}
|
|
|
|
#endif
|
2004-05-19 17:28:20 +00:00
|
|
|
return (UBool)condition;
|
2004-04-28 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC UBool assertEquals(const char* message, const char* expected,
|
|
|
|
const char* actual) {
|
|
|
|
if (uprv_strcmp(expected, actual) != 0) {
|
|
|
|
log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n",
|
|
|
|
message, actual, expected);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
log_verbose("Ok: %s; got \"%s\"\n", message, actual);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-03-31 00:19:21 +00:00
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
* Time bomb - allows temporary behavior that expires at a given
|
|
|
|
* release
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
*/
|
2004-04-28 05:31:02 +00:00
|
|
|
|
2005-03-31 00:19:21 +00:00
|
|
|
U_CFUNC UBool isICUVersionAtLeast(const UVersionInfo x) {
|
|
|
|
UVersionInfo v;
|
|
|
|
u_getVersion(v);
|
|
|
|
return (uprv_memcmp(v, x, U_MAX_VERSION_LENGTH) >= 0);
|
|
|
|
}
|
2000-09-25 20:56:12 +00:00
|
|
|
#endif
|