HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_assertion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4
6
7namespace hart
8{
9
10/// @brief Holds metadata for the condition + the expect/assert level and file/line metadata
11/// @details Meant to add strictness (expect/assert) to the condition, for free-standing assertions like `HART_EXPECT_EQ`.
12/// @private
13class Assertion
14{
15public:
16 enum class Level
17 {
18 expect,
19 assert
20 };
21
22 static Assertion makeExpect (Condition condition, const char* file, int line)
23 {
24 return Assertion (Level::expect, std::move (condition), file, line);
25 }
26
27 static Assertion makeAssert (Condition condition, const char* file, int line)
28 {
29 return Assertion (Level::assert, std::move (condition), file, line);
30 }
31
32 bool hasFailed() const
33 {
34 return m_condition.getResult() == false;
35 }
36
37 Level getLevel() const
38 {
39 return m_level;
40 }
41
42 const char* getFile() const
43 {
44 return m_file;
45 }
46
47 int getLine() const
48 {
49 return m_line;
50 }
51
52 void representWithTokens (std::ostream& stream) const
53 {
54 m_condition.representWithTokens (stream);
55 }
56
57 void representWithStringRepresentations (std::ostream& stream) const
58 {
59 m_condition.representWithStringRepresentations (stream);
60 }
61
62private:
63 Assertion (Level level, Condition condition, const char* file, int line) :
64 m_level (level),
65 m_condition (std::move (condition)),
66 m_file (file),
67 m_line (line)
68 {
69 }
70
71 const Level m_level;
72 const Condition m_condition;
73 const char* const m_file;
74 const int m_line;
75};
76
77} // namespace hart
A class representing some condition.