1 /******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1997-2009, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 /******************************************************************************** 7 * 8 * File CINTLTST.C 9 * 10 * Modification History: 11 * Name Description 12 * Madhu Katragadda Creation 13 ********************************************************************************* 14 */ 15 16 /*The main root for C API tests*/ 17 18 #include <stdlib.h> 19 #include <stdio.h> 20 #include <string.h> 21 #include "unicode/utypes.h" 22 #include "unicode/putil.h" 23 #include "cstring.h" 24 #include "cintltst.h" 25 #include "umutex.h" 26 #include "uassert.h" 27 #include "cmemory.h" 28 #include "unicode/uchar.h" 29 #include "unicode/ustring.h" 30 #include "unicode/ucnv.h" 31 #include "unicode/ures.h" 32 #include "unicode/uclean.h" 33 #include "unicode/ucal.h" 34 #include "uoptions.h" 35 #include "putilimp.h" /* for uprv_getUTCtime() */ 36 37 #ifdef XP_MAC_CONSOLE 38 # include <console.h> 39 #endif 40 41 #define CTST_LEAK_CHECK 1 42 #ifdef CTST_LEAK_CHECK 43 U_CFUNC void ctst_freeAll(void); 44 #endif 45 46 static char* _testDataPath=NULL; 47 48 /* 49 * Forward Declarations 50 */ 51 void ctest_setICU_DATA(void); 52 53 54 55 #if UCONFIG_NO_LEGACY_CONVERSION 56 # define TRY_CNV_1 "iso-8859-1" 57 # define TRY_CNV_2 "ibm-1208" 58 #else 59 # define TRY_CNV_1 "iso-8859-7" 60 # define TRY_CNV_2 "sjis" 61 #endif 62 63 static int gOrigArgc; 64 static const char* const * gOrigArgv; 65 66 int main(int argc, const char* const argv[]) 67 { 68 int nerrors = 0; 69 UBool defaultDataFound; 70 TestNode *root; 71 const char *warnOrErr = "Failure"; 72 UDate startTime, endTime; 73 int32_t diffTime; 74 75 /* initial check for the default converter */ 76 UErrorCode errorCode = U_ZERO_ERROR; 77 UResourceBundle *rb; 78 UConverter *cnv; 79 80 U_MAIN_INIT_ARGS(argc, argv); 81 82 startTime = uprv_getUTCtime(); 83 84 gOrigArgc = argc; 85 gOrigArgv = argv; 86 if (!initArgs(argc, argv, NULL, NULL)) { 87 /* Error already displayed. */ 88 return -1; 89 } 90 91 /* Check whether ICU will initialize without forcing the build data directory into 92 * the ICU_DATA path. Success here means either the data dll contains data, or that 93 * this test program was run with ICU_DATA set externally. Failure of this check 94 * is normal when ICU data is not packaged into a shared library. 95 * 96 * Whether or not this test succeeds, we want to cleanup and reinitialize 97 * with a data path so that data loading from individual files can be tested. 98 */ 99 defaultDataFound = TRUE; 100 u_init(&errorCode); 101 if (U_FAILURE(errorCode)) { 102 fprintf(stderr, 103 "#### Note: ICU Init without build-specific setDataDirectory() failed. %s\n", u_errorName(errorCode)); 104 defaultDataFound = FALSE; 105 } 106 u_cleanup(); 107 108 while (REPEAT_TESTS > 0) { /* Loop runs once per complete execution of the tests 109 * used for -r (repeat) test option. */ 110 if (!initArgs(argc, argv, NULL, NULL)) { 111 /* Error already displayed. */ 112 return -1; 113 } 114 errorCode = U_ZERO_ERROR; 115 116 /* Initialize ICU */ 117 if (!defaultDataFound) { 118 ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */ 119 } 120 u_init(&errorCode); 121 if (U_FAILURE(errorCode)) { 122 fprintf(stderr, 123 "#### ERROR! %s: u_init() failed with status = \"%s\".\n" 124 "*** Check the ICU_DATA environment variable and \n" 125 "*** check that the data files are present.\n", argv[0], u_errorName(errorCode)); 126 if(!WARN_ON_MISSING_DATA) { 127 fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); 128 u_cleanup(); 129 return 1; 130 } 131 } 132 133 134 135 /* try more data */ 136 cnv = ucnv_open(TRY_CNV_2, &errorCode); 137 if(cnv != 0) { 138 /* ok */ 139 ucnv_close(cnv); 140 } else { 141 fprintf(stderr, 142 "*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n" 143 "*** Check the ICU_DATA environment variable and \n" 144 "*** check that the data files are present.\n", warnOrErr); 145 if(!WARN_ON_MISSING_DATA) { 146 fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); 147 u_cleanup(); 148 return 1; 149 } 150 } 151 152 rb = ures_open(NULL, "en", &errorCode); 153 if(U_SUCCESS(errorCode)) { 154 /* ok */ 155 ures_close(rb); 156 } else { 157 fprintf(stderr, 158 "*** %s! The \"en\" locale resource bundle cannot be opened.\n" 159 "*** Check the ICU_DATA environment variable and \n" 160 "*** check that the data files are present.\n", warnOrErr); 161 if(!WARN_ON_MISSING_DATA) { 162 fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n"); 163 u_cleanup(); 164 return 1; 165 } 166 } 167 168 errorCode = U_ZERO_ERROR; 169 rb = ures_open(NULL, NULL, &errorCode); 170 if(U_SUCCESS(errorCode)) { 171 /* ok */ 172 if (errorCode == U_USING_DEFAULT_WARNING || errorCode == U_USING_FALLBACK_WARNING) { 173 fprintf(stderr, 174 "#### Note: The default locale %s is not available\n", uloc_getDefault()); 175 } 176 ures_close(rb); 177 } else { 178 fprintf(stderr, 179 "*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault()); 180 if(!WARN_ON_MISSING_DATA) { 181 fprintf(stderr, "*** Exitting. Use the '-w' option if data files were\n" 182 "*** purposely removed, to continue test anyway.\n"); 183 u_cleanup(); 184 return 1; 185 } 186 } 187 fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault()); 188 189 /* Build a tree of all tests. 190 * Subsequently will be used to find / iterate the tests to run */ 191 root = NULL; 192 addAllTests(&root); 193 194 /* Tests acutally run HERE. TODO: separate command line option parsing & setting from test execution!! */ 195 nerrors = runTestRequest(root, argc, argv); 196 197 if (--REPEAT_TESTS > 0) { 198 printf("Repeating tests %d more time(s)\n", REPEAT_TESTS); 199 } 200 cleanUpTestTree(root); 201 202 #ifdef CTST_LEAK_CHECK 203 ctst_freeAll(); 204 /* To check for leaks */ 205 u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */ 206 #endif 207 208 } /* End of loop that repeats the entire test, if requested. (Normally doesn't loop) */ 209 210 if (ALLOCATION_COUNT > 0) { 211 fprintf(stderr, "There were %d blocks leaked!\n", ALLOCATION_COUNT); 212 nerrors++; 213 } 214 endTime = uprv_getUTCtime(); 215 diffTime = (int32_t)(endTime - startTime); 216 printf("Elapsed Time: %02d:%02d:%02d.%03d\n", 217 (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR), 218 (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), 219 (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND), 220 (int)(diffTime%U_MILLIS_PER_SECOND)); 221 222 return nerrors ? 1 : 0; 223 } 224 225 /* 226 static void ctest_appendToDataDirectory(const char *toAppend) 227 { 228 const char *oldPath =""; 229 char newBuf [1024]; 230 char *newPath = newBuf; 231 int32_t oldLen; 232 int32_t newLen; 233 234 if((toAppend == NULL) || (*toAppend == 0)) { 235 return; 236 } 237 238 oldPath = u_getDataDirectory(); 239 if( (oldPath==NULL) || (*oldPath == 0)) { 240 u_setDataDirectory(toAppend); 241 } else { 242 oldLen = strlen(oldPath); 243 newLen = strlen(toAppend)+1+oldLen; 244 245 if(newLen > 1022) 246 { 247 newPath = (char *)ctst_malloc(newLen); 248 } 249 250 strcpy(newPath, oldPath); 251 strcpy(newPath+oldLen, U_PATH_SEP_STRING); 252 strcpy(newPath+oldLen+1, toAppend); 253 254 u_setDataDirectory(newPath); 255 256 if(newPath != newBuf) 257 { 258 free(newPath); 259 } 260 } 261 } 262 */ 263 264 /* returns the path to icu/source/data */ 265 const char * ctest_dataSrcDir() 266 { 267 static const char *dataSrcDir = NULL; 268 269 if(dataSrcDir) { 270 return dataSrcDir; 271 } 272 273 /* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst 274 // to point to the top of the build hierarchy, which may or 275 // may not be the same as the source directory, depending on 276 // the configure options used. At any rate, 277 // set the data path to the built data from this directory. 278 // The value is complete with quotes, so it can be used 279 // as-is as a string constant. 280 */ 281 #if defined (U_TOPSRCDIR) 282 { 283 dataSrcDir = U_TOPSRCDIR U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; 284 } 285 #else 286 287 /* On Windows, the file name obtained from __FILE__ includes a full path. 288 * This file is "wherever\icu\source\test\cintltst\cintltst.c" 289 * Change to "wherever\icu\source\data" 290 */ 291 { 292 static char p[sizeof(__FILE__) + 20]; 293 char *pBackSlash; 294 int i; 295 296 strcpy(p, __FILE__); 297 /* We want to back over three '\' chars. */ 298 /* Only Windows should end up here, so looking for '\' is safe. */ 299 for (i=1; i<=3; i++) { 300 pBackSlash = strrchr(p, U_FILE_SEP_CHAR); 301 if (pBackSlash != NULL) { 302 *pBackSlash = 0; /* Truncate the string at the '\' */ 303 } 304 } 305 306 if (pBackSlash != NULL) { 307 /* We found and truncated three names from the path. 308 * Now append "source\data" and set the environment 309 */ 310 strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING ); 311 dataSrcDir = p; 312 } 313 else { 314 /* __FILE__ on MSVC7 does not contain the directory */ 315 FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r"); 316 if (file) { 317 fclose(file); 318 dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; 319 } 320 else { 321 dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; 322 } 323 } 324 } 325 #endif 326 327 return dataSrcDir; 328 329 } 330 331 /* returns the path to icu/source/data/out */ 332 const char *ctest_dataOutDir() 333 { 334 static const char *dataOutDir = NULL; 335 336 if(dataOutDir) { 337 return dataOutDir; 338 } 339 340 /* U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst 341 // to point to the top of the build hierarchy, which may or 342 // may not be the same as the source directory, depending on 343 // the configure options used. At any rate, 344 // set the data path to the built data from this directory. 345 // The value is complete with quotes, so it can be used 346 // as-is as a string constant. 347 */ 348 #if defined (U_TOPBUILDDIR) 349 { 350 dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; 351 } 352 #else 353 354 /* On Windows, the file name obtained from __FILE__ includes a full path. 355 * This file is "wherever\icu\source\test\cintltst\cintltst.c" 356 * Change to "wherever\icu\source\data" 357 */ 358 { 359 static char p[sizeof(__FILE__) + 20]; 360 char *pBackSlash; 361 int i; 362 363 strcpy(p, __FILE__); 364 /* We want to back over three '\' chars. */ 365 /* Only Windows should end up here, so looking for '\' is safe. */ 366 for (i=1; i<=3; i++) { 367 pBackSlash = strrchr(p, U_FILE_SEP_CHAR); 368 if (pBackSlash != NULL) { 369 *pBackSlash = 0; /* Truncate the string at the '\' */ 370 } 371 } 372 373 if (pBackSlash != NULL) { 374 /* We found and truncated three names from the path. 375 * Now append "source\data" and set the environment 376 */ 377 strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING); 378 dataOutDir = p; 379 } 380 else { 381 /* __FILE__ on MSVC7 does not contain the directory */ 382 FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r"); 383 if (file) { 384 fclose(file); 385 dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; 386 } 387 else { 388 dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; 389 } 390 } 391 } 392 #endif 393 394 return dataOutDir; 395 } 396 397 /* ctest_setICU_DATA - if the ICU_DATA environment variable is not already 398 * set, try to deduce the directory in which ICU was built, 399 * and set ICU_DATA to "icu/source/data" in that location. 400 * The intent is to allow the tests to have a good chance 401 * of running without requiring that the user manually set 402 * ICU_DATA. Common data isn't a problem, since it is 403 * picked up via a static (build time) reference, but the 404 * tests dynamically load some data. 405 */ 406 void ctest_setICU_DATA() { 407 408 /* No location for the data dir was identifiable. 409 * Add other fallbacks for the test data location here if the need arises 410 */ 411 if (getenv("ICU_DATA") == NULL) { 412 /* If ICU_DATA isn't set, set it to the usual location */ 413 u_setDataDirectory(ctest_dataOutDir()); 414 } 415 } 416 417 /* These tests do cleanup and reinitialize ICU in the course of their operation. 418 * The ICU data directory must be preserved across these operations. 419 * Here is a helper function to assist with that. 420 */ 421 static char *safeGetICUDataDirectory() { 422 const char *dataDir = u_getDataDirectory(); /* Returned string vanashes with u_cleanup */ 423 char *retStr = NULL; 424 if (dataDir != NULL) { 425 retStr = (char *)malloc(strlen(dataDir)+1); 426 strcpy(retStr, dataDir); 427 } 428 return retStr; 429 } 430 431 UBool ctest_resetICU() { 432 UErrorCode status = U_ZERO_ERROR; 433 char *dataDir = safeGetICUDataDirectory(); 434 435 u_cleanup(); 436 if (!initArgs(gOrigArgc, gOrigArgv, NULL, NULL)) { 437 /* Error already displayed. */ 438 return FALSE; 439 } 440 u_setDataDirectory(dataDir); 441 free(dataDir); 442 u_init(&status); 443 if (U_FAILURE(status)) { 444 log_err_status(status, "u_init failed with %s\n", u_errorName(status)); 445 return FALSE; 446 } 447 return TRUE; 448 } 449 450 UChar* CharsToUChars(const char* str) { 451 /* Might be faster to just use uprv_strlen() as the preflight len - liu */ 452 int32_t len = u_unescape(str, 0, 0); /* preflight */ 453 /* Do NOT use malloc() - we are supposed to be acting like user code! */ 454 UChar *buf = (UChar*) malloc(sizeof(UChar) * (len + 1)); 455 u_unescape(str, buf, len + 1); 456 return buf; 457 } 458 459 char *austrdup(const UChar* unichars) 460 { 461 int length; 462 char *newString; 463 464 length = u_strlen ( unichars ); 465 /*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */ 466 newString = (char*)ctst_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */ 467 468 if ( newString == NULL ) 469 return NULL; 470 471 u_austrcpy ( newString, unichars ); 472 473 return newString; 474 } 475 476 char *aescstrdup(const UChar* unichars,int32_t length){ 477 char *newString,*targetLimit,*target; 478 UConverterFromUCallback cb; 479 const void *p; 480 UErrorCode errorCode = U_ZERO_ERROR; 481 #if U_CHARSET_FAMILY==U_EBCDIC_FAMILY 482 # ifdef OS390 483 static const char convName[] = "ibm-1047"; 484 # else 485 static const char convName[] = "ibm-37"; 486 # endif 487 #else 488 static const char convName[] = "US-ASCII"; 489 #endif 490 UConverter* conv = ucnv_open(convName, &errorCode); 491 if(length==-1){ 492 length = u_strlen( unichars); 493 } 494 newString = (char*)ctst_malloc ( sizeof(char) * 8 * (length +1)); 495 target = newString; 496 targetLimit = newString+sizeof(char) * 8 * (length +1); 497 ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_JAVA, &cb, &p, &errorCode); 498 ucnv_fromUnicode(conv,&target,targetLimit, &unichars, (UChar*)(unichars+length),NULL,TRUE,&errorCode); 499 ucnv_close(conv); 500 *target = '\0'; 501 return newString; 502 } 503 504 const char* loadTestData(UErrorCode* err){ 505 if( _testDataPath == NULL){ 506 const char* directory=NULL; 507 UResourceBundle* test =NULL; 508 char* tdpath=NULL; 509 const char* tdrelativepath; 510 #if defined (U_TOPBUILDDIR) 511 tdrelativepath = "test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; 512 directory = U_TOPBUILDDIR; 513 #else 514 tdrelativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; 515 directory= ctest_dataOutDir(); 516 #endif 517 518 tdpath = (char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10)); 519 520 521 /* u_getDataDirectory shoul return \source\data ... set the 522 * directory to ..\source\data\..\test\testdata\out\testdata 523 * 524 * Fallback: When Memory mapped file is built 525 * ..\source\data\out\..\..\test\testdata\out\testdata 526 */ 527 strcpy(tdpath, directory); 528 strcat(tdpath, tdrelativepath); 529 strcat(tdpath,"testdata"); 530 531 532 test=ures_open(tdpath, "testtypes", err); 533 534 /* Fall back did not succeed either so return */ 535 if(U_FAILURE(*err)){ 536 *err = U_FILE_ACCESS_ERROR; 537 log_data_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(*err)); 538 return ""; 539 } 540 ures_close(test); 541 _testDataPath = tdpath; 542 return _testDataPath; 543 } 544 return _testDataPath; 545 } 546 547 #define CTEST_MAX_TIMEZONE_SIZE 256 548 static UChar gOriginalTimeZone[CTEST_MAX_TIMEZONE_SIZE] = {0}; 549 550 /** 551 * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value. 552 * @param optionalTimeZone Set this to a requested timezone. 553 * Set to NULL to use the standard test timezone (Pacific Time) 554 */ 555 U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) { 556 #if !UCONFIG_NO_FORMATTING 557 UChar zoneID[CTEST_MAX_TIMEZONE_SIZE]; 558 559 if (optionalTimeZone == NULL) { 560 optionalTimeZone = "America/Los_Angeles"; 561 } 562 if (gOriginalTimeZone[0]) { 563 log_data_err("*** Error: time zone saved twice. New value will be %s (Are you missing data?)\n", 564 optionalTimeZone); 565 } 566 ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status); 567 if (U_FAILURE(*status)) { 568 log_err("*** Error: Failed to save default time zone: %s\n", 569 u_errorName(*status)); 570 *status = U_ZERO_ERROR; 571 } 572 573 u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1); 574 zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0; 575 ucal_setDefaultTimeZone(zoneID, status); 576 if (U_FAILURE(*status)) { 577 log_err("*** Error: Failed to set default time zone to \"%s\": %s\n", 578 optionalTimeZone, u_errorName(*status)); 579 } 580 #endif 581 } 582 583 /** 584 * Call this once get back the original timezone 585 */ 586 U_CFUNC void ctest_resetTimeZone(void) { 587 #if !UCONFIG_NO_FORMATTING 588 UErrorCode status = U_ZERO_ERROR; 589 590 ucal_setDefaultTimeZone(gOriginalTimeZone, &status); 591 if (U_FAILURE(status)) { 592 log_err("*** Error: Failed to reset default time zone: %s\n", 593 u_errorName(status)); 594 } 595 /* Set to an empty state */ 596 gOriginalTimeZone[0] = 0; 597 #endif 598 } 599 600 #define CTST_MAX_ALLOC 8192 601 /* Array used as a queue */ 602 static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0}; 603 static int ctst_allocated = 0; 604 static UBool ctst_free = FALSE; 605 606 void *ctst_malloc(size_t size) { 607 if(ctst_allocated >= CTST_MAX_ALLOC - 1) { 608 ctst_allocated = 0; 609 ctst_free = TRUE; 610 } 611 if(ctst_allocated_stuff[ctst_allocated]) { 612 free(ctst_allocated_stuff[ctst_allocated]); 613 } 614 return ctst_allocated_stuff[ctst_allocated++] = malloc(size); 615 } 616 617 #ifdef CTST_LEAK_CHECK 618 void ctst_freeAll() { 619 int i; 620 if(ctst_free == 0) { 621 for(i=0; i<ctst_allocated; i++) { 622 free(ctst_allocated_stuff[i]); 623 ctst_allocated_stuff[i] = NULL; 624 } 625 } else { 626 for(i=0; i<CTST_MAX_ALLOC; i++) { 627 free(ctst_allocated_stuff[i]); 628 ctst_allocated_stuff[i] = NULL; 629 } 630 } 631 ctst_allocated = 0; 632 _testDataPath=NULL; 633 } 634 635 #define VERBOSE_ASSERTIONS 636 637 U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) { 638 U_ASSERT(ec!=NULL); 639 if (U_FAILURE(*ec)) { 640 log_err_status(*ec, "FAIL: %s (%s)\n", msg, u_errorName(*ec)); 641 return FALSE; 642 } 643 return TRUE; 644 } 645 646 /* if 'condition' is a UBool, the compiler complains bitterly about 647 expressions like 'a > 0' which it evaluates as int */ 648 U_CFUNC UBool assertTrue(const char* msg, int /*not UBool*/ condition) { 649 if (!condition) { 650 log_err("FAIL: assertTrue() failed: %s\n", msg); 651 } 652 #ifdef VERBOSE_ASSERTIONS 653 else { 654 log_verbose("Ok: %s\n", msg); 655 } 656 #endif 657 return (UBool)condition; 658 } 659 660 U_CFUNC UBool assertEquals(const char* message, const char* expected, 661 const char* actual) { 662 if (uprv_strcmp(expected, actual) != 0) { 663 log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n", 664 message, actual, expected); 665 return FALSE; 666 } 667 #ifdef VERBOSE_ASSERTIONS 668 else { 669 log_verbose("Ok: %s; got \"%s\"\n", message, actual); 670 } 671 #endif 672 return TRUE; 673 } 674 /*-------------------------------------------------------------------- 675 * Time bomb - allows temporary behavior that expires at a given 676 * release 677 *-------------------------------------------------------------------- 678 */ 679 680 U_CFUNC UBool isICUVersionAtLeast(const UVersionInfo x) { 681 UVersionInfo v; 682 u_getVersion(v); 683 return (uprv_memcmp(v, x, U_MAX_VERSION_LENGTH) >= 0); 684 } 685 #endif 686