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

[tor-commits] [tor/master] Combine test_helpers.[ch] and testhelper.[ch]



commit 6cdb213b6cb9f682c3f72bba974f53f588d71b61
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Feb 18 09:19:38 2015 -0500

    Combine test_helpers.[ch] and testhelper.[ch]
---
 src/test/include.am        |    2 --
 src/test/test_entrynodes.c |    1 -
 src/test/test_helpers.c    |   63 +++++++++++++++++++++++++++++++++++++++++
 src/test/test_helpers.h    |    9 +++++-
 src/test/test_hs.c         |    2 +-
 src/test/testhelper.c      |   67 --------------------------------------------
 src/test/testhelper.h      |   12 --------
 7 files changed, 72 insertions(+), 84 deletions(-)

diff --git a/src/test/include.am b/src/test/include.am
index 1c44ff1..d20d2f6 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -64,7 +64,6 @@ src_test_test_SOURCES = \
 	src/test/test_util.c \
 	src/test/test_helpers.c \
 	src/test/testing_common.c \
-	src/test/testhelper.c \
 	src/ext/tinytest.c
 
 src_test_test_slow_SOURCES = \
@@ -122,7 +121,6 @@ src_test_test_workqueue_LDADD = src/or/libtor-testing.a \
 noinst_HEADERS+= \
 	src/test/fakechans.h \
 	src/test/test.h \
-	src/test/testhelper.h \
 	src/test/test_helpers.h \
 	src/test/test_descriptors.inc \
 	src/test/example_extrainfo.inc \
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 3137edb..17cb9d9 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -18,7 +18,6 @@
 #include "statefile.h"
 #include "config.h"
 
-#include "testhelper.h"
 #include "test_helpers.h"
 
 /* TODO:
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index e5a76e0..8f4a3a9 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -6,11 +6,18 @@
  * \brief Some helper functions to avoid code duplication in unit tests.
  */
 
+#define ROUTERLIST_PRIVATE
 #include "orconfig.h"
 #include "or.h"
 
+#include "routerlist.h"
+#include "nodelist.h"
+
+#include "test.h"
 #include "test_helpers.h"
 
+#include "test_descriptors.inc"
+
 /* Return a statically allocated string representing yesterday's date
  * in ISO format. We use it so that state file items are not found to
  * be outdated. */
@@ -24,3 +31,59 @@ get_yesterday_date_str(void)
   return buf;
 }
 
+
+/* 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 tests on it. */
+void
+helper_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, ==, HELPER_NUMBER_OF_DESCRIPTORS);
+
+  /* Sanity checking of routerlist and nodelist. */
+  our_routerlist = router_get_routerlist();
+  tt_int_op(smartlist_len(our_routerlist->routers), ==,
+              HELPER_NUMBER_OF_DESCRIPTORS);
+  routerlist_assert_ok(our_routerlist);
+
+  our_nodelist = nodelist_get_list();
+  tt_int_op(smartlist_len(our_nodelist), ==, HELPER_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);
+}
+
+
+
diff --git a/src/test/test_helpers.h b/src/test/test_helpers.h
index 2618e81..369243b 100644
--- a/src/test/test_helpers.h
+++ b/src/test/test_helpers.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014, The Tor Project, Inc. */
+/* Copyright (c) 2014-2015, The Tor Project, Inc. */
 /* See LICENSE for licensing information */
 
 #ifndef TOR_TEST_HELPERS_H
@@ -6,5 +6,12 @@
 
 const char *get_yesterday_date_str(void);
 
+/* Number of descriptors contained in test_descriptors.txt. */
+#define HELPER_NUMBER_OF_DESCRIPTORS 8
+
+void helper_setup_fake_routerlist(void);
+
+extern const char TEST_DESCRIPTORS[];
+
 #endif
 
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index e70ca5e..67ef646 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -12,10 +12,10 @@
 #include "or.h"
 #include "test.h"
 #include "control.h"
-#include "testhelper.h"
 #include "config.h"
 #include "routerset.h"
 #include "circuitbuild.h"
+#include "test_helpers.h"
 
 /* mock ID digest and longname for node that's in nodelist */
 #define HSDIR_EXIST_ID "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" \
diff --git a/src/test/testhelper.c b/src/test/testhelper.c
deleted file mode 100644
index 8bbc192..0000000
--- a/src/test/testhelper.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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 tests on it. */
-void
-helper_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, ==, HELPER_NUMBER_OF_DESCRIPTORS);
-
-  /* Sanity checking of routerlist and nodelist. */
-  our_routerlist = router_get_routerlist();
-  tt_int_op(smartlist_len(our_routerlist->routers), ==,
-              HELPER_NUMBER_OF_DESCRIPTORS);
-  routerlist_assert_ok(our_routerlist);
-
-  our_nodelist = nodelist_get_list();
-  tt_int_op(smartlist_len(our_nodelist), ==, HELPER_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);
-}
-
diff --git a/src/test/testhelper.h b/src/test/testhelper.h
deleted file mode 100644
index 4a6718a..0000000
--- a/src/test/testhelper.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef TOR_TEST_HELPER_H
-#define TOR_TEST_HELPER_H
-
-/* Number of descriptors contained in test_descriptors.txt. */
-#define HELPER_NUMBER_OF_DESCRIPTORS 8
-
-void helper_setup_fake_routerlist(void);
-
-extern const char TEST_DESCRIPTORS[];
-
-#endif
-

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