void T_CTEST_EXPORT2 cleanUpTestTree(TestNode *tn) { if(tn->child != NULL) { cleanUpTestTree(tn->child); } if(tn->sibling != NULL) { cleanUpTestTree(tn->sibling); } free(tn); }
U_CDECL_END int main(int argc, char* argv[]) { int32_t nerrors = 0; TestNode *root = NULL; UErrorCode errorCode = U_ZERO_ERROR; UDate startTime, endTime; int32_t diffTime; startTime = uprv_getRawUTCtime(); /* 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. */ u_init(&errorCode); if (U_FAILURE(errorCode)) { fprintf(stderr, "#### Note: ICU Init without build-specific setDataDirectory() failed.\n"); } u_cleanup(); errorCode = U_ZERO_ERROR; if (!initArgs(argc, argv, argHandler, (void *) &STANDARD_TEST_FILE)) { /* Error already displayed. */ return -1; } /* Initialize ICU */ ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */ u_init(&errorCode); if (U_FAILURE(errorCode)) { fprintf(stderr, "#### 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)); return 1; } fprintf(stdout, "Default charset for this run is %s\n", ucnv_getDefaultName()); addAllTests(&root); nerrors = runTestRequest(root, argc, argv); #if 1 { FILE* fileToRemove = fopen(STANDARD_TEST_FILE, "r"); /* This should delete any temporary files. */ if (fileToRemove) { fclose(fileToRemove); log_verbose("Deleting: %s\n", STANDARD_TEST_FILE); if (remove(STANDARD_TEST_FILE) != 0) { /* Maybe someone didn't close the file correctly. */ fprintf(stderr, "FAIL: Could not delete %s\n", STANDARD_TEST_FILE); nerrors += 1; } } } #endif cleanUpTestTree(root); DataDrivenLogger::cleanUp(); u_cleanup(); endTime = uprv_getRawUTCtime(); diffTime = (int32_t)(endTime - startTime); printf("Elapsed Time: %02d:%02d:%02d.%03d\n", (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)); return nerrors; }
int main(int argc, const char* const argv[]) { int nerrors = 0; UBool defaultDataFound; TestNode *root; const char *warnOrErr = "Failure"; UDate startTime, endTime; int32_t diffTime; /* initial check for the default converter */ UErrorCode errorCode = U_ZERO_ERROR; UResourceBundle *rb; UConverter *cnv; U_MAIN_INIT_ARGS(argc, argv); startTime = uprv_getRawUTCtime(); gOrigArgc = argc; gOrigArgv = argv; if (!initArgs(argc, argv, NULL, NULL)) { /* Error already displayed. */ return -1; } /* 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. */ 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; } u_cleanup(); #ifdef URES_DEBUG fprintf(stderr, "After initial u_cleanup: RB cache %s empty.\n", ures_dumpCacheContents()?"WAS NOT":"was"); #endif 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. */ return -1; } errorCode = U_ZERO_ERROR; /* Initialize ICU */ if (!defaultDataFound) { ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */ } u_init(&errorCode); if (U_FAILURE(errorCode)) { fprintf(stderr, "#### 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(!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; } } /* try more data */ cnv = ucnv_open(TRY_CNV_2, &errorCode); if(cnv != 0) { /* ok */ ucnv_close(cnv); } else { fprintf(stderr, "*** %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(!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; } } rb = ures_open(NULL, "en", &errorCode); if(U_SUCCESS(errorCode)) { /* ok */ ures_close(rb); } else { fprintf(stderr, "*** %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(!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; } } 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()); 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; } } fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault()); /* Build a tree of all tests. * Subsequently will be used to find / iterate the tests to run */ root = NULL; addAllTests(&root); /* Tests acutally run HERE. TODO: separate command line option parsing & setting from test execution!! */ nerrors = runTestRequest(root, argc, argv); 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); #ifdef CTST_LEAK_CHECK ctst_freeAll(); /* To check for leaks */ u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */ if(getTestOption(VERBOSITY_OPTION) && ctst_allocated_total>0) { fprintf(stderr,"ctst_freeAll(): cleaned up after %d allocations (queue of %d)\n", ctst_allocated_total, CTST_MAX_ALLOC); } #ifdef URES_DEBUG if(ures_dumpCacheContents()) { fprintf(stderr, "Error: After final u_cleanup, RB cache was not empty.\n"); nerrors++; } else { fprintf(stderr,"OK: After final u_cleanup, RB cache was empty.\n"); } #endif #endif } /* End of loop that repeats the entire test, if requested. (Normally doesn't loop) */ #ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS unistr_printLengths(); #endif endTime = uprv_getRawUTCtime(); diffTime = (int32_t)(endTime - startTime); printf("Elapsed Time: %02d:%02d:%02d.%03d\n", (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)); return nerrors ? 1 : 0; }