Line data Source code
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 */ 5 : 6 : #include "orconfig.h" 7 : 8 : #define STATEFILE_PRIVATE 9 : 10 : #include "core/or/or.h" 11 : #include "lib/encoding/confline.h" 12 : #include "app/config/statefile.h" 13 : 14 : #include "test/test.h" 15 : 16 : static void 17 1 : test_statefile_remove_obsolete(void *arg) 18 : { 19 1 : (void)arg; 20 1 : config_line_t *inp = NULL; 21 : /* try empty config */ 22 1 : or_state_remove_obsolete_lines(&inp); 23 1 : tt_assert(!inp); 24 : 25 : /* try removing every line */ 26 1 : config_line_append(&inp, "EntryGuard", "doesn't matter"); 27 1 : config_line_append(&inp, "HidServRevCounter", "ignore"); 28 1 : config_line_append(&inp, "hidservrevcounter", "foobar"); // note case 29 1 : or_state_remove_obsolete_lines(&inp); 30 1 : tt_assert(!inp); 31 : 32 : /* Now try removing a subset of lines. */ 33 1 : config_line_append(&inp, "EntryGuard", "doesn't matter"); 34 1 : config_line_append(&inp, "Guard", "in use"); 35 1 : config_line_append(&inp, "HidServRevCounter", "ignore"); 36 1 : config_line_append(&inp, "TorVersion", "this test doesn't care"); 37 1 : or_state_remove_obsolete_lines(&inp); 38 1 : tt_assert(inp); 39 1 : tt_str_op(inp->key, OP_EQ, "Guard"); 40 1 : tt_str_op(inp->value, OP_EQ, "in use"); 41 1 : tt_assert(inp->next); 42 1 : tt_str_op(inp->next->key, OP_EQ, "TorVersion"); 43 1 : tt_str_op(inp->next->value, OP_EQ, "this test doesn't care"); 44 1 : tt_assert(! inp->next->next); 45 : 46 1 : done: 47 1 : config_free_lines(inp); 48 1 : } 49 : 50 : #define T(name) \ 51 : { #name, test_statefile_##name, 0, NULL, NULL } 52 : 53 : struct testcase_t statefile_tests[] = { 54 : T(remove_obsolete), 55 : END_OF_TESTCASES 56 : };