Add tests for <endian.h>.

Also, for the stuff that's also in <netinet/in.h> as real functions,
check that they're there too (and as functions rather than macros,
since that was historically not true).

Bug: http://b/28432448
Test: ran tests
Change-Id: I7e4ae926f7e02de3b6dd38d1953e5b3b43d44f74
diff --git a/tests/netinet_in_test.cpp b/tests/netinet_in_test.cpp
index a337770..c0d3bc8 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 @@
   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
+}