aboutsummaryrefslogtreecommitdiff
path: root/lib/tst/endian_little.cc
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-12-31 16:03:20 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-01-29 11:41:29 +0200
commitf6b7365dc8759d6df5d340e4a68fb75537c07be4 (patch)
treec15614d8dee445dd4c6ae75da2959c701e69daae /lib/tst/endian_little.cc
parentMove blake2s selftest to test/ (diff)
downloadkernel-f6b7365dc8759d6df5d340e4a68fb75537c07be4.tar.xz
blake2: use makefiles instead of meson.build
Diffstat (limited to 'lib/tst/endian_little.cc')
-rw-r--r--lib/tst/endian_little.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/tst/endian_little.cc b/lib/tst/endian_little.cc
new file mode 100644
index 0000000..f28e0e6
--- /dev/null
+++ b/lib/tst/endian_little.cc
@@ -0,0 +1,38 @@
+#include <endian.h>
+#include <gtest/gtest.h>
+
+namespace libk {
+#include "../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));
+}