00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BASETEST_H_
00017 #define BASETEST_H_
00018
00019 #include <iostream>
00020 #include <vector>
00021 #include <algorithm>
00022 #include <stdexcept>
00023 #include "testThread.h"
00024 #include "threadRunner.h"
00025 #include "randArrayGenerator.h"
00026
00027 using namespace amino;
00028 using namespace test;
00029
00030
00036 #define STR(X) #X
00037 #define DEFINITION(DS,TYPE) extern const char DS##TYPE[] = STR(DS##_##TYPE)
00038 #define NAME(DS,TYPE) DS##TYPE
00039 #define TYPEDEF(TESTCASE,DS,TYPE,NAME) typedef TESTCASE<DS<TYPE >,TYPE, NAME > DS##_##TYPE
00040 #define TYPEDEF_2_PARA(TESTCASE,DS,TYPE1,TYPE2,NAME) typedef TESTCASE<DS<TYPE1,TYPE2 >, TYPE2, NAME > DS##_##TYPE2
00041
00042 #define REGISTRATION_TEST(TESTCASE,DS,TYPE) DEFINITION(DS,TYPE);\
00043 TYPEDEF(TESTCASE,DS,TYPE,NAME(DS,TYPE));\
00044 DS<TYPE > DS##_##TYPE##var;\
00045 DS##_##TYPE DS##_##TYPE##temp;\
00046 CPPUNIT_TEST_SUITE_REGISTRATION( DS##_##TYPE );
00047
00048 #define REGISTRATION_TEST_2_PARA(TESTCASE,DS,TYPE1,TYPE2) DEFINITION(DS,TYPE2);\
00049 TYPEDEF_2_PARA(TESTCASE,DS,TYPE1,TYPE2,NAME(DS,TYPE2));\
00050 CPPUNIT_TEST_SUITE_REGISTRATION( DS##_##TYPE2 );
00051
00052 template<typename DataType> class BaseTest {
00053 public:
00054 int NELEMENT;
00055 int NOPERATION;
00056 int MAXTHREADN;
00057 ConcurrentRunner* runner;
00058
00059 DataType* data;
00060
00061 BaseTest() {
00062 NELEMENT = TestConfig::getInstance()->getElementNum();
00063 NOPERATION = TestConfig::getInstance()->getOperationNum();
00064 vector<int> thread_v = TestConfig::getInstance()->getThreadNum();
00065
00066 if(0 == thread_v.size()) {
00067 MAXTHREADN = 0;
00068 } else {
00069 MAXTHREADN = *max_element(thread_v.begin(), thread_v.end());
00070 }
00071 data = new DataType[NELEMENT * MAXTHREADN];
00072 RandArrayGenerator<DataType>::getRandArray(data, NELEMENT
00073 * MAXTHREADN);
00074 }
00075
00081 virtual void reset(){};
00082
00083 virtual ~BaseTest() {
00084 delete[] data;
00085 }
00086
00087 DataType& getData(int index) {
00088 if (index < 0 || index >= NELEMENT * MAXTHREADN) {
00089 throw range_error();
00090 }
00091 return data[index];
00092 }
00093 };
00094 #endif