William A. Kennington III | 8c5f28c | 2022-12-07 01:21:36 -0800 | [diff] [blame] | 1 | #include <stdplus/numeric/endian.hpp> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace stdplus |
| 8 | { |
| 9 | |
| 10 | TEST(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 |