/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2005, International Business Machines Corporation and
+ * Copyright (c) 1997-2013, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#include "unicode/fmtable.h"
#include "unicode/testlog.h"
+
+#if U_NO_DEFAULT_INCLUDE_UTF_HEADERS
+/* deprecated - make tests pass with U_NO_DEFAULT_INCLUDE_UTF_HEADERS */
+#include "unicode/utf_old.h"
+#endif
+
+/**
+ * \def ICU_USE_THREADS
+ *
+ * Enables multi-threaded testing. Moved here from uconfig.h.
+ * Default: enabled
+ *
+ * This switch used to allow thread support (use of mutexes) to be compiled out of ICU.
+ */
+#ifdef ICU_USE_THREADS
+ /* Use the predefined value. */
+#elif defined(APP_NO_THREADS)
+ /* APP_NO_THREADS is an old symbol. We'll honour it if present. */
+# define ICU_USE_THREADS 0
+#else
+# define ICU_USE_THREADS 1
+#endif
+
U_NAMESPACE_USE
-#ifdef OS390
+#if U_PLATFORM == U_PF_OS390
// avoid collision with math.h/log()
-// this must be after including utypes.h so that OS390 is actually defined
+// this must be after including utypes.h so that U_PLATFORM is actually defined
#pragma map(IntlTest::log( const UnicodeString &message ),"logos390")
#endif
name = #test; \
if (exec) { \
logln(#test "---"); \
- logln((UnicodeString)""); \
+ logln(); \
test(); \
} \
break
+// More convenient macros. These allow easy reordering of the test cases.
+//
+//| void MyTest::runIndexedTest(int32_t index, UBool exec,
+//| const char* &name, char* /*par*/) {
+//| TESTCASE_AUTO_BEGIN;
+//| TESTCASE_AUTO(TestSomething);
+//| TESTCASE_AUTO(TestSomethingElse);
+//| TESTCASE_AUTO(TestAnotherThing);
+//| TESTCASE_AUTO_END;
+//| }
+#define TESTCASE_AUTO_BEGIN \
+ for(;;) { \
+ int32_t testCaseAutoNumber = 0
+
+#define TESTCASE_AUTO(test) \
+ if (index == testCaseAutoNumber++) { \
+ name = #test; \
+ if (exec) { \
+ logln(#test "---"); \
+ logln(); \
+ test(); \
+ } \
+ break; \
+ }
+
+#define TESTCASE_AUTO_END \
+ name = ""; \
+ break; \
+ }
+
+#define TEST_ASSERT_TRUE(x) \
+ assertTrue(#x, (x), FALSE, FALSE, __FILE__, __LINE__)
+
class IntlTest : public TestLog {
public:
IntlTest();
+ // TestLog has a virtual destructor.
- virtual UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden
+ virtual UBool runTest( char* name = NULL, char* par = NULL, char *baseName = NULL); // not to be overidden
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 );
+ virtual UBool setNotime( UBool no_time = TRUE );
virtual UBool setWarnOnMissingData( UBool warn_on_missing_data = TRUE );
+ virtual int32_t setThreadCount( int32_t count = 1);
virtual int32_t getErrors( void );
virtual int32_t getDataErrors (void );
virtual void dataerr( const UnicodeString &message );
virtual void dataerrln( const UnicodeString &message );
+
+ void errcheckln(UErrorCode status, const UnicodeString &message );
// convenience functions: sprintf() + errln() etc.
void log(const char *fmt, ...);
void errln(const char *fmt, ...);
void dataerr(const char *fmt, ...);
void dataerrln(const char *fmt, ...);
+ void errcheckln(UErrorCode status, const char *fmt, ...);
// Print ALL named errors encountered so far
void printErrors();
static float random();
/**
- * Ascertain the version of ICU. Useful for
- * time bomb testing
+ * Returns true if u_getVersion() < major.minor.
*/
- UBool isICUVersionAtLeast(const UVersionInfo x);
+ static UBool isICUVersionBefore(int major, int minor) {
+ return isICUVersionBefore(major, minor, 0);
+ }
+
+ /**
+ * Returns true if u_getVersion() < major.minor.milli.
+ */
+ static UBool isICUVersionBefore(int major, int minor, int milli);
+
+ /**
+ * Returns true if u_getVersion() >= major.minor.
+ */
+ static UBool isICUVersionAtLeast(int major, int minor) {
+ return isICUVersionAtLeast(major, minor, 0);
+ }
+
+ /**
+ * Returns true if u_getVersion() >= major.minor.milli.
+ */
+ static UBool isICUVersionAtLeast(int major, int minor, int milli) {
+ return !isICUVersionBefore(major, minor, milli);
+ }
+
+ enum { kMaxProps = 16 };
+
+ virtual void setProperty(const char* propline);
+ virtual const char* getProperty(const char* prop);
protected:
/* JUnit-like assertions. Each returns TRUE if it succeeds. */
- UBool assertTrue(const char* message, UBool condition, UBool quiet=FALSE);
+ UBool assertTrue(const char* message, UBool condition, UBool quiet=FALSE, UBool possibleDataError=FALSE, const char *file=NULL, int line=0);
UBool assertFalse(const char* message, UBool condition, UBool quiet=FALSE);
- UBool assertSuccess(const char* message, UErrorCode ec);
+ UBool assertSuccess(const char* message, UErrorCode ec, UBool possibleDataError=FALSE);
UBool assertEquals(const char* message, const UnicodeString& expected,
- const UnicodeString& actual);
+ const UnicodeString& actual, UBool possibleDataError=FALSE);
UBool assertEquals(const char* message, const char* expected,
const char* actual);
+ UBool assertEquals(const char* message, int32_t expected, int32_t actual);
#if !UCONFIG_NO_FORMATTING
UBool assertEquals(const char* message, const Formattable& expected,
const Formattable& actual);
virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
- virtual UBool runTestLoop( char* testname, char* par );
+ virtual UBool runTestLoop( char* testname, char* par, char *baseName );
virtual int32_t IncErrorCount( void );
UBool quick;
UBool leaks;
UBool warn_on_missing_data;
+ UBool no_time;
+ int32_t threadCount;
private:
UBool LL_linestart;
int32_t dataErrorCount;
IntlTest* caller;
char* testPath; // specifies subtests
+
+ char basePath[1024];
//FILE *testoutfp;
void *testoutfp;
+ const char* proplines[kMaxProps];
+ int32_t numProps;
+
protected:
virtual void LL_message( UnicodeString message, UBool newline );
static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target);
static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE);
+ // digits=-1 determines the number of digits automatically
static UnicodeString &appendHex(uint32_t number, int32_t digits, UnicodeString &target);
+ static UnicodeString toHex(uint32_t number, int32_t digits=-1);
+ static inline UnicodeString toHex(int32_t number, int32_t digits=-1) {
+ return toHex((uint32_t)number, digits);
+ }
public:
static void setICU_DATA(); // Set up ICU_DATA if necessary.