mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Add a test for clear_fn support in handling non-managed fields
This commit is contained in:
parent
577e628743
commit
a3e99c5f1e
1 changed files with 21 additions and 0 deletions
|
@ -34,6 +34,8 @@ typedef struct {
|
||||||
int cuteness;
|
int cuteness;
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
int eats_meat; /* deprecated; llamas are never carnivorous. */
|
int eats_meat; /* deprecated; llamas are never carnivorous. */
|
||||||
|
|
||||||
|
char *description; // derived from other fields.
|
||||||
} llama_cfg_t;
|
} llama_cfg_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -87,6 +89,16 @@ static config_deprecation_t alpaca_deprecations[] = {
|
||||||
{NULL,NULL}
|
{NULL,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int clear_llama_cfg_called = 0;
|
||||||
|
static void
|
||||||
|
clear_llama_cfg(const config_mgr_t *mgr, void *llamacfg)
|
||||||
|
{
|
||||||
|
(void)mgr;
|
||||||
|
llama_cfg_t *lc = llamacfg;
|
||||||
|
tor_free(lc->description);
|
||||||
|
++clear_llama_cfg_called;
|
||||||
|
}
|
||||||
|
|
||||||
static config_abbrev_t llama_abbrevs[] = {
|
static config_abbrev_t llama_abbrevs[] = {
|
||||||
{ "gracia", "cuteness", 0, 0 },
|
{ "gracia", "cuteness", 0, 0 },
|
||||||
{ "gentillesse", "cuteness", 0, 0 },
|
{ "gentillesse", "cuteness", 0, 0 },
|
||||||
|
@ -115,6 +127,7 @@ static const config_format_t llama_fmt = {
|
||||||
.config_suite_offset = -1,
|
.config_suite_offset = -1,
|
||||||
.deprecations = llama_deprecations,
|
.deprecations = llama_deprecations,
|
||||||
.abbrevs = llama_abbrevs,
|
.abbrevs = llama_abbrevs,
|
||||||
|
.clear_fn = clear_llama_cfg,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const config_format_t alpaca_fmt = {
|
static const config_format_t alpaca_fmt = {
|
||||||
|
@ -250,6 +263,14 @@ test_confmgr_parse(void *arg)
|
||||||
tt_int_op(lc->cuteness, OP_EQ, 42);
|
tt_int_op(lc->cuteness, OP_EQ, 42);
|
||||||
tt_int_op(ac->fuzziness, OP_EQ, 50);
|
tt_int_op(ac->fuzziness, OP_EQ, 50);
|
||||||
|
|
||||||
|
// We set the description for the llama here, so that the clear function
|
||||||
|
// can clear it. (Later we can do this in a verification function.)
|
||||||
|
clear_llama_cfg_called = 0;
|
||||||
|
llama_cfg_t *mut_lc = config_mgr_get_obj_mutable(mgr, p, LLAMA_IDX);
|
||||||
|
mut_lc->description = tor_strdup("A llama named Hugo.");
|
||||||
|
config_free(mgr, p);
|
||||||
|
tt_int_op(clear_llama_cfg_called, OP_EQ, 1);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
config_free_lines(lines);
|
config_free_lines(lines);
|
||||||
config_free(mgr, p);
|
config_free(mgr, p);
|
||||||
|
|
Loading…
Add table
Reference in a new issue