]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/intltest.h
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / intltest.h
index be6993e8d7b701d47af7c578ced1300b4306bd30..b8793ba889de2517aa5e47e8fe41d562bee89f15 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
 /********************************************************************
- * COPYRIGHT: 
- * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * COPYRIGHT:
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
  * others. All Rights Reserved.
  ********************************************************************/
 
 #include "unicode/fmtable.h"
 #include "unicode/testlog.h"
 
 #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
+
 U_NAMESPACE_USE
 
 #if U_PLATFORM == U_PF_OS390
 U_NAMESPACE_USE
 
 #if U_PLATFORM == U_PF_OS390
@@ -32,17 +38,19 @@ UnicodeString Int64ToUnicodeString(int64_t num);
 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, 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, 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);
 #if !UCONFIG_NO_FORMATTING
 UnicodeString toString(const Formattable& f); // liu
 UnicodeString toString(int32_t n);
 #endif
 UnicodeString operator+(const UnicodeString& left, float num);
 #if !UCONFIG_NO_FORMATTING
 UnicodeString toString(const Formattable& f); // liu
 UnicodeString toString(int32_t n);
 #endif
+UnicodeString toString(UBool b);
+
 //-----------------------------------------------------------------------------
 
 // Use the TESTCASE macro in subclasses of IntlTest.  Define the
 //-----------------------------------------------------------------------------
 
 // Use the TESTCASE macro in subclasses of IntlTest.  Define the
@@ -92,11 +100,41 @@ UnicodeString toString(int32_t n);
             break; \
         }
 
             break; \
         }
 
+#define TESTCASE_AUTO_CLASS(TestClass) \
+        if (index == testCaseAutoNumber++) { \
+            name = #TestClass; \
+            if (exec) { \
+                logln(#TestClass "---"); \
+                logln(); \
+                TestClass test; \
+                callTest(test, par); \
+            } \
+            break; \
+        }
+
+#define TESTCASE_AUTO_CREATE_CLASS(TestClass) \
+        if (index == testCaseAutoNumber++) { \
+            name = #TestClass; \
+            if (exec) { \
+                logln(#TestClass "---"); \
+                logln(); \
+                LocalPointer<IntlTest> test(create##TestClass()); \
+                callTest(*test, par); \
+            } \
+            break; \
+        }
+
 #define TESTCASE_AUTO_END \
         name = ""; \
         break; \
     }
 
 #define TESTCASE_AUTO_END \
         name = ""; \
         break; \
     }
 
+#define TEST_ASSERT_TRUE(x) \
+  assertTrue(#x, (x), FALSE, FALSE, __FILE__, __LINE__)
+
+#define TEST_ASSERT_STATUS(x) \
+  assertSuccess(#x, (x), FALSE, __FILE__, __LINE__)
+
 class IntlTest : public TestLog {
 public:
 
 class IntlTest : public TestLog {
 public:
 
@@ -109,6 +147,7 @@ public:
     virtual UBool setNoErrMsg( UBool no_err_msg = TRUE );
     virtual UBool setQuick( UBool quick = TRUE );
     virtual UBool setLeaks( UBool leaks = 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 UBool setWarnOnMissingData( UBool warn_on_missing_data = TRUE );
     virtual int32_t setThreadCount( int32_t count = 1);
 
@@ -124,6 +163,36 @@ public:
 
     virtual void logln( void );
 
 
     virtual void logln( void );
 
+    /**
+     * Replaces isICUVersionAtLeast and isICUVersionBefore
+     * log that an issue is known.
+     * Usually used this way:
+     * <code>if( ... && logKnownIssue("12345", "some bug")) continue; </code>
+     * @param ticket ticket string, "12345" or "cldrbug:1234"
+     * @param message optional message string
+     * @return true if test should be skipped
+     */
+    UBool logKnownIssue( const char *ticket, const UnicodeString &message );
+    /**
+     * Replaces isICUVersionAtLeast and isICUVersionBefore
+     * log that an issue is known.
+     * Usually used this way:
+     * <code>if( ... && logKnownIssue("12345", "some bug")) continue; </code>
+     * @param ticket ticket string, "12345" or "cldrbug:1234"
+     * @return true if test should be skipped
+     */
+    UBool logKnownIssue( const char *ticket );
+    /**
+     * Replaces isICUVersionAtLeast and isICUVersionBefore
+     * log that an issue is known.
+     * Usually used this way:
+     * <code>if( ... && logKnownIssue("12345", "some bug")) continue; </code>
+     * @param ticket ticket string, "12345" or "cldrbug:1234"
+     * @param message optional message string
+     * @return true if test should be skipped
+     */
+    UBool logKnownIssue( const char *ticket, const char *fmt, ...);
+
     virtual void info( const UnicodeString &message );
 
     virtual void infoln( const UnicodeString &message );
     virtual void info( const UnicodeString &message );
 
     virtual void infoln( const UnicodeString &message );
@@ -131,7 +200,7 @@ public:
     virtual void infoln( void );
 
     virtual void err(void);
     virtual void infoln( void );
 
     virtual void err(void);
-    
+
     virtual void err( const UnicodeString &message );
 
     virtual void errln( const UnicodeString &message );
     virtual void err( const UnicodeString &message );
 
     virtual void errln( const UnicodeString &message );
@@ -139,7 +208,7 @@ public:
     virtual void dataerr( const UnicodeString &message );
 
     virtual void dataerrln( const UnicodeString &message );
     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 errcheckln(UErrorCode status, const UnicodeString &message );
 
     // convenience functions: sprintf() + errln() etc.
@@ -151,11 +220,21 @@ public:
     void errln(const char *fmt, ...);
     void dataerr(const char *fmt, ...);
     void dataerrln(const char *fmt, ...);
     void errln(const char *fmt, ...);
     void dataerr(const char *fmt, ...);
     void dataerrln(const char *fmt, ...);
+
+    /**
+     * logs an error (even if status==U_ZERO_ERROR), but
+     * calls dataerrln() or errln() depending on the type of error.
+     * Does not report the status code.
+     * @param status parameter for selecting whether errln or dataerrln is called.
+     */
     void errcheckln(UErrorCode status, const char *fmt, ...);
 
     // Print ALL named errors encountered so far
     void errcheckln(UErrorCode status, const char *fmt, ...);
 
     // Print ALL named errors encountered so far
-    void printErrors(); 
-        
+    void printErrors();
+
+    // print known issues. return TRUE if there were any.
+    UBool printKnownIssues();
+
     virtual void usage( void ) ;
 
     /**
     virtual void usage( void ) ;
 
     /**
@@ -174,31 +253,29 @@ public:
      */
     static float random();
 
      */
     static float random();
 
-    /**
-     * Returns true if u_getVersion() < major.minor.
-     */
-    static UBool isICUVersionBefore(int major, int minor) {
-        return isICUVersionBefore(major, minor, 0);
-    }
 
     /**
 
     /**
-     * Returns true if u_getVersion() < major.minor.milli.
+     *   Integer random numbers, similar to C++ std::minstd_rand, with the same algorithm
+     *   and constants.  Allow additional access to internal state, for use by monkey tests,
+     *   which need to recreate previous random sequences beginning near a failure point.
      */
      */
-    static UBool isICUVersionBefore(int major, int minor, int milli);
+    class icu_rand {
+      public:
+        icu_rand(uint32_t seed = 1);
+        ~icu_rand();
+        void seed(uint32_t seed);
+        uint32_t operator()();
+        /**
+          * Get a seed corresponding to the current state of the generator.
+          * Seeding any generator with this value will cause it to produce the
+          * same sequence as this one will from this point forward.
+          */
+        uint32_t getSeed();
+      private:
+        uint32_t fLast;
+    };
 
 
-    /**
-     * 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 };
 
 
     enum { kMaxProps = 16 };
 
@@ -207,16 +284,25 @@ public:
 
 protected:
     /* JUnit-like assertions. Each returns TRUE if it succeeds. */
 
 protected:
     /* JUnit-like assertions. Each returns TRUE if it succeeds. */
-    UBool assertTrue(const char* message, UBool condition, UBool quiet=FALSE, UBool possibleDataError=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 assertFalse(const char* message, UBool condition, UBool quiet=FALSE);
-    UBool assertSuccess(const char* message, UErrorCode ec, UBool possibleDataError=FALSE);
+    /**
+     * @param possibleDataError - if TRUE, use dataerrln instead of errcheckln on failure
+     * @return TRUE on success, FALSE on failure.
+     */
+    UBool assertSuccess(const char* message, UErrorCode ec, UBool possibleDataError=FALSE, const char *file=NULL, int line=0);
     UBool assertEquals(const char* message, const UnicodeString& expected,
                        const UnicodeString& actual, UBool possibleDataError=FALSE);
     UBool assertEquals(const char* message, const char* expected,
                        const char* actual);
     UBool assertEquals(const char* message, const UnicodeString& expected,
                        const UnicodeString& actual, UBool possibleDataError=FALSE);
     UBool assertEquals(const char* message, const char* expected,
                        const char* actual);
+    UBool assertEquals(const char* message, UBool expected,
+                       UBool actual);
+    UBool assertEquals(const char* message, int32_t expected, int32_t actual);
+    UBool assertEquals(const char* message, int64_t expected, int64_t actual);
+    UBool assertEquals(const char* message, double expected, double actual);
 #if !UCONFIG_NO_FORMATTING
     UBool assertEquals(const char* message, const Formattable& expected,
 #if !UCONFIG_NO_FORMATTING
     UBool assertEquals(const char* message, const Formattable& expected,
-                       const Formattable& actual);
+                       const Formattable& actual, UBool possibleDataError=FALSE);
     UBool assertEquals(const UnicodeString& message, const Formattable& expected,
                        const Formattable& actual);
 #endif
     UBool assertEquals(const UnicodeString& message, const Formattable& expected,
                        const Formattable& actual);
 #endif
@@ -224,9 +310,12 @@ protected:
     UBool assertFalse(const UnicodeString& message, UBool condition, UBool quiet=FALSE);
     UBool assertSuccess(const UnicodeString& message, UErrorCode ec);
     UBool assertEquals(const UnicodeString& message, const UnicodeString& expected,
     UBool assertFalse(const UnicodeString& message, UBool condition, UBool quiet=FALSE);
     UBool assertSuccess(const UnicodeString& message, UErrorCode ec);
     UBool assertEquals(const UnicodeString& message, const UnicodeString& expected,
-                       const UnicodeString& actual);
+                       const UnicodeString& actual, UBool possibleDataError=FALSE);
     UBool assertEquals(const UnicodeString& message, const char* expected,
                        const char* actual);
     UBool assertEquals(const UnicodeString& message, const char* expected,
                        const char* actual);
+    UBool assertEquals(const UnicodeString& message, UBool expected, UBool actual);
+    UBool assertEquals(const UnicodeString& message, int32_t expected, int32_t actual);
+    UBool assertEquals(const UnicodeString& message, int64_t expected, int64_t actual);
 
     virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
 
 
     virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
 
@@ -244,6 +333,7 @@ protected:
     UBool       quick;
     UBool       leaks;
     UBool       warn_on_missing_data;
     UBool       quick;
     UBool       leaks;
     UBool       warn_on_missing_data;
+    UBool       no_time;
     int32_t     threadCount;
 
 private:
     int32_t     threadCount;
 
 private:
@@ -254,8 +344,9 @@ private:
     int32_t     dataErrorCount;
     IntlTest*   caller;
     char*       testPath;           // specifies subtests
     int32_t     dataErrorCount;
     IntlTest*   caller;
     char*       testPath;           // specifies subtests
-    
+
     char basePath[1024];
     char basePath[1024];
+    char currName[1024]; // current test name
 
     //FILE *testoutfp;
     void *testoutfp;
 
     //FILE *testoutfp;
     void *testoutfp;
@@ -271,7 +362,12 @@ protected:
 
     static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target);
     static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE);
 
     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 &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.
 
 public:
     static void setICU_DATA();       // Set up ICU_DATA if necessary.
@@ -283,6 +379,7 @@ public:
     static const char* loadTestData(UErrorCode& err);
     virtual const char* getTestDataPath(UErrorCode& err);
     static const char* getSourceTestData(UErrorCode& err);
     static const char* loadTestData(UErrorCode& err);
     virtual const char* getTestDataPath(UErrorCode& err);
     static const char* getSourceTestData(UErrorCode& err);
+    static char *getUnidataPath(char path[]);
 
 // static members
 public:
 
 // static members
 public: