Skip to content

Commit b8ac820

Browse files
beinhaerterWerner Henze
and
Werner Henze
authored
Force unit tests for byte to use GSL implementation (#1176)
When setting `GSL_USE_STD_BYTE` to zero, then the unit test does not compile because `byte` is ambiguous (could be `std::byte` or `gsl::byte`). So `gsl::` prefix is needed for `byte`. It looks like the unit tests never ran on a platform where `gsl::byte` is not based on `std::byte`. It does not make much sense to test `std::byte` for compliance, so make the unit tests based on the GSL implementation of `gsl::byte` (`#define GSL_USE_STD_BYTE 0`). Co-authored-by: Werner Henze <[email protected]>
1 parent 2724630 commit b8ac820

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/byte_tests.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <gtest/gtest.h>
1818

19+
#define GSL_USE_STD_BYTE 0
1920
#include <gsl/byte> // for to_byte, to_integer, byte, operator&, ope...
2021

2122
using namespace std;
@@ -33,28 +34,28 @@ int modify_both(gsl::byte& b, int& i)
3334
TEST(byte_tests, construction)
3435
{
3536
{
36-
const byte b = static_cast<byte>(4);
37+
const gsl::byte b = static_cast<gsl::byte>(4);
3738
EXPECT_TRUE(static_cast<unsigned char>(b) == 4);
3839
}
3940

4041
{
41-
const byte b = byte(12);
42+
const gsl::byte b = gsl::byte(12);
4243
EXPECT_TRUE(static_cast<unsigned char>(b) == 12);
4344
}
4445

4546
{
46-
const byte b = to_byte<12>();
47+
const gsl::byte b = to_byte<12>();
4748
EXPECT_TRUE(static_cast<unsigned char>(b) == 12);
4849
}
4950
{
5051
const unsigned char uc = 12;
51-
const byte b = to_byte(uc);
52+
const gsl::byte b = to_byte(uc);
5253
EXPECT_TRUE(static_cast<unsigned char>(b) == 12);
5354
}
5455

5556
#if defined(__cplusplus) && (__cplusplus >= 201703L)
5657
{
57-
const byte b{14};
58+
const gsl::byte b{14};
5859
EXPECT_TRUE(static_cast<unsigned char>(b) == 14);
5960
}
6061
#endif
@@ -68,9 +69,9 @@ TEST(byte_tests, construction)
6869

6970
TEST(byte_tests, bitwise_operations)
7071
{
71-
const byte b = to_byte<0xFF>();
72+
const gsl::byte b = to_byte<0xFF>();
7273

73-
byte a = to_byte<0x00>();
74+
gsl::byte a = to_byte<0x00>();
7475
EXPECT_TRUE((b | a) == to_byte<0xFF>());
7576
EXPECT_TRUE(a == to_byte<0x00>());
7677

@@ -104,7 +105,7 @@ TEST(byte_tests, bitwise_operations)
104105

105106
TEST(byte_tests, to_integer)
106107
{
107-
const byte b = to_byte<0x12>();
108+
const gsl::byte b = to_byte<0x12>();
108109

109110
EXPECT_TRUE(0x12 == gsl::to_integer<char>(b));
110111
EXPECT_TRUE(0x12 == gsl::to_integer<short>(b));
@@ -123,7 +124,7 @@ TEST(byte_tests, to_integer)
123124
TEST(byte_tests, aliasing)
124125
{
125126
int i{0};
126-
const int res = modify_both(reinterpret_cast<byte&>(i), i);
127+
const int res = modify_both(reinterpret_cast<gsl::byte&>(i), i);
127128
EXPECT_TRUE(res == i);
128129
}
129130

0 commit comments

Comments
 (0)