00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef THREAD_FACTORY_H
00017 #define THREAD_FACTORY_H
00018
00019 #include <vector>
00020 #include <iostream>
00021 #include "testThread.h"
00022
00023 using namespace amino;
00024
00025 namespace test {
00026
00027 template<typename ParaType> class ThreadFactory {
00028 public:
00029 virtual ~ThreadFactory() {}
00030
00031 vector<ParaType> inVec;
00032 vector<ParaType> outVec;
00038 virtual Runnable ** createThreads(int threadNum, int elementNum,
00039 int operationNum)=0;
00040 virtual void deleteThreads(Runnable ** threads, int threadNum) {
00041 for (int i = 0; i < threadNum; ++i) {
00042 if (TestThread<ParaType> * p
00043 = dynamic_cast<TestThread<ParaType> *> (threads[i])) {
00044 delete p;
00045 }
00046 }
00047 delete[] threads;
00048 }
00052 virtual void verifyResult(int threadNum, int elementNum) {
00053 sort(inVec.begin(), inVec.end());
00054 sort(outVec.begin(), outVec.end());
00055
00056 if (inVec != outVec) {
00057 cout << "inVec .... size: " << inVec.size() << endl;
00058 for (typename vector<ParaType>::iterator ite = inVec.begin(); ite
00059 != inVec.end(); ++ite) {
00060 cout << *ite << " : ";
00061 }
00062 cout << endl;
00063
00064 cout << "outVec .... size: " << outVec.size() << endl;
00065 for (typename vector<ParaType>::iterator ite = outVec.begin(); ite
00066 != outVec.end(); ++ite) {
00067 cout << *ite << " : ";
00068 }
00069 cout << endl;
00070
00071 cout << "difference of inVec and outVec" << endl;
00072 ParaType result[100];
00073 ParaType* resultEnd = set_symmetric_difference(
00074 inVec.begin(), inVec.end(), outVec.begin(), outVec.end(),
00075 result);
00076
00077 for (ParaType* ite = result; ite
00078 != resultEnd; ++ite) {
00079 cout << *ite << " : ";
00080 }
00081 cout << endl;
00082
00083 }
00084
00085 CPPUNIT_ASSERT(inVec == outVec);
00086 }
00087
00091 virtual void collection(Runnable ** threads, int threadNum) {
00092 for (int i = 0; i < threadNum; ++i) {
00093 if (TestThread<ParaType> * p
00094 = dynamic_cast<TestThread<ParaType> *> (threads[i])) {
00095 if (!p->inVec.empty()) {
00096 copy(p->inVec.begin(), p->inVec.end(), back_inserter(inVec));
00097 }
00098 if (!p->outVec.empty()) {
00099 copy(p->outVec.begin(), p->outVec.end(), back_inserter(
00100 outVec));
00101 }
00102 }
00103 }
00104 }
00105 };
00106 }
00107
00108 #endif