OTest2
A C++ testing framework
testmarkhash.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 
20 #ifndef OTest2__LIB_TESTMARKHASH_H_
21 #define OTest2__LIB_TESTMARKHASH_H_
22 
23 #include <cstdint>
24 #include <string>
25 
27 
28 namespace OTest2 {
29 
40 class TestMarkHash {
41  private:
42  TestMarkHashCode hash;
43 
44  public:
48  TestMarkHash();
49 
54  TestMarkHash&& other_) noexcept;
55 
59  ~TestMarkHash();
60 
61  /* -- avoid copying */
63  const TestMarkHash&) = delete;
65  const TestMarkHash&) = delete;
66 
73  void addData(
74  const std::uint8_t* data_,
75  std::size_t size_);
76 
80  void addTerminator();
81 
85  void addHashCode(
86  TestMarkHashCode code_);
87 
91  void addString(
92  const char* string_);
93 
97  TestMarkHashCode getHashCode() const noexcept;
98 
106  void addBasicType(
107  const char* type_name_,
108  const std::uint8_t* data_,
109  std::size_t size_);
110 
117  void addBasicType(
118  const char* type_name_,
119  const std::string& value_);
120 
121  template<typename Type_>
123  const char* type_name_,
124  Type_ value_) {
125  TestMarkHash hash_;
126  hash_.addBasicType(
127  type_name_,
128  reinterpret_cast<const std::uint8_t*>(&value_),
129  sizeof(value_));
130  return hash_.getHashCode();
131  }
132 
134  const char* type_name_,
135  const std::string& value_);
136 };
137 
138 } /* -- namespace OTest2 */
139 
140 #endif /* OTest2__LIB_TESTMARKHASH_H_ */
OTest2::TestMarkHash::addString
void addString(const char *string_)
Append a string literal.
Definition: testmarkhash.cpp:61
OTest2::TestMarkHash::addTerminator
void addTerminator()
Append a terminataor character into the hash.
Definition: testmarkhash.cpp:51
OTest2::TestMarkHash::getHashCode
TestMarkHashCode getHashCode() const noexcept
Get currently computed hash code.
Definition: testmarkhash.cpp:68
testmarkhashcode.h
OTest2::TestMarkHash::operator=
TestMarkHash & operator=(const TestMarkHash &)=delete
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::TestMarkHash::TestMarkHash
TestMarkHash()
Ctor.
Definition: testmarkhash.cpp:26
OTest2::TestMarkHash::~TestMarkHash
~TestMarkHash()
Dtor.
Definition: testmarkhash.cpp:37
OTest2
Definition: assertbean.h:25
OTest2::TestMarkHash
A simple generator of a testmark hash.
Definition: testmarkhash.h:40
OTest2::TestMarkHash::addData
void addData(const std::uint8_t *data_, std::size_t size_)
Append piece of data.
Definition: testmarkhash.cpp:41
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
OTest2::TestMarkHash::addHashCode
void addHashCode(TestMarkHashCode code_)
Append a hash code of another testmark.
Definition: testmarkhash.cpp:56