1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/**
* @file
* Test code for the ConfigSet object
*
* @authors
* Copyright (C) 2020 Richard Russon <rich@flatcap.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define TEST_NO_MAIN
#include "config.h"
#include "acutest.h"
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "common.h" // IWYU pragma: keep
#include "test_common.h"
// clang-format off
static struct ConfigDef Vars[] = {
{ "Apple", DT_STRING, IP "hello", 0, NULL },
{ "Banana", DT_NUMBER, 42, 0, NULL },
{ NULL },
};
// clang-format on
void test_config_variable(void)
{
log_line(__func__);
struct ConfigSubset *sub = NeoMutt->sub;
struct ConfigSet *cs = sub->cs;
if (!TEST_CHECK(cs_register_variables(cs, Vars, DT_NO_FLAGS)))
return;
struct Buffer *err = buf_pool_get();
const char *name = "Apple";
int result = cs_str_string_set(cs, name, "world", err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
buf_reset(err);
result = cs_str_reset(cs, name, err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
struct HashElem *he = cs_get_elem(cs, name);
if (!TEST_CHECK(he != NULL))
return;
buf_reset(err);
result = cs_he_string_get(cs, he, err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
buf_reset(err);
result = cs_he_native_set(cs, he, IP "foo", err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
buf_reset(err);
result = cs_str_native_set(cs, name, IP "bar", err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
buf_reset(err);
intptr_t value = cs_he_native_get(cs, he, err);
if (!TEST_CHECK_STR_EQ((const char *) value, "bar"))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
name = "Banana";
he = cs_get_elem(cs, name);
if (!TEST_CHECK(he != NULL))
return;
result = cs_he_string_plus_equals(cs, he, "23", err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
result = cs_he_string_minus_equals(cs, he, "56", err);
if (!TEST_CHECK(CSR_RESULT(result) == CSR_SUCCESS))
{
TEST_MSG("Error: %s", buf_string(err));
return;
}
buf_pool_release(&err);
log_line(__func__);
}
|