Helios++
Helios software for LiDAR simulations
BaseTest.h
1 #pragma once
2 
3 #include <iostream>
4 #include <iomanip>
5 
6 namespace HeliosTests {
7 
19 class BaseTest {
20 protected:
21  // *** ATTRIBUTES *** //
22  // ******************** //
26  std::string const name;
27 public:
28  // *** CONSTRUCTION *** //
29  // ********************** //
34  BaseTest(std::string const &name) : name(name) {}
35 
36  // *** GETTERS and SETTERS *** //
37  // ***************************** //
42  std::string getName(){return name;}
43 
44  // *** R U N *** //
45  // *************** //
56  virtual bool run() = 0;
57 
58  // *** T E S T *** //
59  // ***************** //
65  void operator()(std::ostream &out=std::cout, bool color=true)
66  {test(out, color);}
71  void test(std::ostream &out=std::cout, bool color=true);
72 };
73 
74 // *** CLASS IMPLEMENTATION *** //
75 // **************************** //
76 void BaseTest::test(std::ostream &out, bool color){
77  // Do test
78  bool status = run();
79 
80  // Report test status
81  if(color) out << "\033[1m";
82  out << "TEST ";
83  if(color) out << "\033[0m";
84  out << std::setw(52) << std::left << name.c_str() << " ";
85  if(color) out << "\033[1m";
86  out << "[";
87  if(color){
88  if(status) out << "\033[32m";
89  else out << "\033[31m";
90  }
91  out << (status ? "PASSED" : "FAILED");
92  if(color) out << "\033[0m\033[1m";
93  out << "]";
94  if(color) out << "\033[0m";
95  out << std::endl;
96 }
97 
98 }
std::string getName()
Definition: BaseTest.h:42
BaseTest class.
Definition: BaseTest.h:19
virtual bool run()=0
Test behavior.
void test(std::ostream &out=std::cout, bool color=true)
Perform the test and output its final status.
Definition: BaseTest.h:76
Definition: BaseTest.h:6
BaseTest(std::string const &name)
Base test constructor.
Definition: BaseTest.h:34
void operator()(std::ostream &out=std::cout, bool color=true)
Another way to call test function.
Definition: BaseTest.h:65
std::string const name
The name for the test.
Definition: BaseTest.h:26