20
20
#include " serialize/extract_append.hpp"
21
21
22
22
#include " utility/repeat.hpp"
23
- #include " utility/make_byte_array .hpp"
23
+ #include " utility/byte_array .hpp"
24
24
25
25
constexpr std::uint32_t val1 = 0xDDCCBBAA ;
26
26
constexpr char val2 = static_cast <char >(0xEE );
@@ -44,17 +44,17 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
44
44
45
45
SECTION (" Append_val with a single value, big endian" ) {
46
46
REQUIRE (chops::append_val<std::endian::big>(buf, v) == 4u );
47
- REQUIRE (buf[0 ] == static_cast <std::byte>( 0x04 ) );
48
- REQUIRE (buf[1 ] == static_cast <std::byte>( 0x03 ) );
49
- REQUIRE (buf[2 ] == static_cast <std::byte>( 0x02 ) );
50
- REQUIRE (buf[3 ] == static_cast <std::byte>( 0x01 ) );
47
+ REQUIRE (std::to_integer< int >( buf[0 ]) == 0x04 );
48
+ REQUIRE (std::to_integer< int >( buf[1 ]) == 0x03 );
49
+ REQUIRE (std::to_integer< int >( buf[2 ]) == 0x02 );
50
+ REQUIRE (std::to_integer< int >( buf[3 ]) == 0x01 );
51
51
}
52
52
SECTION (" Append_val with a single value, little endian" ) {
53
53
REQUIRE (chops::append_val<std::endian::little>(buf, v) == 4u );
54
- REQUIRE (buf[0 ] == static_cast <std::byte>( 0x01 ) );
55
- REQUIRE (buf[1 ] == static_cast <std::byte>( 0x02 ) );
56
- REQUIRE (buf[2 ] == static_cast <std::byte>( 0x03 ) );
57
- REQUIRE (buf[3 ] == static_cast <std::byte>( 0x04 ) );
54
+ REQUIRE (std::to_integer< int >( buf[0 ]) == 0x01 );
55
+ REQUIRE (std::to_integer< int >( buf[1 ]) == 0x02 );
56
+ REQUIRE (std::to_integer< int >( buf[2 ]) == 0x03 );
57
+ REQUIRE (std::to_integer< int >( buf[3 ]) == 0x04 );
58
58
}
59
59
60
60
SECTION (" Append_val with multiple values, big endian" ) {
@@ -65,7 +65,8 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
65
65
REQUIRE (chops::append_val<std::endian::big>(ptr, val4) == 8u ); ptr += sizeof (val4);
66
66
REQUIRE (chops::append_val<std::endian::big>(ptr, val5) == 4u ); ptr += sizeof (val5);
67
67
REQUIRE (chops::append_val<std::endian::big>(ptr, val6) == 1u );
68
- chops::repeat (arr_sz, [&buf] (int i) { REQUIRE (buf[i] == net_buf_big[i]); } );
68
+ chops::repeat (arr_sz, [&buf] (int i) {
69
+ REQUIRE (std::to_integer<int >(buf[i]) == std::to_integer<int >(net_buf_big[i])); } );
69
70
}
70
71
SECTION (" Append_val with multiple values, little endian" ) {
71
72
std::byte* ptr = buf;
@@ -75,7 +76,8 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
75
76
REQUIRE (chops::append_val<std::endian::little>(ptr, val4) == 8u ); ptr += sizeof (val4);
76
77
REQUIRE (chops::append_val<std::endian::little>(ptr, val5) == 4u ); ptr += sizeof (val5);
77
78
REQUIRE (chops::append_val<std::endian::little>(ptr, val6) == 1u );
78
- chops::repeat (arr_sz, [&buf] (int i) { REQUIRE (buf[i] == net_buf_little[i]); } );
79
+ chops::repeat (arr_sz, [&buf] (int i) {
80
+ REQUIRE (std::to_integer<int >(buf[i]) == std::to_integer<int >(net_buf_little[i])); } );
79
81
}
80
82
}
81
83
@@ -95,7 +97,7 @@ TEST_CASE ( "Extract values from a buffer", "[extract_val]" ) {
95
97
REQUIRE (v3 == val3);
96
98
REQUIRE (v4 == val4);
97
99
REQUIRE (v5 == val5);
98
- REQUIRE (v6 == val6);
100
+ REQUIRE (std::to_integer< int >(v6) == std::to_integer< int >( val6) );
99
101
}
100
102
SECTION ( " Extract_val for multiple values in little endian buf" ) {
101
103
const std::byte* ptr = net_buf_little.data ();
@@ -111,7 +113,7 @@ TEST_CASE ( "Extract values from a buffer", "[extract_val]" ) {
111
113
REQUIRE (v3 == val3);
112
114
REQUIRE (v4 == val4);
113
115
REQUIRE (v5 == val5);
114
- REQUIRE (v6 == val6);
116
+ REQUIRE (std::to_integer< int >(v6) == std::to_integer< int >( val6) );
115
117
}
116
118
}
117
119
@@ -131,9 +133,9 @@ TEST_CASE ( "Append and extract variable length integers","[append_var_int]" ) {
131
133
132
134
{
133
135
auto outsize = chops::append_var_int<std::uint32_t >(test_buf, 0xCAFE );
134
- REQUIRE (static_cast <int > (test_buf[0 ]) == 254 );
135
- REQUIRE (static_cast <int > (test_buf[1 ]) == 149 );
136
- REQUIRE (static_cast <int > (test_buf[2 ]) == 3 );
136
+ REQUIRE (std::to_integer <int >(test_buf[0 ]) == 254 );
137
+ REQUIRE (std::to_integer <int >(test_buf[1 ]) == 149 );
138
+ REQUIRE (std::to_integer <int >(test_buf[2 ]) == 3 );
137
139
138
140
auto output = chops::extract_var_int<unsigned int >(test_buf, outsize);
139
141
@@ -163,23 +165,23 @@ TEST_CASE ( "Append var len integer of 127","[append_var_int]" ) {
163
165
164
166
std::byte test_buf [7 ];
165
167
auto outsize = chops::append_var_int<unsigned int >(test_buf, 0x7F );
166
- REQUIRE (static_cast < unsigned int > (test_buf[0 ]) == 127 );
168
+ REQUIRE (std::to_integer< int >(test_buf[0 ]) == 127 );
167
169
REQUIRE (outsize == 1 );
168
170
}
169
171
TEST_CASE ( " Append var len integer of 128" ," [append_var_int]" ) {
170
172
171
173
std::byte test_buf [7 ];
172
174
auto outsize = chops::append_var_int<unsigned int >(test_buf, 0x80 );
173
- REQUIRE (static_cast < unsigned int > (test_buf[0 ]) == 128 ); // byte flag set
174
- REQUIRE (static_cast < unsigned int > (test_buf[1 ]) == 1 );
175
+ REQUIRE (std::to_integer< int >(test_buf[0 ]) == 128 ); // byte flag set
176
+ REQUIRE (std::to_integer< int >(test_buf[1 ]) == 1 );
175
177
REQUIRE (outsize == 2 );
176
178
}
177
179
TEST_CASE ( " Append var len integer larger than 4 bytes" ," [append_var_int]" ) {
178
180
179
181
std::byte test_buf [7 ];
180
182
auto outsize = chops::append_var_int<unsigned int >(test_buf, 0x10000000 );
181
- REQUIRE (static_cast < unsigned int > (test_buf[0 ]) == 128 ); // byte flag set
182
- REQUIRE (static_cast < unsigned int > (test_buf[4 ]) == 1 );
183
+ REQUIRE (std::to_integer< int >(test_buf[0 ]) == 128 ); // byte flag set
184
+ REQUIRE (std::to_integer< int >(test_buf[4 ]) == 1 );
183
185
REQUIRE (outsize == 5 );
184
186
}
185
187
0 commit comments