PlasCom2  1.0
XPACC Multi-physics simluation application
Testing.H
Go to the documentation of this file.
1 #ifndef __TESTING_H__
7 #define __TESTING_H__
8 
9 #include "Parameters.H"
10 
11 namespace ix {
12 
13  namespace test {
14 
18  class results : public util::Parameters
19  {
20  public:
21 
33  template <typename ValueType>
34  void AddResult(const std::string &name,const ValueType &result)
35  {
37  p.Key(name);
38  std::ostringstream Ostr;
39  Ostr << result;
40  p.Value(Ostr.str());
41  this->push_back(p);
42  }
43 
54  template<typename ValueType>
55  void UpdateResult(const std::string &name,const ValueType &result)
56  {
57  std::ostringstream Ostr;
58  Ostr << result;
59  results::iterator _thisit = this->begin();
60  while(_thisit != this->end()){
61  if(_thisit->first == name){
62  _thisit->second = Ostr.str();
63  return;
64  }
65  _thisit++;
66  }
67  return(AddResult<ValueType>(name,result));
68  }
69  };
70 
83  template<typename ResultsType = results>
84  class manager
85  {
86  public:
87  typedef ResultsType Results;
88  typedef void (manager::*TestFunctionType)(ResultsType &);
89  typedef std::map<std::string,TestFunctionType> FunctionMapType;
91  virtual void Prologue(){};
93  virtual void Process(Results &results){
94  Prologue();
95  typename FunctionMapType::iterator testFunctionMapIterator = testFunctionMap.begin();
96  while(testFunctionMapIterator != testFunctionMap.end()){
97  TestFunctionType TestFunction = testFunctionMapIterator++->second;
98  (this->*TestFunction)(results);
99  }
100  Epilogue();
101  };
103  virtual void ProcessTests(std::list<std::string> &names,Results &results){
104  Prologue();
105  std::list<std::string>::iterator nameIterator = names.begin();
106  while(nameIterator != names.end())
107  RunTest(*nameIterator++,results);
108  Epilogue();
109  };
111  virtual void RunTest(const std::string &name,Results &results){
112  typename FunctionMapType::iterator testFunctionMapIterator = testFunctionMap.find(name);
113  if(testFunctionMapIterator != testFunctionMap.end()){
114  Prologue();
115  TestFunctionType TestFunction = testFunctionMapIterator->second;
116  (this->*TestFunction)(results);
117  Epilogue();
118  }
119  };
121  virtual void Epilogue(){};
123  virtual void AddTest(const std::string &testName,TestFunctionType TestFunc){
124  testFunctionMap[testName] = TestFunc;
125  };
126  FunctionMapType &FunctionMap(){return(testFunctionMap);};
127  virtual void ListTests(std::ostream &outStream){
128  typename FunctionMapType::iterator testFunctionMapIterator = testFunctionMap.begin();
129  while(testFunctionMapIterator != testFunctionMap.end())
130  outStream << testFunctionMapIterator++->first << std::endl;
131  };
132  virtual ~manager(){};
133  protected:
134  FunctionMapType testFunctionMap;
135  };
136  };
137 };
138 #endif
FunctionMapType & FunctionMap()
Definition: Testing.H:126
std::map< std::string, TestFunctionType > FunctionMapType
Definition: Testing.H:89
int RunTest(int argc, char *argv[])
Runs test programs and scripts through a standard interface.
Definition: RunTest.C:17
virtual void ListTests(std::ostream &outStream)
Definition: Testing.H:127
virtual void ProcessTests(std::list< std::string > &names, Results &results)
Process named tests from a list and populate a "results" object.
Definition: Testing.H:103
virtual void Process(Results &results)
Process all tests and populate a "results" object.
Definition: Testing.H:93
virtual void Epilogue()
Clean up any test fixtures that need cleaning.
Definition: Testing.H:121
Defines MPI-specific parallel global and program classes.
ResultsType Results
Definition: Testing.H:87
Encapsulating class for collections of test results.
Definition: Testing.H:18
void UpdateResult(const std::string &name, const ValueType &result)
Updates an existing test result.
Definition: Testing.H:55
virtual void RunTest(const std::string &name, Results &results)
Run a particular test.
Definition: Testing.H:111
virtual ~manager()
Definition: Testing.H:132
virtual void AddTest(const std::string &testName, TestFunctionType TestFunc)
Add a test.
Definition: Testing.H:123
Parameters object interface (for config files, etc)
void AddResult(const std::string &name, const ValueType &result)
Add a named result to the test results.
Definition: Testing.H:34
Simple key-value pair.
virtual void Prologue()
Set up the tests and any test fixture constructs.
Definition: Testing.H:91
Interface for a general testing object.
Definition: Testing.H:84