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

[tor-commits] [tor/master] Bring the dimap tests up to 100%



commit 7f9a33a800b0d399942ca0aa98c05a71d08926b4
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Aug 17 12:52:01 2015 -0400

    Bring the dimap tests up to 100%
---
 src/test/test_util.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index a6c423d..8b4513d 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -3611,6 +3611,50 @@ test_util_di_ops(void *arg)
   ;
 }
 
+static void
+test_util_di_map(void *arg)
+{
+  (void)arg;
+  di_digest256_map_t *dimap = NULL;
+  uint8_t key1[] = "Robert Anton Wilson            ";
+  uint8_t key2[] = "Martin Gardner, _Fads&fallacies";
+  uint8_t key3[] = "Tom Lehrer, _Be Prepared_.     ";
+  uint8_t key4[] = "Ursula Le Guin,_A Wizard of... ";
+
+  char dflt_entry[] = "'You have made a good beginning', but no more";
+
+  tt_int_op(32, ==, sizeof(key1));
+  tt_int_op(32, ==, sizeof(key2));
+  tt_int_op(32, ==, sizeof(key3));
+
+  tt_ptr_op(dflt_entry, ==, dimap_search(dimap, key1, dflt_entry));
+
+  char *str1 = tor_strdup("You are precisely as big as what you love"
+                          " and precisely as small as what you allow"
+                          " to annoy you.");
+  char *str2 = tor_strdup("Let us hope that Lysenko's success in Russia will"
+                          " serve for many generations to come as another"
+                          " reminder to the world of how quickly and easily"
+                          " a science can be corrupted when ignorant"
+                          " political leaders deem themselves competent"
+                          " to arbitrate scientific disputes");
+  char *str3 = tor_strdup("Don't write naughty words on walls "
+                          "if you can't spell.");
+
+  dimap_add_entry(&dimap, key1, str1);
+  dimap_add_entry(&dimap, key2, str2);
+  dimap_add_entry(&dimap, key3, str3);
+
+  tt_ptr_op(str1, ==, dimap_search(dimap, key1, dflt_entry));
+  tt_ptr_op(str3, ==, dimap_search(dimap, key3, dflt_entry));
+  tt_ptr_op(str2, ==, dimap_search(dimap, key2, dflt_entry));
+  tt_ptr_op(dflt_entry, ==, dimap_search(dimap, key4, dflt_entry));
+
+ done:
+  dimap_free(dimap, tor_free_);
+}
+
+
 /**
  * Test counting high bits
  */
@@ -4395,6 +4439,7 @@ struct testcase_t util_tests[] = {
   UTIL_LEGACY(path_is_relative),
   UTIL_LEGACY(strtok),
   UTIL_LEGACY(di_ops),
+  UTIL_TEST(di_map, 0),
   UTIL_TEST(round_to_next_multiple_of, 0),
   UTIL_TEST(laplace, 0),
   UTIL_TEST(find_str_at_start_of_line, 0),

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