Skip to content

Commit 93a61d6

Browse files
Working around Catch2 link issues with std::byte formatting
1 parent 9626380 commit 93a61d6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

test/extract_append_test.cpp

+23-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "serialize/extract_append.hpp"
2121

2222
#include "utility/repeat.hpp"
23-
#include "utility/make_byte_array.hpp"
23+
#include "utility/byte_array.hpp"
2424

2525
constexpr std::uint32_t val1 = 0xDDCCBBAA;
2626
constexpr char val2 = static_cast<char>(0xEE);
@@ -44,17 +44,17 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
4444

4545
SECTION ("Append_val with a single value, big endian") {
4646
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);
5151
}
5252
SECTION ("Append_val with a single value, little endian") {
5353
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);
5858
}
5959

6060
SECTION ("Append_val with multiple values, big endian") {
@@ -65,7 +65,8 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
6565
REQUIRE(chops::append_val<std::endian::big>(ptr, val4) == 8u); ptr += sizeof(val4);
6666
REQUIRE(chops::append_val<std::endian::big>(ptr, val5) == 4u); ptr += sizeof(val5);
6767
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])); } );
6970
}
7071
SECTION ("Append_val with multiple values, little endian") {
7172
std::byte* ptr = buf;
@@ -75,7 +76,8 @@ TEST_CASE ( "Append values into a buffer", "[append_val]" ) {
7576
REQUIRE(chops::append_val<std::endian::little>(ptr, val4) == 8u); ptr += sizeof(val4);
7677
REQUIRE(chops::append_val<std::endian::little>(ptr, val5) == 4u); ptr += sizeof(val5);
7778
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])); } );
7981
}
8082
}
8183

@@ -95,7 +97,7 @@ TEST_CASE ( "Extract values from a buffer", "[extract_val]" ) {
9597
REQUIRE(v3 == val3);
9698
REQUIRE(v4 == val4);
9799
REQUIRE(v5 == val5);
98-
REQUIRE(v6 == val6);
100+
REQUIRE(std::to_integer<int>(v6) == std::to_integer<int>(val6));
99101
}
100102
SECTION ( "Extract_val for multiple values in little endian buf") {
101103
const std::byte* ptr = net_buf_little.data();
@@ -111,7 +113,7 @@ TEST_CASE ( "Extract values from a buffer", "[extract_val]" ) {
111113
REQUIRE(v3 == val3);
112114
REQUIRE(v4 == val4);
113115
REQUIRE(v5 == val5);
114-
REQUIRE(v6 == val6);
116+
REQUIRE(std::to_integer<int>(v6) == std::to_integer<int>(val6));
115117
}
116118
}
117119

@@ -131,9 +133,9 @@ TEST_CASE ( "Append and extract variable length integers","[append_var_int]" ) {
131133

132134
{
133135
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);
137139

138140
auto output = chops::extract_var_int<unsigned int>(test_buf, outsize);
139141

@@ -163,23 +165,23 @@ TEST_CASE ( "Append var len integer of 127","[append_var_int]" ) {
163165

164166
std::byte test_buf [7];
165167
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);
167169
REQUIRE(outsize == 1);
168170
}
169171
TEST_CASE ( "Append var len integer of 128","[append_var_int]" ) {
170172

171173
std::byte test_buf [7];
172174
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);
175177
REQUIRE(outsize == 2);
176178
}
177179
TEST_CASE ( "Append var len integer larger than 4 bytes","[append_var_int]" ) {
178180

179181
std::byte test_buf [7];
180182
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);
183185
REQUIRE(outsize == 5);
184186
}
185187

0 commit comments

Comments
 (0)