1 /********************************************************************
3 * Copyright (c) 1997-2014, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
8 #include "unicode/utypes.h"
11 * IntlTest is a base class for tests.
20 #include "unicode/unistr.h"
21 #include "unicode/ures.h"
22 #include "unicode/smpdtfmt.h"
23 #include "unicode/ucnv.h"
24 #include "unicode/uclean.h"
25 #include "unicode/timezone.h"
26 #include "unicode/curramt.h"
27 #include "unicode/putil.h"
38 #include "putilimp.h" // for uprv_getRawUTCtime()
39 #include "unicode/locid.h"
40 #include "unicode/ctest.h" // for str_timeDelta
49 static char* _testDataPath
=NULL
;
51 // Static list of errors found
52 static UnicodeString errorList
;
53 static void *knownList
= NULL
; // known issues
54 static UBool noKnownIssues
= FALSE
; // if TRUE, don't emit known issues
56 //-----------------------------------------------------------------------------
57 //convenience classes to ease porting code that uses the Java
58 //string-concatenation operator (moved from findword test by rtg)
60 // [LIU] Just to get things working
62 UCharToUnicodeString(UChar c
)
63 { return UnicodeString(c
); }
65 // [rtg] Just to get things working
67 operator+(const UnicodeString
& left
,
70 char buffer
[64]; // nos changed from 10 to 64
71 char danger
= 'p'; // guard against overrunning the buffer (rtg)
73 sprintf(buffer
, "%ld", num
);
74 assert(danger
== 'p');
80 operator+(const UnicodeString
& left
,
83 char buffer
[64]; // nos changed from 10 to 64
84 char danger
= 'p'; // guard against overrunning the buffer (rtg)
86 sprintf(buffer
, "%lu", num
);
87 assert(danger
== 'p');
93 Int64ToUnicodeString(int64_t num
)
95 char buffer
[64]; // nos changed from 10 to 64
96 char danger
= 'p'; // guard against overrunning the buffer (rtg)
99 sprintf(buffer
, "%I64d", num
);
101 sprintf(buffer
, "%lld", (long long)num
);
103 assert(danger
== 'p');
108 // [LIU] Just to get things working
110 operator+(const UnicodeString
& left
,
113 char buffer
[64]; // was 32, made it arbitrarily bigger (rtg)
114 char danger
= 'p'; // guard against overrunning the buffer (rtg)
116 // IEEE floating point has 52 bits of mantissa, plus one assumed bit
117 // 53*log(2)/log(10) = 15.95
118 // so there is no need to show more than 16 digits. [alan]
120 sprintf(buffer
, "%.17g", num
);
121 assert(danger
== 'p');
123 return left
+ buffer
;
128 operator+(const UnicodeString
& left
,
130 return left
+ Int64ToUnicodeString(num
);
134 #if !UCONFIG_NO_FORMATTING
137 * Return a string display for this, without surrounding braces.
139 UnicodeString
_toString(const Formattable
& f
) {
141 switch (f
.getType()) {
142 case Formattable::kDate
:
144 UErrorCode status
= U_ZERO_ERROR
;
145 SimpleDateFormat
fmt(status
);
146 if (U_SUCCESS(status
)) {
148 fmt
.format(f
.getDate(), s
, pos
);
149 s
.insert(0, "Date:");
151 s
= UnicodeString("Error creating date format]");
155 case Formattable::kDouble
:
156 s
= UnicodeString("double:") + f
.getDouble();
158 case Formattable::kLong
:
159 s
= UnicodeString("long:") + f
.getLong();
162 case Formattable::kInt64
:
163 s
= UnicodeString("int64:") + Int64ToUnicodeString(f
.getInt64());
166 case Formattable::kString
:
168 s
.insert(0, "String:");
170 case Formattable::kArray
:
173 const Formattable
* array
= f
.getArray(n
);
174 s
.insert(0, UnicodeString("Array:"));
175 UnicodeString
delim(", ");
176 for (i
=0; i
<n
; ++i
) {
180 s
= s
+ _toString(array
[i
]);
184 case Formattable::kObject
: {
185 const CurrencyAmount
* c
= dynamic_cast<const CurrencyAmount
*>(f
.getObject());
187 s
= _toString(c
->getNumber()) + " " + UnicodeString(c
->getISOCurrency());
189 s
= UnicodeString("Unknown UObject");
194 s
= UnicodeString("Unknown Formattable type=") + (int32_t)f
.getType();
201 * Originally coded this as operator+, but that makes the expression
202 * + char* ambiguous. - liu
204 UnicodeString
toString(const Formattable
& f
) {
205 UnicodeString
s((UChar
)91/*[*/);
206 s
.append(_toString(f
));
207 s
.append((UChar
)0x5d/*]*/);
213 // useful when operator+ won't cooperate
214 UnicodeString
toString(int32_t n
) {
215 return UnicodeString() + (long)n
;
220 UnicodeString
toString(UBool b
) {
221 return b
? UnicodeString("TRUE"):UnicodeString("FALSE");
224 // stephen - cleaned up 05/05/99
225 UnicodeString
operator+(const UnicodeString
& left
, char num
)
226 { return left
+ (long)num
; }
227 UnicodeString
operator+(const UnicodeString
& left
, short num
)
228 { return left
+ (long)num
; }
229 UnicodeString
operator+(const UnicodeString
& left
, int num
)
230 { return left
+ (long)num
; }
231 UnicodeString
operator+(const UnicodeString
& left
, unsigned char num
)
232 { return left
+ (unsigned long)num
; }
233 UnicodeString
operator+(const UnicodeString
& left
, unsigned short num
)
234 { return left
+ (unsigned long)num
; }
235 UnicodeString
operator+(const UnicodeString
& left
, unsigned int num
)
236 { return left
+ (unsigned long)num
; }
237 UnicodeString
operator+(const UnicodeString
& left
, float num
)
238 { return left
+ (double)num
; }
242 // Append a hex string to the target
244 IntlTest::appendHex(uint32_t number
,
246 UnicodeString
& target
)
248 static const UChar digitString
[] = {
249 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
250 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0
251 }; /* "0123456789ABCDEF" */
253 if (digits
< 0) { // auto-digits
256 while (number
> max
) {
258 max
= (max
<< 8) | 0xff;
264 target
+= digitString
[(number
>> 28) & 0xF];
266 target
+= digitString
[(number
>> 24) & 0xF];
268 target
+= digitString
[(number
>> 20) & 0xF];
270 target
+= digitString
[(number
>> 16) & 0xF];
272 target
+= digitString
[(number
>> 12) & 0xF];
274 target
+= digitString
[(number
>> 8) & 0xF];
276 target
+= digitString
[(number
>> 4) & 0xF];
278 target
+= digitString
[(number
>> 0) & 0xF];
287 IntlTest::toHex(uint32_t number
, int32_t digits
) {
288 UnicodeString result
;
289 appendHex(number
, digits
, result
);
293 static inline UBool
isPrintable(UChar32 c
) {
294 return c
<= 0x7E && (c
>= 0x20 || c
== 9 || c
== 0xA || c
== 0xD);
297 // Replace nonprintable characters with unicode escapes
299 IntlTest::prettify(const UnicodeString
&source
,
300 UnicodeString
&target
)
307 for (i
= 0; i
< source
.length(); )
309 UChar32 ch
= source
.char32At(i
);
312 if (!isPrintable(ch
))
316 appendHex(ch
, 4, target
);
319 appendHex(ch
, 8, target
);
333 // Replace nonprintable characters with unicode escapes
335 IntlTest::prettify(const UnicodeString
&source
, UBool parseBackslash
)
338 UnicodeString target
;
342 for (i
= 0; i
< source
.length();)
344 UChar32 ch
= source
.char32At(i
);
347 if (!isPrintable(ch
))
349 if (parseBackslash
) {
350 // If we are preceded by an odd number of backslashes,
351 // then this character has already been backslash escaped.
352 // Delete a backslash.
353 int32_t backslashCount
= 0;
354 for (int32_t j
=target
.length()-1; j
>=0; --j
) {
355 if (target
.charAt(j
) == (UChar
)92) {
361 if ((backslashCount
% 2) == 1) {
362 target
.truncate(target
.length() - 1);
367 appendHex(ch
, 4, target
);
370 appendHex(ch
, 8, target
);
384 /* IntlTest::setICU_DATA - if the ICU_DATA environment variable is not already
385 * set, try to deduce the directory in which ICU was built,
386 * and set ICU_DATA to "icu/source/data" in that location.
387 * The intent is to allow the tests to have a good chance
388 * of running without requiring that the user manually set
389 * ICU_DATA. Common data isn't a problem, since it is
390 * picked up via a static (build time) reference, but the
391 * tests dynamically load some data.
393 void IntlTest::setICU_DATA() {
394 const char *original_ICU_DATA
= getenv("ICU_DATA");
396 if (original_ICU_DATA
!= NULL
&& *original_ICU_DATA
!= 0) {
397 /* If the user set ICU_DATA, don't second-guess the person. */
401 // U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst
402 // to point to the top of the build hierarchy, which may or
403 // may not be the same as the source directory, depending on
404 // the configure options used. At any rate,
405 // set the data path to the built data from this directory.
406 // The value is complete with quotes, so it can be used
407 // as-is as a string constant.
409 #if defined (U_TOPBUILDDIR)
411 static char env_string
[] = U_TOPBUILDDIR
"data" U_FILE_SEP_STRING
"out" U_FILE_SEP_STRING
;
412 u_setDataDirectory(env_string
);
417 // Use #else so we don't get compiler warnings due to the return above.
419 /* On Windows, the file name obtained from __FILE__ includes a full path.
420 * This file is "wherever\icu\source\test\cintltst\cintltst.c"
421 * Change to "wherever\icu\source\data"
424 char p
[sizeof(__FILE__
) + 10];
429 /* We want to back over three '\' chars. */
430 /* Only Windows should end up here, so looking for '\' is safe. */
431 for (i
=1; i
<=3; i
++) {
432 pBackSlash
= strrchr(p
, U_FILE_SEP_CHAR
);
433 if (pBackSlash
!= NULL
) {
434 *pBackSlash
= 0; /* Truncate the string at the '\' */
438 if (pBackSlash
!= NULL
) {
439 /* We found and truncated three names from the path.
440 * Now append "source\data" and set the environment
442 strcpy(pBackSlash
, U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
"out" U_FILE_SEP_STRING
);
443 u_setDataDirectory(p
); /* p is "ICU_DATA=wherever\icu\source\data" */
447 /* __FILE__ on MSVC7 does not contain the directory */
448 u_setDataDirectory(".."U_FILE_SEP_STRING
".."U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
"out" U_FILE_SEP_STRING
);
454 /* No location for the data dir was identifiable.
455 * Add other fallbacks for the test data location here if the need arises
460 //--------------------------------------------------------------------------------------
462 static const int32_t indentLevel_offset
= 3;
463 static const char delim
= '/';
465 IntlTest
* IntlTest::gTest
= NULL
;
467 static int32_t execCount
= 0;
469 void it_log( UnicodeString message
)
472 IntlTest::gTest
->log( message
);
475 void it_logln( UnicodeString message
)
478 IntlTest::gTest
->logln( message
);
481 void it_logln( void )
484 IntlTest::gTest
->logln();
487 void it_info( UnicodeString message
)
490 IntlTest::gTest
->info( message
);
493 void it_infoln( UnicodeString message
)
496 IntlTest::gTest
->infoln( message
);
499 void it_infoln( void )
502 IntlTest::gTest
->infoln();
508 IntlTest::gTest
->err();
511 void it_err( UnicodeString message
)
514 IntlTest::gTest
->err( message
);
517 void it_errln( UnicodeString message
)
520 IntlTest::gTest
->errln( message
);
523 void it_dataerr( UnicodeString message
)
526 IntlTest::gTest
->dataerr( message
);
529 void it_dataerrln( UnicodeString message
)
532 IntlTest::gTest
->dataerrln( message
);
545 warn_on_missing_data
= FALSE
;
550 LL_indentlevel
= indentLevel_offset
;
552 strcpy(basePath
, "/");
556 void IntlTest::setCaller( IntlTest
* callingTest
)
558 caller
= callingTest
;
560 warn_on_missing_data
= caller
->warn_on_missing_data
;
561 verbose
= caller
->verbose
;
562 no_err_msg
= caller
->no_err_msg
;
563 quick
= caller
->quick
;
564 testoutfp
= caller
->testoutfp
;
565 LL_indentlevel
= caller
->LL_indentlevel
+ indentLevel_offset
;
566 numProps
= caller
->numProps
;
567 for (int32_t i
= 0; i
< numProps
; i
++) {
568 proplines
[i
] = caller
->proplines
[i
];
573 UBool
IntlTest::callTest( IntlTest
& testToBeCalled
, char* par
)
575 execCount
--; // correct a previously assumed test-exec, as this only calls a subtest
576 testToBeCalled
.setCaller( this );
577 strcpy(testToBeCalled
.basePath
, this->basePath
);
578 UBool result
= testToBeCalled
.runTest( testPath
, par
, testToBeCalled
.basePath
);
579 strcpy(testToBeCalled
.basePath
, this->basePath
); // reset it.
583 void IntlTest::setPath( char* pathVal
)
585 this->testPath
= pathVal
;
588 UBool
IntlTest::setVerbose( UBool verboseVal
)
590 UBool rval
= this->verbose
;
591 this->verbose
= verboseVal
;
595 UBool
IntlTest::setNotime( UBool no_time
)
597 UBool rval
= this->no_time
;
598 this->no_time
= no_time
;
602 UBool
IntlTest::setWarnOnMissingData( UBool warn_on_missing_dataVal
)
604 UBool rval
= this->warn_on_missing_data
;
605 this->warn_on_missing_data
= warn_on_missing_dataVal
;
609 UBool
IntlTest::setNoErrMsg( UBool no_err_msgVal
)
611 UBool rval
= this->no_err_msg
;
612 this->no_err_msg
= no_err_msgVal
;
616 UBool
IntlTest::setQuick( UBool quickVal
)
618 UBool rval
= this->quick
;
619 this->quick
= quickVal
;
623 UBool
IntlTest::setLeaks( UBool leaksVal
)
625 UBool rval
= this->leaks
;
626 this->leaks
= leaksVal
;
630 int32_t IntlTest::setThreadCount( int32_t count
)
632 int32_t rval
= this->threadCount
;
633 this->threadCount
= count
;
637 int32_t IntlTest::getErrors( void )
642 int32_t IntlTest::getDataErrors( void )
644 return dataErrorCount
;
647 UBool
IntlTest::runTest( char* name
, char* par
, char *baseName
)
652 char* baseNameBuffer
= NULL
;
654 if(baseName
== NULL
) {
655 baseNameBuffer
= (char*)malloc(1024);
656 baseName
=baseNameBuffer
;
657 strcpy(baseName
, "/");
661 pos
= strchr( name
, delim
); // check if name contains path (by looking for '/')
663 testPath
= pos
+1; // store subpath for calling subtest
664 *pos
= 0; // split into two strings
669 if (!name
|| (name
[0] == 0) || (strcmp(name
, "*") == 0)) {
670 rval
= runTestLoop( NULL
, par
, baseName
);
672 }else if (strcmp( name
, "LIST" ) == 0) {
677 rval
= runTestLoop( name
, par
, baseName
);
681 *pos
= delim
; // restore original value at pos
682 if(baseNameBuffer
!=NULL
) {
683 free(baseNameBuffer
);
688 // call individual tests, to be overriden to call implementations
689 void IntlTest::runIndexedTest( int32_t /*index*/, UBool
/*exec*/, const char* & /*name*/, char* /*par*/ )
691 // to be overriden by a method like:
694 case 0: name = "First Test"; if (exec) FirstTest( par ); break;
695 case 1: name = "Second Test"; if (exec) SecondTest( par ); break;
696 default: name = ""; break;
699 this->errln("*** runIndexedTest needs to be overriden! ***");
703 UBool
IntlTest::runTestLoop( char* testname
, char* par
, char *baseName
)
708 int32_t lastErrorCount
;
710 UBool lastTestFailed
;
712 if(baseName
== NULL
) {
713 printf("ERROR: baseName can't be null.\n");
716 if ((char *)this->basePath
!= baseName
) {
717 strcpy(this->basePath
, baseName
);
721 char * saveBaseLoc
= baseName
+strlen(baseName
);
723 IntlTest
* saveTest
= gTest
;
726 this->runIndexedTest( index
, FALSE
, name
, par
);
727 if (strcmp(name
,"skip") == 0) {
728 run_this_test
= FALSE
;
730 if (!name
|| (name
[0] == 0))
733 run_this_test
= TRUE
;
735 run_this_test
= (UBool
) (strcmp( name
, testname
) == 0);
739 lastErrorCount
= errorCount
;
742 sprintf(msg
, "%s {", name
);
743 LL_message(msg
, TRUE
);
744 UDate timeStart
= uprv_getRawUTCtime();
745 strcpy(saveBaseLoc
,name
);
746 strcat(saveBaseLoc
,"/");
748 strcpy(currName
, name
); // set
749 this->runIndexedTest( index
, TRUE
, name
, par
);
750 currName
[0]=0; // reset
752 UDate timeStop
= uprv_getRawUTCtime();
753 rval
= TRUE
; // at least one test has been called
756 sprintf(secs
, "%f", (timeStop
-timeStart
)/1000.0);
762 strcpy(saveBaseLoc
,name
);
765 ctest_xml_testcase(baseName
, name
, secs
, (lastErrorCount
!=errorCount
)?"err":NULL
);
768 saveBaseLoc
[0]=0; /* reset path */
770 if (lastErrorCount
== errorCount
) {
771 sprintf( msg
, " } OK: %s ", name
);
772 if(!no_time
) str_timeDelta(msg
+strlen(msg
),timeStop
-timeStart
);
773 lastTestFailed
= FALSE
;
775 sprintf(msg
, " } ERRORS (%li) in %s", (long)(errorCount
-lastErrorCount
), name
);
776 if(!no_time
) str_timeDelta(msg
+strlen(msg
),timeStop
-timeStart
);
778 for(int i
=0;i
<LL_indentlevel
;i
++) {
783 lastTestFailed
= TRUE
;
786 if (lastTestFailed
) {
787 LL_message( "", TRUE
);
789 LL_message( msg
, TRUE
);
790 if (lastTestFailed
) {
791 LL_message( "", TRUE
);
806 * Adds given string to the log if we are in verbose mode.
808 void IntlTest::log( const UnicodeString
&message
)
811 LL_message( message
, FALSE
);
816 * Adds given string to the log if we are in verbose mode. Adds a new line to
819 void IntlTest::logln( const UnicodeString
&message
)
822 LL_message( message
, TRUE
);
826 void IntlTest::logln( void )
829 LL_message( "", TRUE
);
834 * Unconditionally adds given string to the log.
836 void IntlTest::info( const UnicodeString
&message
)
838 LL_message( message
, FALSE
);
842 * Unconditionally adds given string to the log. Adds a new line to
845 void IntlTest::infoln( const UnicodeString
&message
)
847 LL_message( message
, TRUE
);
850 void IntlTest::infoln( void )
852 LL_message( "", TRUE
);
855 int32_t IntlTest::IncErrorCount( void )
858 if (caller
) caller
->IncErrorCount();
862 int32_t IntlTest::IncDataErrorCount( void )
865 if (caller
) caller
->IncDataErrorCount();
866 return dataErrorCount
;
874 void IntlTest::err( const UnicodeString
&message
)
877 if (!no_err_msg
) LL_message( message
, FALSE
);
880 void IntlTest::errln( const UnicodeString
&message
)
883 if (!no_err_msg
) LL_message( message
, TRUE
);
886 void IntlTest::dataerr( const UnicodeString
&message
)
890 if (!warn_on_missing_data
) {
894 if (!no_err_msg
) LL_message( message
, FALSE
);
897 void IntlTest::dataerrln( const UnicodeString
&message
)
899 int32_t errCount
= IncDataErrorCount();
901 if (!warn_on_missing_data
) {
905 msg
= UnicodeString("[DATA] " + message
);
909 if ( errCount
== 1) {
910 LL_message( msg
+ " - (Are you missing data?)", TRUE
); // only show this message the first time
912 LL_message( msg
, TRUE
);
917 void IntlTest::errcheckln(UErrorCode status
, const UnicodeString
&message
) {
918 if (status
== U_FILE_ACCESS_ERROR
|| status
== U_MISSING_RESOURCE_ERROR
) {
925 /* convenience functions that include sprintf formatting */
926 void IntlTest::log(const char *fmt
, ...)
932 /* sprintf it just to make sure that the information is valid */
933 vsprintf(buffer
, fmt
, ap
);
936 log(UnicodeString(buffer
, ""));
940 void IntlTest::logln(const char *fmt
, ...)
946 /* sprintf it just to make sure that the information is valid */
947 vsprintf(buffer
, fmt
, ap
);
950 logln(UnicodeString(buffer
, ""));
954 UBool
IntlTest::logKnownIssue(const char *ticket
, const char *fmt
, ...)
960 /* sprintf it just to make sure that the information is valid */
961 vsprintf(buffer
, fmt
, ap
);
963 return logKnownIssue(ticket
, UnicodeString(buffer
, ""));
966 UBool
IntlTest::logKnownIssue(const char *ticket
) {
967 return logKnownIssue(ticket
, UnicodeString());
970 UBool
IntlTest::logKnownIssue(const char *ticket
, const UnicodeString
&msg
) {
971 if(noKnownIssues
) return FALSE
;
974 strcpy(fullpath
, basePath
);
975 strcat(fullpath
, currName
);
976 UnicodeString msg2
=msg
;
977 UBool firstForTicket
, firstForWhere
;
978 knownList
= udbg_knownIssue_openU(knownList
, ticket
, fullpath
, msg2
.getTerminatedBuffer(), &firstForTicket
, &firstForWhere
);
980 if(firstForTicket
|| firstForWhere
) {
981 infoln(UnicodeString("(Known issue #","") + UnicodeString(ticket
,"")+ UnicodeString(") \"","") + msg
);
983 logln(UnicodeString("(Known issue #","") + UnicodeString(ticket
,"")+ UnicodeString(") \"","") + msg
);
989 /* convenience functions that include sprintf formatting */
990 void IntlTest::info(const char *fmt
, ...)
996 /* sprintf it just to make sure that the information is valid */
997 vsprintf(buffer
, fmt
, ap
);
999 info(UnicodeString(buffer
, ""));
1002 void IntlTest::infoln(const char *fmt
, ...)
1008 /* sprintf it just to make sure that the information is valid */
1009 vsprintf(buffer
, fmt
, ap
);
1011 infoln(UnicodeString(buffer
, ""));
1014 void IntlTest::err(const char *fmt
, ...)
1020 vsprintf(buffer
, fmt
, ap
);
1022 err(UnicodeString(buffer
, ""));
1025 void IntlTest::errln(const char *fmt
, ...)
1031 vsprintf(buffer
, fmt
, ap
);
1033 errln(UnicodeString(buffer
, ""));
1036 void IntlTest::dataerrln(const char *fmt
, ...)
1042 vsprintf(buffer
, fmt
, ap
);
1044 dataerrln(UnicodeString(buffer
, ""));
1047 void IntlTest::errcheckln(UErrorCode status
, const char *fmt
, ...)
1053 vsprintf(buffer
, fmt
, ap
);
1056 if (status
== U_FILE_ACCESS_ERROR
|| status
== U_MISSING_RESOURCE_ERROR
) {
1057 dataerrln(UnicodeString(buffer
, ""));
1059 errln(UnicodeString(buffer
, ""));
1063 void IntlTest::printErrors()
1065 IntlTest::LL_message(errorList
, TRUE
);
1068 UBool
IntlTest::printKnownIssues()
1070 if(knownList
!= NULL
) {
1071 udbg_knownIssue_print(knownList
);
1072 udbg_knownIssue_close(knownList
);
1079 void IntlTest::LL_message( UnicodeString message
, UBool newline
)
1081 // string that starts with a LineFeed character and continues
1082 // with spaces according to the current indentation
1083 static const UChar indentUChars
[] = {
1085 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1086 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1087 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1088 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1089 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1090 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1091 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1092 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1093 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1094 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
1096 UnicodeString
indent(FALSE
, indentUChars
, 1 + LL_indentlevel
);
1101 // stream out the indentation string first if necessary
1102 length
= indent
.extract(1, indent
.length(), buffer
, sizeof(buffer
));
1104 fwrite(buffer
, sizeof(*buffer
), length
, (FILE *)testoutfp
);
1107 // replace each LineFeed by the indentation string
1108 message
.findAndReplace(UnicodeString((UChar
)'\n'), indent
);
1110 // stream out the message
1111 length
= message
.extract(0, message
.length(), buffer
, sizeof(buffer
));
1113 length
= length
> 30000 ? 30000 : length
;
1114 fwrite(buffer
, sizeof(*buffer
), length
, (FILE *)testoutfp
);
1118 char newLine
= '\n';
1119 fwrite(&newLine
, sizeof(newLine
), 1, (FILE *)testoutfp
);
1122 // A newline usually flushes the buffer, but
1123 // flush the message just in case of a core dump.
1124 fflush((FILE *)testoutfp
);
1128 * Print a usage message for this test class.
1130 void IntlTest::usage( void )
1132 UBool save_verbose
= setVerbose( TRUE
);
1133 logln("Test names:");
1134 logln("-----------");
1137 const char* name
= NULL
;
1139 this->runIndexedTest( index
, FALSE
, name
);
1143 }while (name
&& (name
[0] != 0));
1144 setVerbose( save_verbose
);
1148 // memory leak reporting software will be able to take advantage of the testsuite
1149 // being run a second time local to a specific method in order to report only actual leaks
1151 IntlTest::run_phase2( char* name
, char* par
) // supports reporting memory leaks
1153 UnicodeString
* strLeak
= new UnicodeString("forced leak"); // for verifying purify filter
1154 strLeak
->append(" for verifying purify filter");
1155 return this->runTest( name
, par
);
1159 #if UCONFIG_NO_LEGACY_CONVERSION
1160 # define TRY_CNV_1 "iso-8859-1"
1161 # define TRY_CNV_2 "ibm-1208"
1163 # define TRY_CNV_1 "iso-8859-7"
1164 # define TRY_CNV_2 "sjis"
1168 main(int argc
, char* argv
[])
1170 UBool syntax
= FALSE
;
1172 UBool verbose
= FALSE
;
1173 UBool no_err_msg
= FALSE
;
1174 UBool no_time
= FALSE
;
1177 UBool leaks
= FALSE
;
1179 const char *summary_file
= NULL
;
1180 UBool warnOnMissingData
= FALSE
;
1181 UBool defaultDataFound
= FALSE
;
1182 int32_t threadCount
= 1;
1183 UErrorCode errorCode
= U_ZERO_ERROR
;
1184 UConverter
*cnv
= NULL
;
1185 const char *warnOrErr
= "Failure";
1186 UDate startTime
, endTime
;
1188 const char *props
[IntlTest::kMaxProps
];
1191 U_MAIN_INIT_ARGS(argc
, argv
);
1193 startTime
= uprv_getRawUTCtime();
1195 for (int i
= 1; i
< argc
; ++i
) {
1196 if (argv
[i
][0] == '-') {
1197 const char* str
= argv
[i
] + 1;
1198 if (strcmp("verbose", str
) == 0 ||
1199 strcmp("v", str
) == 0)
1201 else if (strcmp("noerrormsg", str
) == 0 ||
1202 strcmp("n", str
) == 0)
1204 else if (strcmp("exhaustive", str
) == 0 ||
1205 strcmp("e", str
) == 0)
1207 else if (strcmp("all", str
) == 0 ||
1208 strcmp("a", str
) == 0)
1210 else if (strcmp("utf-8", str
) == 0 ||
1211 strcmp("u", str
) == 0)
1213 else if (strcmp("noknownissues", str
) == 0 ||
1214 strcmp("K", str
) == 0)
1215 noKnownIssues
= TRUE
;
1216 else if (strcmp("leaks", str
) == 0 ||
1217 strcmp("l", str
) == 0)
1219 else if (strcmp("notime", str
) == 0 ||
1220 strcmp("T", str
) == 0)
1222 else if (strncmp("E", str
, 1) == 0)
1223 summary_file
= str
+1;
1224 else if (strcmp("x", str
)==0) {
1226 printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n");
1229 if(ctest_xml_setFileName(argv
[i
])) { /* set the name */
1230 return 1; /* error */
1232 } else if (strcmp("w", str
) == 0) {
1233 warnOnMissingData
= TRUE
;
1234 warnOrErr
= "WARNING";
1236 else if (strncmp("threads:", str
, 8) == 0) {
1237 threadCount
= atoi(str
+ 8);
1239 else if (strncmp("prop:", str
, 5) == 0) {
1240 if (nProps
< IntlTest::kMaxProps
) {
1241 props
[nProps
] = str
+ 5;
1253 if (!all
&& !name
) {
1255 } else if (all
&& name
) {
1262 "### IntlTest [-option1 -option2 ...] [testname1 testname2 ...] \n"
1264 "### Options are: verbose (v), all (a), noerrormsg (n), \n"
1265 "### exhaustive (e), leaks (l), -x xmlfile.xml, prop:<propery>=<value>, \n"
1266 "### notime (T), \n"
1267 "### threads:<threadCount> (Mulithreading must first be \n"
1268 "### enabled otherwise this will be ignored. \n"
1269 "### The default thread count is 1.),\n"
1270 "### (Specify either -all (shortcut -a) or a test name). \n"
1271 "### -all will run all of the tests.\n"
1273 "### To get a list of the test names type: intltest LIST \n"
1274 "### To run just the utility tests type: intltest utility \n"
1276 "### Test names can be nested using slashes (\"testA/subtest1\") \n"
1277 "### For example to list the utility tests type: intltest utility/LIST \n"
1278 "### To run just the Locale test type: intltest utility/LocaleTest \n"
1280 "### A parameter can be specified for a test by appending '@' and the value \n"
1281 "### to the testname. \n\n");
1285 if (nProps
> IntlTest::kMaxProps
) {
1286 fprintf(stdout
, "### Too many properties. Exiting.\n");
1289 MajorTestLevel major
;
1290 major
.setVerbose( verbose
);
1291 major
.setNoErrMsg( no_err_msg
);
1292 major
.setQuick( quick
);
1293 major
.setLeaks( leaks
);
1294 major
.setThreadCount( threadCount
);
1295 major
.setWarnOnMissingData( warnOnMissingData
);
1296 major
.setNotime (no_time
);
1297 for (int32_t i
= 0; i
< nProps
; i
++) {
1298 major
.setProperty(props
[i
]);
1302 fprintf(stdout
, "-----------------------------------------------\n");
1303 fprintf(stdout
, " IntlTest (C++) Test Suite for \n");
1304 fprintf(stdout
, " International Components for Unicode %s\n", U_ICU_VERSION
);
1308 const char *charsetFamily
= "Unknown";
1309 int32_t voidSize
= (int32_t)sizeof(void*);
1310 int32_t bits
= voidSize
* 8;
1311 if(U_CHARSET_FAMILY
==U_ASCII_FAMILY
) {
1312 charsetFamily
="ASCII";
1313 } else if(U_CHARSET_FAMILY
==U_EBCDIC_FAMILY
) {
1314 charsetFamily
="EBCDIC";
1317 " Bits: %d, Byte order: %s, Chars: %s\n",
1318 bits
, U_IS_BIG_ENDIAN
?"Big endian":"Little endian",
1321 fprintf(stdout
, "-----------------------------------------------\n");
1322 fprintf(stdout
, " Options: \n");
1323 fprintf(stdout
, " all (a) : %s\n", (all
? "On" : "Off"));
1324 fprintf(stdout
, " Verbose (v) : %s\n", (verbose
? "On" : "Off"));
1325 fprintf(stdout
, " No error messages (n) : %s\n", (no_err_msg
? "On" : "Off"));
1326 fprintf(stdout
, " Exhaustive (e) : %s\n", (!quick
? "On" : "Off"));
1327 fprintf(stdout
, " Leaks (l) : %s\n", (leaks
? "On" : "Off"));
1328 fprintf(stdout
, " utf-8 (u) : %s\n", (utf8
? "On" : "Off"));
1329 fprintf(stdout
, " notime (T) : %s\n", (no_time
? "On" : "Off"));
1330 fprintf(stdout
, " noknownissues (K) : %s\n", (noKnownIssues
? "On" : "Off"));
1331 fprintf(stdout
, " Warn on missing data (w) : %s\n", (warnOnMissingData
? "On" : "Off"));
1332 #if (ICU_USE_THREADS==0)
1333 fprintf(stdout
, " Threads : Disabled\n");
1335 fprintf(stdout
, " Threads : %d\n", threadCount
);
1337 for (int32_t i
= 0; i
< nProps
; i
++) {
1338 fprintf(stdout
, " Custom property (prop:) : %s\n", props
[i
]);
1340 fprintf(stdout
, "-----------------------------------------------\n");
1343 ucnv_setDefaultName("utf-8");
1345 /* Check whether ICU will initialize without forcing the build data directory into
1346 * the ICU_DATA path. Success here means either the data dll contains data, or that
1347 * this test program was run with ICU_DATA set externally. Failure of this check
1348 * is normal when ICU data is not packaged into a shared library.
1350 * Whether or not this test succeeds, we want to cleanup and reinitialize
1351 * with a data path so that data loading from individual files can be tested.
1354 if (U_FAILURE(errorCode
)) {
1356 "#### Note: ICU Init without build-specific setDataDirectory() failed.\n");
1357 defaultDataFound
= FALSE
;
1360 defaultDataFound
= TRUE
;
1364 ucnv_setDefaultName("utf-8");
1366 errorCode
= U_ZERO_ERROR
;
1368 /* Initialize ICU */
1369 if (!defaultDataFound
) {
1370 IntlTest::setICU_DATA(); // Must set data directory before u_init() is called.
1373 if (U_FAILURE(errorCode
)) {
1375 "#### ERROR! %s: u_init() failed with status = \"%s\".\n"
1376 "*** Check the ICU_DATA environment variable and \n"
1377 "*** check that the data files are present.\n", argv
[0], u_errorName(errorCode
));
1378 if(warnOnMissingData
== 0) {
1379 fprintf(stderr
, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
1385 // initial check for the default converter
1386 errorCode
= U_ZERO_ERROR
;
1387 cnv
= ucnv_open(0, &errorCode
);
1393 "*** %s! The default converter [%s] cannot be opened.\n"
1394 "*** Check the ICU_DATA environment variable and\n"
1395 "*** check that the data files are present.\n",
1396 warnOrErr
, ucnv_getDefaultName());
1397 if(!warnOnMissingData
) {
1398 fprintf(stdout
, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
1404 cnv
= ucnv_open(TRY_CNV_2
, &errorCode
);
1410 "*** %s! The converter for " TRY_CNV_2
" cannot be opened.\n"
1411 "*** Check the ICU_DATA environment variable and \n"
1412 "*** check that the data files are present.\n", warnOrErr
);
1413 if(!warnOnMissingData
) {
1414 fprintf(stdout
, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
1419 UResourceBundle
*rb
= ures_open(0, "en", &errorCode
);
1421 if(U_FAILURE(errorCode
)) {
1423 "*** %s! The \"en\" locale resource bundle cannot be opened.\n"
1424 "*** Check the ICU_DATA environment variable and \n"
1425 "*** check that the data files are present.\n", warnOrErr
);
1426 if(!warnOnMissingData
) {
1427 fprintf(stdout
, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
1432 Locale originalLocale
; // Save the default locale for comparison later on.
1434 if(ctest_xml_init("intltest"))
1438 /* TODO: Add option to call u_cleanup and rerun tests. */
1442 major
.run_phase2( NULL
, NULL
);
1445 for (int i
= 1; i
< argc
; ++i
) {
1446 if (argv
[i
][0] != '-') {
1447 char* name
= argv
[i
];
1448 fprintf(stdout
, "\n=== Handling test: %s: ===\n", name
);
1450 char baseName
[1024];
1451 sprintf(baseName
, "/%s/", name
);
1453 char* parameter
= strchr( name
, '@' );
1459 UBool res
= major
.runTest( name
, parameter
, baseName
);
1461 major
.run_phase2( name
, parameter
);
1463 if (!res
|| (execCount
<= 0)) {
1464 fprintf(stdout
, "\n---ERROR: Test doesn't exist: %s!\n", name
);
1466 } else if(!strcmp(argv
[i
],"-x")) {
1473 #if !UCONFIG_NO_FORMATTING
1474 CalendarTimeZoneTest::cleanup();
1477 free(_testDataPath
);
1480 Locale lastDefaultLocale
;
1481 if (originalLocale
!= lastDefaultLocale
) {
1482 major
.errln("FAILURE: A test changed the default locale without resetting it.");
1485 fprintf(stdout
, "\n--------------------------------------\n");
1486 if( major
.printKnownIssues() ) {
1487 fprintf(stdout
, " To run suppressed tests, use the -K option. \n");
1489 if (major
.getErrors() == 0) {
1490 /* Call it twice to make sure that the defaults were reset. */
1491 /* Call it before the OK message to verify proper cleanup. */
1495 fprintf(stdout
, "OK: All tests passed without error.\n");
1497 if (major
.getDataErrors() != 0) {
1498 fprintf(stdout
, "\t*WARNING* some data-loading errors were ignored by the -w option.\n");
1501 fprintf(stdout
, "Errors in total: %ld.\n", (long)major
.getErrors());
1502 major
.printErrors();
1504 if(summary_file
!= NULL
) {
1505 FILE *summf
= fopen(summary_file
, "w");
1506 if( summf
!= NULL
) {
1508 int32_t length
= errorList
.extract(0, errorList
.length(), buf
, sizeof(buf
));
1509 fwrite(buf
, sizeof(*buf
), length
, (FILE*)summf
);
1515 if (major
.getDataErrors() != 0) {
1516 fprintf(stdout
, "\t*Note* some errors are data-loading related. If the data used is not the \n"
1517 "\tstock ICU data (i.e some have been added or removed), consider using\n"
1518 "\tthe '-w' option to turn these errors into warnings.\n");
1521 /* Call afterwards to display errors. */
1525 fprintf(stdout
, "--------------------------------------\n");
1527 if (execCount
<= 0) {
1528 fprintf(stdout
, "***** Not all called tests actually exist! *****\n");
1531 endTime
= uprv_getRawUTCtime();
1532 diffTime
= (int32_t)(endTime
- startTime
);
1533 printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
1534 (int)((diffTime%U_MILLIS_PER_DAY
)/U_MILLIS_PER_HOUR
),
1535 (int)((diffTime%U_MILLIS_PER_HOUR
)/U_MILLIS_PER_MINUTE
),
1536 (int)((diffTime%U_MILLIS_PER_MINUTE
)/U_MILLIS_PER_SECOND
),
1537 (int)(diffTime%U_MILLIS_PER_SECOND
));
1540 if(ctest_xml_fini())
1543 return major
.getErrors();
1546 const char* IntlTest::loadTestData(UErrorCode
& err
){
1547 if( _testDataPath
== NULL
){
1548 const char* directory
=NULL
;
1549 UResourceBundle
* test
=NULL
;
1551 const char* tdrelativepath
;
1553 #if defined (U_TOPBUILDDIR)
1554 tdrelativepath
= "test" U_FILE_SEP_STRING
"testdata" U_FILE_SEP_STRING
"out" U_FILE_SEP_STRING
;
1555 directory
= U_TOPBUILDDIR
;
1557 tdrelativepath
= ".." U_FILE_SEP_STRING
"test" U_FILE_SEP_STRING
"testdata" U_FILE_SEP_STRING
"out" U_FILE_SEP_STRING
;
1558 directory
= pathToDataDirectory();
1561 tdpath
= (char*) malloc(sizeof(char) *(( strlen(directory
) * strlen(tdrelativepath
)) + 100));
1564 /* u_getDataDirectory shoul return \source\data ... set the
1565 * directory to ..\source\data\..\test\testdata\out\testdata
1567 strcpy(tdpath
, directory
);
1568 strcat(tdpath
, tdrelativepath
);
1569 strcat(tdpath
,"testdata");
1571 test
=ures_open(tdpath
, "testtypes", &err
);
1574 err
= U_FILE_ACCESS_ERROR
;
1575 it_dataerrln((UnicodeString
)"Could not load testtypes.res in testdata bundle with path " + tdpath
+ (UnicodeString
)" - " + u_errorName(err
));
1579 _testDataPath
= tdpath
;
1580 return _testDataPath
;
1582 return _testDataPath
;
1585 const char* IntlTest::getTestDataPath(UErrorCode
& err
) {
1586 return loadTestData(err
);
1589 /* Returns the path to icu/source/test/testdata/ */
1590 const char *IntlTest::getSourceTestData(UErrorCode
& /*err*/) {
1591 const char *srcDataDir
= NULL
;
1593 srcDataDir
= U_TOPSRCDIR U_FILE_SEP_STRING
"test" U_FILE_SEP_STRING
"testdata" U_FILE_SEP_STRING
;
1595 srcDataDir
= ".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
"test" U_FILE_SEP_STRING
"testdata" U_FILE_SEP_STRING
;
1596 FILE *f
= fopen(".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
"test" U_FILE_SEP_STRING
"testdata" U_FILE_SEP_STRING
"rbbitst.txt", "r");
1598 /* We're in icu/source/test/intltest/ */
1602 /* We're in icu/source/test/intltest/Platform/(Debug|Release) */
1603 srcDataDir
= ".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
"test" U_FILE_SEP_STRING
"testdata"U_FILE_SEP_STRING
;
1609 const char* IntlTest::fgDataDir
= NULL
;
1611 /* returns the path to icu/source/data */
1612 const char * IntlTest::pathToDataDirectory()
1615 if(fgDataDir
!= NULL
) {
1619 /* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst
1620 // to point to the top of the build hierarchy, which may or
1621 // may not be the same as the source directory, depending on
1622 // the configure options used. At any rate,
1623 // set the data path to the built data from this directory.
1624 // The value is complete with quotes, so it can be used
1625 // as-is as a string constant.
1627 #if defined (U_TOPSRCDIR)
1629 fgDataDir
= U_TOPSRCDIR U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
;
1633 /* On Windows, the file name obtained from __FILE__ includes a full path.
1634 * This file is "wherever\icu\source\test\cintltst\cintltst.c"
1635 * Change to "wherever\icu\source\data"
1638 static char p
[sizeof(__FILE__
) + 10];
1642 strcpy(p
, __FILE__
);
1643 /* We want to back over three '\' chars. */
1644 /* Only Windows should end up here, so looking for '\' is safe. */
1645 for (i
=1; i
<=3; i
++) {
1646 pBackSlash
= strrchr(p
, U_FILE_SEP_CHAR
);
1647 if (pBackSlash
!= NULL
) {
1648 *pBackSlash
= 0; /* Truncate the string at the '\' */
1652 if (pBackSlash
!= NULL
) {
1653 /* We found and truncated three names from the path.
1654 * Now append "source\data" and set the environment
1656 strcpy(pBackSlash
, U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
);
1660 /* __FILE__ on MSVC7 does not contain the directory */
1661 FILE *file
= fopen(".." U_FILE_SEP_STRING
".."U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
"Makefile.in", "r");
1664 fgDataDir
= ".." U_FILE_SEP_STRING
".."U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
;
1667 fgDataDir
= ".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
".." U_FILE_SEP_STRING
".."U_FILE_SEP_STRING
"data" U_FILE_SEP_STRING
;
1678 * This is a variant of cintltst/ccolltst.c:CharsToUChars().
1679 * It converts an invariant-character string into a UnicodeString, with
1680 * unescaping \u sequences.
1682 UnicodeString
CharsToUnicodeString(const char* chars
){
1683 return UnicodeString(chars
, -1, US_INV
).unescape();
1686 UnicodeString
ctou(const char* chars
) {
1687 return CharsToUnicodeString(chars
);
1690 #define RAND_M (714025)
1691 #define RAND_IA (1366)
1692 #define RAND_IC (150889)
1694 static int32_t RAND_SEED
;
1697 * Returns a uniform random value x, with 0.0 <= x < 1.0. Use
1698 * with care: Does not return all possible values; returns one of
1699 * 714,025 values, uniformly spaced. However, the period is
1700 * effectively infinite. See: Numerical Recipes, section 7.1.
1702 * @param seedp pointer to seed. Set *seedp to any negative value
1703 * to restart the sequence.
1705 float IntlTest::random(int32_t* seedp
) {
1706 static int32_t iy
, ir
[98];
1707 static UBool first
=TRUE
;
1709 if (*seedp
< 0 || first
) {
1711 if ((*seedp
=(RAND_IC
-(*seedp
)) % RAND_M
) < 0) *seedp
= -(*seedp
);
1712 for (j
=1;j
<=97;++j
) {
1713 *seedp
=(RAND_IA
*(*seedp
)+RAND_IC
) % RAND_M
;
1716 *seedp
=(RAND_IA
*(*seedp
)+RAND_IC
) % RAND_M
;
1719 j
=(int32_t)(1 + 97.0*iy
/RAND_M
);
1720 U_ASSERT(j
>=1 && j
<=97);
1722 *seedp
=(RAND_IA
*(*seedp
)+RAND_IC
) % RAND_M
;
1724 return (float) iy
/RAND_M
;
1728 * Convenience method using a global seed.
1730 float IntlTest::random() {
1731 return random(&RAND_SEED
);
1734 static inline UChar
toHex(int32_t i
) {
1735 return (UChar
)(i
+ (i
< 10 ? 0x30 : (0x41 - 10)));
1738 static UnicodeString
& escape(const UnicodeString
& s
, UnicodeString
& result
) {
1739 for (int32_t i
=0; i
<s
.length(); ++i
) {
1741 if (c
<= (UChar
)0x7F) {
1744 result
+= (UChar
)0x5c;
1745 result
+= (UChar
)0x75;
1746 result
+= toHex((c
>> 12) & 0xF);
1747 result
+= toHex((c
>> 8) & 0xF);
1748 result
+= toHex((c
>> 4) & 0xF);
1749 result
+= toHex( c
& 0xF);
1755 #define VERBOSE_ASSERTIONS
1757 UBool
IntlTest::assertTrue(const char* message
, UBool condition
, UBool quiet
, UBool possibleDataError
, const char *file
, int line
) {
1760 if (possibleDataError
) {
1761 dataerrln("%s:%d: FAIL: assertTrue() failed: %s", file
, line
, message
);
1763 errln("%s:%d: FAIL: assertTrue() failed: %s", file
, line
, message
);
1765 } else if (!quiet
) {
1766 logln("%s:%d: Ok: %s", file
, line
, message
);
1770 if (possibleDataError
) {
1771 dataerrln("FAIL: assertTrue() failed: %s", message
);
1773 errln("FAIL: assertTrue() failed: %s", message
);
1775 } else if (!quiet
) {
1776 logln("Ok: %s", message
);
1783 UBool
IntlTest::assertFalse(const char* message
, UBool condition
, UBool quiet
) {
1785 errln("FAIL: assertFalse() failed: %s", message
);
1786 } else if (!quiet
) {
1787 logln("Ok: %s", message
);
1792 UBool
IntlTest::assertSuccess(const char* message
, UErrorCode ec
, UBool possibleDataError
, const char *file
, int line
) {
1794 file
= ""; // prevent failure if no file given
1796 if (U_FAILURE(ec
)) {
1797 if (possibleDataError
) {
1798 dataerrln("FAIL: %s:%d: %s (%s)", file
, line
, message
, u_errorName(ec
));
1800 errcheckln(ec
, "FAIL: %s:%d: %s (%s)", file
, line
, message
, u_errorName(ec
));
1804 logln("OK: %s:%d: %s - (%s)", file
, line
, message
, u_errorName(ec
));
1809 UBool
IntlTest::assertEquals(const char* message
,
1810 const UnicodeString
& expected
,
1811 const UnicodeString
& actual
,
1812 UBool possibleDataError
) {
1813 if (expected
!= actual
) {
1814 if (possibleDataError
) {
1815 dataerrln((UnicodeString
)"FAIL: " + message
+ "; got " +
1817 "; expected " + prettify(expected
));
1819 errln((UnicodeString
)"FAIL: " + message
+ "; got " +
1821 "; expected " + prettify(expected
));
1825 #ifdef VERBOSE_ASSERTIONS
1827 logln((UnicodeString
)"Ok: " + message
+ "; got " + prettify(actual
));
1833 UBool
IntlTest::assertEquals(const char* message
,
1834 const char* expected
,
1835 const char* actual
) {
1836 if (uprv_strcmp(expected
, actual
) != 0) {
1837 errln((UnicodeString
)"FAIL: " + message
+ "; got \"" +
1839 "\"; expected \"" + expected
+ "\"");
1842 #ifdef VERBOSE_ASSERTIONS
1844 logln((UnicodeString
)"Ok: " + message
+ "; got \"" + actual
+ "\"");
1850 UBool
IntlTest::assertEquals(const char* message
,
1853 if (expected
!= actual
) {
1854 errln((UnicodeString
)"FAIL: " + message
+ "; got " +
1855 actual
+ "=0x" + toHex(actual
) +
1856 "; expected " + expected
+ "=0x" + toHex(expected
));
1859 #ifdef VERBOSE_ASSERTIONS
1861 logln((UnicodeString
)"Ok: " + message
+ "; got " + actual
+ "=0x" + toHex(actual
));
1867 UBool
IntlTest::assertEquals(const char* message
,
1870 if (expected
!= actual
) {
1871 errln((UnicodeString
)"FAIL: " + message
+ "; got int64 " +
1872 Int64ToUnicodeString(actual
) +
1873 "; expected " + Int64ToUnicodeString(expected
) );
1876 #ifdef VERBOSE_ASSERTIONS
1878 logln((UnicodeString
)"Ok: " + message
+ "; got int64 " + Int64ToUnicodeString(actual
));
1884 UBool
IntlTest::assertEquals(const char* message
,
1887 if (expected
!= actual
) {
1888 errln((UnicodeString
)"FAIL: " + message
+ "; got " +
1890 "; expected " + toString(expected
));
1893 #ifdef VERBOSE_ASSERTIONS
1895 logln((UnicodeString
)"Ok: " + message
+ "; got " + toString(actual
));
1901 #if !UCONFIG_NO_FORMATTING
1902 UBool
IntlTest::assertEquals(const char* message
,
1903 const Formattable
& expected
,
1904 const Formattable
& actual
,
1905 UBool possibleDataError
) {
1906 if (expected
!= actual
) {
1907 if (possibleDataError
) {
1908 dataerrln((UnicodeString
)"FAIL: " + message
+ "; got " +
1910 "; expected " + toString(expected
));
1912 errln((UnicodeString
)"FAIL: " + message
+ "; got " +
1914 "; expected " + toString(expected
));
1918 #ifdef VERBOSE_ASSERTIONS
1920 logln((UnicodeString
)"Ok: " + message
+ "; got " + toString(actual
));
1927 static char ASSERT_BUF
[256];
1929 static const char* extractToAssertBuf(const UnicodeString
& message
) {
1931 escape(message
, buf
);
1932 buf
.extract(0, 0x7FFFFFFF, ASSERT_BUF
, sizeof(ASSERT_BUF
)-1, 0);
1933 ASSERT_BUF
[sizeof(ASSERT_BUF
)-1] = 0;
1937 UBool
IntlTest::assertTrue(const UnicodeString
& message
, UBool condition
, UBool quiet
) {
1938 return assertTrue(extractToAssertBuf(message
), condition
, quiet
);
1941 UBool
IntlTest::assertFalse(const UnicodeString
& message
, UBool condition
, UBool quiet
) {
1942 return assertFalse(extractToAssertBuf(message
), condition
, quiet
);
1945 UBool
IntlTest::assertSuccess(const UnicodeString
& message
, UErrorCode ec
) {
1946 return assertSuccess(extractToAssertBuf(message
), ec
);
1949 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1950 const UnicodeString
& expected
,
1951 const UnicodeString
& actual
,
1952 UBool possibleDataError
) {
1953 return assertEquals(extractToAssertBuf(message
), expected
, actual
, possibleDataError
);
1956 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1957 const char* expected
,
1958 const char* actual
) {
1959 return assertEquals(extractToAssertBuf(message
), expected
, actual
);
1961 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1964 return assertEquals(extractToAssertBuf(message
), expected
, actual
);
1966 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1969 return assertEquals(extractToAssertBuf(message
), expected
, actual
);
1971 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1974 return assertEquals(extractToAssertBuf(message
), expected
, actual
);
1977 #if !UCONFIG_NO_FORMATTING
1978 UBool
IntlTest::assertEquals(const UnicodeString
& message
,
1979 const Formattable
& expected
,
1980 const Formattable
& actual
) {
1981 return assertEquals(extractToAssertBuf(message
), expected
, actual
);
1985 void IntlTest::setProperty(const char* propline
) {
1986 if (numProps
< kMaxProps
) {
1987 proplines
[numProps
] = propline
;
1992 const char* IntlTest::getProperty(const char* prop
) {
1993 const char* val
= NULL
;
1994 for (int32_t i
= 0; i
< numProps
; i
++) {
1995 int32_t plen
= uprv_strlen(prop
);
1996 if ((int32_t)uprv_strlen(proplines
[i
]) > plen
+ 1
1997 && proplines
[i
][plen
] == '='
1998 && uprv_strncmp(proplines
[i
], prop
, plen
) == 0) {
1999 val
= &(proplines
[i
][plen
+1]);
2007 * Hey, Emacs, please set the following:
2010 * indent-tabs-mode: nil