42#ifndef _DWMUNITASSERT_HH_
43#define _DWMUNITASSERT_HH_
109 Assertion(
const std::string & filename,
const std::string & function,
110 int line,
const std::string & expression);
140 friend std::ostream &
144 std::string _filename;
145 std::string _function;
147 std::string _expression;
160 void Failed(
const std::string & filename,
const std::string & function,
161 int lineNumber,
const std::string & test);
166 void Passed(
const std::string & filename,
const std::string & function,
167 int lineNumber,
const std::string & test);
177 std::ostream &
Print(std::ostream & os,
bool onlyFailed =
false)
const;
183 PrintJson(std::ostream & os,
bool onlyFailed =
false)
const;
189 PrintXML(std::ostream & os,
bool onlyFailed =
false)
const;
192 std::string _function;
193 std::map<Assertion,AssertionCounter> _assertions;
206 void Failed(
const std::string & filename,
const std::string & function,
207 int lineNumber,
const std::string & test);
212 void Passed(
const std::string & filename,
const std::string & function,
213 int lineNumber,
const std::string & test);
223 std::ostream &
Print(std::ostream & os,
bool onlyFailed =
false)
const;
228 std::ostream &
PrintJson(std::ostream & os,
bool onlyFailed =
false)
const;
233 std::ostream &
PrintXML(std::ostream & os,
bool onlyFailed =
false)
const;
236 std::string _filename;
237 std::map<std::string,FunctionAssertions> _assertions;
250 static bool Failed(
const std::string & filename,
251 const std::string & function,
252 int lineNumber,
const std::string & test);
258 static bool Passed(
const std::string & filename,
259 const std::string & function,
260 int lineNumber,
const std::string & test);
271 static std::ostream &
Print(std::ostream & os,
bool onlyFailed =
false);
286 bool onlyFailed =
false);
291 static std::ostream &
PrintXML(std::ostream & os,
bool onlyFailed =
false);
294 static std::map<std::string,FileAssertions> _assertions;
295 static std::mutex _mutex;
303#define UnitAssert(e) ((e) ? \
304 Dwm::Assertions::Passed(__FILE__, __PRETTY_FUNCTION__, __LINE__, #e) : \
305 Dwm::Assertions::Failed(__FILE__, __PRETTY_FUNCTION__, __LINE__, #e))
Holds 'passed' and 'failed' counters.
Definition DwmUnitAssert.hh:57
AssertionCounter()
Constructor.
void AddFailed()
Increments the failed counter.
uint64_t Passed() const
Returns the passed counter.
AssertionCounter & operator+=(const AssertionCounter &assertionCounter)
operator +=
void AddPassed()
Increments the passed counter.
friend std::ostream & operator<<(std::ostream &os, const AssertionCounter &assertionCounter)
Prints to an ostream.
uint64_t Failed() const
Returns the failed counter.
Holds assertion information.
Definition DwmUnitAssert.hh:104
const std::string & Filename()
Returns the name of the file where the assertion is located.
friend std::ostream & operator<<(std::ostream &os, const Assertion &assertion)
Prints to an ostream.
const std::string & Expression() const
Returns the assertion test expression.
const std::string & Function()
Returns the function where the assertion is located.
int Line() const
Returns the line number where the assertion is located.
Assertion(const std::string &filename, const std::string &function, int line, const std::string &expression)
Constructor.
bool operator<(const Assertion &assertion) const
operator <
A container to hold all assertions. Note everything is static here.
Definition DwmUnitAssert.hh:244
static int PrintAndReturn()
Prints failed tests to cerr and successful test count to cout in a simple form that I use in unit tes...
static bool Failed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Adds a failed assertion.
static std::ostream & Print(std::ostream &os, bool onlyFailed=false)
Prints to an ostream.
static AssertionCounter Total()
Returns the total passed and failed counter.
static bool Passed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Adds a passed assertion.
static std::ostream & PrintXML(std::ostream &os, bool onlyFailed=false)
Prints to an ostream in XML format.
static std::ostream & PrintJson(std::ostream &os, bool onlyFailed=false)
Prints to an ostream in JSON format.
A container class to hold all assertions called from a single source file.
Definition DwmUnitAssert.hh:201
void Failed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Add a failed assertion.
void Passed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Add a passed assertion.
std::ostream & PrintJson(std::ostream &os, bool onlyFailed=false) const
Prints JSON to an ostream.
AssertionCounter Total() const
Returns the total passed and failed counter.
std::ostream & PrintXML(std::ostream &os, bool onlyFailed=false) const
Prints XML to an ostream.
std::ostream & Print(std::ostream &os, bool onlyFailed=false) const
Prints to an ostream.
A container class to hold all assertions called from a single function.
Definition DwmUnitAssert.hh:155
void Failed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Add a failed assertion.
std::ostream & PrintJson(std::ostream &os, bool onlyFailed=false) const
Prints to an ostream in JSON format.
std::ostream & PrintXML(std::ostream &os, bool onlyFailed=false) const
Prints to an ostream in XML format.
AssertionCounter Total() const
Returns the total passed and failed counter.
std::ostream & Print(std::ostream &os, bool onlyFailed=false) const
Prints to an ostream.
void Passed(const std::string &filename, const std::string &function, int lineNumber, const std::string &test)
Add a passed assertion.