]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add unit test to check if we detected byte order correctly
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 14 Jul 2013 18:24:04 +0000 (20:24 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 14 Jul 2013 18:24:04 +0000 (20:24 +0200)
pdns/test-misc_hh.cc

index b8e94bf5a7f47369433d0481c9e0fc6b9878e28d..d50201e6515e325070c454c7f6a1520c204dec16 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <boost/test/unit_test.hpp>
 #include "misc.hh"
+#include "dns.hh"
 #include <utility>
 
 using std::string;
@@ -67,6 +68,17 @@ BOOST_AUTO_TEST_CASE(test_AtomicCounter) {
     BOOST_CHECK_EQUAL(ac, 2);
 }
 
+BOOST_AUTO_TEST_CASE(test_endianness) {
+  uint32_t i = 1;
+#if BYTE_ORDER == BIG_ENDIAN
+  BOOST_CHECK_EQUAL(i, htonl(i));
+#elif BYTE_ORDER == LITTLE_ENDIAN 
+  uint32_t j=0x01000000;
+  BOOST_CHECK_EQUAL(i, ntohl(j));
+#else
+  BOOST_FAIL("Did not detect endianness at all");
+#endif
+}
 
 BOOST_AUTO_TEST_CASE(test_parseService) {
     ServiceTuple tp;