Tor  0.4.6.0-alpha-dev
conftesting.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2020, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file conftesting.h
9  * @brief Macro and type declarations for testing
10  **/
11 
12 #ifndef TOR_LIB_CONF_CONFTESTING_H
13 #define TOR_LIB_CONF_CONFTESTING_H
14 
15 #include "lib/cc/torint.h"
16 
17 #ifndef COCCI
18 #ifdef TOR_UNIT_TESTS
19 #define USE_CONF_TESTING
20 /**
21  * Union used when building in test mode typechecking the members of a type
22  * used with confmgt.c. See CONF_CHECK_VAR_TYPE for a description of how
23  * it is used. */
24 typedef union {
25  char **STRING;
26  char **FILENAME;
27  int *POSINT; /* yes, this is really an int, and not an unsigned int. For
28  * historical reasons, many configuration values are restricted
29  * to the range [0,INT_MAX], and stored in signed ints.
30  */
31  uint64_t *UINT64;
32  int *INT;
33  int *INTERVAL;
34  int *MSEC_INTERVAL;
35  uint64_t *MEMUNIT;
36  double *DOUBLE;
37  int *BOOL;
38  int *AUTOBOOL;
39  time_t *ISOTIME;
40  struct smartlist_t **CSV;
41  int *CSV_INTERVAL;
42  struct config_line_t **LINELIST;
43  struct config_line_t **LINELIST_S;
44  struct config_line_t **LINELIST_V;
45  // XXXX this doesn't belong at this level of abstraction.
46  struct routerset_t **ROUTERSET;
47 } confparse_dummy_values_t;
48 
49 /* Macros to define extra members inside config_var_t fields, and at the
50  * end of a list of them.
51  */
52 /* This is a somewhat magic type-checking macro for users of confmgt.c.
53  * It initializes a union member "confparse_dummy_values_t.conftype" with
54  * the address of a static member "tp_dummy.member". This
55  * will give a compiler warning unless the member field is of the correct
56  * type.
57  *
58  * (This warning is mandatory, because a type mismatch here violates the type
59  * compatibility constraint for simple assignment, and requires a diagnostic,
60  * according to the C spec.)
61  *
62  * For example, suppose you say:
63  * "CONF_CHECK_VAR_TYPE(or_options_t, STRING, Address)".
64  * Then this macro will evaluate to:
65  * { .STRING = &or_options_t_dummy.Address }
66  * And since confparse_dummy_values_t.STRING has type "char **", that
67  * expression will create a warning unless or_options_t.Address also
68  * has type "char *".
69  */
70 #define CONF_CHECK_VAR_TYPE(tp, conftype, member) \
71  { . conftype = &tp ## _dummy . member }
72 #define CONF_TEST_MEMBERS(tp, conftype, member) \
73  , .var_ptr_dummy=CONF_CHECK_VAR_TYPE(tp, conftype, member)
74 #define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL }
75 #define DUMMY_TYPECHECK_INSTANCE(tp) \
76  static tp tp ## _dummy
77 #endif /* defined(TOR_UNIT_TESTS) */
78 #endif /* !defined(COCCI) */
79 
80 #ifndef USE_CONF_TESTING
81 #define CONF_TEST_MEMBERS(tp, conftype, member)
82 /* Repeatedly declarable incomplete struct to absorb redundant semicolons */
83 #define DUMMY_TYPECHECK_INSTANCE(tp) \
84  struct tor_semicolon_eater
85 #define DUMMY_CONF_TEST_MEMBERS
86 
87 #endif /* !defined(USE_CONF_TESTING) */
88 
89 #endif /* !defined(TOR_LIB_CONF_CONFTESTING_H) */
torint.h
Integer definitions used throughout Tor.
config_line_t
Definition: confline.h:29
smartlist_t
Definition: smartlist_core.h:26