2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-1999, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
|
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 <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2001-01-23 23:51:55 +00:00
|
|
|
#include <stdarg.h>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
2000-03-29 21:48:44 +00:00
|
|
|
#include "unicode/ures.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/coll.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
2000-07-16 13:42:38 +00:00
|
|
|
#include "unicode/ustring.h"
|
2001-01-02 19:01:49 +00:00
|
|
|
#include "unicode/ucnv.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#include "intltest.h"
|
|
|
|
#include "itmajor.h"
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#include <console.h>
|
|
|
|
#include "Files.h"
|
|
|
|
#endif
|
2000-08-29 07:28:22 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static char* _testDirectory=NULL;
|
2000-12-03 03:29:39 +00:00
|
|
|
|
|
|
|
// Static list of errors found
|
|
|
|
static UnicodeString errorList = UnicodeString("", "");
|
|
|
|
|
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); }
|
|
|
|
|
|
|
|
// [LIU] Just to get things working
|
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
|
|
|
const UnicodeString& right)
|
|
|
|
{
|
|
|
|
UnicodeString str(left);
|
|
|
|
str += right;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [rtg] Just to get things working
|
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
|
|
|
long num)
|
|
|
|
{
|
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
|
|
|
sprintf(buffer, "%d", num);
|
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
|
|
|
unsigned long num)
|
|
|
|
{
|
|
|
|
char buffer[64]; // nos changed from 10 to 64
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
|
|
|
sprintf(buffer, "%u", num);
|
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [LIU] Just to get things working
|
|
|
|
UnicodeString
|
|
|
|
operator+(const UnicodeString& left,
|
|
|
|
double num)
|
|
|
|
{
|
|
|
|
char buffer[64]; // was 32, made it arbitrarily bigger (rtg)
|
|
|
|
char danger = 'p'; // guard against overrunning the buffer (rtg)
|
|
|
|
|
|
|
|
sprintf(buffer, "%.30g", num); // nos changed from 99 to 30
|
|
|
|
assert(danger == 'p');
|
|
|
|
|
|
|
|
return left + buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Originally coded this as operator+, but that makes the expression
|
|
|
|
* + char* ambiguous. - liu
|
|
|
|
*/
|
|
|
|
UnicodeString toString(const Formattable& f) {
|
|
|
|
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);
|
|
|
|
s.insert(0, "[Date:");
|
2000-06-28 22:26:59 +00:00
|
|
|
s.insert(s.length(), (UChar)0x005d);
|
1999-08-16 21:50:52 +00:00
|
|
|
} else {
|
|
|
|
s = UnicodeString("[Error creating date format]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Formattable::kDouble:
|
|
|
|
s = UnicodeString("[Double:") + f.getDouble() + "]";
|
|
|
|
break;
|
|
|
|
case Formattable::kLong:
|
|
|
|
s = UnicodeString("[Long:") + f.getLong() + "]";
|
|
|
|
break;
|
|
|
|
case Formattable::kString:
|
|
|
|
f.getString(s);
|
|
|
|
s.insert(0, "[String:");
|
2000-06-28 22:26:59 +00:00
|
|
|
s.insert(s.length(), (UChar)0x005d);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
case Formattable::kArray:
|
|
|
|
{
|
|
|
|
int32_t i, n;
|
|
|
|
const Formattable* array = f.getArray(n);
|
|
|
|
s.insert(0, UnicodeString("[Array:"));
|
|
|
|
UnicodeString delim(", ");
|
|
|
|
for (i=0; i<n; ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
s.append(delim);
|
|
|
|
}
|
|
|
|
s = s + toString(array[i]);
|
|
|
|
}
|
2000-06-28 22:26:59 +00:00
|
|
|
s.append(UChar(0x005d));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stephen - cleaned up 05/05/99
|
|
|
|
UnicodeString operator+(const UnicodeString& left, char num)
|
|
|
|
{ return left + (long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, short num)
|
|
|
|
{ return left + (long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, int num)
|
|
|
|
{ return left + (long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned char num)
|
|
|
|
{ return left + (unsigned long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned short num)
|
|
|
|
{ return left + (unsigned long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned int num)
|
|
|
|
{ return left + (unsigned long)num; }
|
|
|
|
UnicodeString operator+(const UnicodeString& left, float num)
|
|
|
|
{ return left + (double)num; }
|
|
|
|
|
|
|
|
//------------------
|
|
|
|
|
|
|
|
// used for collation result reporting, defined here for convenience
|
|
|
|
// (maybe moved later)
|
|
|
|
void
|
|
|
|
IntlTest::reportCResult( UnicodeString &source, UnicodeString &target,
|
|
|
|
CollationKey &sourceKey, CollationKey &targetKey,
|
|
|
|
Collator::EComparisonResult compareResult,
|
|
|
|
Collator::EComparisonResult keyResult,
|
2000-12-12 19:40:58 +00:00
|
|
|
Collator::EComparisonResult incResult,
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator::EComparisonResult expectedResult )
|
|
|
|
{
|
2000-07-12 17:18:37 +00:00
|
|
|
if (expectedResult < -1 || expectedResult > 1)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-12 17:18:37 +00:00
|
|
|
errln("***** invalid call to reportCResult ****");
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
UBool ok1 = (compareResult == expectedResult);
|
|
|
|
UBool ok2 = (keyResult == expectedResult);
|
2000-12-12 19:40:58 +00:00
|
|
|
UBool ok3 = (incResult == expectedResult);
|
2000-07-12 17:18:37 +00:00
|
|
|
|
2000-12-12 19:40:58 +00:00
|
|
|
|
|
|
|
if (ok1 && ok2 && ok3 && !verbose) {
|
2000-07-12 17:18:37 +00:00
|
|
|
// Keep non-verbose, passing tests fast
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
UnicodeString msg1(ok1 ? "Ok: compare(" : "FAIL: compare(");
|
|
|
|
UnicodeString msg2(", "), msg3(") returned "), msg4("; expected ");
|
|
|
|
UnicodeString prettySource, prettyTarget, sExpect, sResult;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
prettify(source, prettySource);
|
|
|
|
prettify(target, prettyTarget);
|
|
|
|
appendCompareResult(compareResult, sResult);
|
|
|
|
appendCompareResult(expectedResult, sExpect);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
if (ok1) {
|
|
|
|
logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
|
|
|
|
} else {
|
|
|
|
errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg1 = UnicodeString(ok2 ? "Ok: key(" : "FAIL: key(");
|
|
|
|
msg2 = ").compareTo(key(";
|
|
|
|
msg3 = ")) returned ";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
appendCompareResult(keyResult, sResult);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
if (ok2) {
|
|
|
|
logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
|
|
|
|
} else {
|
|
|
|
errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
msg1 = " ";
|
|
|
|
msg2 = " vs. ";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
prettify(sourceKey, prettySource);
|
|
|
|
prettify(targetKey, prettyTarget);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 17:18:37 +00:00
|
|
|
errln(msg1 + prettySource + msg2 + prettyTarget);
|
|
|
|
}
|
2000-12-12 19:40:58 +00:00
|
|
|
msg1 = UnicodeString (ok3 ? "Ok: incCompare(" : "FAIL: incCompare(");
|
|
|
|
msg2 = ", ";
|
|
|
|
msg3 = ") returned ";
|
|
|
|
|
|
|
|
appendCompareResult(incResult, sResult);
|
|
|
|
|
|
|
|
if (ok3) {
|
|
|
|
logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
|
|
|
|
} else {
|
|
|
|
errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append a hex string to the target
|
|
|
|
UnicodeString&
|
|
|
|
IntlTest::appendHex(uint32_t number,
|
|
|
|
int8_t digits,
|
|
|
|
UnicodeString& target)
|
|
|
|
{
|
|
|
|
static const UnicodeString digitString("0123456789ABCDEF");
|
|
|
|
|
|
|
|
switch (digits)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
target += digitString[(number >> 28) & 0xF];
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
target += digitString[(number >> 24) & 0xF];
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
target += digitString[(number >> 20) & 0xF];
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
target += digitString[(number >> 16) & 0xF];
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
target += digitString[(number >> 12) & 0xF];
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
target += digitString[(number >> 8) & 0xF];
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
target += digitString[(number >> 4) & 0xF];
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
target += digitString[(number >> 0) & 0xF];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
target += "**";
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
IntlTest::appendCompareResult(Collator::EComparisonResult result,
|
|
|
|
UnicodeString& target)
|
|
|
|
{
|
|
|
|
if (result == Collator::LESS)
|
|
|
|
{
|
|
|
|
target += "LESS";
|
|
|
|
}
|
|
|
|
else if (result == Collator::EQUAL)
|
|
|
|
{
|
|
|
|
target += "EQUAL";
|
|
|
|
}
|
|
|
|
else if (result == Collator::GREATER)
|
|
|
|
{
|
|
|
|
target += "GREATER";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnicodeString huh = "?";
|
|
|
|
|
|
|
|
target += (huh + (int32_t)result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace nonprintable characters with unicode escapes
|
|
|
|
UnicodeString&
|
|
|
|
IntlTest::prettify(const UnicodeString &source,
|
|
|
|
UnicodeString &target)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
target.remove();
|
|
|
|
target += "\"";
|
|
|
|
|
1999-12-08 02:11:04 +00:00
|
|
|
for (i = 0; i < source.length(); i += 1)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UChar ch = source[i];
|
|
|
|
|
|
|
|
if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
|
|
|
|
{
|
|
|
|
target += "\\u";
|
|
|
|
appendHex(ch, 4, target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target += "\"";
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
2000-01-15 01:55:02 +00:00
|
|
|
// Replace nonprintable characters with unicode escapes
|
|
|
|
UnicodeString
|
|
|
|
IntlTest::prettify(const UnicodeString &source)
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
UnicodeString target;
|
|
|
|
target.remove();
|
|
|
|
target += "\"";
|
|
|
|
|
|
|
|
for (i = 0; i < source.length(); i += 1)
|
|
|
|
{
|
|
|
|
UChar ch = source[i];
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 01:55:02 +00:00
|
|
|
if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
|
|
|
|
{
|
|
|
|
target += "\\u";
|
|
|
|
appendHex(ch, 4, target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target += "\"";
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
// Produce a printable representation of a CollationKey
|
|
|
|
UnicodeString &IntlTest::prettify(const CollationKey &source, UnicodeString &target)
|
|
|
|
{
|
|
|
|
int32_t i, byteCount;
|
|
|
|
const uint8_t *bytes = source.getByteArray(byteCount);
|
|
|
|
|
|
|
|
target.remove();
|
|
|
|
target += "[";
|
|
|
|
|
|
|
|
for (i = 0; i < byteCount; i += 1)
|
|
|
|
{
|
|
|
|
appendHex(bytes[i], 2, target);
|
|
|
|
target += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
target += "]";
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IntlTest::pathnameInContext( char* fullname, int32_t maxsize, const char* relPath ) //nosmac
|
|
|
|
{
|
1999-12-07 00:07:17 +00:00
|
|
|
const char* mainDir;
|
1999-08-16 21:50:52 +00:00
|
|
|
char sepChar;
|
|
|
|
const char inpSepChar = '|';
|
1999-12-07 00:07:17 +00:00
|
|
|
|
2000-12-03 03:58:52 +00:00
|
|
|
// So what's going on is that ICU_DATA during tests points to:
|
|
|
|
// ICU | source | data
|
|
|
|
//and we want ICU | source |
|
|
|
|
//
|
|
|
|
// We'll add | test | testdata
|
|
|
|
//
|
|
|
|
// So, just add a .. here - back up one level
|
|
|
|
|
1999-12-07 00:07:17 +00:00
|
|
|
mainDir = u_getDataDirectory();
|
1999-12-28 18:40:36 +00:00
|
|
|
sepChar = U_FILE_SEP_CHAR;
|
|
|
|
char sepString[] = U_FILE_SEP_STRING;
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(WIN32) || defined(__OS2__) || defined(OS2)
|
|
|
|
char mainDirBuffer[200];
|
|
|
|
if(mainDir!=NULL) {
|
|
|
|
strcpy(mainDirBuffer, mainDir);
|
2000-12-03 03:58:52 +00:00
|
|
|
strcat(mainDirBuffer, "..");
|
1999-12-28 18:40:36 +00:00
|
|
|
} else {
|
|
|
|
mainDirBuffer[0]='\0';
|
|
|
|
}
|
|
|
|
mainDir=mainDirBuffer;
|
2000-06-30 21:35:03 +00:00
|
|
|
#elif defined(_AIX) || defined(U_SOLARIS) || defined(U_LINUX) || defined(HPUX) || defined(POSIX) || defined(OS390)
|
2000-02-16 22:38:38 +00:00
|
|
|
char mainDirBuffer[200];
|
|
|
|
strcpy(mainDirBuffer, u_getDataDirectory());
|
|
|
|
strcat(mainDirBuffer, "/../");
|
|
|
|
mainDir = mainDirBuffer;
|
1999-12-28 18:40:36 +00:00
|
|
|
#elif defined(XP_MAC)
|
|
|
|
Str255 volName;
|
|
|
|
int16_t volNum;
|
|
|
|
OSErr err = GetVol( volName, &volNum );
|
|
|
|
if (err != noErr) volName[0] = 0;
|
|
|
|
mainDir = (char*) &(volName[1]);
|
|
|
|
mainDir[volName[0]] = 0;
|
|
|
|
#else
|
|
|
|
mainDir = "";
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (relPath[0] == '|') relPath++;
|
|
|
|
int32_t lenMainDir = strlen( mainDir );
|
|
|
|
int32_t lenRelPath = strlen( relPath );
|
|
|
|
if (maxsize < lenMainDir + lenRelPath + 2) { fullname[0] = 0; return; }
|
|
|
|
strcpy( fullname, mainDir );
|
|
|
|
strcat( fullname, sepString );
|
|
|
|
strcat( fullname, relPath );
|
|
|
|
char* tmp = strchr( fullname, inpSepChar );
|
|
|
|
while (tmp) {
|
|
|
|
*tmp = sepChar;
|
|
|
|
tmp = strchr( tmp+1, inpSepChar );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to get and set the directory containing the Test files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char*
|
|
|
|
IntlTest::getTestDirectory()
|
|
|
|
{
|
2000-08-24 01:12:12 +00:00
|
|
|
if (_testDirectory == NULL)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-08-29 07:28:22 +00:00
|
|
|
setTestDirectory("test|testdata|");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
return _testDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IntlTest::setTestDirectory(const char* newDir)
|
|
|
|
{
|
|
|
|
char newTestDir[256];
|
|
|
|
IntlTest::pathnameInContext(newTestDir, sizeof(newTestDir), newDir);
|
|
|
|
if(_testDirectory != NULL)
|
2000-08-24 01:12:12 +00:00
|
|
|
delete _testDirectory;
|
|
|
|
_testDirectory = new char[strlen(newTestDir) + 1];
|
1999-08-16 21:50:52 +00:00
|
|
|
strcpy(_testDirectory, newTestDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->log( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_logln( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->logln( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_logln( void )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->logln();
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_err()
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->err();
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_err( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->err( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
void it_errln( UnicodeString message )
|
|
|
|
{
|
|
|
|
if (IntlTest::gTest) IntlTest::gTest->errln( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
IntlTest& operator<<(IntlTest& test, const UnicodeString& string)
|
|
|
|
{
|
|
|
|
if (&test == NULL) return *((IntlTest*) NULL);
|
|
|
|
test.log( string );
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntlTest& operator<<(IntlTest& test, const char* string)
|
|
|
|
{
|
|
|
|
if (&test == NULL) return *((IntlTest*) NULL);
|
|
|
|
test.log( string );
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntlTest& operator<<(IntlTest& test, const int32_t num)
|
|
|
|
{
|
|
|
|
if (&test == NULL) return *((IntlTest*) NULL);
|
|
|
|
char convert[20];
|
|
|
|
sprintf( convert, "%li", num );
|
|
|
|
test.log( convert );
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntlTest& endl( IntlTest& test )
|
|
|
|
{
|
|
|
|
test.logln();
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntlTest& operator<<(IntlTest& test, IntlTest& ( * _f)(IntlTest&))
|
|
|
|
{
|
|
|
|
(*_f)(test);
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IntlTest::IntlTest()
|
|
|
|
{
|
|
|
|
caller = NULL;
|
|
|
|
path = NULL;
|
|
|
|
LL_linestart = TRUE;
|
|
|
|
errorCount = 0;
|
|
|
|
verbose = FALSE;
|
|
|
|
no_err_msg = FALSE;
|
|
|
|
quick = FALSE;
|
|
|
|
leaks = FALSE;
|
2000-04-25 21:32:10 +00:00
|
|
|
testoutfp = stdout;
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel = indentLevel_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::setCaller( IntlTest* callingTest )
|
|
|
|
{
|
|
|
|
caller = callingTest;
|
|
|
|
if (caller) {
|
|
|
|
verbose = caller->verbose;
|
|
|
|
no_err_msg = caller->no_err_msg;
|
|
|
|
quick = caller->quick;
|
2000-04-25 21:32:10 +00:00
|
|
|
testoutfp = caller->testoutfp;
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel = caller->LL_indentlevel + indentLevel_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
return testToBeCalled.runTest( path, par );
|
|
|
|
}
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
void IntlTest::setPath( char* pathVal )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-12-08 20:33:48 +00:00
|
|
|
this->path = 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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t IntlTest::getErrors( void )
|
|
|
|
{
|
|
|
|
return errorCount;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool IntlTest::runTest( char* name, char* par )
|
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;
|
|
|
|
|
|
|
|
if (name) pos = strchr( name, delim ); // check if name contains path (by looking for '/')
|
|
|
|
if (pos) {
|
|
|
|
path = pos+1; // store subpath for calling subtest
|
|
|
|
*pos = 0; // split into two strings
|
|
|
|
}else{
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || (name[0] == 0) || (strcmp(name, "*") == 0)) {
|
|
|
|
rval = runTestLoop( NULL, NULL );
|
|
|
|
|
|
|
|
}else if (strcmp( name, "LIST" ) == 0) {
|
|
|
|
this->usage();
|
|
|
|
rval = TRUE;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
rval = runTestLoop( name, par );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos) *pos = delim; // restore original value at pos
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// call individual tests, to be overriden to call implementations
|
2000-08-14 21:42:36 +00:00
|
|
|
void IntlTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// to be overriden by a method like:
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
this->errln("*** runIndexedTest needs to be overriden! ***");
|
|
|
|
name = ""; exec = exec; index = index; par = par;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool IntlTest::runTestLoop( char* testname, char* par )
|
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;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
IntlTest* saveTest = gTest;
|
|
|
|
gTest = this;
|
|
|
|
do {
|
|
|
|
this->runIndexedTest( index, FALSE, name );
|
2000-12-09 02:02:29 +00:00
|
|
|
if (!name || (name[0] == 0))
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!testname) {
|
|
|
|
run_this_test = TRUE;
|
|
|
|
}else{
|
2000-05-18 22:08:39 +00:00
|
|
|
run_this_test = (UBool) (strcmp( name, testname ) == 0);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
if (run_this_test) {
|
|
|
|
lastErrorCount = errorCount;
|
|
|
|
execCount++;
|
|
|
|
this->runIndexedTest( index, TRUE, name, par );
|
|
|
|
rval = TRUE; // at least one test has been called
|
|
|
|
char msg[256];
|
|
|
|
if (lastErrorCount == errorCount) {
|
|
|
|
sprintf( msg, "---OK: %s", name );
|
2000-12-09 02:02:29 +00:00
|
|
|
lastTestFailed = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}else{
|
|
|
|
sprintf( msg, "---ERRORS (%li) in %s", (errorCount-lastErrorCount), name );
|
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) {
|
|
|
|
LL_message( "", TRUE);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_message( msg, TRUE);
|
2000-12-09 02:02:29 +00:00
|
|
|
if (lastTestFailed) {
|
|
|
|
LL_message( "", TRUE);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
LL_indentlevel += 3;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}while(name);
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t IntlTest::IncErrorCount( void )
|
|
|
|
{
|
|
|
|
errorCount++;
|
|
|
|
if (caller) caller->IncErrorCount();
|
|
|
|
return errorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::err() {
|
|
|
|
IncErrorCount();
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2001-01-23 23:51:55 +00:00
|
|
|
/* convenience functions that include sprintf formatting */
|
|
|
|
void IntlTest::log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[300];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
log(UnicodeString(buffer, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::logln(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[300];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
logln(UnicodeString(buffer, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::err(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[300];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
err(UnicodeString(buffer, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntlTest::errln(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[300];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
errln(UnicodeString(buffer, ""));
|
|
|
|
}
|
|
|
|
|
2000-12-03 03:29:39 +00:00
|
|
|
void IntlTest::printErrors()
|
|
|
|
{
|
|
|
|
IntlTest::LL_message(errorList, TRUE);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
void IntlTest::LL_message( UnicodeString message, UBool newline )
|
1999-08-16 21:50:52 +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
|
|
|
|
};
|
|
|
|
UnicodeString indent(FALSE, indentUChars, 1 + LL_indentlevel);
|
|
|
|
|
2000-06-15 22:33:16 +00:00
|
|
|
char buffer[10000];
|
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) {
|
|
|
|
fwrite(buffer, sizeof(*buffer), length, testoutfp);
|
|
|
|
}
|
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) {
|
|
|
|
fwrite(buffer, sizeof(*buffer), length, testoutfp);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-26 02:05:37 +00:00
|
|
|
if (newline) {
|
|
|
|
char newLine = '\n';
|
|
|
|
fwrite(&newLine, sizeof(newLine), 1, testoutfp);
|
|
|
|
}
|
2000-08-28 19:23:42 +00:00
|
|
|
|
|
|
|
// A newline usually flushes the buffer, but
|
|
|
|
// flush the message just in case of a core dump.
|
|
|
|
fflush(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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// memory leak reporting software will be able to take advantage of the testsuite
|
|
|
|
// 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
|
|
|
|
return this->runTest( name, par );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
argc = ccommand( &argv );
|
|
|
|
#endif
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool syntax = FALSE;
|
|
|
|
UBool all = TRUE;
|
|
|
|
UBool verbose = FALSE;
|
|
|
|
UBool no_err_msg = FALSE;
|
|
|
|
UBool quick = TRUE;
|
|
|
|
UBool name = FALSE;
|
|
|
|
UBool leaks = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
const char* str = argv[i] + 1;
|
|
|
|
if (strcmp("verbose", str) == 0)
|
|
|
|
verbose = TRUE;
|
|
|
|
else if (strcmp("v", str) == 0)
|
|
|
|
verbose = TRUE;
|
|
|
|
else if (strcmp("noerrormsg", str) == 0)
|
|
|
|
no_err_msg = TRUE;
|
|
|
|
else if (strcmp("n", str) == 0)
|
|
|
|
no_err_msg = TRUE;
|
|
|
|
else if (strcmp("exhaustive", str) == 0)
|
|
|
|
quick = FALSE;
|
|
|
|
else if (strcmp("e", str) == 0)
|
|
|
|
quick = FALSE;
|
|
|
|
else if (strcmp("all", str) == 0)
|
|
|
|
all = TRUE;
|
|
|
|
else if (strcmp("a", str) == 0)
|
|
|
|
all = TRUE;
|
|
|
|
else if (strcmp("leaks", str) == 0)
|
|
|
|
leaks = TRUE;
|
|
|
|
else if (strcmp("l", str) == 0)
|
|
|
|
leaks = TRUE;
|
|
|
|
else {
|
|
|
|
syntax = TRUE;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
name = TRUE;
|
|
|
|
all = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all && name) syntax = TRUE;
|
|
|
|
if (!all && !name) syntax = TRUE;
|
|
|
|
|
|
|
|
if (syntax) {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout,
|
|
|
|
"### Syntax:\n"
|
1999-08-16 21:50:52 +00:00
|
|
|
"### IntlTest [-option1 -option2 ...] [testname1 testname2 ...] \n"
|
|
|
|
"### where options are: verbose (v), all (a), noerrormsg (n), \n"
|
|
|
|
"### exhaustive (e) and leaks (l). \n"
|
|
|
|
"### (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"
|
2000-04-25 21:32:10 +00:00
|
|
|
"### to the testname. \n\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool all_tests_exist = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
MajorTestLevel major;
|
|
|
|
major.setVerbose( verbose );
|
|
|
|
major.setNoErrMsg( no_err_msg );
|
|
|
|
major.setQuick( quick );
|
|
|
|
major.setLeaks( leaks );
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
|
|
|
fprintf(stdout, " IntlTest Test Suite for \n");
|
|
|
|
fprintf(stdout, " International Classes for Unicode \n");
|
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
|
|
|
fprintf(stdout, " Options: \n");
|
|
|
|
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"));
|
|
|
|
fprintf(stdout, "-----------------------------------------------\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
// initial check for the default converter
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
UConverter *cnv = ucnv_open(0, &errorCode);
|
|
|
|
if(cnv != 0) {
|
|
|
|
// ok
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout,
|
2000-06-29 01:10:27 +00:00
|
|
|
"*** Failure! The default converter [%s] cannot be opened.\n"
|
2000-04-25 21:32:10 +00:00
|
|
|
"*** Check the ICU_DATA environment variable and\n"
|
2000-06-29 01:10:27 +00:00
|
|
|
"*** check that the data files are present.\n",
|
|
|
|
ucnv_getDefaultName());
|
1999-12-08 00:15:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-03-29 21:48:44 +00:00
|
|
|
// try more data
|
|
|
|
cnv = ucnv_open("iso-8859-7", &errorCode);
|
|
|
|
if(cnv != 0) {
|
|
|
|
// ok
|
|
|
|
ucnv_close(cnv);
|
|
|
|
} else {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout,
|
|
|
|
"*** Failure! The converter for iso-8859-7 cannot be opened.\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n");
|
2000-03-29 21:48:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
UResourceBundle *rb = ures_open(0, "en", &errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
// ok
|
|
|
|
ures_close(rb);
|
|
|
|
} else {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout,
|
|
|
|
"*** Failure! The \"en\" locale resource bundle cannot be opened.\n"
|
|
|
|
"*** Check the ICU_DATA environment variable and \n"
|
|
|
|
"*** check that the data files are present.\n");
|
2000-03-29 21:48:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
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];
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "\n=== Handling test: %s: ===\n", name);
|
1999-08-16 21:50:52 +00:00
|
|
|
char* parameter = strchr( name, '@' );
|
|
|
|
if (parameter) {
|
|
|
|
*parameter = 0;
|
|
|
|
parameter += 1;
|
|
|
|
}
|
|
|
|
execCount = 0;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool res = major.runTest( name, parameter );
|
1999-08-16 21:50:52 +00:00
|
|
|
if (leaks && res) {
|
|
|
|
major.run_phase2( name, parameter );
|
|
|
|
}
|
|
|
|
if (!res || (execCount <= 0)) {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "\n---ERROR: Test doesn't exist: %s!\n", name);
|
1999-08-16 21:50:52 +00:00
|
|
|
all_tests_exist = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "\n--------------------------------------\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
if (major.getErrors() == 0) {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "OK: All tests passed without error.\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
}else{
|
2000-08-11 22:26:55 +00:00
|
|
|
fprintf(stdout, "Errors in total: %ld.\n", major.getErrors());
|
2000-12-03 03:29:39 +00:00
|
|
|
major.printErrors();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "--------------------------------------\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (execCount <= 0) {
|
2000-04-25 21:32:10 +00:00
|
|
|
fprintf(stdout, "***** Not all called tests actually exist! *****\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return major.getErrors();
|
|
|
|
}
|
2000-03-22 23:17:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a variant of cintltst/ccolltst.c:CharsToUChars().
|
|
|
|
* It converts a character string into a UnicodeString, with
|
|
|
|
* unescaping \u sequences.
|
|
|
|
*/
|
|
|
|
UnicodeString CharsToUnicodeString(const char* chars)
|
|
|
|
{
|
2000-07-16 13:42:38 +00:00
|
|
|
UnicodeString str(chars, ""); // Invariant conversion
|
|
|
|
return str.unescape();
|
2000-03-22 23:17:42 +00:00
|
|
|
}
|
2000-04-25 21:32:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|