diff --git a/icu4c/source/test/cintltst/callcoll.c b/icu4c/source/test/cintltst/callcoll.c index 12b9a395adc..ce90476adcd 100644 --- a/icu4c/source/test/cintltst/callcoll.c +++ b/icu4c/source/test/cintltst/callcoll.c @@ -287,7 +287,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC } /* convert the strings to UTF-8 and do try comparing with char iterator */ - if(QUICK <= 0) { /*!QUICK*/ + if(getTestOption(QUICK_OPTION) <= 0) { /*!QUICK*/ char utf8Source[256], utf8Target[256]; int32_t utf8SourceLen = 0, utf8TargetLen = 0; u_strToUTF8(utf8Source, 256, &utf8SourceLen, source, sLen, &status); @@ -329,7 +329,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC int32_t i = 0; int32_t partialSizes[] = { 3, 1, 2, 4, 8, 20, 80 }; /* just size 3 in the quick mode */ int32_t partialSizesSize = 1; - if(QUICK <= 0) { + if(getTestOption(QUICK_OPTION) <= 0) { partialSizesSize = 7; } /*log_verbose("partial sortkey test piecesize=");*/ @@ -344,7 +344,7 @@ static void doTestVariant(UCollator* myCollation, const UChar source[], const UC aescstrdup(source,-1), aescstrdup(target,-1), partialSizes[i]); } - if(QUICK <= 0 && norm != UCOL_ON) { + if(getTestOption(QUICK_OPTION) <= 0 && norm != UCOL_ON) { /*log_verbose("N ");*/ ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); partialNormalizedSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status); diff --git a/icu4c/source/test/cintltst/capitst.c b/icu4c/source/test/cintltst/capitst.c index 7475c0cbc4e..e4e4b310ba2 100644 --- a/icu4c/source/test/cintltst/capitst.c +++ b/icu4c/source/test/cintltst/capitst.c @@ -1,5 +1,5 @@ /******************************************************************** - * Copyright (c) 1997-2009 International Business Machines + * Copyright (c) 1997-2010 International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************/ /***************************************************************************** @@ -899,7 +899,7 @@ void TestOpenVsOpenRules(){ sizeOfStdSet = uset_size(stdSet); adder = 1; - if(QUICK) + if(getTestOption(QUICK_OPTION)) { adder = 10; } diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index 07f57e48203..a1aa6813a08 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -111,7 +111,7 @@ int main(int argc, const char* const argv[]) fprintf(stderr, "After initial u_cleanup: RB cache %s empty.\n", ures_dumpCacheContents()?"WAS NOT":"was"); #endif - while (REPEAT_TESTS > 0) { /* Loop runs once per complete execution of the tests + while (getTestOption(REPEAT_TESTS_OPTION) > 0) { /* Loop runs once per complete execution of the tests * used for -r (repeat) test option. */ if (!initArgs(argc, argv, NULL, NULL)) { /* Error already displayed. */ @@ -129,7 +129,7 @@ int main(int argc, const char* const argv[]) "#### 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)); - if(!WARN_ON_MISSING_DATA) { + if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; @@ -148,7 +148,7 @@ int main(int argc, const char* const argv[]) "*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n" "*** Check the ICU_DATA environment variable and \n" "*** check that the data files are present.\n", warnOrErr); - if(!WARN_ON_MISSING_DATA) { + if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; @@ -164,7 +164,7 @@ int main(int argc, const char* const argv[]) "*** %s! 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", warnOrErr); - if(!WARN_ON_MISSING_DATA) { + if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); u_cleanup(); return 1; @@ -183,7 +183,7 @@ int main(int argc, const char* const argv[]) } else { fprintf(stderr, "*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault()); - if(!WARN_ON_MISSING_DATA) { + if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) { fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n" "*** purposely removed, to continue test anyway.\n"); u_cleanup(); @@ -200,8 +200,9 @@ int main(int argc, const char* const argv[]) /* Tests acutally run HERE. TODO: separate command line option parsing & setting from test execution!! */ nerrors = runTestRequest(root, argc, argv); - if (--REPEAT_TESTS > 0) { - printf("Repeating tests %d more time(s)\n", REPEAT_TESTS); + setTestOption(REPEAT_TESTS_OPTION, DECREMENT_OPTION_VALUE); + if (getTestOption(REPEAT_TESTS_OPTION) > 0) { + printf("Repeating tests %d more time(s)\n", getTestOption(REPEAT_TESTS_OPTION)); } cleanUpTestTree(root); diff --git a/icu4c/source/test/cintltst/citertst.c b/icu4c/source/test/cintltst/citertst.c index eb159e63b9b..89d802afefd 100644 --- a/icu4c/source/test/cintltst/citertst.c +++ b/icu4c/source/test/cintltst/citertst.c @@ -1696,7 +1696,7 @@ static void TestCEValidity() /* testing tailored collation elements */ log_verbose("Testing tailored elements\n"); - if(QUICK) { + if(getTestOption(QUICK_OPTION)) { maxCount = sizeof(locale)/sizeof(locale[0]); } else { maxCount = uloc_countAvailable(); @@ -1719,7 +1719,7 @@ static void TestCEValidity() UColTokenParser src; uint32_t strength = 0; uint16_t specs = 0; - if(QUICK) { + if(getTestOption(QUICK_OPTION)) { loc = locale[count]; } else { loc = uloc_getAvailable(count); diff --git a/icu4c/source/test/cintltst/cldrtest.c b/icu4c/source/test/cintltst/cldrtest.c index 0543af1bf19..a0c61d26fc7 100644 --- a/icu4c/source/test/cintltst/cldrtest.c +++ b/icu4c/source/test/cintltst/cldrtest.c @@ -982,7 +982,7 @@ static void VerifyTranslation(void) { if (U_FAILURE(errorCode)) { log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode)); } - else if (QUICK && exemplarLen > 2048) { + else if (getTestOption(QUICK_OPTION) && exemplarLen > 2048) { log_verbose("skipping test for %s\n", currLoc); } else if (uprv_strncmp(currLoc,"bem",3) == 0) { @@ -1024,7 +1024,7 @@ static void VerifyTranslation(void) { if (U_FAILURE(errorCode)) { log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); } - if (QUICK) { + if (getTestOption(QUICK_OPTION)) { end = 1; } else { @@ -1054,7 +1054,7 @@ static void VerifyTranslation(void) { if (U_FAILURE(errorCode)) { log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); } - if (QUICK) { + if (getTestOption(QUICK_OPTION)) { end = 1; } else { diff --git a/icu4c/source/test/cintltst/cmsccoll.c b/icu4c/source/test/cintltst/cmsccoll.c index a0c1fb08666..cb9cc2c74ae 100644 --- a/icu4c/source/test/cintltst/cmsccoll.c +++ b/icu4c/source/test/cintltst/cmsccoll.c @@ -770,7 +770,7 @@ static void logFailure (const char *platform, const char *test, *sEsc = *tEsc = *s = *t = 0; if(error == TRUE) { log_err("Difference between expected and generated order. Run test with -v for more info\n"); - } else if(VERBOSITY == 0) { + } else if(getTestOption(VERBOSITY_OPTION) == 0) { return; } for(i = 0; i"); diff --git a/icu4c/source/test/cintltst/cucdtst.c b/icu4c/source/test/cintltst/cucdtst.c index 1ba7f396a4c..3f102b5b459 100644 --- a/icu4c/source/test/cintltst/cucdtst.c +++ b/icu4c/source/test/cintltst/cucdtst.c @@ -1689,7 +1689,7 @@ TestCharNames() { } /* Test getCharNameCharacters */ - if(!QUICK) { + if(!getTestOption(QUICK_OPTION)) { enum { BUFSIZE = 256 }; UErrorCode ec = U_ZERO_ERROR; char buf[BUFSIZE]; @@ -1798,7 +1798,7 @@ TestCharNames() { if (!ok) { log_err("FAIL: uprv_getCharNameCharacters() returned %s, expected %s (too many lowercase a-z are ok)\n", aescstrdup(pat, l1), aescstrdup(dumbPat, l2)); - } else if(VERBOSITY) { + } else if(getTestOption(VERBOSITY_OPTION)) { log_verbose("Ok: uprv_getCharNameCharacters() returned %s\n", aescstrdup(pat, l1)); } diff --git a/icu4c/source/test/cintltst/nccbtst.c b/icu4c/source/test/cintltst/nccbtst.c index 2c826f6c3a7..628965e6d16 100644 --- a/icu4c/source/test/cintltst/nccbtst.c +++ b/icu4c/source/test/cintltst/nccbtst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2008, International Business Machines Corporation and + * Copyright (c) 1997-2010, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /* @@ -2743,7 +2743,7 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const uint8_t log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { junk[0] = 0; @@ -2941,7 +2941,7 @@ UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *e log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { junk[0] = 0; @@ -3120,7 +3120,7 @@ UBool testConvertFromUnicodeWithContext(const UChar *source, int sourceLen, con log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { junk[0] = 0; @@ -3298,7 +3298,7 @@ UBool testConvertToUnicodeWithContext( const uint8_t *source, int sourcelen, con log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { junk[0] = 0; diff --git a/icu4c/source/test/cintltst/ncnvfbts.c b/icu4c/source/test/cintltst/ncnvfbts.c index 6a6e5467af9..43f8c48b4bd 100644 --- a/icu4c/source/test/cintltst/ncnvfbts.c +++ b/icu4c/source/test/cintltst/ncnvfbts.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2009, International Business Machines Corporation and + * Copyright (c) 1997-2010, International Business Machines Corporation and * others. All Rights Reserved. ***************************************************************************/ /***************************************************************************** @@ -224,7 +224,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen, const u log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[9999]; char offset_str[9999]; @@ -387,7 +387,7 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { junk[0] = 0; diff --git a/icu4c/source/test/cintltst/ncnvtst.c b/icu4c/source/test/cintltst/ncnvtst.c index 83e2567d6c6..10d85341da5 100644 --- a/icu4c/source/test/cintltst/ncnvtst.c +++ b/icu4c/source/test/cintltst/ncnvtst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2009, International Business Machines Corporation and + * Copyright (c) 1997-2010, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /***************************************************************************** @@ -1273,7 +1273,7 @@ static UBool testConvertFromU( const UChar *source, int sourceLen, const uint8_ log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[999]; char offset_str[999]; @@ -1448,7 +1448,7 @@ static UBool testConvertToU( const uint8_t *source, int sourcelen, const UChar * log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[999]; char offset_str[999]; diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c index 6a238a54c7b..e3d99a9126c 100644 --- a/icu4c/source/test/cintltst/nucnvtst.c +++ b/icu4c/source/test/cintltst/nucnvtst.c @@ -428,7 +428,7 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[9999]; char offset_str[9999]; @@ -589,7 +589,7 @@ static ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[9999]; char offset_str[9999]; @@ -3530,7 +3530,7 @@ TestFullRoundtrip(const char* cp){ static void TestRoundTrippingAllUTF(void){ - if(!QUICK){ + if(!getTestOption(QUICK_OPTION)){ log_verbose("Running exhaustive round trip test for BOCU-1\n"); TestFullRoundtrip("BOCU-1"); log_verbose("Running exhaustive round trip test for SCSU\n"); diff --git a/icu4c/source/test/cintltst/putiltst.c b/icu4c/source/test/cintltst/putiltst.c index 8833f1e92ac..6a8d0193038 100644 --- a/icu4c/source/test/cintltst/putiltst.c +++ b/icu4c/source/test/cintltst/putiltst.c @@ -41,7 +41,7 @@ static void TestPUtilAPI(void){ log_err("Error in uprv_modf. Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n", expn1, n1, expy1, y1); } - if(VERBOSITY){ + if(getTestOption(VERBOSITY_OPTION)){ log_verbose("[float] x = %f n = %f y = %f\n", value1, n1, y1); } log_verbose("Testing the API uprv_fmod()\n"); diff --git a/icu4c/source/test/cintltst/ucnvseltst.c b/icu4c/source/test/cintltst/ucnvseltst.c index 076120864e0..32ed2d95633 100644 --- a/icu4c/source/test/cintltst/ucnvseltst.c +++ b/icu4c/source/test/cintltst/ucnvseltst.c @@ -1,5 +1,5 @@ /******************************************************************** - * Copyright (c) 1997-2009, International Business Machines + * Copyright (c) 1997-2010, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************** * @@ -395,7 +395,7 @@ static void TestSelector() int32_t excluded_set_id; int32_t num_encodings; const char **encodings = getEncodingsFns[testCaseIdx](&num_encodings); - if (QUICK && num_encodings > 25) { + if (getTestOption(QUICK_OPTION) && num_encodings > 25) { uprv_free((void *)encodings); continue; } @@ -446,7 +446,7 @@ static void TestSelector() int32_t length8, length16; s = text_nextString(&text, &length8); - if (s == NULL || (QUICK && text.number > 3)) { + if (s == NULL || (getTestOption(QUICK_OPTION) && text.number > 3)) { break; } diff --git a/icu4c/source/tools/ctestfw/ctest.c b/icu4c/source/tools/ctestfw/ctest.c index 92f5fb9a502..825e34294e6 100644 --- a/icu4c/source/tools/ctestfw/ctest.c +++ b/icu4c/source/tools/ctestfw/ctest.c @@ -1,7 +1,7 @@ /* ******************************************************************************** * -* Copyright (C) 1996-2009, International Business Machines +* Copyright (C) 1996-2010, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************** @@ -830,3 +830,49 @@ static void help ( const char *argv0 ) printf(" eg: to run just the utility tests type: cintltest /tsutil) \n"); } +int32_t T_CTEST_EXPORT2 +getTestOption ( int32_t testOption ) { + switch (testOption) { + case VERBOSITY_OPTION: + return VERBOSITY; + case WARN_ON_MISSING_DATA_OPTION: + return WARN_ON_MISSING_DATA; + case QUICK_OPTION: + return QUICK; + case REPEAT_TESTS_OPTION: + return REPEAT_TESTS; + case ERR_MSG_OPTION: + return ERR_MSG; + case ICU_TRACE_OPTION: + return ICU_TRACE; + default : + return 0; + } +} + +void T_CTEST_EXPORT2 +setTestOption ( int32_t testOption, int32_t value) { + if (value == DECREMENT_OPTION_VALUE) { + value = getTestOption(testOption); + --value; + } + switch (testOption) { + case VERBOSITY_OPTION: + VERBOSITY = value; + break; + case WARN_ON_MISSING_DATA_OPTION: + WARN_ON_MISSING_DATA = value; + break; + case QUICK_OPTION: + QUICK = value; + break; + case REPEAT_TESTS_OPTION: + REPEAT_TESTS = value; + break; + case ICU_TRACE_OPTION: + ICU_TRACE = value; + break; + default : + break; + } +} diff --git a/icu4c/source/tools/ctestfw/unicode/ctest.h b/icu4c/source/tools/ctestfw/unicode/ctest.h index e292e8a1a71..535e34c915b 100644 --- a/icu4c/source/tools/ctestfw/unicode/ctest.h +++ b/icu4c/source/tools/ctestfw/unicode/ctest.h @@ -1,7 +1,7 @@ /* ******************************************************************************** * - * Copyright (C) 1996-2009, International Business Machines + * Copyright (C) 1996-2010, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************** @@ -23,53 +23,61 @@ typedef struct TestNode TestNode; U_CDECL_END /** - * Set this to zero to disable log_verbose() messages. - * Otherwise nonzero to see log_verbose() messages. - * - * @internal Internal APIs for testing purpose only - */ -extern T_CTEST_EXPORT_API int REPEAT_TESTS; - -/** - * Set this to zero to disable log_verbose() messages. - * Otherwise nonzero to see log_verbose() messages. - * - * @internal Internal APIs for testing purpose only - */ -extern T_CTEST_EXPORT_API int VERBOSITY; - -/** - * Set this to zero to disable log_verbose() messages. - * Otherwise nonzero to see log_verbose() messages. - * - * @internal Internal APIs for testing purpose only - */ -extern T_CTEST_EXPORT_API int ERR_MSG; - -/** - * Set this to zero to disable some of the slower tests. - * Otherwise nonzero to run the slower tests. - * - * @internal Internal APIs for testing purpose only - */ -extern T_CTEST_EXPORT_API int QUICK; - -/** - * Set this to nonzero to warn (not error) on missing data. - * Otherwise, zero will cause an error to be propagated when data is not available. - * Affects the behavior of log_dataerr. - * - * @see log_data_err - * @internal Internal APIs for testing purpose only - */ -extern T_CTEST_EXPORT_API int WARN_ON_MISSING_DATA; - -/** - * ICU tracing level, is set by command line option + * This is use to set or get the option value for REPEAT_TESTS. + * Use with set/getTestOption(). * * @internal */ -extern T_CTEST_EXPORT_API UTraceLevel ICU_TRACE; +#define REPEAT_TESTS_OPTION 1 + +/** + * This is use to set or get the option value for VERBOSITY. + * When option is set to zero to disable log_verbose() messages. + * Otherwise nonzero to see log_verbose() messages. + * Use with set/getTestOption(). + * + * @internal + */ +#define VERBOSITY_OPTION 2 + +/** + * This is use to set or get the option value for ERR_MSG. + * Use with set/getTestOption(). + * + * @internal + */ +#define ERR_MSG_OPTION 3 + +/** + * This is use to set or get the option value for QUICK. + * When option is zero, disable some of the slower tests. + * Otherwise nonzero to run the slower tests. + * Use with set/getTestOption(). + * + * @internal + */ +#define QUICK_OPTION 4 + +/** + * This is use to set or get the option value for WARN_ON_MISSING_DATA. + * When option is nonzero, warn on missing data. + * Otherwise, errors are propagated when data is not available. + * Affects the behavior of log_dataerr. + * Use with set/getTestOption(). + * + * @see log_data_err + * @internal + */ +#define WARN_ON_MISSING_DATA_OPTION 5 + +/** + * This is use to set or get the option value for ICU_TRACE. + * ICU tracing level, is set by command line option. + * Use with set/getTestOption(). + * + * @internal + */ +#define ICU_TRACE_OPTION 6 /** * Maximum amount of memory uprv_malloc should allocate before returning NULL. @@ -85,6 +93,32 @@ extern T_CTEST_EXPORT_API size_t MAX_MEMORY_ALLOCATION; */ extern T_CTEST_EXPORT_API int32_t ALLOCATION_COUNT; +/** + * Pass to setTestOption to decrement the test option value. + * + * @internal + */ +#define DECREMENT_OPTION_VALUE -99 + +/** + * Gets the test option set on commandline. + * + * @param testOption macro definition for the individual test option + * @return value of test option, zero if option is not set or off + * @internal Internal APIs for testing purpose only + */ +T_CTEST_API int32_t T_CTEST_EXPORT2 +getTestOption ( int32_t testOption ); + +/** + * Sets the test option with value given on commandline. + * + * @param testOption macro definition for the individual test option + * @param value to set the test option to + * @internal Internal APIs for testing purpose only + */ +T_CTEST_API void T_CTEST_EXPORT2 +setTestOption ( int32_t testOption, int32_t value); /** * Show the names of all nodes.