summaryrefslogtreecommitdiff
path: root/tests/netinet_in_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-02-24 16:19:53 -0800
committerElliott Hughes <enh@google.com>2017-02-24 16:19:53 -0800
commitba267f45d62f5b33a6bbb96147d88fbab017b4ef (patch)
tree60de02ea20e7b3aec2047c9891a711dde41c4fb6 /tests/netinet_in_test.cpp
parent5927b04ce7d9d4727a4a644f8af4040b8dab5d0a (diff)
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
Diffstat (limited to 'tests/netinet_in_test.cpp')
-rw-r--r--tests/netinet_in_test.cpp42
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
+}