99
99
TEST_FEATURE ("with new path");
100
100
TEST_ALLOC_FAIL {
101
conf_file = conf_file_get (source, "/tmp/foo");
101
file = conf_file_get (source, "/tmp/foo");
103
103
if (test_alloc_failed) {
104
TEST_EQ_P (conf_file, NULL);
104
TEST_EQ_P (file, NULL);
108
TEST_ALLOC_SIZE (conf_file, sizeof (ConfFile));
109
TEST_ALLOC_PARENT (conf_file, source);
110
TEST_LIST_NOT_EMPTY (&conf_file->entry);
111
TEST_ALLOC_PARENT (conf_file->path, conf_file);
112
TEST_EQ_STR (conf_file->path, "/tmp/foo");
113
TEST_EQ (conf_file->flag, source->flag);
114
TEST_NE_P (conf_file->items, NULL);
108
TEST_ALLOC_SIZE (file, sizeof (ConfFile));
109
TEST_ALLOC_PARENT (file, source);
110
TEST_LIST_NOT_EMPTY (&file->entry);
111
TEST_ALLOC_PARENT (file->path, file);
112
TEST_EQ_STR (file->path, "/tmp/foo");
113
TEST_EQ (file->flag, source->flag);
114
TEST_LIST_EMPTY (&file->items);
116
116
TEST_EQ_P ((void *)nih_hash_lookup (source->files, "/tmp/foo"),
119
nih_list_free (&conf_file->entry);
119
nih_list_free (&file->entry);
124
124
* source, and that the flag is updated to the new value.
126
126
TEST_FEATURE ("with existing path");
127
conf_file = conf_file_get (source, "/tmp/foo");
127
file = conf_file_get (source, "/tmp/foo");
128
128
source->flag = (! source->flag);
130
130
TEST_ALLOC_FAIL {
138
TEST_EQ_P (ptr, conf_file);
138
TEST_EQ_P (ptr, file);
140
TEST_ALLOC_SIZE (conf_file, sizeof (ConfFile));
141
TEST_ALLOC_PARENT (conf_file, source);
142
TEST_LIST_NOT_EMPTY (&conf_file->entry);
143
TEST_ALLOC_PARENT (conf_file->path, conf_file);
144
TEST_EQ_STR (conf_file->path, "/tmp/foo");
145
TEST_EQ (conf_file->flag, source->flag);
146
TEST_NE_P (conf_file->items, NULL);
140
TEST_ALLOC_SIZE (file, sizeof (ConfFile));
141
TEST_ALLOC_PARENT (file, source);
142
TEST_LIST_NOT_EMPTY (&file->entry);
143
TEST_ALLOC_PARENT (file->path, file);
144
TEST_EQ_STR (file->path, "/tmp/foo");
145
TEST_EQ (file->flag, source->flag);
146
TEST_LIST_EMPTY (&file->items);
148
148
TEST_EQ_P ((void *)nih_hash_lookup (source->files, "/tmp/foo"),
152
nih_list_free (&conf_file->entry);
152
nih_list_free (&file->entry);
153
153
nih_list_free (&source->entry);
159
159
ConfSource *source;
161
ConfItem *item, *ptr;
164
TEST_FUNCTION ("conf_item_set");
163
TEST_FUNCTION ("conf_item_new");
165
164
source = conf_source_new (NULL, "/tmp", CONF_JOB_DIR);
166
conf_file = conf_file_get (source, "/tmp/foo");
165
file = conf_file_get (source, "/tmp/foo");
168
167
/* Check that we can request a new Confitem structure, it should be
169
* allocated with nih_alloc and placed into the items hash table of
168
* allocated with nih_alloc and placed into the items list of
170
169
* the file, with the flag copied.
172
171
TEST_FEATURE ("with new item");
173
job1 = job_new (NULL, "foo");
175
172
TEST_ALLOC_FAIL {
176
item = conf_item_set (source, conf_file, "foo", job1);
173
item = conf_item_new (source, file, CONF_JOB);
178
175
if (test_alloc_failed) {
179
176
TEST_EQ_P (item, NULL);
183
180
TEST_ALLOC_SIZE (item, sizeof (ConfItem));
184
TEST_ALLOC_PARENT (item, conf_file);
181
TEST_ALLOC_PARENT (item, file);
185
182
TEST_LIST_NOT_EMPTY (&item->entry);
186
TEST_ALLOC_PARENT (item->name, item);
187
TEST_EQ_STR (item->name, "foo");
188
TEST_EQ (item->flag, conf_file->flag);
189
TEST_EQ_P (item->data, job1);
191
TEST_EQ_P ((void *)nih_hash_lookup (conf_file->items, "foo"),
183
TEST_EQ (item->type, CONF_JOB);
184
TEST_EQ (item->flag, file->flag);
185
TEST_EQ_P (item->data, NULL);
194
187
nih_list_free (&item->entry);
197
/* Check that we can retrieve an existing ConfItem for a given name,
198
* and that the flag and data are both updated to the new value.
200
TEST_FEATURE ("with existing item");
201
item = conf_item_set (source, conf_file, "foo", job1);
202
source->flag = (! source->flag);
204
job2 = job_new (NULL, "foo");
207
ptr = conf_item_set (source, conf_file, "foo", job2);
209
if (test_alloc_failed) {
210
TEST_EQ_P (ptr, NULL);
214
TEST_EQ_P (ptr, item);
216
TEST_ALLOC_SIZE (item, sizeof (ConfItem));
217
TEST_ALLOC_PARENT (item, conf_file);
218
TEST_LIST_NOT_EMPTY (&item->entry);
219
TEST_ALLOC_PARENT (item->name, item);
220
TEST_EQ_STR (item->name, "foo");
221
TEST_EQ (item->flag, conf_file->flag);
222
TEST_EQ_P (item->data, job2);
224
TEST_EQ_P ((void *)nih_hash_lookup (conf_file->items, "foo"),
228
nih_list_free (&conf_file->entry);
190
nih_list_free (&file->entry);
229
191
nih_list_free (&source->entry);