summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_entrynodes.c17
-rw-r--r--src/test/test_status.c28
2 files changed, 28 insertions, 17 deletions
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 00efa81768..fbb7625f84 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -325,6 +325,19 @@ state_lines_free(smartlist_t *entry_guard_lines)
smartlist_free(entry_guard_lines);
}
+/* 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. */
+static const char *
+get_yesterday_date_str(void)
+{
+ static char buf[ISO_TIME_LEN+1];
+
+ time_t yesterday = time(NULL) - 24*60*60;
+ format_iso_time(buf, yesterday);
+ return buf;
+}
+
/* Tests entry_guards_parse_state(). It creates a fake Tor state with
a saved entry guard and makes sure that Tor can parse it and
creates the right entry node out of it.
@@ -342,7 +355,7 @@ test_entry_guards_parse_state_simple(void *arg)
const char *nickname = "hagbard";
const char *fpr = "B29D536DD1752D542E1FBB3C9CE4449D51298212";
const char *tor_version = "0.2.5.3-alpha-dev";
- const char *added_at = "2014-05-22 02:40:47";
+ const char *added_at = get_yesterday_date_str();
const char *unlisted_since = "2014-06-08 16:16:50";
(void) arg;
@@ -457,7 +470,7 @@ test_entry_guards_parse_state_pathbias(void *arg)
smartlist_add_asprintf(state_line, "EntryGuardAddedBy");
smartlist_add_asprintf(state_line,
"B29D536DD1752D542E1FBB3C9CE4449D51298212 0.2.5.3-alpha-dev "
- "2014-05-22 02:40:47");
+ "%s", get_yesterday_date_str());
smartlist_add(entry_state_lines, state_line);
state_line = smartlist_new();
diff --git a/src/test/test_status.c b/src/test/test_status.c
index 46dd473132..8bc0152ffb 100644
--- a/src/test/test_status.c
+++ b/src/test/test_status.c
@@ -30,27 +30,24 @@
* global circuits.
*/
-struct global_circuitlist_s mock_global_circuitlist =
- TOR_LIST_HEAD_INITIALIZER(global_circuitlist);
+static smartlist_t * mock_global_circuitlist = NULL;
-NS_DECL(struct global_circuitlist_s *, circuit_get_global_list, (void));
+NS_DECL(smartlist_t *, circuit_get_global_list, (void));
static void
NS(test_main)(void *arg)
{
/* Choose origin_circuit_t wlog. */
origin_circuit_t *mock_circuit1, *mock_circuit2;
- circuit_t *circ, *tmp;
int expected_circuits = 2, actual_circuits;
(void)arg;
mock_circuit1 = tor_malloc_zero(sizeof(origin_circuit_t));
mock_circuit2 = tor_malloc_zero(sizeof(origin_circuit_t));
- TOR_LIST_INSERT_HEAD(
- &mock_global_circuitlist, TO_CIRCUIT(mock_circuit1), head);
- TOR_LIST_INSERT_HEAD(
- &mock_global_circuitlist, TO_CIRCUIT(mock_circuit2), head);
+ mock_global_circuitlist = smartlist_new();
+ smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit1));
+ smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit2));
NS_MOCK(circuit_get_global_list);
@@ -58,17 +55,18 @@ NS(test_main)(void *arg)
tt_assert(expected_circuits == actual_circuits);
- done:
- TOR_LIST_FOREACH_SAFE(
- circ, NS(circuit_get_global_list)(), head, tmp);
- tor_free(circ);
- NS_UNMOCK(circuit_get_global_list);
+ done:
+ tor_free(mock_circuit1);
+ tor_free(mock_circuit2);
+ smartlist_free(mock_global_circuitlist);
+ mock_global_circuitlist = NULL;
+ NS_UNMOCK(circuit_get_global_list);
}
-static struct global_circuitlist_s *
+static smartlist_t *
NS(circuit_get_global_list)(void)
{
- return &mock_global_circuitlist;
+ return mock_global_circuitlist;
}
#undef NS_SUBMODULE