mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
Unittest prep: Move get_yesterday_date_str() to helper file.
We want to use this function in our guardfraction unittests, so make a test_helpers module and move it there.
This commit is contained in:
parent
b941f109ac
commit
c2b13e22e7
4 changed files with 39 additions and 13 deletions
|
@ -61,6 +61,7 @@ src_test_test_SOURCES = \
|
||||||
src/test/test_status.c \
|
src/test/test_status.c \
|
||||||
src/test/test_threads.c \
|
src/test/test_threads.c \
|
||||||
src/test/test_util.c \
|
src/test/test_util.c \
|
||||||
|
src/test/test_helpers.c \
|
||||||
src/test/testing_common.c \
|
src/test/testing_common.c \
|
||||||
src/ext/tinytest.c
|
src/ext/tinytest.c
|
||||||
|
|
||||||
|
@ -119,6 +120,7 @@ src_test_test_workqueue_LDADD = src/or/libtor-testing.a \
|
||||||
noinst_HEADERS+= \
|
noinst_HEADERS+= \
|
||||||
src/test/fakechans.h \
|
src/test/fakechans.h \
|
||||||
src/test/test.h \
|
src/test/test.h \
|
||||||
|
src/test/test_helpers.h \
|
||||||
src/test/test_descriptors.inc \
|
src/test/test_descriptors.inc \
|
||||||
src/test/example_extrainfo.inc \
|
src/test/example_extrainfo.inc \
|
||||||
src/test/failing_routerdescs.inc \
|
src/test/failing_routerdescs.inc \
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "test_descriptors.inc"
|
#include "test_descriptors.inc"
|
||||||
|
#include "test_helpers.h"
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* choose_random_entry() test with state set.
|
* choose_random_entry() test with state set.
|
||||||
|
@ -326,19 +327,6 @@ state_lines_free(smartlist_t *entry_guard_lines)
|
||||||
smartlist_free(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
|
/* 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
|
a saved entry guard and makes sure that Tor can parse it and
|
||||||
creates the right entry node out of it.
|
creates the right entry node out of it.
|
||||||
|
|
26
src/test/test_helpers.c
Normal file
26
src/test/test_helpers.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* Copyright (c) 2014, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file test_helpers.c
|
||||||
|
* \brief Some helper functions to avoid code duplication in unit tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "orconfig.h"
|
||||||
|
#include "or.h"
|
||||||
|
|
||||||
|
#include "test_helpers.h"
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
10
src/test/test_helpers.h
Normal file
10
src/test/test_helpers.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/* Copyright (c) 2014, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
#ifndef TOR_TEST_HELPERS_H
|
||||||
|
#define TOR_TEST_HELPERS_H
|
||||||
|
|
||||||
|
const char *get_yesterday_date_str(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue