aboutsummaryrefslogtreecommitdiff
path: root/lib/tst/endian_little.cc
blob: 9c8c73babf3b384f6e3c53d1cb49f52db8afb351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <endian.h>
#include <gtest/gtest.h>

namespace libk {
#include "../libk/endian/little.c"
} // namespace libk

TEST(endian_little, htole16)
{
  EXPECT_EQ(static_cast<uint16_t>(0xabcd), libk::htole16(0xabcd));
  EXPECT_EQ(libk::htole16(0xabcd), htole16(0xabcd));
}
TEST(endian_little, htole32)
{
  EXPECT_EQ(static_cast<uint32_t>(0xabcd0123), libk::htole32(0xabcd0123));
  EXPECT_EQ(libk::htole32(0xabcd0123), htole32(0xabcd0123));
}
TEST(endian_little, htole64)
{
  EXPECT_EQ(static_cast<uint64_t>(0x0123456789abcdef), libk::htole64(0x0123456789abcdef));
  EXPECT_EQ(libk::htole64(0xabcdef0123456789), htole64(0xabcdef0123456789));
}

TEST(endian_little, htobe16)
{
  EXPECT_EQ(static_cast<uint16_t>(0xabcd), libk::htobe16(0xcdab));
  EXPECT_EQ(libk::htobe16(0xabcd), htobe16(0xabcd));
}
TEST(endian_little, htobe32)
{
  EXPECT_EQ(static_cast<uint32_t>(0xabcd0123), libk::htobe32(0x2301cdab));
  EXPECT_EQ(libk::htobe32(0xabcd0123), htobe32(0xabcd0123));
}
TEST(endian_little, htobe64)
{
  EXPECT_EQ(static_cast<uint64_t>(0x0123456789abcdef), libk::htobe64(0xefcdab8967452301));
  EXPECT_EQ(libk::htobe64(0xabcdef0123456789), htobe64(0xabcdef0123456789));
}