OTest2
A C++ testing framework
testmarklist.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 <testmarklist.h>
20 
21 #include <assert.h>
22 
23 #include <testmarkhash.h>
24 #include <testmarkin.h>
25 #include <testmarkout.h>
26 
27 namespace OTest2 {
28 
29 namespace {
30 
31 const char SERIALIZE_TYPE_MARK[] = "ot2:list";
32 
33 } /* -- namespace */
34 
36  TestMarkPrefix(SERIALIZE_TYPE_MARK, ""),
37  list() {
38 
39 }
40 
42  const std::string& prefix_) :
43  TestMarkPrefix(SERIALIZE_TYPE_MARK, prefix_) {
44 
45 }
46 
48  const CtorMark* ctor_mark_) :
49  TestMarkPrefix(ctor_mark_, SERIALIZE_TYPE_MARK),
50  list() {
51 
52 }
53 
55 
56 }
57 
58 const char* TestMarkList::typeMark() {
59  return SERIALIZE_TYPE_MARK;
60 }
61 
62 bool TestMarkList::doIsEqualPrefixed(
63  const TestMark& other_,
64  long double precision_) const {
65  const TestMarkList* o_(static_cast<const TestMarkList*>(&other_));
66  if(list.size() != o_->list.size())
67  return false;
68  for(int i_(0); i_ < list.size(); ++i_)
69  if(!list[i_]->isEqual(*o_->list[i_], precision_))
70  return false;
71  return true;
72 }
73 
74 void TestMarkList::doDiffArray(
75  int level_,
76  std::vector<LinearizedRecord>& array_) const
77 {
78  for(const auto& item_ : list) {
79  array_.push_back({level_, item_.get(), ""});
80  }
81 }
82 
83 void TestMarkList::doLinearizedMark(
84  int level_,
85  const std::string& label_,
86  std::vector<LinearizedRecord>& array_) const {
87  array_.push_back({level_, this, label_});
88  for(const auto& item_ : list) {
89  item_->doLinearizedMark(level_ + 1, "", array_);
90  }
91 }
92 
93 const char* TestMarkList::getParenthesis() const {
94  return "[]";
95 }
96 
97 void TestMarkList::serializeItems(
98  TestMarkOut& serializer_) const {
99  serializer_.writeInt(list.size());
100  for(const auto& item_ : list) {
101  item_->serializeMark(serializer_);
102  }
103 }
104 
105 void TestMarkList::deserializeItems(
106  TestMarkFactory& factory_,
107  TestMarkIn& deserializer_) {
108  const std::int64_t size_(deserializer_.readInt());
109  for(std::int64_t i_(0); i_ < size_; ++i_) {
110  TestMarkPtr item_(TestMarkIn::deserialize(factory_, deserializer_));
111  append(item_);
112  }
113 }
114 
116  TestMarkPtr mark_) {
117  assert(mark_ != nullptr);
118 
119  list.push_back(mark_);
120  hash.addHashCode(mark_->getHashCode());
122 }
123 
124 } /* namespace OTest2 */
OTest2::TestMarkHash::addTerminator
void addTerminator()
Append a terminataor character into the hash.
Definition: testmarkhash.cpp:51
OTest2::TestMark::isEqual
bool isEqual(const TestMark &other_, long double precision_=DEFAULT_FLOAT_PRECISION) const
Compare two marks for equality.
Definition: testmark.cpp:87
testmarkhash.h
OTest2::TestMarkList::~TestMarkList
virtual ~TestMarkList()
Dtor.
Definition: testmarklist.cpp:54
OTest2::TestMarkIn::deserialize
static TestMarkPtr deserialize(TestMarkFactory &factory_, TestMarkIn &deserializer_)
Deserialize a testmark.
Definition: testmarkin.cpp:37
OTest2::TestMarkPrefix
A generic test mark with string prefix.
Definition: testmarkprefix.h:35
OTest2::TestMarkPrefix::hash
TestMarkHash hash
Definition: testmarkprefix.h:41
OTest2::TestMarkList::append
void append(TestMarkPtr mark_)
Append a test mark into the list.
Definition: testmarklist.cpp:115
OTest2::TestMarkList::TestMarkList
TestMarkList()
Ctor.
Definition: testmarklist.cpp:35
OTest2::TestMarkPtr
std::shared_ptr< TestMark > TestMarkPtr
Definition: testmarkptr.h:26
OTest2
Definition: assertbean.h:25
testmarkin.h
testmarklist.h
testmarkout.h
OTest2::TestMarkList::typeMark
static const char * typeMark()
Get serialization typemark.
Definition: testmarklist.cpp:58
OTest2::TestMarkList
Ordered list of nested test marks.
Definition: testmarklist.h:34
OTest2::TestMark
Generic interface of a test mark node.
Definition: testmark.h:41
OTest2::TestMarkHash::addHashCode
void addHashCode(TestMarkHashCode code_)
Append a hash code of another testmark.
Definition: testmarkhash.cpp:56