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

[tor-commits] [tor/master] Move some useful unittest functions to a testhelper.c file.



commit 532ab7e13cac4c9ba1cdb1e6e008b0e5cb2afff4
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Mon Sep 15 15:50:38 2014 +0300

    Move some useful unittest functions to a testhelper.c file.
    
    This commit only moves code.
---
 src/test/test_entrynodes.c |   55 -------------------------------------
 src/test/testhelper.c      |   65 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 55 deletions(-)

diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index fab82c3..0f7fcb0 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -37,61 +37,6 @@ get_or_state_replacement(void)
   return dummy_state;
 }
 
-/* NOP replacement for router_descriptor_is_older_than() */
-static int
-router_descriptor_is_older_than_replacement(const routerinfo_t *router,
-                                            int seconds)
-{
-  (void) router;
-  (void) seconds;
-  return 0;
-}
-
-/* Number of descriptors contained in test_descriptors.txt. */
-#define NUMBER_OF_DESCRIPTORS 8
-
-/** Parse a file containing router descriptors and load them to our
-    routerlist. This function is used to setup an artificial network
-    so that we can conduct entry guard tests. */
-static void
-setup_fake_routerlist(void)
-{
-  int retval;
-  routerlist_t *our_routerlist = NULL;
-  smartlist_t *our_nodelist = NULL;
-
-  /* Read the file that contains our test descriptors. */
-
-  /* We need to mock this function otherwise the descriptors will not
-     accepted as they are too old. */
-  MOCK(router_descriptor_is_older_than,
-       router_descriptor_is_older_than_replacement);
-
-  /* Load all the test descriptors to the routerlist. */
-  retval = router_load_routers_from_string(TEST_DESCRIPTORS,
-                                           NULL, SAVED_IN_JOURNAL,
-                                           NULL, 0, NULL);
-  tt_int_op(retval, ==, NUMBER_OF_DESCRIPTORS);
-
-  /* Sanity checking of routerlist and nodelist. */
-  our_routerlist = router_get_routerlist();
-  tt_int_op(smartlist_len(our_routerlist->routers), ==, NUMBER_OF_DESCRIPTORS);
-  routerlist_assert_ok(our_routerlist);
-
-  our_nodelist = nodelist_get_list();
-  tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
-
-  /* Mark all routers as non-guards but up and running! */
-  SMARTLIST_FOREACH_BEGIN(our_nodelist, node_t *, node) {
-    node->is_running = 1;
-    node->is_valid = 1;
-    node->is_possible_guard = 0;
-  } SMARTLIST_FOREACH_END(node);
-
- done:
-  UNMOCK(router_descriptor_is_older_than);
-}
-
 /* Unittest cleanup function: Cleanup the fake network. */
 static int
 fake_network_cleanup(const struct testcase_t *testcase, void *ptr)
diff --git a/src/test/testhelper.c b/src/test/testhelper.c
new file mode 100644
index 0000000..4e23f0c
--- /dev/null
+++ b/src/test/testhelper.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 2014, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#define ROUTERLIST_PRIVATE
+
+#include "or.h"
+#include "routerlist.h"
+#include "testhelper.h"
+#include "nodelist.h"
+
+#include "test.h"
+
+#include "test_descriptors.inc"
+
+/* NOP replacement for router_descriptor_is_older_than() */
+static int
+router_descriptor_is_older_than_replacement(const routerinfo_t *router,
+                                            int seconds)
+{
+  (void) router;
+  (void) seconds;
+  return 0;
+}
+
+/** Parse a file containing router descriptors and load them to our
+    routerlist. This function is used to setup an artificial network
+    so that we can conduct entry guard tests. */
+static void
+setup_fake_routerlist(void)
+{
+  int retval;
+  routerlist_t *our_routerlist = NULL;
+  smartlist_t *our_nodelist = NULL;
+
+  /* Read the file that contains our test descriptors. */
+
+  /* We need to mock this function otherwise the descriptors will not
+     accepted as they are too old. */
+  MOCK(router_descriptor_is_older_than,
+       router_descriptor_is_older_than_replacement);
+
+  /* Load all the test descriptors to the routerlist. */
+  retval = router_load_routers_from_string(TEST_DESCRIPTORS,
+                                           NULL, SAVED_IN_JOURNAL,
+                                           NULL, 0, NULL);
+  tt_int_op(retval, ==, NUMBER_OF_DESCRIPTORS);
+
+  /* Sanity checking of routerlist and nodelist. */
+  our_routerlist = router_get_routerlist();
+  tt_int_op(smartlist_len(our_routerlist->routers), ==, NUMBER_OF_DESCRIPTORS);
+  routerlist_assert_ok(our_routerlist);
+
+  our_nodelist = nodelist_get_list();
+  tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
+
+  /* Mark all routers as non-guards but up and running! */
+  SMARTLIST_FOREACH_BEGIN(our_nodelist, node_t *, node) {
+    node->is_running = 1;
+    node->is_valid = 1;
+    node->is_possible_guard = 0;
+  } SMARTLIST_FOREACH_END(node);
+
+ done:
+  UNMOCK(router_descriptor_is_older_than);
+}



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