2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 20:09:56 +00:00
|
|
|
* Copyright (c) 1997-2001, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2000-03-10 00:42:27 +00:00
|
|
|
* IntlTest is a base class for tests. */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#ifndef _INTLTEST
|
|
|
|
#define _INTLTEST
|
|
|
|
|
2000-04-25 21:32:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unistr.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
#include "unicode/fmtable.h"
|
2001-08-31 18:02:09 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-04-04 22:31:44 +00:00
|
|
|
#ifdef OS390
|
|
|
|
// avoid collision with math.h/log()
|
|
|
|
// this must be after including utypes.h so that OS390 is actually defined
|
|
|
|
#pragma map(IntlTest::log( const UnicodeString &message ),"logos390")
|
|
|
|
#endif
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#define it_out (*IntlTest::gTest)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//convenience classes to ease porting code that uses the Java
|
|
|
|
//string-concatenation operator (moved from findword test by rtg)
|
|
|
|
UnicodeString UCharToUnicodeString(UChar c);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, const UnicodeString& right);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, long num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned long num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, double num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, char num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, short num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, int num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned char num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned short num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, unsigned int num);
|
|
|
|
UnicodeString operator+(const UnicodeString& left, float num);
|
2002-09-21 00:43:14 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString toString(const Formattable& f); // liu
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-06-11 17:21:58 +00:00
|
|
|
// Use the TESTCASE macro in subclasses of IntlTest. Define the
|
|
|
|
// runIndexedTest method in this fashion:
|
|
|
|
//
|
|
|
|
//| void MyTest::runIndexedTest(int32_t index, UBool exec,
|
|
|
|
//| const char* &name, char* /*par*/) {
|
|
|
|
//| switch (index) {
|
|
|
|
//| TESTCASE(0,TestSomething);
|
|
|
|
//| TESTCASE(1,TestSomethingElse);
|
|
|
|
//| TESTCASE(2,TestAnotherThing);
|
|
|
|
//| default: name = ""; break;
|
|
|
|
//| }
|
|
|
|
//| }
|
|
|
|
#define TESTCASE(id,test) \
|
|
|
|
case id: \
|
|
|
|
name = #test; \
|
|
|
|
if (exec) { \
|
|
|
|
logln(#test "---"); \
|
|
|
|
logln((UnicodeString)""); \
|
|
|
|
test(); \
|
|
|
|
} \
|
|
|
|
break
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
class IntlTest {
|
|
|
|
public:
|
|
|
|
|
|
|
|
IntlTest();
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool setVerbose( UBool verbose = TRUE );
|
|
|
|
virtual UBool setNoErrMsg( UBool no_err_msg = TRUE );
|
|
|
|
virtual UBool setQuick( UBool quick = TRUE );
|
|
|
|
virtual UBool setLeaks( UBool leaks = TRUE );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
virtual int32_t getErrors( void );
|
|
|
|
|
|
|
|
virtual void setCaller( IntlTest* callingTest ); // for internal use only
|
|
|
|
virtual void setPath( char* path ); // for internal use only
|
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
virtual void log( const UnicodeString &message );
|
|
|
|
|
|
|
|
virtual void logln( const UnicodeString &message );
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
virtual void logln( void );
|
|
|
|
|
2002-07-11 17:40:35 +00:00
|
|
|
virtual void info( const UnicodeString &message );
|
|
|
|
|
|
|
|
virtual void infoln( const UnicodeString &message );
|
|
|
|
|
|
|
|
virtual void infoln( void );
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
virtual void err(void);
|
|
|
|
|
1999-12-08 00:15:46 +00:00
|
|
|
virtual void err( const UnicodeString &message );
|
|
|
|
|
|
|
|
virtual void errln( const UnicodeString &message );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-23 23:51:55 +00:00
|
|
|
// convenience functions: sprintf() + errln() etc.
|
|
|
|
void log(const char *fmt, ...);
|
|
|
|
void logln(const char *fmt, ...);
|
2002-07-11 17:40:35 +00:00
|
|
|
void info(const char *fmt, ...);
|
|
|
|
void infoln(const char *fmt, ...);
|
2001-01-23 23:51:55 +00:00
|
|
|
void err(const char *fmt, ...);
|
|
|
|
void errln(const char *fmt, ...);
|
|
|
|
|
2000-12-03 03:29:39 +00:00
|
|
|
// Print ALL named errors encountered so far
|
|
|
|
void printErrors();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
virtual void usage( void ) ;
|
|
|
|
|
2000-04-25 21:32:10 +00:00
|
|
|
FILE *testoutfp;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
protected:
|
2000-08-14 21:42:36 +00:00
|
|
|
virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool runTestLoop( char* testname, char* par );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
virtual int32_t IncErrorCount( void );
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool callTest( IntlTest& testToBeCalled, char* par );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool verbose;
|
|
|
|
UBool no_err_msg;
|
|
|
|
UBool quick;
|
|
|
|
UBool leaks;
|
2000-12-08 20:33:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
UBool LL_linestart;
|
|
|
|
int32_t LL_indentlevel;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t errorCount;
|
|
|
|
IntlTest* caller;
|
|
|
|
char* path; // specifies subtests
|
|
|
|
|
2000-12-08 20:33:48 +00:00
|
|
|
protected:
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual void LL_message( UnicodeString message, UBool newline );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// used for collation result reporting, defined here for convenience
|
|
|
|
|
|
|
|
static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target);
|
2001-07-18 18:38:53 +00:00
|
|
|
static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE);
|
2001-09-18 17:44:50 +00:00
|
|
|
static UnicodeString &appendHex(uint32_t number, int32_t digits, UnicodeString &target);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* complete a relative path to a full pathname, and convert to platform-specific syntax. */
|
|
|
|
/* The character seperating directories for the relative path is '|'. */
|
|
|
|
static void pathnameInContext( char* fullname, int32_t maxsize, const char* relpath );
|
2002-02-07 19:37:34 +00:00
|
|
|
|
2001-07-31 17:29:43 +00:00
|
|
|
public:
|
2001-08-10 20:50:07 +00:00
|
|
|
static void setICU_DATA(); // Set up ICU_DATA if necessary.
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-02-28 21:37:55 +00:00
|
|
|
static const char* pathToDataDirectory();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
public:
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks
|
2002-06-10 18:31:34 +00:00
|
|
|
static const char* loadTestData(UErrorCode& err);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// static members
|
|
|
|
public:
|
|
|
|
static IntlTest* gTest;
|
2003-02-28 21:37:55 +00:00
|
|
|
static const char* fgDataDir;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void it_log( UnicodeString message );
|
|
|
|
void it_logln( UnicodeString message );
|
|
|
|
void it_logln( void );
|
2002-07-11 17:40:35 +00:00
|
|
|
void it_info( UnicodeString message );
|
|
|
|
void it_infoln( UnicodeString message );
|
|
|
|
void it_infoln( void );
|
1999-08-16 21:50:52 +00:00
|
|
|
void it_err(void);
|
|
|
|
void it_err( UnicodeString message );
|
|
|
|
void it_errln( UnicodeString message );
|
|
|
|
|
|
|
|
IntlTest& operator<<(IntlTest& test, const UnicodeString& string);
|
|
|
|
IntlTest& operator<<(IntlTest& test, const char* string);
|
|
|
|
IntlTest& operator<<(IntlTest& test, const int32_t num);
|
|
|
|
|
|
|
|
IntlTest& endl( IntlTest& test );
|
|
|
|
IntlTest& operator<<(IntlTest& test, IntlTest& ( * _f)(IntlTest&));
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
extern UnicodeString CharsToUnicodeString(const char* chars);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#endif // _INTLTEST
|