2 **********************************************************************
3 * Copyright (c) 2002-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
10 #include "unicode/utypes.h"
11 #include "unicode/unistr.h"
12 #include "unicode/ustring.h"
14 #include "unicode/testtype.h"
15 #include "unicode/utimer.h"
18 // Forward declarations from uoptions.h.
20 typedef struct UOption UOption;
22 #if !UCONFIG_NO_CONVERSION
25 // Use the TESTCASE macro in subclasses of IntlTest. Define the
26 // runIndexedTest method in this fashion:
28 //| void MyTest::runIndexedTest(int32_t index, UBool exec,
29 //| const char* &name, char* /*par*/) {
31 //| TESTCASE(0,TestSomething);
32 //| TESTCASE(1,TestSomethingElse);
33 //| TESTCASE(2,TestAnotherThing);
40 #define TESTCASE(id,test) \
44 fprintf(stdout,#test "---"); \
45 fprintf(stdout,"\n"); \
51 #define TESTCASE(id,test) \
60 * Subclasses of PerfTest will need to create subclasses of
61 * Function that define a call() method which contains the code to
62 * be timed. They then call setTestFunction() in their "Test..."
63 * method to establish this as the current test functor.
65 class T_CTEST_EXPORT_API UPerfFunction {
70 virtual ~UPerfFunction();
73 * Subclasses must implement this method to do the action to be
76 virtual void call(UErrorCode* status)=0;
79 * Subclasses must implement this method to return positive
80 * integer indicating the number of operations in a single
81 * call to this object's call() method.
83 virtual long getOperationsPerIteration()=0;
85 * Subclasses should override this method to return either positive
86 * or negative integer indicating the number of events in a single
87 * call to this object's call() method, if applicable
88 * e.g: Number of breaks / iterations for break iterator
90 virtual long getEventsPerIteration(){
94 * Call call() n times in a tight loop and return the elapsed
95 * milliseconds. If n is small and call() is fast the return
96 * result may be zero. Small return values have limited
97 * meaningfulness, depending on the underlying CPU and OS.
99 virtual double time(int32_t n, UErrorCode* status) {
101 utimer_getTime(&start);
105 utimer_getTime(&stop);
106 return utimer_getDeltaSeconds(&start,&stop); // ms
112 class T_CTEST_EXPORT_API UPerfTest {
115 UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden
117 virtual void usage( void ) ;
119 virtual ~UPerfTest();
121 void setCaller( UPerfTest* callingTest ); // for internal use only
123 void setPath( char* path ); // for internal use only
125 ULine* getLines(UErrorCode& status);
127 const UChar* getBuffer(int32_t& len,UErrorCode& status);
130 UPerfTest(int32_t argc, const char* argv[], UErrorCode& status);
132 UPerfTest(int32_t argc, const char* argv[],
133 UOption addOptions[], int32_t addOptionsCount,
134 const char *addUsage,
137 void init(UOption addOptions[], int32_t addOptionsCount,
140 virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
142 virtual UBool runTestLoop( char* testname, char* par );
144 virtual UBool callTest( UPerfTest& testToBeCalled, char* par );
148 const char * _addUsage;
149 char* resolvedFileName;
151 const char* encoding;
153 const char* fileName;
154 const char* sourceDir;
155 int32_t _remainingArgc;
169 char* path; // specifies subtests
173 static UPerfTest* gTest;
174 static const char gUsageString[];