2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2001-07-31 23:32:59 +00:00
|
|
|
* COPYRIGHT:
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 1997-2016, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
2000-01-15 02:00:06 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-29 07:28:22 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* IntlTest is a base class for tests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2001-01-23 23:51:55 +00:00
|
|
|
#include <stdarg.h>
|
2015-10-06 23:13:49 +00:00
|
|
|
#include <stdio.h>
|
2001-08-31 18:02:09 +00:00
|
|
|
#include <stdlib.h>
|
2015-10-06 23:13:49 +00:00
|
|
|
#include <string.h>
|
2018-02-09 02:35:02 +00:00
|
|
|
#include <cmath>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "unicode/ctest.h" // for str_timeDelta
|
2004-04-27 21:47:09 +00:00
|
|
|
#include "unicode/curramt.h"
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "unicode/locid.h"
|
2004-11-10 03:47:56 +00:00
|
|
|
#include "unicode/putil.h"
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/uclean.h"
|
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "unicode/ures.h"
|
2017-09-14 06:24:35 +00:00
|
|
|
#include "unicode/utf16.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#include "intltest.h"
|
2015-10-06 23:13:49 +00:00
|
|
|
|
2001-09-01 01:55:48 +00:00
|
|
|
#include "caltztst.h"
|
2004-08-02 20:06:55 +00:00
|
|
|
#include "cmemory.h"
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "cstring.h"
|
|
|
|
#include "itmajor.h"
|
|
|
|
#include "mutex.h"
|
2010-05-25 19:55:05 +00:00
|
|
|
#include "putilimp.h" // for uprv_getRawUTCtime()
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "uassert.h"
|
2013-09-16 22:07:02 +00:00
|
|
|
#include "udbgutil.h"
|
2015-10-06 23:13:49 +00:00
|
|
|
#include "umutex.h"
|
|
|
|
#include "uoptions.h"
|
2005-07-07 07:54:43 +00:00
|
|
|
|
2001-05-03 00:20:53 +00:00
|
|
|
#ifdef XP_MAC_CONSOLE
|
1999-08-16 21:50:52 +00:00
|
|
|
#include <console.h>
|
2001-05-03 00:29:26 +00:00
|
|
|
#include "Files.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
2000-08-29 07:28:22 +00:00
|
|
|
|
2001-06-20 22:25:25 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
static char* _testDataPath=NULL;
|
2000-12-03 03:29:39 +00:00
|
|
|
|
|
|
|
// Static list of errors found
|
2001-07-11 18:30:18 +00:00
|
|
|
static UnicodeString errorList;
|
2013-09-17 00:21:47 +00:00
|
|
|
static void *knownList = NULL; // known issues
|
|
|
|
static UBool noKnownIssues = FALSE; // if TRUE, don't emit known issues
|
2000-12-03 03:29:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//convenience classes to ease porting code that uses the Java
|
|
|
|
//string-concatenation operator (moved from findword test by rtg)
|
|
|
|
|
|
|
|
// [LIU] Just to get things working
|
|
|
|
UnicodeString
|
|
|
|
UCharToUnicodeString(UChar c)
|
|
|
|
{ return UnicodeString(c); }
|
|
|
|
|
|
|
|
// [rtg] Just to get things working
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
1999-08-16 21:50:52 +00:00
|
|
|
long num)
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
2001-03-27 00:23:32 +00:00
|
|
|
sprintf(buffer, "%ld", num);
|
2001-03-13 00:57:41 +00:00
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
1999-08-16 21:50:52 +00:00
|
|
|
unsigned long num)
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
2001-03-27 00:23:32 +00:00
|
|
|
sprintf(buffer, "%lu", num);
|
2001-03-13 00:57:41 +00:00
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 04:42:44 +00:00
|
|
|
UnicodeString
|
2003-11-21 00:10:52 +00:00
|
|
|
Int64ToUnicodeString(int64_t num)
|
2003-11-19 04:42:44 +00:00
|
|
|
{
|
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if defined(_MSC_VER)
|
2003-11-21 00:10:52 +00:00
|
|
|
sprintf(buffer, "%I64d", num);
|
|
|
|
#else
|
2006-05-26 06:04:01 +00:00
|
|
|
sprintf(buffer, "%lld", (long long)num);
|
2003-11-21 00:10:52 +00:00
|
|
|
#endif
|
2003-11-19 04:42:44 +00:00
|
|
|
assert(danger == 'p');
|
|
|
|
|
2003-11-21 00:10:52 +00:00
|
|
|
return buffer;
|
2003-11-19 04:42:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 22:31:07 +00:00
|
|
|
UnicodeString
|
|
|
|
DoubleToUnicodeString(double num)
|
|
|
|
{
|
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
|
|
|
sprintf(buffer, "%1.14e", num);
|
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// [LIU] Just to get things working
|
|
|
|
UnicodeString
|
2001-07-31 23:32:59 +00:00
|
|
|
operator+(const UnicodeString& left,
|
1999-08-16 21:50:52 +00:00
|
|
|
double num)
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
char buffer[64]; // was 32, made it arbitrarily bigger (rtg)
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
2004-04-15 06:19:10 +00:00
|
|
|
// IEEE floating point has 52 bits of mantissa, plus one assumed bit
|
|
|
|
// 53*log(2)/log(10) = 15.95
|
|
|
|
// so there is no need to show more than 16 digits. [alan]
|
|
|
|
|
2007-08-17 05:27:19 +00:00
|
|
|
sprintf(buffer, "%.17g", num);
|
2001-03-13 00:57:41 +00:00
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 15:27:41 +00:00
|
|
|
#if 0
|
2013-06-26 06:31:09 +00:00
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
|
|
|
int64_t num) {
|
|
|
|
return left + Int64ToUnicodeString(num);
|
|
|
|
}
|
2013-06-26 15:27:41 +00:00
|
|
|
#endif
|
2013-06-26 06:31:09 +00:00
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
2010-05-19 17:29:33 +00:00
|
|
|
* Return a string display for this, without surrounding braces.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2004-04-27 21:47:09 +00:00
|
|
|
UnicodeString _toString(const Formattable& f) {
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString s;
|
|
|
|
switch (f.getType()) {
|
|
|
|
case Formattable::kDate:
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
SimpleDateFormat fmt(status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
FieldPosition pos;
|
|
|
|
fmt.format(f.getDate(), s, pos);
|
2004-04-27 21:47:09 +00:00
|
|
|
s.insert(0, "Date:");
|
1999-08-16 21:50:52 +00:00
|
|
|
} else {
|
2004-04-27 21:47:09 +00:00
|
|
|
s = UnicodeString("Error creating date format]");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Formattable::kDouble:
|
2004-04-27 21:47:09 +00:00
|
|
|
s = UnicodeString("double:") + f.getDouble();
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
case Formattable::kLong:
|
2004-04-27 21:47:09 +00:00
|
|
|
s = UnicodeString("long:") + f.getLong();
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
2003-11-19 04:42:44 +00:00
|
|
|
|
|
|
|
case Formattable::kInt64:
|
2004-04-27 21:47:09 +00:00
|
|
|
s = UnicodeString("int64:") + Int64ToUnicodeString(f.getInt64());
|
2003-11-19 04:42:44 +00:00
|
|
|
break;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case Formattable::kString:
|
|
|
|
f.getString(s);
|
2004-04-27 21:47:09 +00:00
|
|
|
s.insert(0, "String:");
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
case Formattable::kArray:
|
|
|
|
{
|
|
|
|
int32_t i, n;
|
|
|
|
const Formattable* array = f.getArray(n);
|
2004-04-27 21:47:09 +00:00
|
|
|
s.insert(0, UnicodeString("Array:"));
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString delim(", ");
|
|
|
|
for (i=0; i<n; ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
s.append(delim);
|
|
|
|
}
|
2004-04-27 21:47:09 +00:00
|
|
|
s = s + _toString(array[i]);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-05-19 17:29:33 +00:00
|
|
|
case Formattable::kObject: {
|
|
|
|
const CurrencyAmount* c = dynamic_cast<const CurrencyAmount*>(f.getObject());
|
|
|
|
if (c != NULL) {
|
|
|
|
s = _toString(c->getNumber()) + " " + UnicodeString(c->getISOCurrency());
|
2004-04-27 21:47:09 +00:00
|
|
|
} else {
|
|
|
|
s = UnicodeString("Unknown UObject");
|
|
|
|
}
|
|
|
|
break;
|
2010-05-19 17:29:33 +00:00
|
|
|
}
|
2004-04-27 21:47:09 +00:00
|
|
|
default:
|
|
|
|
s = UnicodeString("Unknown Formattable type=") + (int32_t)f.getType();
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-04-27 21:47:09 +00:00
|
|
|
/**
|
|
|
|
* Originally coded this as operator+, but that makes the expression
|
|
|
|
* + char* ambiguous. - liu
|
|
|
|
*/
|
|
|
|
UnicodeString toString(const Formattable& f) {
|
|
|
|
UnicodeString s((UChar)91/*[*/);
|
|
|
|
s.append(_toString(f));
|
|
|
|
s.append((UChar)0x5d/*]*/);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-24 02:53:56 +00:00
|
|
|
// useful when operator+ won't cooperate
|
|
|
|
UnicodeString toString(int32_t n) {
|
|
|
|
return UnicodeString() + (long)n;
|
|
|
|
}
|
|
|
|
|
2013-06-26 06:31:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
UnicodeString toString(UBool b) {
|
2013-09-20 05:00:30 +00:00
|
|
|
return b ? UnicodeString("TRUE"):UnicodeString("FALSE");
|
2013-06-26 06:31:09 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
UnicodeString toString(const UnicodeSet& uniset, UErrorCode& status) {
|
|
|
|
UnicodeString result;
|
|
|
|
uniset.toPattern(result, status);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// stephen - cleaned up 05/05/99
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, char num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, short num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, int num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned char num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (unsigned long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned short num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (unsigned long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned int num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (unsigned long)num; }
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, float num)
|
1999-08-16 21:50:52 +00:00
|
|
|
{ return left + (double)num; }
|
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
//------------------
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Append a hex string to the target
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString&
|
|
|
|
IntlTest::appendHex(uint32_t number,
|
2001-09-18 17:44:50 +00:00
|
|
|
int32_t digits,
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString& target)
|
|
|
|
{
|
2001-07-11 18:30:18 +00:00
|
|
|
static const UChar digitString[] = {
|
|
|
|
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
|
|
|
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0
|
|
|
|
}; /* "0123456789ABCDEF" */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2013-02-15 22:11:33 +00:00
|
|
|
if (digits < 0) { // auto-digits
|
|
|
|
digits = 2;
|
|
|
|
uint32_t max = 0xff;
|
|
|
|
while (number > max) {
|
|
|
|
digits += 2;
|
|
|
|
max = (max << 8) | 0xff;
|
|
|
|
}
|
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
switch (digits)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
case 8:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 28) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 7:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 24) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 6:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 20) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 5:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 16) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 4:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 12) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 3:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 8) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 2:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 4) & 0xF];
|
2016-03-01 07:44:57 +00:00
|
|
|
U_FALLTHROUGH;
|
1999-08-16 21:50:52 +00:00
|
|
|
case 1:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += digitString[(number >> 0) & 0xF];
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
default:
|
2001-03-13 00:57:41 +00:00
|
|
|
target += "**";
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
return target;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 22:11:33 +00:00
|
|
|
UnicodeString
|
|
|
|
IntlTest::toHex(uint32_t number, int32_t digits) {
|
|
|
|
UnicodeString result;
|
|
|
|
appendHex(number, digits, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:54:53 +00:00
|
|
|
static inline UBool isPrintable(UChar32 c) {
|
|
|
|
return c <= 0x7E && (c >= 0x20 || c == 9 || c == 0xA || c == 0xD);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// Replace nonprintable characters with unicode escapes
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString&
|
|
|
|
IntlTest::prettify(const UnicodeString &source,
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString &target)
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
int32_t i;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
target.remove();
|
|
|
|
target += "\"";
|
|
|
|
|
2001-07-25 19:11:02 +00:00
|
|
|
for (i = 0; i < source.length(); )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-07-25 19:11:02 +00:00
|
|
|
UChar32 ch = source.char32At(i);
|
2010-06-15 15:54:53 +00:00
|
|
|
i += U16_LENGTH(ch);
|
2001-03-13 00:57:41 +00:00
|
|
|
|
2010-06-15 15:54:53 +00:00
|
|
|
if (!isPrintable(ch))
|
2001-03-13 00:57:41 +00:00
|
|
|
{
|
2001-07-25 19:11:02 +00:00
|
|
|
if (ch <= 0xFFFF) {
|
|
|
|
target += "\\u";
|
|
|
|
appendHex(ch, 4, target);
|
|
|
|
} else {
|
|
|
|
target += "\\U";
|
|
|
|
appendHex(ch, 8, target);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
target += ch;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
target += "\"";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
return target;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
|
2000-01-15 01:55:02 +00:00
|
|
|
// Replace nonprintable characters with unicode escapes
|
2001-07-31 23:32:59 +00:00
|
|
|
UnicodeString
|
2001-07-18 18:38:53 +00:00
|
|
|
IntlTest::prettify(const UnicodeString &source, UBool parseBackslash)
|
2000-01-15 01:55:02 +00:00
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
int32_t i;
|
|
|
|
UnicodeString target;
|
|
|
|
target.remove();
|
|
|
|
target += "\"";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-25 19:11:02 +00:00
|
|
|
for (i = 0; i < source.length();)
|
2000-01-15 01:55:02 +00:00
|
|
|
{
|
2001-07-25 19:11:02 +00:00
|
|
|
UChar32 ch = source.char32At(i);
|
2010-06-15 15:54:53 +00:00
|
|
|
i += U16_LENGTH(ch);
|
2001-03-13 00:57:41 +00:00
|
|
|
|
2010-06-15 15:54:53 +00:00
|
|
|
if (!isPrintable(ch))
|
2001-03-13 00:57:41 +00:00
|
|
|
{
|
2001-07-18 18:38:53 +00:00
|
|
|
if (parseBackslash) {
|
|
|
|
// If we are preceded by an odd number of backslashes,
|
|
|
|
// then this character has already been backslash escaped.
|
|
|
|
// Delete a backslash.
|
|
|
|
int32_t backslashCount = 0;
|
|
|
|
for (int32_t j=target.length()-1; j>=0; --j) {
|
|
|
|
if (target.charAt(j) == (UChar)92) {
|
|
|
|
++backslashCount;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((backslashCount % 2) == 1) {
|
|
|
|
target.truncate(target.length() - 1);
|
|
|
|
}
|
|
|
|
}
|
2001-07-25 19:11:02 +00:00
|
|
|
if (ch <= 0xFFFF) {
|
|
|
|
target += "\\u";
|
|
|
|
appendHex(ch, 4, target);
|
|
|
|
} else {
|
|
|
|
target += "\\U";
|
|
|
|
appendHex(ch, 8, target);
|
|
|
|
}
|
2000-01-15 01:55:02 +00:00
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
target += ch;
|
2000-01-15 01:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
target += "\"";
|
2000-01-15 01:55:02 +00:00
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
return target;
|
2000-01-15 01:55:02 +00:00
|
|
|
}
|
2001-03-13 00:57:41 +00:00
|
|
|
|
2001-07-31 17:29:43 +00:00
|
|
|
/* IntlTest::setICU_DATA - if the ICU_DATA environment variable is not already
|
|
|
|
* set, try to deduce the directory in which ICU was built,
|
|
|
|
* and set ICU_DATA to "icu/source/data" in that location.
|
|
|
|
* The intent is to allow the tests to have a good chance
|
|
|
|
* of running without requiring that the user manually set
|
|
|
|
* ICU_DATA. Common data isn't a problem, since it is
|
|
|
|
* picked up via a static (build time) reference, but the
|
|
|
|
* tests dynamically load some data.
|
|
|
|
*/
|
|
|
|
void IntlTest::setICU_DATA() {
|
2001-08-20 23:48:50 +00:00
|
|
|
const char *original_ICU_DATA = getenv("ICU_DATA");
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2001-11-08 01:29:11 +00:00
|
|
|
if (original_ICU_DATA != NULL && *original_ICU_DATA != 0) {
|
2001-08-20 23:25:53 +00:00
|
|
|
/* If the user set ICU_DATA, don't second-guess the person. */
|
2001-07-31 17:29:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
// U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst
|
|
|
|
// to point to the top of the build hierarchy, which may or
|
|
|
|
// may not be the same as the source directory, depending on
|
|
|
|
// the configure options used. At any rate,
|
|
|
|
// set the data path to the built data from this directory.
|
2003-08-16 02:17:56 +00:00
|
|
|
// The value is complete with quotes, so it can be used
|
2002-04-02 02:55:31 +00:00
|
|
|
// as-is as a string constant.
|
2001-11-02 02:24:15 +00:00
|
|
|
|
|
|
|
#if defined (U_TOPBUILDDIR)
|
2001-07-31 17:29:43 +00:00
|
|
|
{
|
2002-07-31 22:36:08 +00:00
|
|
|
static char env_string[] = U_TOPBUILDDIR "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
|
2001-08-20 23:25:53 +00:00
|
|
|
u_setDataDirectory(env_string);
|
2001-07-31 18:52:47 +00:00
|
|
|
return;
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
2001-10-30 01:43:05 +00:00
|
|
|
|
|
|
|
#else
|
2001-11-02 02:24:15 +00:00
|
|
|
// Use #else so we don't get compiler warnings due to the return above.
|
2001-07-31 17:29:43 +00:00
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
/* On Windows, the file name obtained from __FILE__ includes a full path.
|
|
|
|
* This file is "wherever\icu\source\test\cintltst\cintltst.c"
|
|
|
|
* Change to "wherever\icu\source\data"
|
2001-07-31 17:29:43 +00:00
|
|
|
*/
|
|
|
|
{
|
2001-11-02 02:24:15 +00:00
|
|
|
char p[sizeof(__FILE__) + 10];
|
2001-07-31 17:29:43 +00:00
|
|
|
char *pBackSlash;
|
|
|
|
int i;
|
2001-07-31 23:32:59 +00:00
|
|
|
|
2001-08-20 23:25:53 +00:00
|
|
|
strcpy(p, __FILE__);
|
2001-07-31 17:29:43 +00:00
|
|
|
/* We want to back over three '\' chars. */
|
|
|
|
/* Only Windows should end up here, so looking for '\' is safe. */
|
|
|
|
for (i=1; i<=3; i++) {
|
2001-08-20 23:25:53 +00:00
|
|
|
pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
|
2001-07-31 17:29:43 +00:00
|
|
|
if (pBackSlash != NULL) {
|
|
|
|
*pBackSlash = 0; /* Truncate the string at the '\' */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBackSlash != NULL) {
|
2001-07-31 23:32:59 +00:00
|
|
|
/* We found and truncated three names from the path.
|
2001-07-31 17:29:43 +00:00
|
|
|
* Now append "source\data" and set the environment
|
|
|
|
*/
|
2002-02-19 02:07:41 +00:00
|
|
|
strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING);
|
2001-08-20 23:25:53 +00:00
|
|
|
u_setDataDirectory(p); /* p is "ICU_DATA=wherever\icu\source\data" */
|
2001-07-31 17:29:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-05-15 18:48:56 +00:00
|
|
|
else {
|
|
|
|
/* __FILE__ on MSVC7 does not contain the directory */
|
2014-12-19 23:41:18 +00:00
|
|
|
u_setDataDirectory(".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING);
|
2003-05-15 19:51:46 +00:00
|
|
|
return;
|
2003-05-15 18:48:56 +00:00
|
|
|
}
|
2001-07-31 17:29:43 +00:00
|
|
|
}
|
2001-10-30 01:43:05 +00:00
|
|
|
#endif
|
2001-07-31 17:29:43 +00:00
|
|
|
|
|
|
|
/* No location for the data dir was identifiable.
|
|
|
|
* Add other fallbacks for the test data location here if the need arises
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const int32_t indentLevel_offset = 3;
|
|
|
|
static const char delim = '/';
|
|
|
|
|
|
|
|
IntlTest* IntlTest::gTest = NULL;
|
|
|
|
|
|
|
|
static int32_t execCount = 0;
|
|
|
|
|
|
|
|
void it_log( UnicodeString message )
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->log( message );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_logln( UnicodeString message )
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->logln( message );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_logln( void )
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->logln();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
2002-07-11 17:40:35 +00:00
|
|
|
void it_info( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->info( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_infoln( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->infoln( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_infoln( void )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->infoln();
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_err()
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->err();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_err( UnicodeString message )
|
|
|
|
{
|
2001-03-13 00:57:41 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->err( message );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_errln( UnicodeString message )
|
|
|
|
{
|
2001-10-30 01:43:05 +00:00
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->errln( message );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2005-07-05 18:39:00 +00:00
|
|
|
void it_dataerr( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->dataerr( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_dataerrln( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest)
|
|
|
|
IntlTest::gTest->dataerrln( message );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
IntlTest::IntlTest()
|
|
|
|
{
|
|
|
|
caller = NULL;
|
2005-07-18 16:32:26 +00:00
|
|
|
testPath = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_linestart = TRUE;
|
|
|
|
errorCount = 0;
|
2005-04-06 00:38:48 +00:00
|
|
|
dataErrorCount = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
verbose = FALSE;
|
2012-05-30 00:37:33 +00:00
|
|
|
no_time = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
no_err_msg = FALSE;
|
2005-04-06 00:38:48 +00:00
|
|
|
warn_on_missing_data = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
quick = FALSE;
|
|
|
|
leaks = FALSE;
|
2015-12-03 23:10:38 +00:00
|
|
|
threadCount = 12;
|
2000-04-25 21:32:10 +00:00
|
|
|
testoutfp = stdout;
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel = indentLevel_offset;
|
2008-09-22 22:02:44 +00:00
|
|
|
numProps = 0;
|
2010-07-12 15:24:57 +00:00
|
|
|
strcpy(basePath, "/");
|
2013-09-16 22:07:02 +00:00
|
|
|
currName[0]=0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::setCaller( IntlTest* callingTest )
|
|
|
|
{
|
|
|
|
caller = callingTest;
|
|
|
|
if (caller) {
|
2008-04-10 23:19:16 +00:00
|
|
|
warn_on_missing_data = caller->warn_on_missing_data;
|
1999-08-16 21:50:52 +00:00
|
|
|
verbose = caller->verbose;
|
|
|
|
no_err_msg = caller->no_err_msg;
|
|
|
|
quick = caller->quick;
|
2015-04-23 23:59:24 +00:00
|
|
|
threadCount = caller->threadCount;
|
2000-04-25 21:32:10 +00:00
|
|
|
testoutfp = caller->testoutfp;
|
2019-08-13 04:16:25 +00:00
|
|
|
write_golden_data = caller->write_golden_data;
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel = caller->LL_indentlevel + indentLevel_offset;
|
2008-09-22 22:02:44 +00:00
|
|
|
numProps = caller->numProps;
|
|
|
|
for (int32_t i = 0; i < numProps; i++) {
|
|
|
|
proplines[i] = caller->proplines[i];
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool IntlTest::callTest( IntlTest& testToBeCalled, char* par )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
execCount--; // correct a previously assumed test-exec, as this only calls a subtest
|
|
|
|
testToBeCalled.setCaller( this );
|
2010-07-12 15:24:57 +00:00
|
|
|
strcpy(testToBeCalled.basePath, this->basePath );
|
|
|
|
UBool result = testToBeCalled.runTest( testPath, par, testToBeCalled.basePath );
|
|
|
|
strcpy(testToBeCalled.basePath, this->basePath ); // reset it.
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
void IntlTest::setPath( char* pathVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2005-07-18 16:32:26 +00:00
|
|
|
this->testPath = pathVal;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
UBool IntlTest::setVerbose( UBool verboseVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval = this->verbose;
|
2000-12-08 20:33:48 +00:00
|
|
|
this->verbose = verboseVal;
|
1999-08-16 21:50:52 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2012-05-30 00:37:33 +00:00
|
|
|
UBool IntlTest::setNotime( UBool no_time )
|
|
|
|
{
|
|
|
|
UBool rval = this->no_time;
|
|
|
|
this->no_time = no_time;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
UBool IntlTest::setWarnOnMissingData( UBool warn_on_missing_dataVal )
|
|
|
|
{
|
|
|
|
UBool rval = this->warn_on_missing_data;
|
|
|
|
this->warn_on_missing_data = warn_on_missing_dataVal;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2019-08-13 04:16:25 +00:00
|
|
|
UBool IntlTest::setWriteGoldenData( UBool write_golden_data )
|
|
|
|
{
|
|
|
|
UBool rval = this->write_golden_data;
|
|
|
|
this->write_golden_data = write_golden_data;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
UBool IntlTest::setNoErrMsg( UBool no_err_msgVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval = this->no_err_msg;
|
2000-12-08 20:33:48 +00:00
|
|
|
this->no_err_msg = no_err_msgVal;
|
1999-08-16 21:50:52 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
UBool IntlTest::setQuick( UBool quickVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval = this->quick;
|
2000-12-08 20:33:48 +00:00
|
|
|
this->quick = quickVal;
|
1999-08-16 21:50:52 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
UBool IntlTest::setLeaks( UBool leaksVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval = this->leaks;
|
2000-12-08 20:33:48 +00:00
|
|
|
this->leaks = leaksVal;
|
1999-08-16 21:50:52 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2009-08-13 00:11:21 +00:00
|
|
|
int32_t IntlTest::setThreadCount( int32_t count )
|
|
|
|
{
|
|
|
|
int32_t rval = this->threadCount;
|
|
|
|
this->threadCount = count;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t IntlTest::getErrors( void )
|
|
|
|
{
|
|
|
|
return errorCount;
|
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
int32_t IntlTest::getDataErrors( void )
|
|
|
|
{
|
2005-04-06 00:38:48 +00:00
|
|
|
return dataErrorCount;
|
2005-04-05 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
UBool IntlTest::runTest( char* name, char* par, char *baseName )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval;
|
1999-08-16 21:50:52 +00:00
|
|
|
char* pos = NULL;
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
char* baseNameBuffer = NULL;
|
|
|
|
|
|
|
|
if(baseName == NULL) {
|
|
|
|
baseNameBuffer = (char*)malloc(1024);
|
|
|
|
baseName=baseNameBuffer;
|
|
|
|
strcpy(baseName, "/");
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
if (name)
|
|
|
|
pos = strchr( name, delim ); // check if name contains path (by looking for '/')
|
1999-08-16 21:50:52 +00:00
|
|
|
if (pos) {
|
2005-07-18 16:32:26 +00:00
|
|
|
testPath = pos+1; // store subpath for calling subtest
|
1999-08-16 21:50:52 +00:00
|
|
|
*pos = 0; // split into two strings
|
|
|
|
}else{
|
2005-07-18 16:32:26 +00:00
|
|
|
testPath = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || (name[0] == 0) || (strcmp(name, "*") == 0)) {
|
2010-07-12 15:24:57 +00:00
|
|
|
rval = runTestLoop( NULL, par, baseName );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
}else if (strcmp( name, "LIST" ) == 0) {
|
|
|
|
this->usage();
|
|
|
|
rval = TRUE;
|
|
|
|
|
|
|
|
}else{
|
2010-07-12 15:24:57 +00:00
|
|
|
rval = runTestLoop( name, par, baseName );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 00:57:41 +00:00
|
|
|
if (pos)
|
|
|
|
*pos = delim; // restore original value at pos
|
2010-07-12 15:24:57 +00:00
|
|
|
if(baseNameBuffer!=NULL) {
|
|
|
|
free(baseNameBuffer);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2017-10-26 21:33:43 +00:00
|
|
|
// call individual tests, to be overridden to call implementations
|
2012-08-15 17:46:17 +00:00
|
|
|
void IntlTest::runIndexedTest( int32_t /*index*/, UBool /*exec*/, const char* & /*name*/, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2017-10-26 21:33:43 +00:00
|
|
|
// to be overridden by a method like:
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
switch (index) {
|
|
|
|
case 0: name = "First Test"; if (exec) FirstTest( par ); break;
|
|
|
|
case 1: name = "Second Test"; if (exec) SecondTest( par ); break;
|
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
*/
|
2017-10-26 21:33:43 +00:00
|
|
|
this->errln("*** runIndexedTest needs to be overridden! ***");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
UBool IntlTest::runTestLoop( char* testname, char* par, char *baseName )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t index = 0;
|
2000-08-14 21:42:36 +00:00
|
|
|
const char* name;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool run_this_test;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t lastErrorCount;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool rval = FALSE;
|
2000-12-09 02:02:29 +00:00
|
|
|
UBool lastTestFailed;
|
2001-07-31 23:32:59 +00:00
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
if(baseName == NULL) {
|
|
|
|
printf("ERROR: baseName can't be null.\n");
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
2010-07-15 15:16:41 +00:00
|
|
|
if ((char *)this->basePath != baseName) {
|
|
|
|
strcpy(this->basePath, baseName);
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char * saveBaseLoc = baseName+strlen(baseName);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
IntlTest* saveTest = gTest;
|
|
|
|
gTest = this;
|
|
|
|
do {
|
2003-08-12 19:10:36 +00:00
|
|
|
this->runIndexedTest( index, FALSE, name, par );
|
2009-08-04 21:09:17 +00:00
|
|
|
if (strcmp(name,"skip") == 0) {
|
|
|
|
run_this_test = FALSE;
|
|
|
|
} else {
|
|
|
|
if (!name || (name[0] == 0))
|
|
|
|
break;
|
|
|
|
if (!testname) {
|
|
|
|
run_this_test = TRUE;
|
|
|
|
}else{
|
|
|
|
run_this_test = (UBool) (strcmp( name, testname ) == 0);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
if (run_this_test) {
|
|
|
|
lastErrorCount = errorCount;
|
|
|
|
execCount++;
|
2010-05-06 22:22:38 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "%s {", name);
|
|
|
|
LL_message(msg, TRUE);
|
2010-05-25 19:55:05 +00:00
|
|
|
UDate timeStart = uprv_getRawUTCtime();
|
2010-07-12 15:24:57 +00:00
|
|
|
strcpy(saveBaseLoc,name);
|
|
|
|
strcat(saveBaseLoc,"/");
|
|
|
|
|
2013-09-16 22:07:02 +00:00
|
|
|
strcpy(currName, name); // set
|
1999-08-16 21:50:52 +00:00
|
|
|
this->runIndexedTest( index, TRUE, name, par );
|
2013-09-16 22:07:02 +00:00
|
|
|
currName[0]=0; // reset
|
2010-07-12 15:24:57 +00:00
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
UDate timeStop = uprv_getRawUTCtime();
|
1999-08-16 21:50:52 +00:00
|
|
|
rval = TRUE; // at least one test has been called
|
2010-07-12 15:24:57 +00:00
|
|
|
char secs[256];
|
2012-05-30 00:37:33 +00:00
|
|
|
if(!no_time) {
|
|
|
|
sprintf(secs, "%f", (timeStop-timeStart)/1000.0);
|
|
|
|
} else {
|
|
|
|
secs[0]=0;
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
strcpy(saveBaseLoc,name);
|
|
|
|
|
|
|
|
|
|
|
|
ctest_xml_testcase(baseName, name, secs, (lastErrorCount!=errorCount)?"err":NULL);
|
|
|
|
|
|
|
|
|
|
|
|
saveBaseLoc[0]=0; /* reset path */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (lastErrorCount == errorCount) {
|
2010-05-25 19:55:05 +00:00
|
|
|
sprintf( msg, " } OK: %s ", name );
|
2012-05-30 00:37:33 +00:00
|
|
|
if(!no_time) str_timeDelta(msg+strlen(msg),timeStop-timeStart);
|
2000-12-09 02:02:29 +00:00
|
|
|
lastTestFailed = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}else{
|
2010-05-06 22:22:38 +00:00
|
|
|
sprintf(msg, " } ERRORS (%li) in %s", (long)(errorCount-lastErrorCount), name);
|
2012-05-30 00:37:33 +00:00
|
|
|
if(!no_time) str_timeDelta(msg+strlen(msg),timeStop-timeStart);
|
2000-12-03 03:29:39 +00:00
|
|
|
|
|
|
|
for(int i=0;i<LL_indentlevel;i++) {
|
|
|
|
errorList += " ";
|
|
|
|
}
|
|
|
|
errorList += name;
|
|
|
|
errorList += "\n";
|
2000-12-09 02:02:29 +00:00
|
|
|
lastTestFailed = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
LL_indentlevel -= 3;
|
2000-12-09 02:02:29 +00:00
|
|
|
if (lastTestFailed) {
|
2001-07-31 23:32:59 +00:00
|
|
|
LL_message( "", TRUE);
|
2000-12-09 02:02:29 +00:00
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
LL_message( msg, TRUE);
|
2000-12-09 02:02:29 +00:00
|
|
|
if (lastTestFailed) {
|
2001-07-31 23:32:59 +00:00
|
|
|
LL_message( "", TRUE);
|
2000-12-09 02:02:29 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel += 3;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}while(name);
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
*saveBaseLoc = 0;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
gTest = saveTest;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds given string to the log if we are in verbose mode.
|
|
|
|
*/
|
1999-12-08 00:15:46 +00:00
|
|
|
void IntlTest::log( const UnicodeString &message )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if( verbose ) {
|
|
|
|
LL_message( message, FALSE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds given string to the log if we are in verbose mode. Adds a new line to
|
|
|
|
* the given message.
|
|
|
|
*/
|
1999-12-08 00:15:46 +00:00
|
|
|
void IntlTest::logln( const UnicodeString &message )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if( verbose ) {
|
|
|
|
LL_message( message, TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::logln( void )
|
|
|
|
{
|
|
|
|
if( verbose ) {
|
|
|
|
LL_message( "", TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-11 17:40:35 +00:00
|
|
|
/**
|
|
|
|
* Unconditionally adds given string to the log.
|
|
|
|
*/
|
|
|
|
void IntlTest::info( const UnicodeString &message )
|
|
|
|
{
|
|
|
|
LL_message( message, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unconditionally adds given string to the log. Adds a new line to
|
|
|
|
* the given message.
|
|
|
|
*/
|
|
|
|
void IntlTest::infoln( const UnicodeString &message )
|
|
|
|
{
|
|
|
|
LL_message( message, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::infoln( void )
|
|
|
|
{
|
|
|
|
LL_message( "", TRUE );
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t IntlTest::IncErrorCount( void )
|
|
|
|
{
|
|
|
|
errorCount++;
|
|
|
|
if (caller) caller->IncErrorCount();
|
|
|
|
return errorCount;
|
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
int32_t IntlTest::IncDataErrorCount( void )
|
|
|
|
{
|
2005-04-06 00:38:48 +00:00
|
|
|
dataErrorCount++;
|
|
|
|
if (caller) caller->IncDataErrorCount();
|
|
|
|
return dataErrorCount;
|
2005-04-05 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::err()
|
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
IncErrorCount();
|
|
|
|
}
|
2001-07-31 23:32:59 +00:00
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
void IntlTest::err( const UnicodeString &message )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
IncErrorCount();
|
|
|
|
if (!no_err_msg) LL_message( message, FALSE );
|
|
|
|
}
|
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
void IntlTest::errln( const UnicodeString &message )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
IncErrorCount();
|
|
|
|
if (!no_err_msg) LL_message( message, TRUE );
|
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
void IntlTest::dataerr( const UnicodeString &message )
|
|
|
|
{
|
|
|
|
IncDataErrorCount();
|
|
|
|
|
2005-04-06 00:38:48 +00:00
|
|
|
if (!warn_on_missing_data) {
|
|
|
|
IncErrorCount();
|
|
|
|
}
|
2005-04-05 20:12:22 +00:00
|
|
|
|
|
|
|
if (!no_err_msg) LL_message( message, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::dataerrln( const UnicodeString &message )
|
|
|
|
{
|
2013-09-05 03:55:29 +00:00
|
|
|
int32_t errCount = IncDataErrorCount();
|
2009-06-12 19:34:21 +00:00
|
|
|
UnicodeString msg;
|
2005-04-06 00:38:48 +00:00
|
|
|
if (!warn_on_missing_data) {
|
|
|
|
IncErrorCount();
|
2009-06-12 19:34:21 +00:00
|
|
|
msg = message;
|
|
|
|
} else {
|
|
|
|
msg = UnicodeString("[DATA] " + message);
|
2005-04-06 00:38:48 +00:00
|
|
|
}
|
2005-04-05 20:12:22 +00:00
|
|
|
|
2013-09-19 02:32:57 +00:00
|
|
|
if (!no_err_msg) {
|
|
|
|
if ( errCount == 1) {
|
|
|
|
LL_message( msg + " - (Are you missing data?)", TRUE ); // only show this message the first time
|
|
|
|
} else {
|
|
|
|
LL_message( msg , TRUE );
|
|
|
|
}
|
2013-09-13 18:38:36 +00:00
|
|
|
}
|
2009-06-12 19:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::errcheckln(UErrorCode status, const UnicodeString &message ) {
|
|
|
|
if (status == U_FILE_ACCESS_ERROR || status == U_MISSING_RESOURCE_ERROR) {
|
|
|
|
dataerrln(message);
|
|
|
|
} else {
|
|
|
|
errln(message);
|
|
|
|
}
|
2005-04-05 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
2001-01-23 23:51:55 +00:00
|
|
|
/* convenience functions that include sprintf formatting */
|
|
|
|
void IntlTest::log(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2001-01-23 23:51:55 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2001-08-31 18:02:09 +00:00
|
|
|
/* sprintf it just to make sure that the information is valid */
|
2001-01-23 23:51:55 +00:00
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2001-08-31 18:02:09 +00:00
|
|
|
if( verbose ) {
|
2015-10-09 18:14:23 +00:00
|
|
|
log(UnicodeString(buffer, (const char *)NULL));
|
2001-08-31 18:02:09 +00:00
|
|
|
}
|
2001-01-23 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::logln(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2001-01-23 23:51:55 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2001-08-31 18:02:09 +00:00
|
|
|
/* sprintf it just to make sure that the information is valid */
|
2001-01-23 23:51:55 +00:00
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2001-08-31 18:02:09 +00:00
|
|
|
if( verbose ) {
|
2015-10-09 18:14:23 +00:00
|
|
|
logln(UnicodeString(buffer, (const char *)NULL));
|
2001-08-31 18:02:09 +00:00
|
|
|
}
|
2001-01-23 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 22:07:02 +00:00
|
|
|
UBool IntlTest::logKnownIssue(const char *ticket, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[4000];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
/* sprintf it just to make sure that the information is valid */
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
return logKnownIssue(ticket, UnicodeString(buffer, (const char *)NULL));
|
2013-09-16 22:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::logKnownIssue(const char *ticket) {
|
|
|
|
return logKnownIssue(ticket, UnicodeString());
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::logKnownIssue(const char *ticket, const UnicodeString &msg) {
|
2013-09-17 00:21:47 +00:00
|
|
|
if(noKnownIssues) return FALSE;
|
2013-09-16 22:07:02 +00:00
|
|
|
|
2013-09-17 00:21:47 +00:00
|
|
|
char fullpath[2048];
|
|
|
|
strcpy(fullpath, basePath);
|
|
|
|
strcat(fullpath, currName);
|
2015-08-25 16:55:52 +00:00
|
|
|
UnicodeString msg2 = msg;
|
|
|
|
UBool firstForTicket = TRUE, firstForWhere = TRUE;
|
2013-09-17 00:21:47 +00:00
|
|
|
knownList = udbg_knownIssue_openU(knownList, ticket, fullpath, msg2.getTerminatedBuffer(), &firstForTicket, &firstForWhere);
|
|
|
|
|
2020-05-20 20:29:35 +00:00
|
|
|
msg2 = UNICODE_STRING_SIMPLE("(Known issue ") +
|
2014-04-01 19:59:27 +00:00
|
|
|
UnicodeString(ticket, -1, US_INV) + UNICODE_STRING_SIMPLE(") ") + msg;
|
2013-09-17 00:21:47 +00:00
|
|
|
if(firstForTicket || firstForWhere) {
|
2014-04-01 19:59:27 +00:00
|
|
|
infoln(msg2);
|
2013-09-17 00:21:47 +00:00
|
|
|
} else {
|
2014-04-01 19:59:27 +00:00
|
|
|
logln(msg2);
|
2013-09-17 00:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2013-09-16 22:07:02 +00:00
|
|
|
}
|
|
|
|
|
2002-07-11 17:40:35 +00:00
|
|
|
/* convenience functions that include sprintf formatting */
|
|
|
|
void IntlTest::info(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2002-07-11 17:40:35 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
/* sprintf it just to make sure that the information is valid */
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
info(UnicodeString(buffer, (const char *)NULL));
|
2002-07-11 17:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::infoln(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2002-07-11 17:40:35 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
/* sprintf it just to make sure that the information is valid */
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
infoln(UnicodeString(buffer, (const char *)NULL));
|
2002-07-11 17:40:35 +00:00
|
|
|
}
|
|
|
|
|
2001-01-23 23:51:55 +00:00
|
|
|
void IntlTest::err(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2001-01-23 23:51:55 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
err(UnicodeString(buffer, (const char *)NULL));
|
2001-01-23 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::errln(const char *fmt, ...)
|
|
|
|
{
|
2003-07-24 00:30:02 +00:00
|
|
|
char buffer[4000];
|
2001-01-23 23:51:55 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
errln(UnicodeString(buffer, (const char *)NULL));
|
2001-01-23 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
void IntlTest::dataerrln(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[4000];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
2015-10-09 18:14:23 +00:00
|
|
|
dataerrln(UnicodeString(buffer, (const char *)NULL));
|
2005-04-05 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 19:34:21 +00:00
|
|
|
void IntlTest::errcheckln(UErrorCode status, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[4000];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (status == U_FILE_ACCESS_ERROR || status == U_MISSING_RESOURCE_ERROR) {
|
2015-10-09 18:14:23 +00:00
|
|
|
dataerrln(UnicodeString(buffer, (const char *)NULL));
|
2009-06-12 19:34:21 +00:00
|
|
|
} else {
|
2015-10-09 18:14:23 +00:00
|
|
|
errln(UnicodeString(buffer, (const char *)NULL));
|
2009-06-12 19:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-03 03:29:39 +00:00
|
|
|
void IntlTest::printErrors()
|
|
|
|
{
|
|
|
|
IntlTest::LL_message(errorList, TRUE);
|
|
|
|
}
|
|
|
|
|
2013-09-16 22:07:02 +00:00
|
|
|
UBool IntlTest::printKnownIssues()
|
|
|
|
{
|
2013-09-17 00:21:47 +00:00
|
|
|
if(knownList != NULL) {
|
2013-09-17 06:26:26 +00:00
|
|
|
udbg_knownIssue_print(knownList);
|
2013-09-17 00:21:47 +00:00
|
|
|
udbg_knownIssue_close(knownList);
|
2013-09-16 22:07:02 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 23:13:49 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
void IntlTest::LL_message( UnicodeString message, UBool newline )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2015-10-06 23:13:49 +00:00
|
|
|
// Synchronize this function.
|
|
|
|
// All error messages generated by tests funnel through here.
|
2017-10-26 21:33:43 +00:00
|
|
|
// Multithreaded tests can concurrently generate errors, requiring synchronization
|
2015-10-06 23:13:49 +00:00
|
|
|
// to keep each message together.
|
2019-05-10 23:23:21 +00:00
|
|
|
static UMutex messageMutex;
|
|
|
|
Mutex lock(&messageMutex);
|
2015-10-06 23:13:49 +00:00
|
|
|
|
2000-03-30 23:26:36 +00:00
|
|
|
// string that starts with a LineFeed character and continues
|
|
|
|
// with spaces according to the current indentation
|
2000-08-26 02:05:37 +00:00
|
|
|
static const UChar indentUChars[] = {
|
|
|
|
'\n',
|
2000-03-30 23:26:36 +00:00
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
|
|
|
|
};
|
2015-10-06 23:13:49 +00:00
|
|
|
U_ASSERT(1 + LL_indentlevel <= UPRV_LENGTHOF(indentUChars));
|
2000-03-30 23:26:36 +00:00
|
|
|
UnicodeString indent(FALSE, indentUChars, 1 + LL_indentlevel);
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
char buffer[30000];
|
2000-03-30 23:26:36 +00:00
|
|
|
int32_t length;
|
|
|
|
|
|
|
|
// stream out the indentation string first if necessary
|
2000-08-28 19:23:42 +00:00
|
|
|
length = indent.extract(1, indent.length(), buffer, sizeof(buffer));
|
2001-02-16 21:58:12 +00:00
|
|
|
if (length > 0) {
|
2003-10-15 08:03:56 +00:00
|
|
|
fwrite(buffer, sizeof(*buffer), length, (FILE *)testoutfp);
|
2001-02-16 21:58:12 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-30 23:26:36 +00:00
|
|
|
// replace each LineFeed by the indentation string
|
2000-08-26 02:05:37 +00:00
|
|
|
message.findAndReplace(UnicodeString((UChar)'\n'), indent);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-30 23:26:36 +00:00
|
|
|
// stream out the message
|
2000-08-28 19:23:42 +00:00
|
|
|
length = message.extract(0, message.length(), buffer, sizeof(buffer));
|
2001-02-16 21:58:12 +00:00
|
|
|
if (length > 0) {
|
2014-02-25 21:21:49 +00:00
|
|
|
length = length > 30000 ? 30000 : length;
|
2003-10-15 08:03:56 +00:00
|
|
|
fwrite(buffer, sizeof(*buffer), length, (FILE *)testoutfp);
|
2001-02-16 21:58:12 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-26 02:05:37 +00:00
|
|
|
if (newline) {
|
|
|
|
char newLine = '\n';
|
2003-10-15 08:03:56 +00:00
|
|
|
fwrite(&newLine, sizeof(newLine), 1, (FILE *)testoutfp);
|
2000-08-26 02:05:37 +00:00
|
|
|
}
|
2000-08-28 19:23:42 +00:00
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
// A newline usually flushes the buffer, but
|
2000-08-28 19:23:42 +00:00
|
|
|
// flush the message just in case of a core dump.
|
2003-10-15 08:03:56 +00:00
|
|
|
fflush((FILE *)testoutfp);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a usage message for this test class.
|
|
|
|
*/
|
|
|
|
void IntlTest::usage( void )
|
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool save_verbose = setVerbose( TRUE );
|
1999-08-16 21:50:52 +00:00
|
|
|
logln("Test names:");
|
|
|
|
logln("-----------");
|
|
|
|
|
|
|
|
int32_t index = 0;
|
2000-08-14 23:44:25 +00:00
|
|
|
const char* name = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
do{
|
|
|
|
this->runIndexedTest( index, FALSE, name );
|
|
|
|
if (!name) break;
|
|
|
|
logln(name);
|
|
|
|
index++;
|
|
|
|
}while (name && (name[0] != 0));
|
|
|
|
setVerbose( save_verbose );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 23:32:59 +00:00
|
|
|
// memory leak reporting software will be able to take advantage of the testsuite
|
1999-08-16 21:50:52 +00:00
|
|
|
// being run a second time local to a specific method in order to report only actual leaks
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
IntlTest::run_phase2( char* name, char* par ) // supports reporting memory leaks
|
|
|
|
{
|
|
|
|
UnicodeString* strLeak = new UnicodeString("forced leak"); // for verifying purify filter
|
2001-08-31 18:28:56 +00:00
|
|
|
strLeak->append(" for verifying purify filter");
|
1999-08-16 21:50:52 +00:00
|
|
|
return this->runTest( name, par );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#if UCONFIG_NO_LEGACY_CONVERSION
|
|
|
|
# define TRY_CNV_1 "iso-8859-1"
|
|
|
|
# define TRY_CNV_2 "ibm-1208"
|
|
|
|
#else
|
|
|
|
# define TRY_CNV_1 "iso-8859-7"
|
|
|
|
# define TRY_CNV_2 "sjis"
|
|
|
|
#endif
|
|
|
|
|
2015-04-15 18:49:55 +00:00
|
|
|
#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
|
|
|
|
U_CAPI void unistr_printLengths();
|
|
|
|
#endif
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
2002-02-07 19:37:34 +00:00
|
|
|
UBool syntax = FALSE;
|
2003-09-22 19:48:43 +00:00
|
|
|
UBool all = FALSE;
|
2002-02-07 19:37:34 +00:00
|
|
|
UBool verbose = FALSE;
|
|
|
|
UBool no_err_msg = FALSE;
|
2012-05-30 00:37:33 +00:00
|
|
|
UBool no_time = FALSE;
|
2002-02-07 19:37:34 +00:00
|
|
|
UBool quick = TRUE;
|
|
|
|
UBool name = FALSE;
|
|
|
|
UBool leaks = FALSE;
|
2013-06-20 22:05:51 +00:00
|
|
|
UBool utf8 = FALSE;
|
2013-07-09 01:16:33 +00:00
|
|
|
const char *summary_file = NULL;
|
2002-09-24 23:52:03 +00:00
|
|
|
UBool warnOnMissingData = FALSE;
|
2019-08-13 04:16:25 +00:00
|
|
|
UBool writeGoldenData = FALSE;
|
2004-12-02 07:09:05 +00:00
|
|
|
UBool defaultDataFound = FALSE;
|
2015-12-03 23:10:38 +00:00
|
|
|
int32_t threadCount = 12;
|
2002-03-20 18:36:17 +00:00
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
2002-04-23 23:24:25 +00:00
|
|
|
UConverter *cnv = NULL;
|
2003-08-16 02:17:56 +00:00
|
|
|
const char *warnOrErr = "Failure";
|
2005-03-16 00:33:39 +00:00
|
|
|
UDate startTime, endTime;
|
|
|
|
int32_t diffTime;
|
2008-09-22 22:02:44 +00:00
|
|
|
const char *props[IntlTest::kMaxProps];
|
|
|
|
int32_t nProps = 0;
|
2002-04-23 23:24:25 +00:00
|
|
|
|
2004-12-02 07:09:05 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
2002-02-07 19:37:34 +00:00
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
startTime = uprv_getRawUTCtime();
|
2005-03-16 00:33:39 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
const char* str = argv[i] + 1;
|
2003-09-22 19:48:43 +00:00
|
|
|
if (strcmp("verbose", str) == 0 ||
|
|
|
|
strcmp("v", str) == 0)
|
2002-02-07 19:37:34 +00:00
|
|
|
verbose = TRUE;
|
2003-09-22 19:48:43 +00:00
|
|
|
else if (strcmp("noerrormsg", str) == 0 ||
|
|
|
|
strcmp("n", str) == 0)
|
2002-02-07 19:37:34 +00:00
|
|
|
no_err_msg = TRUE;
|
2003-09-22 19:48:43 +00:00
|
|
|
else if (strcmp("exhaustive", str) == 0 ||
|
|
|
|
strcmp("e", str) == 0)
|
2002-02-07 19:37:34 +00:00
|
|
|
quick = FALSE;
|
2003-09-22 19:48:43 +00:00
|
|
|
else if (strcmp("all", str) == 0 ||
|
|
|
|
strcmp("a", str) == 0)
|
2002-02-07 19:37:34 +00:00
|
|
|
all = TRUE;
|
2013-06-20 22:05:51 +00:00
|
|
|
else if (strcmp("utf-8", str) == 0 ||
|
|
|
|
strcmp("u", str) == 0)
|
|
|
|
utf8 = TRUE;
|
2013-09-17 00:21:47 +00:00
|
|
|
else if (strcmp("noknownissues", str) == 0 ||
|
|
|
|
strcmp("K", str) == 0)
|
|
|
|
noKnownIssues = TRUE;
|
2003-09-22 19:48:43 +00:00
|
|
|
else if (strcmp("leaks", str) == 0 ||
|
|
|
|
strcmp("l", str) == 0)
|
2002-02-07 19:37:34 +00:00
|
|
|
leaks = TRUE;
|
2012-05-30 00:37:33 +00:00
|
|
|
else if (strcmp("notime", str) == 0 ||
|
|
|
|
strcmp("T", str) == 0)
|
|
|
|
no_time = TRUE;
|
2019-08-13 04:16:25 +00:00
|
|
|
else if (strcmp("goldens", str) == 0 ||
|
|
|
|
strcmp("G", str) == 0)
|
|
|
|
writeGoldenData = TRUE;
|
2013-07-09 01:16:33 +00:00
|
|
|
else if (strncmp("E", str, 1) == 0)
|
|
|
|
summary_file = str+1;
|
2010-07-12 15:24:57 +00:00
|
|
|
else if (strcmp("x", str)==0) {
|
|
|
|
if(++i>=argc) {
|
|
|
|
printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n");
|
|
|
|
syntax = TRUE;
|
|
|
|
}
|
|
|
|
if(ctest_xml_setFileName(argv[i])) { /* set the name */
|
|
|
|
return 1; /* error */
|
|
|
|
}
|
|
|
|
} else if (strcmp("w", str) == 0) {
|
2002-09-24 23:52:03 +00:00
|
|
|
warnOnMissingData = TRUE;
|
|
|
|
warnOrErr = "WARNING";
|
2003-09-30 18:55:33 +00:00
|
|
|
}
|
2009-08-13 00:11:21 +00:00
|
|
|
else if (strncmp("threads:", str, 8) == 0) {
|
|
|
|
threadCount = atoi(str + 8);
|
|
|
|
}
|
2008-09-22 22:02:44 +00:00
|
|
|
else if (strncmp("prop:", str, 5) == 0) {
|
|
|
|
if (nProps < IntlTest::kMaxProps) {
|
|
|
|
props[nProps] = str + 5;
|
|
|
|
}
|
|
|
|
nProps++;
|
|
|
|
}
|
2003-09-30 18:55:33 +00:00
|
|
|
else {
|
2002-02-07 19:37:34 +00:00
|
|
|
syntax = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}else{
|
|
|
|
name = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-09-22 19:48:43 +00:00
|
|
|
if (!all && !name) {
|
|
|
|
all = TRUE;
|
|
|
|
} else if (all && name) {
|
|
|
|
syntax = TRUE;
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
|
|
|
|
if (syntax) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"### Syntax:\n"
|
|
|
|
"### IntlTest [-option1 -option2 ...] [testname1 testname2 ...] \n"
|
2009-08-13 00:11:21 +00:00
|
|
|
"### \n"
|
|
|
|
"### Options are: verbose (v), all (a), noerrormsg (n), \n"
|
2010-07-12 15:24:57 +00:00
|
|
|
"### exhaustive (e), leaks (l), -x xmlfile.xml, prop:<propery>=<value>, \n"
|
2012-05-30 00:37:33 +00:00
|
|
|
"### notime (T), \n"
|
2015-12-03 23:10:38 +00:00
|
|
|
"### threads:<threadCount>\n"
|
|
|
|
"### (The default thread count is 12.),\n"
|
2002-02-07 19:37:34 +00:00
|
|
|
"### (Specify either -all (shortcut -a) or a test name). \n"
|
|
|
|
"### -all will run all of the tests.\n"
|
|
|
|
"### \n"
|
|
|
|
"### To get a list of the test names type: intltest LIST \n"
|
|
|
|
"### To run just the utility tests type: intltest utility \n"
|
|
|
|
"### \n"
|
|
|
|
"### Test names can be nested using slashes (\"testA/subtest1\") \n"
|
|
|
|
"### For example to list the utility tests type: intltest utility/LIST \n"
|
|
|
|
"### To run just the Locale test type: intltest utility/LocaleTest \n"
|
|
|
|
"### \n"
|
|
|
|
"### A parameter can be specified for a test by appending '@' and the value \n"
|
|
|
|
"### to the testname. \n\n");
|
|
|
|
return 1;
|
|
|
|
}
|
1999-12-08 00:15:46 +00:00
|
|
|
|
2008-09-22 22:02:44 +00:00
|
|
|
if (nProps > IntlTest::kMaxProps) {
|
|
|
|
fprintf(stdout, "### Too many properties. Exiting.\n");
|
|
|
|
}
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
MajorTestLevel major;
|
|
|
|
major.setVerbose( verbose );
|
|
|
|
major.setNoErrMsg( no_err_msg );
|
|
|
|
major.setQuick( quick );
|
|
|
|
major.setLeaks( leaks );
|
2009-08-13 00:11:21 +00:00
|
|
|
major.setThreadCount( threadCount );
|
2005-04-06 00:38:48 +00:00
|
|
|
major.setWarnOnMissingData( warnOnMissingData );
|
2019-08-13 04:16:25 +00:00
|
|
|
major.setWriteGoldenData( writeGoldenData );
|
2012-05-30 00:37:33 +00:00
|
|
|
major.setNotime (no_time);
|
2008-09-22 22:02:44 +00:00
|
|
|
for (int32_t i = 0; i < nProps; i++) {
|
|
|
|
major.setProperty(props[i]);
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
|
|
|
fprintf(stdout, " IntlTest (C++) Test Suite for \n");
|
|
|
|
fprintf(stdout, " International Components for Unicode %s\n", U_ICU_VERSION);
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
|
2009-04-06 23:27:57 +00:00
|
|
|
{
|
|
|
|
const char *charsetFamily = "Unknown";
|
|
|
|
int32_t voidSize = (int32_t)sizeof(void*);
|
|
|
|
int32_t bits = voidSize * 8;
|
|
|
|
if(U_CHARSET_FAMILY==U_ASCII_FAMILY) {
|
|
|
|
charsetFamily="ASCII";
|
|
|
|
} else if(U_CHARSET_FAMILY==U_EBCDIC_FAMILY) {
|
|
|
|
charsetFamily="EBCDIC";
|
|
|
|
}
|
|
|
|
fprintf(stdout,
|
|
|
|
" Bits: %d, Byte order: %s, Chars: %s\n",
|
|
|
|
bits, U_IS_BIG_ENDIAN?"Big endian":"Little endian",
|
|
|
|
charsetFamily);
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
|
|
|
fprintf(stdout, " Options: \n");
|
2005-04-05 20:12:22 +00:00
|
|
|
fprintf(stdout, " all (a) : %s\n", (all? "On" : "Off"));
|
|
|
|
fprintf(stdout, " Verbose (v) : %s\n", (verbose? "On" : "Off"));
|
|
|
|
fprintf(stdout, " No error messages (n) : %s\n", (no_err_msg? "On" : "Off"));
|
|
|
|
fprintf(stdout, " Exhaustive (e) : %s\n", (!quick? "On" : "Off"));
|
|
|
|
fprintf(stdout, " Leaks (l) : %s\n", (leaks? "On" : "Off"));
|
2013-06-20 22:05:51 +00:00
|
|
|
fprintf(stdout, " utf-8 (u) : %s\n", (utf8? "On" : "Off"));
|
2019-08-13 04:16:25 +00:00
|
|
|
fprintf(stdout, " notime (T) : %s\n", (no_time? "On" : "Off"));
|
|
|
|
fprintf(stdout, " noknownissues (K) : %s\n", (noKnownIssues? "On" : "Off"));
|
2005-04-06 00:38:48 +00:00
|
|
|
fprintf(stdout, " Warn on missing data (w) : %s\n", (warnOnMissingData? "On" : "Off"));
|
2019-08-13 04:16:25 +00:00
|
|
|
fprintf(stdout, " Write golden data (G) : %s\n", (writeGoldenData? "On" : "Off"));
|
2009-08-13 00:11:21 +00:00
|
|
|
fprintf(stdout, " Threads : %d\n", threadCount);
|
2008-09-22 22:02:44 +00:00
|
|
|
for (int32_t i = 0; i < nProps; i++) {
|
|
|
|
fprintf(stdout, " Custom property (prop:) : %s\n", props[i]);
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
|
|
|
|
2013-06-20 22:05:51 +00:00
|
|
|
if(utf8) {
|
|
|
|
ucnv_setDefaultName("utf-8");
|
|
|
|
}
|
2004-12-02 07:09:05 +00:00
|
|
|
/* 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");
|
|
|
|
defaultDataFound = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
defaultDataFound = TRUE;
|
|
|
|
}
|
|
|
|
u_cleanup();
|
2013-06-20 22:05:51 +00:00
|
|
|
if(utf8) {
|
|
|
|
ucnv_setDefaultName("utf-8");
|
|
|
|
}
|
2003-04-30 00:09:18 +00:00
|
|
|
errorCode = U_ZERO_ERROR;
|
2004-12-02 07:09:05 +00:00
|
|
|
|
|
|
|
/* Initialize ICU */
|
|
|
|
if (!defaultDataFound) {
|
|
|
|
IntlTest::setICU_DATA(); // Must set data directory before u_init() is called.
|
|
|
|
}
|
2003-04-30 00:09:18 +00:00
|
|
|
u_init(&errorCode);
|
|
|
|
if (U_FAILURE(errorCode)) {
|
2004-12-02 07:09:05 +00:00
|
|
|
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(warnOnMissingData == 0) {
|
|
|
|
fprintf(stderr, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
|
|
|
u_cleanup();
|
|
|
|
return 1;
|
|
|
|
}
|
2003-04-30 00:09:18 +00:00
|
|
|
}
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
// initial check for the default converter
|
2002-03-20 18:36:17 +00:00
|
|
|
errorCode = U_ZERO_ERROR;
|
|
|
|
cnv = ucnv_open(0, &errorCode);
|
2002-02-07 19:37:34 +00:00
|
|
|
if(cnv != 0) {
|
|
|
|
// ok
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
|
|
|
fprintf(stdout,
|
2002-09-24 23:52:03 +00:00
|
|
|
"*** %s! The default converter [%s] cannot be opened.\n"
|
2002-02-07 19:37:34 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and\n"
|
|
|
|
"*** check that the data files are present.\n",
|
2002-09-24 23:52:03 +00:00
|
|
|
warnOrErr, ucnv_getDefaultName());
|
|
|
|
if(!warnOnMissingData) {
|
2003-09-22 19:48:43 +00:00
|
|
|
fprintf(stdout, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
2002-09-24 23:52:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
2000-03-29 21:48:44 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
// try more data
|
2002-09-21 00:43:14 +00:00
|
|
|
cnv = ucnv_open(TRY_CNV_2, &errorCode);
|
2002-02-07 19:37:34 +00:00
|
|
|
if(cnv != 0) {
|
|
|
|
// ok
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
|
|
|
fprintf(stdout,
|
2002-09-24 23:52:03 +00:00
|
|
|
"*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n"
|
2002-02-07 19:37:34 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
2002-09-24 23:52:03 +00:00
|
|
|
"*** check that the data files are present.\n", warnOrErr);
|
|
|
|
if(!warnOnMissingData) {
|
2003-09-22 19:48:43 +00:00
|
|
|
fprintf(stdout, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
2002-09-24 23:52:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
2000-03-29 21:48:44 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
UResourceBundle *rb = ures_open(0, "en", &errorCode);
|
2003-06-05 18:15:20 +00:00
|
|
|
ures_close(rb);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout,
|
2002-09-24 23:52:03 +00:00
|
|
|
"*** %s! The \"en\" locale resource bundle cannot be opened.\n"
|
2002-02-07 19:37:34 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
2002-09-24 23:52:03 +00:00
|
|
|
"*** check that the data files are present.\n", warnOrErr);
|
|
|
|
if(!warnOnMissingData) {
|
2003-09-22 19:48:43 +00:00
|
|
|
fprintf(stdout, "*** Exiting. Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
|
2002-09-24 23:52:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
2002-02-05 17:59:16 +00:00
|
|
|
|
2004-12-22 19:28:42 +00:00
|
|
|
Locale originalLocale; // Save the default locale for comparison later on.
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
if(ctest_xml_init("intltest"))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
/* TODO: Add option to call u_cleanup and rerun tests. */
|
|
|
|
if (all) {
|
|
|
|
major.runTest();
|
|
|
|
if (leaks) {
|
|
|
|
major.run_phase2( NULL, NULL );
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (argv[i][0] != '-') {
|
|
|
|
char* name = argv[i];
|
|
|
|
fprintf(stdout, "\n=== Handling test: %s: ===\n", name);
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
char baseName[1024];
|
|
|
|
sprintf(baseName, "/%s/", name);
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
char* parameter = strchr( name, '@' );
|
|
|
|
if (parameter) {
|
|
|
|
*parameter = 0;
|
|
|
|
parameter += 1;
|
|
|
|
}
|
|
|
|
execCount = 0;
|
2010-07-12 15:24:57 +00:00
|
|
|
UBool res = major.runTest( name, parameter, baseName );
|
2002-02-07 19:37:34 +00:00
|
|
|
if (leaks && res) {
|
|
|
|
major.run_phase2( name, parameter );
|
|
|
|
}
|
|
|
|
if (!res || (execCount <= 0)) {
|
|
|
|
fprintf(stdout, "\n---ERROR: Test doesn't exist: %s!\n", name);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
} else if(!strcmp(argv[i],"-x")) {
|
|
|
|
i++;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
2001-09-01 02:57:07 +00:00
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2002-02-07 19:37:34 +00:00
|
|
|
CalendarTimeZoneTest::cleanup();
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif
|
|
|
|
|
2003-05-17 09:55:03 +00:00
|
|
|
free(_testDataPath);
|
2002-02-07 19:37:34 +00:00
|
|
|
_testDataPath = 0;
|
2001-09-01 02:57:07 +00:00
|
|
|
|
2004-12-22 19:28:42 +00:00
|
|
|
Locale lastDefaultLocale;
|
|
|
|
if (originalLocale != lastDefaultLocale) {
|
|
|
|
major.errln("FAILURE: A test changed the default locale without resetting it.");
|
|
|
|
}
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "\n--------------------------------------\n");
|
2013-09-17 00:21:47 +00:00
|
|
|
if( major.printKnownIssues() ) {
|
|
|
|
fprintf(stdout, " To run suppressed tests, use the -K option. \n");
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
if (major.getErrors() == 0) {
|
|
|
|
/* Call it twice to make sure that the defaults were reset. */
|
|
|
|
/* Call it before the OK message to verify proper cleanup. */
|
|
|
|
u_cleanup();
|
2004-12-22 19:28:42 +00:00
|
|
|
u_cleanup();
|
2001-10-23 01:20:10 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "OK: All tests passed without error.\n");
|
2005-04-05 20:12:22 +00:00
|
|
|
|
2005-04-06 00:38:48 +00:00
|
|
|
if (major.getDataErrors() != 0) {
|
|
|
|
fprintf(stdout, "\t*WARNING* some data-loading errors were ignored by the -w option.\n");
|
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
}else{
|
|
|
|
fprintf(stdout, "Errors in total: %ld.\n", (long)major.getErrors());
|
|
|
|
major.printErrors();
|
2001-10-23 01:20:10 +00:00
|
|
|
|
2013-07-09 01:16:33 +00:00
|
|
|
if(summary_file != NULL) {
|
|
|
|
FILE *summf = fopen(summary_file, "w");
|
|
|
|
if( summf != NULL) {
|
|
|
|
char buf[10000];
|
|
|
|
int32_t length = errorList.extract(0, errorList.length(), buf, sizeof(buf));
|
|
|
|
fwrite(buf, sizeof(*buf), length, (FILE*)summf);
|
|
|
|
fclose(summf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-05 20:12:22 +00:00
|
|
|
|
2005-04-06 00:38:48 +00:00
|
|
|
if (major.getDataErrors() != 0) {
|
|
|
|
fprintf(stdout, "\t*Note* some errors are data-loading related. If the data used is not the \n"
|
|
|
|
"\tstock ICU data (i.e some have been added or removed), consider using\n"
|
|
|
|
"\tthe '-w' option to turn these errors into warnings.\n");
|
|
|
|
}
|
2005-04-05 20:12:22 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
/* Call afterwards to display errors. */
|
|
|
|
u_cleanup();
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2015-04-15 18:49:55 +00:00
|
|
|
#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
|
|
|
|
unistr_printLengths();
|
|
|
|
#endif
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
fprintf(stdout, "--------------------------------------\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
if (execCount <= 0) {
|
|
|
|
fprintf(stdout, "***** Not all called tests actually exist! *****\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2012-05-30 00:37:33 +00:00
|
|
|
if(!no_time) {
|
|
|
|
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));
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
if(ctest_xml_fini())
|
|
|
|
return 1;
|
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
return major.getErrors();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-04-25 22:15:52 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
const char* IntlTest::loadTestData(UErrorCode& err){
|
|
|
|
if( _testDataPath == NULL){
|
2003-05-21 20:10:38 +00:00
|
|
|
const char* directory=NULL;
|
|
|
|
UResourceBundle* test =NULL;
|
|
|
|
char* tdpath=NULL;
|
|
|
|
const char* tdrelativepath;
|
|
|
|
|
|
|
|
#if defined (U_TOPBUILDDIR)
|
2012-08-31 19:12:19 +00:00
|
|
|
tdrelativepath = "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
|
2003-05-21 20:10:38 +00:00
|
|
|
directory = U_TOPBUILDDIR;
|
|
|
|
#else
|
2012-08-31 19:12:19 +00:00
|
|
|
tdrelativepath = ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
|
2003-05-21 20:10:38 +00:00
|
|
|
directory = pathToDataDirectory();
|
|
|
|
#endif
|
2002-07-31 21:41:03 +00:00
|
|
|
|
2003-05-16 19:52:01 +00:00
|
|
|
tdpath = (char*) malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 100));
|
2002-02-07 19:37:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* u_getDataDirectory shoul return \source\data ... set the
|
|
|
|
* directory to ..\source\data\..\test\testdata\out\testdata
|
|
|
|
*/
|
2004-11-11 23:34:58 +00:00
|
|
|
strcpy(tdpath, directory);
|
2002-02-07 19:37:34 +00:00
|
|
|
strcat(tdpath, tdrelativepath);
|
|
|
|
strcat(tdpath,"testdata");
|
2003-05-16 19:52:01 +00:00
|
|
|
|
2002-02-07 19:37:34 +00:00
|
|
|
test=ures_open(tdpath, "testtypes", &err);
|
2003-05-16 19:52:01 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(err)){
|
|
|
|
err = U_FILE_ACCESS_ERROR;
|
2009-06-12 19:34:21 +00:00
|
|
|
it_dataerrln((UnicodeString)"Could not load testtypes.res in testdata bundle with path " + tdpath + (UnicodeString)" - " + u_errorName(err));
|
2003-05-16 19:52:01 +00:00
|
|
|
return "";
|
2002-01-29 03:56:11 +00:00
|
|
|
}
|
|
|
|
ures_close(test);
|
2002-02-07 19:37:34 +00:00
|
|
|
_testDataPath = tdpath;
|
|
|
|
return _testDataPath;
|
2002-01-29 03:56:11 +00:00
|
|
|
}
|
2002-02-07 19:37:34 +00:00
|
|
|
return _testDataPath;
|
2002-01-29 03:56:11 +00:00
|
|
|
}
|
2003-02-28 21:37:55 +00:00
|
|
|
|
2004-03-23 06:37:36 +00:00
|
|
|
const char* IntlTest::getTestDataPath(UErrorCode& err) {
|
|
|
|
return loadTestData(err);
|
|
|
|
}
|
|
|
|
|
2004-08-04 23:40:31 +00:00
|
|
|
/* Returns the path to icu/source/test/testdata/ */
|
2004-10-28 00:05:24 +00:00
|
|
|
const char *IntlTest::getSourceTestData(UErrorCode& /*err*/) {
|
2004-08-04 23:40:31 +00:00
|
|
|
const char *srcDataDir = NULL;
|
|
|
|
#ifdef U_TOPSRCDIR
|
2012-08-31 19:12:19 +00:00
|
|
|
srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING"test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
|
2004-08-04 23:40:31 +00:00
|
|
|
#else
|
2012-08-31 19:12:19 +00:00
|
|
|
srcDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
|
|
|
|
FILE *f = fopen(".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "rbbitst.txt", "r");
|
2004-08-05 23:35:31 +00:00
|
|
|
if (f) {
|
|
|
|
/* We're in icu/source/test/intltest/ */
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
2008-08-12 16:34:55 +00:00
|
|
|
/* We're in icu/source/test/intltest/Platform/(Debug|Release) */
|
2014-12-19 23:41:18 +00:00
|
|
|
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;
|
2004-08-05 23:35:31 +00:00
|
|
|
}
|
2004-08-04 23:40:31 +00:00
|
|
|
#endif
|
|
|
|
return srcDataDir;
|
|
|
|
}
|
|
|
|
|
2014-04-14 22:30:09 +00:00
|
|
|
char *IntlTest::getUnidataPath(char path[]) {
|
|
|
|
const int kUnicodeDataTxtLength = 15; // strlen("UnicodeData.txt")
|
|
|
|
|
|
|
|
// Look inside ICU_DATA first.
|
|
|
|
strcpy(path, pathToDataDirectory());
|
|
|
|
strcat(path, "unidata" U_FILE_SEP_STRING "UnicodeData.txt");
|
|
|
|
FILE *f = fopen(path, "r");
|
|
|
|
if(f != NULL) {
|
|
|
|
fclose(f);
|
|
|
|
*(strchr(path, 0) - kUnicodeDataTxtLength) = 0; // Remove the basename.
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// As a fallback, try to guess where the source data was located
|
|
|
|
// at the time ICU was built, and look there.
|
|
|
|
# ifdef U_TOPSRCDIR
|
|
|
|
strcpy(path, U_TOPSRCDIR U_FILE_SEP_STRING "data");
|
|
|
|
# else
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
const char *testDataPath = loadTestData(errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
it_errln(UnicodeString(
|
|
|
|
"unable to find path to source/data/unidata/ and loadTestData() failed: ") +
|
|
|
|
u_errorName(errorCode));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
strcpy(path, testDataPath);
|
|
|
|
strcat(path, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".."
|
|
|
|
U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".."
|
|
|
|
U_FILE_SEP_STRING "data");
|
|
|
|
# endif
|
|
|
|
strcat(path, U_FILE_SEP_STRING);
|
|
|
|
strcat(path, "unidata" U_FILE_SEP_STRING "UnicodeData.txt");
|
|
|
|
f = fopen(path, "r");
|
|
|
|
if(f != NULL) {
|
|
|
|
fclose(f);
|
|
|
|
*(strchr(path, 0) - kUnicodeDataTxtLength) = 0; // Remove the basename.
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-28 21:37:55 +00:00
|
|
|
const char* IntlTest::fgDataDir = NULL;
|
|
|
|
|
|
|
|
/* returns the path to icu/source/data */
|
|
|
|
const char * IntlTest::pathToDataDirectory()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(fgDataDir != NULL) {
|
|
|
|
return fgDataDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst
|
|
|
|
// to point to the top of the build hierarchy, which may or
|
|
|
|
// may not be the same as the source directory, depending on
|
|
|
|
// the configure options used. At any rate,
|
|
|
|
// set the data path to the built data from this directory.
|
|
|
|
// The value is complete with quotes, so it can be used
|
|
|
|
// as-is as a string constant.
|
|
|
|
*/
|
|
|
|
#if defined (U_TOPSRCDIR)
|
|
|
|
{
|
|
|
|
fgDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* On Windows, the file name obtained from __FILE__ includes a full path.
|
|
|
|
* This file is "wherever\icu\source\test\cintltst\cintltst.c"
|
|
|
|
* Change to "wherever\icu\source\data"
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
static char p[sizeof(__FILE__) + 10];
|
|
|
|
char *pBackSlash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
strcpy(p, __FILE__);
|
|
|
|
/* We want to back over three '\' chars. */
|
|
|
|
/* Only Windows should end up here, so looking for '\' is safe. */
|
2003-05-15 18:44:00 +00:00
|
|
|
for (i=1; i<=3; i++) {
|
|
|
|
pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
|
2003-02-28 21:37:55 +00:00
|
|
|
if (pBackSlash != NULL) {
|
2003-05-15 18:44:00 +00:00
|
|
|
*pBackSlash = 0; /* Truncate the string at the '\' */
|
2003-02-28 21:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-15 18:44:00 +00:00
|
|
|
|
|
|
|
if (pBackSlash != NULL) {
|
|
|
|
/* We found and truncated three names from the path.
|
|
|
|
* Now append "source\data" and set the environment
|
|
|
|
*/
|
|
|
|
strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING );
|
|
|
|
fgDataDir = p;
|
|
|
|
}
|
2003-05-01 01:10:19 +00:00
|
|
|
else {
|
|
|
|
/* __FILE__ on MSVC7 does not contain the directory */
|
2014-12-19 23:41:18 +00:00
|
|
|
FILE *file = fopen(".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
|
2004-11-11 23:34:58 +00:00
|
|
|
if (file) {
|
|
|
|
fclose(file);
|
2014-12-19 23:41:18 +00:00
|
|
|
fgDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
2004-11-11 23:34:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-12-19 23:41:18 +00:00
|
|
|
fgDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
|
2004-11-11 23:34:58 +00:00
|
|
|
}
|
2003-02-28 21:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return fgDataDir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-03-22 23:17:42 +00:00
|
|
|
/*
|
|
|
|
* This is a variant of cintltst/ccolltst.c:CharsToUChars().
|
2010-06-15 15:54:53 +00:00
|
|
|
* It converts an invariant-character string into a UnicodeString, with
|
2000-03-22 23:17:42 +00:00
|
|
|
* unescaping \u sequences.
|
|
|
|
*/
|
2009-08-13 00:11:21 +00:00
|
|
|
UnicodeString CharsToUnicodeString(const char* chars){
|
2010-06-15 15:54:53 +00:00
|
|
|
return UnicodeString(chars, -1, US_INV).unescape();
|
2000-03-22 23:17:42 +00:00
|
|
|
}
|
2000-04-25 21:32:10 +00:00
|
|
|
|
2004-02-12 01:09:13 +00:00
|
|
|
UnicodeString ctou(const char* chars) {
|
|
|
|
return CharsToUnicodeString(chars);
|
|
|
|
}
|
|
|
|
|
2003-08-12 19:51:03 +00:00
|
|
|
#define RAND_M (714025)
|
|
|
|
#define RAND_IA (1366)
|
|
|
|
#define RAND_IC (150889)
|
|
|
|
|
|
|
|
static int32_t RAND_SEED;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a uniform random value x, with 0.0 <= x < 1.0. Use
|
|
|
|
* with care: Does not return all possible values; returns one of
|
|
|
|
* 714,025 values, uniformly spaced. However, the period is
|
|
|
|
* effectively infinite. See: Numerical Recipes, section 7.1.
|
|
|
|
*
|
|
|
|
* @param seedp pointer to seed. Set *seedp to any negative value
|
|
|
|
* to restart the sequence.
|
|
|
|
*/
|
|
|
|
float IntlTest::random(int32_t* seedp) {
|
|
|
|
static int32_t iy, ir[98];
|
|
|
|
static UBool first=TRUE;
|
|
|
|
int32_t j;
|
|
|
|
if (*seedp < 0 || first) {
|
|
|
|
first = FALSE;
|
|
|
|
if ((*seedp=(RAND_IC-(*seedp)) % RAND_M) < 0) *seedp = -(*seedp);
|
|
|
|
for (j=1;j<=97;++j) {
|
|
|
|
*seedp=(RAND_IA*(*seedp)+RAND_IC) % RAND_M;
|
|
|
|
ir[j]=(*seedp);
|
|
|
|
}
|
|
|
|
*seedp=(RAND_IA*(*seedp)+RAND_IC) % RAND_M;
|
|
|
|
iy=(*seedp);
|
|
|
|
}
|
|
|
|
j=(int32_t)(1 + 97.0*iy/RAND_M);
|
|
|
|
U_ASSERT(j>=1 && j<=97);
|
|
|
|
iy=ir[j];
|
|
|
|
*seedp=(RAND_IA*(*seedp)+RAND_IC) % RAND_M;
|
|
|
|
ir[j]=(*seedp);
|
|
|
|
return (float) iy/RAND_M;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method using a global seed.
|
|
|
|
*/
|
|
|
|
float IntlTest::random() {
|
|
|
|
return random(&RAND_SEED);
|
|
|
|
}
|
|
|
|
|
2016-02-26 21:58:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Integer random number class implementation.
|
|
|
|
* Similar to C++ std::minstd_rand, with the same algorithm & constants.
|
|
|
|
*/
|
|
|
|
IntlTest::icu_rand::icu_rand(uint32_t seed) {
|
|
|
|
seed = seed % 2147483647UL;
|
|
|
|
if (seed == 0) {
|
|
|
|
seed = 1;
|
|
|
|
}
|
|
|
|
fLast = seed;
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:18:32 +00:00
|
|
|
IntlTest::icu_rand::~icu_rand() {}
|
2016-02-26 21:58:26 +00:00
|
|
|
|
|
|
|
void IntlTest::icu_rand::seed(uint32_t seed) {
|
|
|
|
if (seed == 0) {
|
|
|
|
seed = 1;
|
|
|
|
}
|
|
|
|
fLast = seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t IntlTest::icu_rand::operator() () {
|
|
|
|
fLast = ((uint64_t)fLast * 48271UL) % 2147483647UL;
|
|
|
|
return fLast;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t IntlTest::icu_rand::getSeed() {
|
|
|
|
return (uint32_t) fLast;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-04-15 06:19:10 +00:00
|
|
|
static inline UChar toHex(int32_t i) {
|
|
|
|
return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static UnicodeString& escape(const UnicodeString& s, UnicodeString& result) {
|
|
|
|
for (int32_t i=0; i<s.length(); ++i) {
|
|
|
|
UChar c = s[i];
|
|
|
|
if (c <= (UChar)0x7F) {
|
|
|
|
result += c;
|
|
|
|
} else {
|
|
|
|
result += (UChar)0x5c;
|
|
|
|
result += (UChar)0x75;
|
|
|
|
result += toHex((c >> 12) & 0xF);
|
|
|
|
result += toHex((c >> 8) & 0xF);
|
|
|
|
result += toHex((c >> 4) & 0xF);
|
|
|
|
result += toHex( c & 0xF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-02-12 01:09:13 +00:00
|
|
|
#define VERBOSE_ASSERTIONS
|
|
|
|
|
2013-02-12 06:46:51 +00:00
|
|
|
UBool IntlTest::assertTrue(const char* message, UBool condition, UBool quiet, UBool possibleDataError, const char *file, int line) {
|
|
|
|
if (file != NULL) {
|
|
|
|
if (!condition) {
|
|
|
|
if (possibleDataError) {
|
|
|
|
dataerrln("%s:%d: FAIL: assertTrue() failed: %s", file, line, message);
|
|
|
|
} else {
|
|
|
|
errln("%s:%d: FAIL: assertTrue() failed: %s", file, line, message);
|
|
|
|
}
|
|
|
|
} else if (!quiet) {
|
|
|
|
logln("%s:%d: Ok: %s", file, line, message);
|
2009-06-12 19:34:21 +00:00
|
|
|
}
|
2013-02-12 06:46:51 +00:00
|
|
|
} else {
|
|
|
|
if (!condition) {
|
|
|
|
if (possibleDataError) {
|
|
|
|
dataerrln("FAIL: assertTrue() failed: %s", message);
|
|
|
|
} else {
|
|
|
|
errln("FAIL: assertTrue() failed: %s", message);
|
|
|
|
}
|
|
|
|
} else if (!quiet) {
|
|
|
|
logln("Ok: %s", message);
|
2012-12-10 19:18:04 +00:00
|
|
|
}
|
2013-02-12 06:46:51 +00:00
|
|
|
|
2012-12-10 19:18:04 +00:00
|
|
|
}
|
|
|
|
return condition;
|
|
|
|
}
|
|
|
|
|
2018-05-16 22:46:40 +00:00
|
|
|
UBool IntlTest::assertFalse(const char* message, UBool condition, UBool quiet, UBool possibleDataError) {
|
2004-02-12 01:09:13 +00:00
|
|
|
if (condition) {
|
2018-05-16 22:46:40 +00:00
|
|
|
if (possibleDataError) {
|
|
|
|
dataerrln("FAIL: assertTrue() failed: %s", message);
|
|
|
|
} else {
|
|
|
|
errln("FAIL: assertTrue() failed: %s", message);
|
|
|
|
}
|
2004-06-04 00:19:50 +00:00
|
|
|
} else if (!quiet) {
|
2004-02-12 01:09:13 +00:00
|
|
|
logln("Ok: %s", message);
|
|
|
|
}
|
|
|
|
return !condition;
|
|
|
|
}
|
|
|
|
|
2013-09-12 01:27:29 +00:00
|
|
|
UBool IntlTest::assertSuccess(const char* message, UErrorCode ec, UBool possibleDataError, const char *file, int line) {
|
2013-09-24 23:40:46 +00:00
|
|
|
if( file==NULL ) {
|
|
|
|
file = ""; // prevent failure if no file given
|
|
|
|
}
|
2004-02-12 01:09:13 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
2009-06-12 19:34:21 +00:00
|
|
|
if (possibleDataError) {
|
2013-09-12 01:27:29 +00:00
|
|
|
dataerrln("FAIL: %s:%d: %s (%s)", file, line, message, u_errorName(ec));
|
2008-04-10 23:19:16 +00:00
|
|
|
} else {
|
2013-09-12 01:27:29 +00:00
|
|
|
errcheckln(ec, "FAIL: %s:%d: %s (%s)", file, line, message, u_errorName(ec));
|
2008-04-10 23:19:16 +00:00
|
|
|
}
|
2004-02-12 01:09:13 +00:00
|
|
|
return FALSE;
|
2013-09-12 01:27:29 +00:00
|
|
|
} else {
|
|
|
|
logln("OK: %s:%d: %s - (%s)", file, line, message, u_errorName(ec));
|
2004-02-12 01:09:13 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
const UnicodeString& expected,
|
2009-06-12 19:34:21 +00:00
|
|
|
const UnicodeString& actual,
|
|
|
|
UBool possibleDataError) {
|
2004-02-12 01:09:13 +00:00
|
|
|
if (expected != actual) {
|
2009-06-12 19:34:21 +00:00
|
|
|
if (possibleDataError) {
|
|
|
|
dataerrln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
prettify(actual) +
|
|
|
|
"; expected " + prettify(expected));
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
prettify(actual) +
|
|
|
|
"; expected " + prettify(expected));
|
|
|
|
}
|
2004-02-12 01:09:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + prettify(actual));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-26 19:10:13 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
const char* expected,
|
|
|
|
const char* actual) {
|
|
|
|
if (uprv_strcmp(expected, actual) != 0) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got \"" +
|
|
|
|
actual +
|
|
|
|
"\"; expected \"" + expected + "\"");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got \"" + actual + "\"");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:11:33 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
int32_t expected,
|
|
|
|
int32_t actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
actual + "=0x" + toHex(actual) +
|
|
|
|
"; expected " + expected + "=0x" + toHex(expected));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + actual + "=0x" + toHex(actual));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-26 06:31:09 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
int64_t expected,
|
|
|
|
int64_t actual) {
|
|
|
|
if (expected != actual) {
|
2013-06-26 15:27:41 +00:00
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got int64 " +
|
|
|
|
Int64ToUnicodeString(actual) +
|
|
|
|
"; expected " + Int64ToUnicodeString(expected) );
|
2013-06-26 06:31:09 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
2013-06-26 15:27:41 +00:00
|
|
|
logln((UnicodeString)"Ok: " + message + "; got int64 " + Int64ToUnicodeString(actual));
|
2013-06-26 06:31:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-30 22:45:39 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
double expected,
|
|
|
|
double actual) {
|
2018-02-09 02:35:02 +00:00
|
|
|
bool bothNaN = std::isnan(expected) && std::isnan(actual);
|
|
|
|
if (expected != actual && !bothNaN) {
|
2015-07-30 22:45:39 +00:00
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
actual +
|
|
|
|
"; expected " + expected);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + actual);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-26 06:31:09 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
UBool expected,
|
|
|
|
UBool actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
toString(actual) +
|
|
|
|
"; expected " + toString(expected));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + toString(actual));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-08 06:06:08 +00:00
|
|
|
|
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
UErrorCode expected,
|
|
|
|
UErrorCode actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
u_errorName(actual) +
|
|
|
|
"; expected " + u_errorName(expected));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + u_errorName(actual));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
const UnicodeSet& expected,
|
|
|
|
const UnicodeSet& actual) {
|
|
|
|
IcuTestErrorCode status(*this, "assertEqualsUniSet");
|
|
|
|
if (expected != actual) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
toString(actual, status) +
|
|
|
|
"; expected " + toString(expected, status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + toString(actual, status));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-08 06:06:08 +00:00
|
|
|
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2004-03-25 02:23:22 +00:00
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
const Formattable& expected,
|
2013-09-19 02:32:57 +00:00
|
|
|
const Formattable& actual,
|
|
|
|
UBool possibleDataError) {
|
2004-03-25 02:23:22 +00:00
|
|
|
if (expected != actual) {
|
2013-09-19 02:32:57 +00:00
|
|
|
if (possibleDataError) {
|
|
|
|
dataerrln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
toString(actual) +
|
|
|
|
"; expected " + toString(expected));
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: " + message + "; got " +
|
|
|
|
toString(actual) +
|
|
|
|
"; expected " + toString(expected));
|
|
|
|
}
|
2004-03-25 02:23:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + toString(actual));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-06-10 23:51:33 +00:00
|
|
|
#endif
|
2004-03-25 02:23:22 +00:00
|
|
|
|
2019-06-07 21:05:14 +00:00
|
|
|
std::string vectorToString(const std::vector<std::string>& strings) {
|
|
|
|
std::string result = "{";
|
|
|
|
bool first = true;
|
|
|
|
for (auto element : strings) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
result += ", ";
|
|
|
|
}
|
|
|
|
result += "\"";
|
|
|
|
result += element;
|
|
|
|
result += "\"";
|
|
|
|
}
|
|
|
|
result += "}";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::assertEquals(const char* message,
|
|
|
|
const std::vector<std::string>& expected,
|
|
|
|
const std::vector<std::string>& actual) {
|
|
|
|
if (expected != actual) {
|
|
|
|
std::string expectedAsString = vectorToString(expected);
|
|
|
|
std::string actualAsString = vectorToString(actual);
|
|
|
|
errln((UnicodeString)"FAIL: " + message +
|
|
|
|
"; got " + actualAsString.c_str() +
|
|
|
|
"; expected " + expectedAsString.c_str());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef VERBOSE_ASSERTIONS
|
|
|
|
else {
|
|
|
|
logln((UnicodeString)"Ok: " + message + "; got " + vectorToString(actual).c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-11 14:06:25 +00:00
|
|
|
static char ASSERT_BUF[256];
|
|
|
|
|
|
|
|
static const char* extractToAssertBuf(const UnicodeString& message) {
|
2004-04-15 06:19:10 +00:00
|
|
|
UnicodeString buf;
|
|
|
|
escape(message, buf);
|
|
|
|
buf.extract(0, 0x7FFFFFFF, ASSERT_BUF, sizeof(ASSERT_BUF)-1, 0);
|
2004-03-11 14:06:25 +00:00
|
|
|
ASSERT_BUF[sizeof(ASSERT_BUF)-1] = 0;
|
|
|
|
return ASSERT_BUF;
|
|
|
|
}
|
|
|
|
|
2018-05-16 22:46:40 +00:00
|
|
|
UBool IntlTest::assertTrue(const UnicodeString& message, UBool condition, UBool quiet, UBool possibleDataError) {
|
|
|
|
return assertTrue(extractToAssertBuf(message), condition, quiet, possibleDataError);
|
2004-03-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 22:46:40 +00:00
|
|
|
UBool IntlTest::assertFalse(const UnicodeString& message, UBool condition, UBool quiet, UBool possibleDataError) {
|
|
|
|
return assertFalse(extractToAssertBuf(message), condition, quiet, possibleDataError);
|
2004-03-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::assertSuccess(const UnicodeString& message, UErrorCode ec) {
|
|
|
|
return assertSuccess(extractToAssertBuf(message), ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
const UnicodeString& expected,
|
2013-09-19 02:32:57 +00:00
|
|
|
const UnicodeString& actual,
|
|
|
|
UBool possibleDataError) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual, possibleDataError);
|
2004-03-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 19:10:13 +00:00
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
const char* expected,
|
|
|
|
const char* actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
|
|
|
}
|
2013-06-26 06:31:09 +00:00
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
UBool expected,
|
|
|
|
UBool actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
int32_t expected,
|
|
|
|
int32_t actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
int64_t expected,
|
|
|
|
int64_t actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
2018-02-08 06:06:08 +00:00
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
double expected,
|
|
|
|
double actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
UErrorCode expected,
|
|
|
|
UErrorCode actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
2018-02-10 06:36:07 +00:00
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
const UnicodeSet& expected,
|
|
|
|
const UnicodeSet& actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
2019-06-07 21:05:14 +00:00
|
|
|
}
|
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
const std::vector<std::string>& expected,
|
|
|
|
const std::vector<std::string>& actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
2013-06-26 06:31:09 +00:00
|
|
|
}
|
2004-04-26 19:10:13 +00:00
|
|
|
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2004-03-25 02:23:22 +00:00
|
|
|
UBool IntlTest::assertEquals(const UnicodeString& message,
|
|
|
|
const Formattable& expected,
|
|
|
|
const Formattable& actual) {
|
|
|
|
return assertEquals(extractToAssertBuf(message), expected, actual);
|
|
|
|
}
|
2004-06-10 23:51:33 +00:00
|
|
|
#endif
|
2004-03-25 02:23:22 +00:00
|
|
|
|
2008-09-22 22:02:44 +00:00
|
|
|
void IntlTest::setProperty(const char* propline) {
|
|
|
|
if (numProps < kMaxProps) {
|
|
|
|
proplines[numProps] = propline;
|
|
|
|
}
|
|
|
|
numProps++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* IntlTest::getProperty(const char* prop) {
|
|
|
|
const char* val = NULL;
|
|
|
|
for (int32_t i = 0; i < numProps; i++) {
|
2019-01-11 20:23:43 +00:00
|
|
|
int32_t plen = static_cast<int32_t>(uprv_strlen(prop));
|
2008-09-22 22:02:44 +00:00
|
|
|
if ((int32_t)uprv_strlen(proplines[i]) > plen + 1
|
|
|
|
&& proplines[i][plen] == '='
|
|
|
|
&& uprv_strncmp(proplines[i], prop, plen) == 0) {
|
|
|
|
val = &(proplines[i][plen+1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2000-04-25 21:32:10 +00:00
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|