DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Public Member Functions | Private Attributes | List of all members
dd4hep::DDTest Class Reference

Simple class for defining unit tests. More...

#include <DDTest.h>

Public Member Functions

 DDTest ()=delete
 Default constructor. More...
 
 DDTest (const DDTest &copy)=delete
 Copy constructor. More...
 
DDTestoperator= (const DDTest &copy)=delete
 Assignment operator. More...
 
 DDTest (const std::string &testname, std::ostream &stream=std::cout)
 
 ~DDTest ()
 
template<class V1 , class V2 >
void operator() (const V1 &v1, const V2 &v2, const std::string &name)
 
template<class Cond >
void operator() (const Cond &c, const std::string &name)
 
void log (const std::string &msg)
 
void pass (const std::string &msg)
 
void error (const std::string &msg)
 
void fatal_error (const std::string &msg)
 
const char * last_test_status ()
 
 DDTest ()=delete
 Default constructor. More...
 
 DDTest (const DDTest &copy)=delete
 Copy constructor. More...
 
DDTestoperator= (const DDTest &copy)=delete
 Assignment operator. More...
 
 DDTest (const std::string &testname, std::ostream &stream=std::cout)
 
 ~DDTest ()
 
template<class V1 , class V2 >
void operator() (const V1 &v1, const V2 &v2, const std::string &name)
 
template<class Cond >
void operator() (const Cond &c, const std::string &name)
 
void log (const std::string &msg)
 
void pass (const std::string &msg)
 
void error (const std::string &msg)
 
void fatal_error (const std::string &msg)
 
const char * last_test_status ()
 

Private Attributes

std::string _testname
 
std::ostream & _out = std::cout
 
unsigned int _failed = 0
 
unsigned int _passed = 0
 
bool _last_test_status = false
 

Detailed Description

Simple class for defining unit tests.

Use in main program that is added as a test to ctest:

DDTest test = DDTest( "example" ) ; test.log( "example test" ); test( "Example", "Example", "example test - string comparison " ); // this test will pass test( "Example", "BadExample", "example test - string comparison " ); // this test will fail

Author
F.Gaede, DESY, 2014 based on original version from J.Engels

Definition at line 21 of file DDTest.h.

Constructor & Destructor Documentation

◆ DDTest() [1/6]

dd4hep::DDTest::DDTest ( )
delete

Default constructor.

◆ DDTest() [2/6]

dd4hep::DDTest::DDTest ( const DDTest copy)
delete

Copy constructor.

◆ DDTest() [3/6]

dd4hep::DDTest::DDTest ( const std::string &  testname,
std::ostream &  stream = std::cout 
)
inline

Only constructor

Definition at line 36 of file DDTest.h.

◆ ~DDTest() [1/2]

dd4hep::DDTest::~DDTest ( )
inline

Destructor - print summary of tests passed and failed

Definition at line 52 of file DDTest.h.

◆ DDTest() [4/6]

dd4hep::DDTest::DDTest ( )
delete

Default constructor.

◆ DDTest() [5/6]

dd4hep::DDTest::DDTest ( const DDTest copy)
delete

Copy constructor.

◆ DDTest() [6/6]

dd4hep::DDTest::DDTest ( const std::string &  testname,
std::ostream &  stream = std::cout 
)
inline

Only constructor

Definition at line 36 of file DDTest.h.

◆ ~DDTest() [2/2]

dd4hep::DDTest::~DDTest ( )
inline

Destructor - print summary of tests passed and failed

Definition at line 52 of file DDTest.h.

Member Function Documentation

◆ error() [1/2]

void dd4hep::DDTest::error ( const std::string &  msg)
inline

print message when test failed

Definition at line 138 of file DDTest.h.

◆ error() [2/2]

void dd4hep::DDTest::error ( const std::string &  msg)
inline

print message when test failed

Definition at line 138 of file DDTest.h.

◆ fatal_error() [1/2]

void dd4hep::DDTest::fatal_error ( const std::string &  msg)
inline

Fatal error ...

Definition at line 157 of file DDTest.h.

◆ fatal_error() [2/2]

void dd4hep::DDTest::fatal_error ( const std::string &  msg)
inline

Fatal error ...

Definition at line 157 of file DDTest.h.

◆ last_test_status() [1/2]

const char* dd4hep::DDTest::last_test_status ( )
inline

Return the status from the last test - either PASSED or FAILED

Definition at line 164 of file DDTest.h.

◆ last_test_status() [2/2]

const char* dd4hep::DDTest::last_test_status ( )
inline

Return the status from the last test - either PASSED or FAILED

Definition at line 164 of file DDTest.h.

◆ log() [1/2]

void dd4hep::DDTest::log ( const std::string &  msg)
inline

Simple log message

Definition at line 121 of file DDTest.h.

◆ log() [2/2]

void dd4hep::DDTest::log ( const std::string &  msg)
inline

Simple log message

Definition at line 121 of file DDTest.h.

◆ operator()() [1/4]

template<class Cond >
void dd4hep::DDTest::operator() ( const Cond &  c,
const std::string &  name 
)
inline

Operator for calling a test - test is passed if (!c)==false

Definition at line 100 of file DDTest.h.

◆ operator()() [2/4]

template<class Cond >
void dd4hep::DDTest::operator() ( const Cond &  c,
const std::string &  name 
)
inline

Operator for calling a test - test is passed if (!c)==false

Definition at line 100 of file DDTest.h.

◆ operator()() [3/4]

template<class V1 , class V2 >
void dd4hep::DDTest::operator() ( const V1 &  v1,
const V2 &  v2,
const std::string &  name 
)
inline

Operator for calling a test - test is passed if v1 == v2

Definition at line 77 of file DDTest.h.

◆ operator()() [4/4]

template<class V1 , class V2 >
void dd4hep::DDTest::operator() ( const V1 &  v1,
const V2 &  v2,
const std::string &  name 
)
inline

Operator for calling a test - test is passed if v1 == v2

Definition at line 77 of file DDTest.h.

◆ operator=() [1/2]

DDTest& dd4hep::DDTest::operator= ( const DDTest copy)
delete

Assignment operator.

◆ operator=() [2/2]

DDTest& dd4hep::DDTest::operator= ( const DDTest copy)
delete

Assignment operator.

◆ pass() [1/2]

void dd4hep::DDTest::pass ( const std::string &  msg)
inline

print message when test passed

Definition at line 127 of file DDTest.h.

◆ pass() [2/2]

void dd4hep::DDTest::pass ( const std::string &  msg)
inline

print message when test passed

Definition at line 127 of file DDTest.h.

Member Data Documentation

◆ _failed

unsigned int dd4hep::DDTest::_failed = 0
private

Definition at line 173 of file DDTest.h.

◆ _last_test_status

bool dd4hep::DDTest::_last_test_status = false
private

Definition at line 175 of file DDTest.h.

◆ _out

std::ostream & dd4hep::DDTest::_out = std::cout
private

Definition at line 171 of file DDTest.h.

◆ _passed

unsigned int dd4hep::DDTest::_passed = 0
private

Definition at line 174 of file DDTest.h.

◆ _testname

std::string dd4hep::DDTest::_testname
private

Definition at line 170 of file DDTest.h.


The documentation for this class was generated from the following file: