OTest2
A C++ testing framework
testmarkprefix.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 #include <testmarkprefix.h>
20 
21 #include <iostream>
22 
23 #include <testmarkhash.h>
24 #include <testmarkin.h>
25 #include <testmarkout.h>
26 
27 namespace OTest2 {
28 
30  const char* serialize_type_mark_,
31  const std::string& prefix_) :
32  serialize_type_mark(serialize_type_mark_),
33  prefix(prefix_),
34  hash() {
35  hash.addBasicType(serialize_type_mark_, prefix);
36 }
37 
39  const CtorMark*,
40  const char* serialize_type_mark_) :
41  serialize_type_mark(serialize_type_mark_),
42  prefix(),
43  hash() {
44 
45 }
46 
48 
49 }
50 
51 TestMarkHashCode TestMarkPrefix::doGetHashCode() const noexcept {
52  return hash.getHashCode();
53 }
54 
55 bool TestMarkPrefix::doIsEqual(
56  const TestMark& other_,
57  long double precision_) const {
58  if(!doIsEqualValue(other_, precision_))
59  return false;
60  return doIsEqualPrefixed(other_, precision_);
61 }
62 
63 bool TestMarkPrefix::doIsEqualValue(
64  const TestMark& other_,
65  long double precision_) const {
66  return prefix == static_cast<const TestMarkPrefix*>(&other_)->prefix;
67 }
68 
69 void TestMarkPrefix::doPrintOpen(
70  std::ostream& os_,
71  const std::string& prefix_) const {
72  os_ << prefix_;
73  if(!prefix.empty())
74  os_ << prefix << ' ';
75  const char* pars_(getParenthesis());
76  os_ << pars_[0] << '\n';
77 }
78 
79 void TestMarkPrefix::doPrintClose(
80  std::ostream& os_,
81  const std::string& prefix_) const {
82  const char* pars_(getParenthesis());
83  os_ << prefix_ << pars_[1] << '\n';
84 }
85 
86 void TestMarkPrefix::doSerializeMark(
87  TestMarkOut& serializer_) const {
88  serializer_.writeTypeMark(serialize_type_mark);
89  serializer_.writeString(prefix);
90  serializeItems(serializer_);
91 }
92 
93 void TestMarkPrefix::doDeserializeMark(
94  TestMarkFactory& factory_,
95  TestMarkIn& deserializer_) {
96  prefix = deserializer_.readString();
97  hash.addBasicType(serialize_type_mark, prefix);
98  deserializeItems(factory_, deserializer_);
99 }
100 
101 } /* namespace OTest2 */
OTest2::TestMarkHash::getHashCode
TestMarkHashCode getHashCode() const noexcept
Get currently computed hash code.
Definition: testmarkhash.cpp:68
testmarkhash.h
OTest2::TestMarkPrefix::TestMarkPrefix
TestMarkPrefix(const char *serialize_type_mark_, const std::string &prefix_)
Ctor.
Definition: testmarkprefix.cpp:29
OTest2::TestMarkHashCode
std::uint64_t TestMarkHashCode
Definition: testmarkhashcode.h:28
OTest2::TestMarkPrefix::hash
TestMarkHash hash
Definition: testmarkprefix.h:41
OTest2
Definition: assertbean.h:25
testmarkin.h
OTest2::TestMarkPrefix::~TestMarkPrefix
virtual ~TestMarkPrefix()
Dtor.
Definition: testmarkprefix.cpp:47
testmarkout.h
OTest2::TestMarkHash::addBasicType
void addBasicType(const char *type_name_, const std::uint8_t *data_, std::size_t size_)
Add hash for a value of a basic type.
Definition: testmarkhash.cpp:72
testmarkprefix.h