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