ICU-1075 Change tests to try to run if ICU_DATA is not set in environment
X-SVN-Rev: 5394
This commit is contained in:
parent
6a2748274c
commit
09e1c00ed1
@ -39,6 +39,14 @@ U_CAPI void U_EXPORT2 ucnv_orphanAllConverters();
|
||||
|
||||
static char* _testDirectory=NULL;
|
||||
|
||||
/*
|
||||
* Forward Declarations
|
||||
*/
|
||||
void ctest_setICU_DATA();
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, const char* const argv[])
|
||||
{
|
||||
int nerrors;
|
||||
@ -49,6 +57,10 @@ int main(int argc, const char* const argv[])
|
||||
UResourceBundle *rb;
|
||||
UConverter *cnv;
|
||||
|
||||
|
||||
/* If no ICU_DATA environment was set, try to fake up one. */
|
||||
ctest_setICU_DATA();
|
||||
|
||||
#ifdef XP_MAC_CONSOLE
|
||||
argc = ccommand((char***)&argv);
|
||||
#endif
|
||||
@ -191,6 +203,79 @@ ctest_setTestDirectory(const char* newDir)
|
||||
strcpy(_testDirectory, newTestDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 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() {
|
||||
const char *original_ICU_DATA;
|
||||
|
||||
original_ICU_DATA = getenv("ICU_DATA");
|
||||
if (original_ICU_DATA != NULL) {
|
||||
/* If the user set ICU_DATA, don't second-guess him. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* U_SRCDATADIR is set by the makefiles on UNIXes when building cintltst and intltst
|
||||
* to point to the right place, "wherever/icu/source/data"
|
||||
* The value is complete with quotes, so it can be used as-is as a string constant.
|
||||
*/
|
||||
#if defined (U_SRCDATADIR)
|
||||
{
|
||||
static const char env_string = "ICU_DATA=" U_SRCDATADIR;
|
||||
_putenv(env_string);
|
||||
return
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
/* 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"
|
||||
*/
|
||||
{
|
||||
char *p;
|
||||
char *pBackSlash;
|
||||
int i;
|
||||
|
||||
p = ctst_malloc(strlen("ICU_DATA=\\data") + strlen(__FILE__) + 1);
|
||||
strcpy(p, "ICU_DATA=");
|
||||
strcat(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, '\\');
|
||||
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, "\\data");
|
||||
_putenv(p); /* p is "ICU_DATA=wherever\icu\source\data" */
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* No location for the data dir was identifiable.
|
||||
* Add other fallbacks for the test data location here if the need arises
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char *austrdup(const UChar* unichars)
|
||||
{
|
||||
int length;
|
||||
|
@ -498,6 +498,78 @@ IntlTest::setTestDirectory(const char* newDir)
|
||||
strcpy(_testDirectory, newTestDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* IntlTest::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.
|
||||
*
|
||||
* TODO: The use of ICU_DATA can be eliminated once the proposed
|
||||
* udata_setApplicationData() API exists.
|
||||
*/
|
||||
void IntlTest::setICU_DATA() {
|
||||
const char *original_ICU_DATA;
|
||||
|
||||
original_ICU_DATA = getenv("ICU_DATA");
|
||||
if (original_ICU_DATA != NULL) {
|
||||
/* If the user set ICU_DATA, don't second-guess him. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* U_SRCDATADIR is set by the makefiles on UNIXes when building cintltst and intltst
|
||||
* to point to the right place, "wherever/icu/source/data"
|
||||
* The value is complete with quotes, so it can be used as-is as a string constant.
|
||||
*/
|
||||
#if defined (U_SRCDATADIR)
|
||||
{
|
||||
static const char env_string = "ICU_DATA=" U_SRCDATADIR;
|
||||
putenv(env_string);
|
||||
return
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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"
|
||||
*/
|
||||
{
|
||||
char *p;
|
||||
char *pBackSlash;
|
||||
int i;
|
||||
|
||||
p = new char [strlen("ICU_DATA=\\data") + strlen(__FILE__) + 1]; // <<< LEAK
|
||||
strcpy(p, "ICU_DATA=");
|
||||
strcat(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, '\\');
|
||||
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, "\\data");
|
||||
putenv(p); /* p is "ICU_DATA=wherever\icu\source\data" */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* No location for the data dir was identifiable.
|
||||
* Add other fallbacks for the test data location here if the need arises
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
static const int32_t indentLevel_offset = 3;
|
||||
@ -950,6 +1022,9 @@ main(int argc, char* argv[])
|
||||
UBool name = FALSE;
|
||||
UBool leaks = FALSE;
|
||||
|
||||
// If user didn't set ICU_DATA, attempt to generate one.
|
||||
IntlTest::setICU_DATA();
|
||||
|
||||
/* ### TODO: remove when the new normalization implementation is finished */
|
||||
if(argc>1 && argv[1][0]=='N') {
|
||||
unorm_setNewImplementation((UBool)(argv[1][1]=='+'));
|
||||
|
@ -12,6 +12,7 @@
|
||||
#define _INTLTEST
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/unistr.h"
|
||||
@ -156,6 +157,8 @@ protected:
|
||||
static void setTestDirectory(const char* newDir);
|
||||
/*The function to get the Test Directory*/
|
||||
static const char* getTestDirectory(void);
|
||||
public:
|
||||
static void IntlTest::setICU_DATA(); // Set up ICU_DATA if necessary.
|
||||
|
||||
public:
|
||||
UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks
|
||||
|
Loading…
Reference in New Issue
Block a user