[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Refactor tests for tor_htonll and tor_ntohll



commit c613446ca2fa0d81fcf1f3169a2a6caa8e7a8ba3
Author: overcaffeinated <overcaffeinated@xxxxxxxxxx>
Date:   Thu Nov 3 20:52:11 2016 +0000

    Refactor tests for tor_htonll and tor_ntohll
    
    Following kind feedback from dgoulet: add tests for min (0) and
    max (UINT64_MAX) values. Rename expected results to something more
    sensible than 'n'.
---
 src/test/test_util.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index ea6e946..b74f658 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -5616,14 +5616,23 @@ static void
 test_util_htonll(void *arg)
 {
   (void)arg;
-  const uint64_t n = 0x1122334455667788;
+#ifdef WORDS_BIGENDIAN
+  const uint64_t res_be = 0x8877665544332211;
+#else
+  const uint64_t res_le = 0x1122334455667788;
+#endif
+
+  tt_u64_op(0, OP_EQ, tor_htonll(0));
+  tt_u64_op(0, OP_EQ, tor_ntohll(0));
+  tt_u64_op(UINT64_MAX, OP_EQ, tor_htonll(UINT64_MAX));
+  tt_u64_op(UINT64_MAX, OP_EQ, tor_ntohll(UINT64_MAX));
 
 #ifdef WORDS_BIGENDIAN
-  tt_u64_op(tor_htonll(n), OP_EQ, n);
-  tt_u64_op(tor_ntohll(0x8877665544332211), OP_EQ, 0x8877665544332211);
+  tt_u64_op(res_be, OP_EQ, tor_htonll(0x8877665544332211));
+  tt_u64_op(res_be, OP_EQ, tor_ntohll(0x8877665544332211));
 #else
-  tt_u64_op(tor_htonll(n), OP_EQ, 0x8877665544332211);
-  tt_u64_op(tor_ntohll(0x8877665544332211), OP_EQ, n);
+  tt_u64_op(res_le, OP_EQ, tor_htonll(0x8877665544332211));
+  tt_u64_op(res_le, OP_EQ, tor_ntohll(0x8877665544332211));
 #endif
 
  done:



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits