OTest2
A C++ testing framework
testmark.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OTest2__LIB_TESTMARK_H_
20 #define OTest2__LIB_TESTMARK_H_
21 
22 #include <cstdint>
23 #include <string>
24 #include <vector>
25 
26 #include <otest2/const.h>
28 
29 namespace OTest2 {
30 
31 class DiffLogBuilder;
32 class TestMarkFactory;
33 class TestMarkFormatter;
34 class TestMarkIn;
35 class TestMarkOut;
36 
37 
41 class TestMark {
42  public:
47  const int level;
48  const TestMark* me;
49  std::string label;
50  };
51 
52  private:
56  virtual TestMarkHashCode doGetHashCode() const noexcept = 0;
57 
66  virtual bool doIsEqual(
67  const TestMark& other_,
68  long double precision_) const = 0;
69 
82  virtual bool doIsEqualValue(
83  const TestMark& other_,
84  long double precision_) const = 0;
85 
92  virtual void doDiffArray(
93  int level_,
94  std::vector<LinearizedRecord>& array_) const = 0;
95 
96  public:
104  virtual void doLinearizedMark(
105  int level_,
106  const std::string& label_,
107  std::vector<LinearizedRecord>& array_) const = 0;
108 
109  private:
113  virtual void doPrintOpen(
114  std::ostream& os_,
115  const std::string& prefix_) const = 0;
116 
120  virtual void doPrintClose(
121  std::ostream& os_,
122  const std::string& prefix_) const = 0;
123 
127  virtual void doSerializeMark(
128  TestMarkOut& serializer_) const = 0;
129 
133  virtual void doDeserializeMark(
134  TestMarkFactory& factory_,
135  TestMarkIn& deserializer_) = 0;
136 
137  static void computeDiff(
138  int level_,
139  const std::vector<LinearizedRecord>& left_,
140  const std::vector<LinearizedRecord>& right_,
141  std::vector<LinearizedRecord>& left_result_,
142  std::vector<LinearizedRecord>& right_result_,
143  DiffLogBuilder& diff_);
144 
145  public:
149  TestMark();
150 
154  virtual ~TestMark();
155 
156  /* -- avoid copying */
157  TestMark(
158  const TestMark&) = delete;
159  TestMark& operator =(
160  const TestMark&) = delete;
161 
165  TestMarkHashCode getHashCode() const noexcept;
166 
175  bool isEqual(
176  const TestMark& other_,
177  long double precision_ = DEFAULT_FLOAT_PRECISION) const;
178 
190  bool isEqualValue(
191  const TestMark& other_,
192  long double precision_ = DEFAULT_FLOAT_PRECISION) const;
193 
206  bool isEqualValueHash(
207  const TestMark& other_,
208  long double precision_ = DEFAULT_FLOAT_PRECISION) const;
209 
215  void linearizedMark(
216  std::vector<LinearizedRecord>& array_) const;
217 
224  void printOpen(
225  std::ostream& os_,
226  const std::string& prefix_) const;
227 
234  void printClose(
235  std::ostream& os_,
236  const std::string& prefix_) const;
237 
243  void serializeMark(
244  TestMarkOut& serializer_) const;
245 
259  void deserializeMark(
260  TestMarkFactory& factory_,
261  TestMarkIn& deserializer_);
262 
271  void computeDiff(
272  const TestMark& other_,
273  std::vector<LinearizedRecord>& left_,
274  std::vector<LinearizedRecord>& right_,
275  DiffLogBuilder& diff_) const;
276 
282  void printMark(
283  TestMarkFormatter& formatter_) const;
284 
290  void printAddMark(
291  TestMarkFormatter& formatter_) const;
292 };
293 
294 } /* namespace OTest2 */
295 
296 #endif /* OTest2__LIB_TESTMARK_H_ */
OTest2::TestMark::isEqual
bool isEqual(const TestMark &other_, long double precision_=DEFAULT_FLOAT_PRECISION) const
Compare two marks for equality.
Definition: testmark.cpp:87
testmarkhashcode.h
OTest2::TestMark::linearizedMark
void linearizedMark(std::vector< LinearizedRecord > &array_) const
Create the linearized test mark.
Definition: testmark.cpp:115
OTest2::TestMark::printOpen
void printOpen(std::ostream &os_, const std::string &prefix_) const
Print opening of the node into a stream.
Definition: testmark.cpp:120
OTest2::TestMarkIn
A generic interface of a testmark deserializer.
Definition: testmarkin.h:35
OTest2::TestMark::printAddMark
void printAddMark(TestMarkFormatter &formatter_) const
Print the testmark as it's completely new.
Definition: testmark.cpp:324
OTest2::TestMark::isEqualValue
bool isEqualValue(const TestMark &other_, long double precision_=DEFAULT_FLOAT_PRECISION) const
Compare values of 2 test mark nodes.
Definition: testmark.cpp:96
OTest2::TestMarkHashCode
std::uint64_t TestMarkHashCode
Definition: testmarkhashcode.h:28
OTest2::TestMark::deserializeMark
void deserializeMark(TestMarkFactory &factory_, TestMarkIn &deserializer_)
Deserialize the testmark.
Definition: testmark.cpp:137
OTest2::TestMark::isEqualValueHash
bool isEqualValueHash(const TestMark &other_, long double precision_=DEFAULT_FLOAT_PRECISION) const
Compare values of 2 testmark nodes and their hash codes.
Definition: testmark.cpp:105
OTest2::TestMark::getHashCode
TestMarkHashCode getHashCode() const noexcept
Get testmarks' hash code.
Definition: testmark.cpp:83
OTest2::TestMarkOut
A generic interface of a serializer of test marks.
Definition: testmarkout.h:31
OTest2::TestMark::printMark
void printMark(TestMarkFormatter &formatter_) const
Print the testmark.
Definition: testmark.cpp:315
OTest2::DiffLogBuilder
Generic interface of the log builder.
Definition: difflogbuilder.h:30
OTest2::TestMark::LinearizedRecord::level
const int level
Definition: testmark.h:47
OTest2::TestMark::doLinearizedMark
virtual void doLinearizedMark(int level_, const std::string &label_, std::vector< LinearizedRecord > &array_) const =0
Create linearized test mark.
const.h
OTest2
Definition: assertbean.h:25
OTest2::DEFAULT_FLOAT_PRECISION
constexpr long double DEFAULT_FLOAT_PRECISION(1.0e-12)
Default precision for floating point comparisons.
OTest2::TestMark::printClose
void printClose(std::ostream &os_, const std::string &prefix_) const
Print closing of the node into a stream.
Definition: testmark.cpp:126
OTest2::TestMark::serializeMark
void serializeMark(TestMarkOut &serializer_) const
Serialize the testmark into a serializer.
Definition: testmark.cpp:132
OTest2::TestMark::LinearizedRecord
One item of linearized test mark.
Definition: testmark.h:46
OTest2::TestMark::LinearizedRecord::me
const TestMark * me
Definition: testmark.h:48
OTest2::TestMark
Generic interface of a test mark node.
Definition: testmark.h:41
OTest2::TestMarkFactory
A factory of testmark objects used for deserialization.
Definition: testmarkfactory.h:45
OTest2::TestMarkFormatter
Generic interface of the testmark formatter.
Definition: testmarkformatter.h:32
OTest2::TestMark::LinearizedRecord::label
std::string label
Definition: testmark.h:49