OTest2
A C++ testing framework
testmarkbool.cpp
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 
20 #include <testmarkbool.h>
21 
22 #include <assert.h>
23 #include <iostream>
24 #include <string>
25 
26 #include <exctestmarkin.h>
27 #include <testmarkhash.h>
28 #include <testmarkin.h>
29 #include <testmarkout.h>
30 
31 namespace OTest2 {
32 
33 namespace {
34 
35 const char SERIALIZE_TYPE_MARK[] = "ot2:bool";
36 
37 } /* -- namespace */
38 
40  bool value_) :
41  value(value_) {
42 
43 }
44 
46  const CtorMark*) :
47  value(false) {
48 
49 }
50 
52 
53 }
54 
55 const char* TestMarkBool::typeMark() {
56  return SERIALIZE_TYPE_MARK;
57 }
58 
59 TestMarkHashCode TestMarkBool::doGetHashCode() const noexcept {
60  return TestMarkHash::hashBasicType(SERIALIZE_TYPE_MARK, value);
61 }
62 
63 bool TestMarkBool::doIsEqual(
64  const TestMark& other_,
65  long double precision_) const {
66  return value == static_cast<const TestMarkBool*>(&other_)->value;
67 }
68 
69 bool TestMarkBool::doIsEqualValue(
70  const TestMark& other_,
71  long double precision_) const {
72  return doIsEqual(other_, precision_);
73 }
74 
75 void TestMarkBool::doDiffArray(
76  int level_,
77  std::vector<LinearizedRecord>& array_) const
78 {
79  /* -- there are no children */
80 }
81 
82 void TestMarkBool::doLinearizedMark(
83  int level_,
84  const std::string& label_,
85  std::vector<LinearizedRecord>& array_) const {
86  array_.push_back({level_, this, label_});
87 }
88 
89 void TestMarkBool::doPrintOpen(
90  std::ostream& os_,
91  const std::string& prefix_) const {
92  os_ << prefix_;
93  if(value)
94  os_ << "true";
95  else
96  os_ << "false";
97  os_ << '\n';
98 }
99 
100 void TestMarkBool::doPrintClose(
101  std::ostream& os_,
102  const std::string& prefix_) const {
103  /* -- nothing to do */
104 }
105 
106 void TestMarkBool::doSerializeMark(
107  TestMarkOut& serializer_) const {
108  serializer_.writeTypeMark(SERIALIZE_TYPE_MARK);
109  serializer_.writeInt(value ? 1 : 0);
110 }
111 
112 void TestMarkBool::doDeserializeMark(
113  TestMarkFactory& factory_,
114  TestMarkIn& deserializer_) {
115  auto value_(deserializer_.readInt());
116  switch(value_) {
117  case 0:
118  value = false;
119  break;
120  case 1:
121  value = true;
122  break;
123  default:
124  throw ExcTestMarkIn("invalid bool value " + std::to_string(value_));
125  }
126 }
127 
128 } /* namespace OTest2 */
testmarkhash.h
OTest2::TestMarkBool::TestMarkBool
TestMarkBool(bool value_)
Ctor.
Definition: testmarkbool.cpp:39
OTest2::TestMarkHashCode
std::uint64_t TestMarkHashCode
Definition: testmarkhashcode.h:28
OTest2::TestMarkHash::hashBasicType
static TestMarkHashCode hashBasicType(const char *type_name_, Type_ value_)
Definition: testmarkhash.h:122
OTest2::TestMarkBool::~TestMarkBool
virtual ~TestMarkBool()
Dtor.
Definition: testmarkbool.cpp:51
exctestmarkin.h
OTest2
Definition: assertbean.h:25
testmarkin.h
testmarkout.h
testmarkbool.h
OTest2::TestMarkBool::typeMark
static const char * typeMark()
Definition: testmarkbool.cpp:55
value
std::string value
Definition: runnerfiltertags.cpp:503