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

[tor-commits] [tor/master] Add unit tests for cast_double_to_int64().



commit 0fcd150959c82add23e82532a29e874ce9e84468
Author: teor <teor2345@xxxxxxxxx>
Date:   Wed May 6 18:08:18 2015 +1000

    Add unit tests for cast_double_to_int64().
---
 src/test/test_util.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index 3310316..3580493 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4237,6 +4237,62 @@ test_util_laplace(void *arg)
   ;
 }
 
+static void
+test_util_cast_double_to_int64(void *arg)
+{
+  (void)arg;
+
+  tt_i64_op(INT64_MIN, ==, cast_double_to_int64(-INFINITY));
+  tt_i64_op(INT64_MIN, ==,
+            cast_double_to_int64(-1.0 * pow(2.0, 64.0) - 1.0));
+  tt_i64_op(INT64_MIN, ==,
+            cast_double_to_int64(-1.0 * pow(2.0, 63.0) - 1.0));
+  tt_i64_op(((int64_t) -1) << 53, ==,
+            cast_double_to_int64(-1.0 * pow(2.0, 53.0)));
+  tt_i64_op((((int64_t) -1) << 53) + 1, ==,
+            cast_double_to_int64(-1.0 * pow(2.0, 53.0) + 1.0));
+  tt_i64_op(-1, ==, cast_double_to_int64(-1.0));
+  tt_i64_op(0, ==, cast_double_to_int64(-0.9));
+  tt_i64_op(0, ==, cast_double_to_int64(-0.1));
+  tt_i64_op(0, ==, cast_double_to_int64(0.0));
+  tt_i64_op(0, ==, cast_double_to_int64(NAN));
+  tt_i64_op(0, ==, cast_double_to_int64(0.1));
+  tt_i64_op(0, ==, cast_double_to_int64(0.9));
+  tt_i64_op(1, ==, cast_double_to_int64(1.0));
+  tt_i64_op((((int64_t) 1) << 53) - 1, ==,
+            cast_double_to_int64(pow(2.0, 53.0) - 1.0));
+  tt_i64_op(((int64_t) 1) << 53, ==,
+            cast_double_to_int64(pow(2.0, 53.0)));
+  tt_i64_op(INT64_MAX, ==,
+            cast_double_to_int64(pow(2.0, 63.0)));
+  tt_i64_op(INT64_MAX, ==,
+            cast_double_to_int64(pow(2.0, 64.0)));
+  tt_i64_op(INT64_MAX, ==, cast_double_to_int64(INFINITY));
+
+ done:
+  ;
+}
+
+static void
+test_util_strclear(void *arg)
+{
+  static const char *vals[] = { "", "a", "abcdef", "abcdefgh", NULL };
+  int i;
+  char *v = NULL;
+  (void)arg;
+
+  for (i = 0; vals[i]; ++i) {
+    size_t n;
+    v = tor_strdup(vals[i]);
+    n = strlen(v);
+    tor_strclear(v);
+    tt_assert(tor_mem_is_zero(v, n+1));
+    tor_free(v);
+  }
+ done:
+  tor_free(v);
+}
+
 #define UTIL_LEGACY(name)                                               \
   { #name, test_util_ ## name , 0, NULL, NULL }
 
@@ -4454,6 +4510,8 @@ struct testcase_t util_tests[] = {
   UTIL_LEGACY(di_ops),
   UTIL_TEST(round_to_next_multiple_of, 0),
   UTIL_TEST(laplace, 0),
+  UTIL_TEST(cast_double_to_int64, 0),
+  UTIL_TEST(strclear, 0),
   UTIL_TEST(find_str_at_start_of_line, 0),
   UTIL_TEST(string_is_C_identifier, 0),
   UTIL_TEST(asprintf, 0),



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