X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..f59164e3d128c7675a4d3934206346a3384e53a5:/icuSources/tools/ctestfw/unicode/uperf.h diff --git a/icuSources/tools/ctestfw/unicode/uperf.h b/icuSources/tools/ctestfw/unicode/uperf.h index 76776946..a5f7151a 100644 --- a/icuSources/tools/ctestfw/unicode/uperf.h +++ b/icuSources/tools/ctestfw/unicode/uperf.h @@ -1,9 +1,8 @@ /* ********************************************************************** -* Copyright (c) 2002-2005, International Business Machines +* Copyright (c) 2002-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** -********************************************************************** */ #ifndef _UPERF_H #define _UPERF_H @@ -16,10 +15,14 @@ #include "unicode/utimer.h" #include "ucbuf.h" +// Forward declarations from uoptions.h. +struct UOption; +typedef struct UOption UOption; + #if !UCONFIG_NO_CONVERSION U_NAMESPACE_USE -// Use the TESTCASE macro in subclasses of IntlTest. Define the +// Use the TESTCASE macro in subclasses of UPerfTest. Define the // runIndexedTest method in this fashion: // //| void MyTest::runIndexedTest(int32_t index, UBool exec, @@ -29,29 +32,48 @@ U_NAMESPACE_USE //| TESTCASE(1,TestSomethingElse); //| TESTCASE(2,TestAnotherThing); //| default: -//| name = ""; -//| return NULL; +//| name = ""; +//| break; //| } +//| return NULL; //| } -#if 0 #define TESTCASE(id,test) \ case id: \ name = #test; \ if (exec) { \ - fprintf(stdout,#test "---"); \ - fprintf(stdout,"\n"); \ return test(); \ } \ break -#endif -#define TESTCASE(id,test) \ - case id: \ - name = #test; \ - if (exec) { \ - return test(); \ - } \ - break +// More convenient macros. These allow easy reordering of the test cases. +// Copied from intltest.h, and adjusted to not logln() but return a UPerfFunction. +// +//| 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; +//| return NULL; +//| } +#define TESTCASE_AUTO_BEGIN \ + for(;;) { \ + int32_t testCaseAutoNumber = 0 + +#define TESTCASE_AUTO(test) \ + if (index == testCaseAutoNumber++) { \ + name = #test; \ + if (exec) { \ + return test(); \ + } \ + break; \ + } + +#define TESTCASE_AUTO_END \ + name = ""; \ + break; \ + } /** * Subclasses of PerfTest will need to create subclasses of @@ -61,6 +83,11 @@ U_NAMESPACE_USE */ class T_CTEST_EXPORT_API UPerfFunction { public: + /** + * destructor + */ + virtual ~UPerfFunction(); + /** * Subclasses must implement this method to do the action to be * measured. @@ -82,11 +109,6 @@ public: virtual long getEventsPerIteration(){ return -1; } - /** - * destructor - */ - virtual ~UPerfFunction() {} - /** * Call call() n times in a tight loop and return the elapsed * milliseconds. If n is small and call() is fast the return @@ -126,31 +148,40 @@ public: protected: UPerfTest(int32_t argc, const char* argv[], UErrorCode& status); + UPerfTest(int32_t argc, const char* argv[], + UOption addOptions[], int32_t addOptionsCount, + const char *addUsage, + UErrorCode& status); + + void init(UOption addOptions[], int32_t addOptionsCount, + UErrorCode& status); + virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide ! virtual UBool runTestLoop( char* testname, char* par ); virtual UBool callTest( UPerfTest& testToBeCalled, char* par ); - UBool verbose; - const char* sourceDir; - const char* fileName; + int32_t _argc; + const char** _argv; + const char * _addUsage; char* resolvedFileName; + UCHARBUF* ucharBuf; const char* encoding; UBool uselen; - int32_t iterations; - int32_t passes; - int32_t time; - const char** _argv; - int32_t _argc; + const char* fileName; + const char* sourceDir; int32_t _remainingArgc; ULine* lines; int32_t numLines; - UCHARBUF* ucharBuf; UBool line_mode; - UBool bulk_mode; UChar* buffer; int32_t bufferLen; + UBool verbose; + UBool bulk_mode; + int32_t passes; + int32_t iterations; + int32_t time; const char* locale; private: UPerfTest* caller;