Skip to content

Commit cac94b9

Browse files
Adding generic append test
1 parent e13405e commit cac94b9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/shared_buffer_test.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <list>
2121
#include <string_view>
2222
#include <span>
23-
#include <span> // std::bit_cast
23+
#include <bit> // std::bit_cast
2424

2525
#include "buffer/shared_buffer.hpp"
2626

@@ -32,12 +32,24 @@ constexpr int N = 11;
3232

3333

3434
template <typename SB, typename PT>
35-
void generic_pointer_construction_test() {
35+
SB generic_pointer_construction_test() {
3636
auto arr = chops::make_byte_array( 40, 41, 42, 43, 44, 60, 59, 58, 57, 56, 42, 42 );
37-
const PT* ptr = std::bit_cast<const PT *>(arr.data());
37+
auto ptr = std::bit_cast<const PT *>(arr.data());
3838
SB sb(ptr, arr.size());
3939
REQUIRE_FALSE (sb.empty());
4040
chops::repeat(static_cast<int>(arr.size()), [&sb, arr] (int i) { REQUIRE(*(sb.data()+i) == arr[i]); } );
41+
return sb;
42+
}
43+
44+
template <typename PT>
45+
void generic_pointer_append_test() {
46+
auto sb { generic_pointer_construction_test<chops::mutable_shared_buffer, PT>() };
47+
auto sav_sz { sb.size() };
48+
const PT arr[] { 5, 6, 7 };
49+
sb.append (arr, 3);
50+
REQUIRE (sb.size() == (sav_sz + 3));
51+
// sb.append (std::span<PT>(arr, 3));
52+
// REQUIRE (sb.size() == (sav_sz + 6));
4153
}
4254

4355
template <typename SB>
@@ -84,15 +96,15 @@ void byte_vector_move_test() {
8496
REQUIRE_FALSE (bv.size() == sb.size());
8597
}
8698

87-
TEMPLATE_TEST_CASE ( "Checking generic pointer construction",
99+
TEMPLATE_TEST_CASE ( "Generic pointer construction",
88100
"[common]",
89-
char, unsigned char, signed char ) {
101+
char, unsigned char, signed char, std::uint8_t ) {
90102
generic_pointer_construction_test<chops::mutable_shared_buffer, TestType>();
91103
generic_pointer_construction_test<chops::const_shared_buffer, TestType>();
92104
}
93105

94106

95-
TEMPLATE_TEST_CASE ( "Shared buffer common methods test",
107+
TEMPLATE_TEST_CASE ( "Shared buffer common methods",
96108
"[const_shared_buffer] [common]",
97109
chops::mutable_shared_buffer, chops::const_shared_buffer ) {
98110
auto arr = chops::make_byte_array ( 80, 81, 82, 83, 84, 90, 91, 92 );
@@ -213,6 +225,12 @@ TEST_CASE ( "Mutable shared buffer append",
213225
}
214226
}
215227

228+
TEMPLATE_TEST_CASE ( "Generic pointer append",
229+
"[mutable_shared_buffer] [pointer] [append]",
230+
char, unsigned char, signed char, std::uint8_t ) {
231+
generic_pointer_append_test<TestType>();
232+
}
233+
216234
TEST_CASE ( "Compare a mutable shared_buffer with a const shared buffer",
217235
"[mutable_shared_buffer] [const_shared_buffer] [compare]" ) {
218236

0 commit comments

Comments
 (0)