+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* 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
#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,
//| 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
*/
class T_CTEST_EXPORT_API UPerfFunction {
public:
+ /**
+ * destructor
+ */
+ virtual ~UPerfFunction();
+
/**
* Subclasses must implement this method to do the action to be
* measured.
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
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;