tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

test_statefile.c (1617B)


      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 test_statefile_remove_obsolete(void *arg)
     18 {
     19  (void)arg;
     20  config_line_t *inp = NULL;
     21  /* try empty config */
     22  or_state_remove_obsolete_lines(&inp);
     23  tt_assert(!inp);
     24 
     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);
     31 
     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);
     45 
     46 done:
     47  config_free_lines(inp);
     48 }
     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 };