diff options
Diffstat (limited to 'tests/netinet_in_test.cpp')
-rw-r--r-- | tests/netinet_in_test.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/netinet_in_test.cpp b/tests/netinet_in_test.cpp index a3377709f..c0d3bc80a 100644 --- a/tests/netinet_in_test.cpp +++ b/tests/netinet_in_test.cpp @@ -20,6 +20,16 @@ #include <gtest/gtest.h> +#include <android-base/macros.h> + +static constexpr uint16_t le16 = 0x1234; +static constexpr uint32_t le32 = 0x12345678; +static constexpr uint64_t le64 = 0x123456789abcdef0; + +static constexpr uint16_t be16 = 0x3412; +static constexpr uint32_t be32 = 0x78563412; +static constexpr uint64_t be64 = 0xf0debc9a78563412; + TEST(netinet_in, bindresvport) { // This isn't something we can usually test, so just check the symbol's there. ASSERT_EQ(-1, bindresvport(-1, nullptr)); @@ -34,3 +44,35 @@ TEST(netinet_in, in6addr_loopback) { in6_addr loopback = IN6ADDR_LOOPBACK_INIT; ASSERT_EQ(0, memcmp(&loopback, &in6addr_loopback, sizeof(in6addr_loopback))); } + +TEST(netinet_in, htons_function) { + ASSERT_EQ(be16, (htons)(le16)); +} + +TEST(netinet_in, htonl_function) { + ASSERT_EQ(be32, (htonl)(le32)); +} + +TEST(netinet_in, htonq_macro) { +#if defined(__BIONIC__) + ASSERT_EQ(be64, htonq(le64)); +#else + UNUSED(be64); +#endif +} + +TEST(netinet_in, ntohs_function) { + ASSERT_EQ(le16, (ntohs)(be16)); +} + +TEST(netinet_in, ntohl_function) { + ASSERT_EQ(le32, (ntohl)(be32)); +} + +TEST(netinet_in, ntohq_macro) { +#if defined(__BIONIC__) + ASSERT_EQ(le64, ntohq(be64)); +#else + UNUSED(le64); +#endif +} |