diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-02-18 09:19:38 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-02-18 09:19:38 -0500 |
commit | 6cdb213b6cb9f682c3f72bba974f53f588d71b61 (patch) | |
tree | cb8baf0137e8ca104ed8da10738c217bb111beb9 /src/test/test_helpers.c | |
parent | 96211bcf714ac739f605dc0b5b8754418080591f (diff) | |
download | tor-6cdb213b6cb9f682c3f72bba974f53f588d71b61.tar.gz tor-6cdb213b6cb9f682c3f72bba974f53f588d71b61.zip |
Combine test_helpers.[ch] and testhelper.[ch]
Diffstat (limited to 'src/test/test_helpers.c')
-rw-r--r-- | src/test/test_helpers.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c index e5a76e0360..8f4a3a9ab2 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); +} + + + |