API Documentation
TestClass.h
1 // TestClass.h
3 //
5 
6 namespace nkDebug
7 {
61  class TestClass
62  {
63  public :
64 
65  // Constructor, destructor
69  TestClass () noexcept ;
75  TestClass (nkMemory::StringView name) noexcept ;
79  virtual ~TestClass () ;
80 
81  // Getters
93  const FunctionSet& getFunctionSet () const ;
97  std::function<bool ()> getClassInitFunction () const ;
101  std::function<void ()> getClassShutdownFunction () const ;
105  std::function<bool ()> getFunctionInitFunction () const ;
109  std::function<void ()> getFunctionShutdownFunction () const ;
113  nkMemory::StringView getName () const ;
114 
115  // Setters
126  bool setClassInitFunction (std::function<bool ()> func) ;
133  bool setClassShutdownFunction (std::function<void ()> func) ;
144  bool setTestFunctionInitFunction (std::function<bool ()> func) ;
151  bool setTestFunctionShutdownFunction (std::function<void ()> func) ;
157  void setName (nkMemory::StringView value) ;
158 
159  // Execution
165  void execute (const TestRunParameters& parameters) const ;
166  } ;
167 
168  static const char NK_DEBUG_STATIC_EMPTY_CHAR [] = "" ;
169 
178  template <typename T, const char* T_NAME>
180  {
181  public :
182 
183  // Functions
184  // Constructor
189  : TestClass (T_NAME)
190  {
191  // Nothing to do
192  }
193 
194  // Factory
201  {
202  return new T () ;
203  }
204 
205  public :
206 
207  // Attributes
208  // Registered class pointer
209  inline static TestClass* _registered = UnitTester::registerTestClass(&factoryFunc) ;
210  } ;
211 }
212 
213 #define NK_TEST_CLASS(name) \
214  static const char NK_DEBUG_STATIC_CHAR_##name [] = #name ; \
215  class name : public nkDebug::RegisteredTestClass<name, NK_DEBUG_STATIC_CHAR_##name>
216 
217 #define NK_TEST_CLASS_NS(ns, name) \
218  namespace ns \
219  { \
220  static const char NK_DEBUG_STATIC_CHAR_##name [] = #ns "::" #name ; \
221  class name : public nkDebug::RegisteredTestClass<name, NK_DEBUG_STATIC_CHAR_##name> \
222 
223 #define NK_TEST_CLASS_NS_END }
224 
225 #define NK_TEST_FUNCTION(name) \
226  static void caller_##name () \
227  { \
228  return name() ; \
229  } \
230  \
231  inline static const std::function<void ()>& registered_##name = _registered->_testFunctions.registerFunction(#name, &caller_##name) ; \
232  \
233  static void name () \
234 
235 #define NK_TEST_CLASS_INIT \
236  static bool classInitFunctionCaller () \
237  { \
238  return classInitFunction() ; \
239  } \
240  \
241  inline static const bool classInitRegistered = _registered->setClassInitFunction(classInitFunctionCaller) ; \
242  \
243  static bool classInitFunction () \
244 
245 #define NK_TEST_CLASS_SHUTDOWN \
246  static void classShutdownFunctionCaller () \
247  { \
248  classShutdownFunction() ; \
249  } \
250  \
251  inline static const bool classShutdownRegistered = _registered->setClassShutdownFunction(classShutdownFunctionCaller) ; \
252  \
253  static void classShutdownFunction () \
254 
255 #define NK_TEST_FUNCTION_INIT \
256  static bool testFunctionInitFunctionCaller () \
257  { \
258  return testFunctionInitFunction() ; \
259  } \
260  \
261  inline static const bool testFunctionInitRegistered = _registered->setTestFunctionInitFunction(testFunctionInitFunctionCaller) ; \
262  \
263  static bool testFunctionInitFunction () \
264 
265 #define NK_TEST_FUNCTION_SHUTDOWN \
266  static void testFunctionShutdownFunctionCaller () \
267  { \
268  testFunctionShutdownFunction() ; \
269  } \
270  \
271  inline static const bool testFunctionShutdownRegistered = _registered->setTestFunctionShutdownFunction(testFunctionShutdownFunctionCaller) ; \
272  \
273  static void testFunctionShutdownFunction () \
nkDebug::RegisteredTestClass
Holds informations about a registered test class.
Definition: TestClass.h:180
nkDebug::TestClass::getFunctionShutdownFunction
std::function< void()> getFunctionShutdownFunction() const
nkDebug::FunctionSet
A function set holding testing functions.
Definition: FunctionSet.h:14
nkDebug::TestClass::execute
void execute(const TestRunParameters &parameters) const
nkDebug::TestClass::setTestFunctionInitFunction
bool setTestFunctionInitFunction(std::function< bool()> func)
nkDebug::TestClass::getClassShutdownFunction
std::function< void()> getClassShutdownFunction() const
nkDebug::TestClass::setName
void setName(nkMemory::StringView value)
nkDebug::TestClass::setClassShutdownFunction
bool setClassShutdownFunction(std::function< void()> func)
nkDebug::UnitTester::registerTestClass
static TestClass * registerTestClass(std::function< TestClass *()> factoryFunction)
nkDebug::TestClass::setTestFunctionShutdownFunction
bool setTestFunctionShutdownFunction(std::function< void()> func)
nkDebug::RegisteredTestClass::factoryFunc
static TestClass * factoryFunc()
Definition: TestClass.h:200
nkDebug::TestClass::getClassInitFunction
std::function< bool()> getClassInitFunction() const
nkDebug::TestClass::TestClass
TestClass() noexcept
nkDebug::TestClass::getName
nkMemory::StringView getName() const
nkDebug::TestRunParameters
Parameters allowing to drive a test run sequence.
Definition: TestRunParameters.h:12
nkDebug::TestClass::getFunctionSet
FunctionSet & getFunctionSet()
nkDebug::RegisteredTestClass::RegisteredTestClass
RegisteredTestClass()
Definition: TestClass.h:188
nkDebug::TestClass::getFunctionInitFunction
std::function< bool()> getFunctionInitFunction() const
nkDebug
Encompasses all API of component NilkinsDebug.
Definition: LogManager.h:7
nkDebug::TestClass
The test enabling class, allowing registration within the UnitTester.
Definition: TestClass.h:62
nkDebug::TestClass::setClassInitFunction
bool setClassInitFunction(std::function< bool()> func)
nkMemory
Encompasses all API of component NilkinsMemory.
Definition: Allocator.h:7