blob: d8f2ae89f3ca6e38d7a519ce463d420fedb98fae [file] [log] [blame]
William A. Kennington III8c5f28c2022-12-07 01:21:36 -08001#include <stdplus/numeric/endian.hpp>
2
3#include <array>
4
5#include <gtest/gtest.h>
6
7namespace stdplus
8{
9
10TEST(Byteswap, Swap)
11{
12 EXPECT_EQ(38, bswap(uint8_t{38}));
13 EXPECT_EQ(38 << 8, bswap(uint16_t{38}));
14 EXPECT_EQ(0x240082fe, bswap(uint32_t{0xfe820024}));
15 EXPECT_EQ(0x240082fe00000000, bswap(uint64_t{0xfe820024}));
16 struct
17 {
18 std::array<char, 4> a = {1, 2, 3, 4};
19 } s;
20 EXPECT_EQ((std::array<char, 4>{4, 3, 2, 1}), bswap(s).a);
21 EXPECT_EQ(40, ntoh(hton(40)));
22}
23
24} // namespace stdplus