Merge branch 'maint-0.4.8'
[tor.git] / src / test / test_statefile.c
blobaedf76a69459b62f5db937b7a510e05b41dd446e
1 /* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #include "orconfig.h"
8 #define STATEFILE_PRIVATE
10 #include "core/or/or.h"
11 #include "lib/encoding/confline.h"
12 #include "app/config/statefile.h"
14 #include "test/test.h"
16 static void
17 test_statefile_remove_obsolete(void *arg)
19 (void)arg;
20 config_line_t *inp = NULL;
21 /* try empty config */
22 or_state_remove_obsolete_lines(&inp);
23 tt_assert(!inp);
25 /* try removing every line */
26 config_line_append(&inp, "EntryGuard", "doesn't matter");
27 config_line_append(&inp, "HidServRevCounter", "ignore");
28 config_line_append(&inp, "hidservrevcounter", "foobar"); // note case
29 or_state_remove_obsolete_lines(&inp);
30 tt_assert(!inp);
32 /* Now try removing a subset of lines. */
33 config_line_append(&inp, "EntryGuard", "doesn't matter");
34 config_line_append(&inp, "Guard", "in use");
35 config_line_append(&inp, "HidServRevCounter", "ignore");
36 config_line_append(&inp, "TorVersion", "this test doesn't care");
37 or_state_remove_obsolete_lines(&inp);
38 tt_assert(inp);
39 tt_str_op(inp->key, OP_EQ, "Guard");
40 tt_str_op(inp->value, OP_EQ, "in use");
41 tt_assert(inp->next);
42 tt_str_op(inp->next->key, OP_EQ, "TorVersion");
43 tt_str_op(inp->next->value, OP_EQ, "this test doesn't care");
44 tt_assert(! inp->next->next);
46 done:
47 config_free_lines(inp);
50 #define T(name) \
51 { #name, test_statefile_##name, 0, NULL, NULL }
53 struct testcase_t statefile_tests[] = {
54 T(remove_obsolete),
55 END_OF_TESTCASES