~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/tests/test_conf.c

  • Committer: Scott James Remnant
  • Date: 2007-06-08 15:04:50 UTC
  • Revision ID: scott@netsplit.com-20070608150450-am3zsvx61k1tkxhl
* init/conf.h (ConfItem): Drop the name and replace it with a type.
(ConfItemType): Enum for different types of configuration items
(ConfFile): Change items from a hash table to a list.
* init/conf.c (conf_file_get): Initialise the items member as a list.
(conf_item_set): Rename to conf_item_new again.
(conf_item_new): Allocates a new ConfItem and adds it to the file's
list, we won't reuse items anymore since it doesn't really make sense.
(conf_source_reload): Adjust clean-up code now that items is a list.
(conf_reload_path): Work out the name of jobs found by filename,
allocate a new item for them and parse the job into it.  Perform
handling of errors by outputting a warning.
(conf_item_delete): Takes both source and file so we can make
intelligent decisions.
(conf_file_delete): Takes a source and passes it to conf_item_delete
(conf_delete_handler): Pass both source and file to conf_file_delet
* init/tests/test_conf.c (test_file_get): Check that the items
list is empty; rather than the hash being unallocated.
(test_item_set): Rename back to test_item_new and only allocate a
single item which should get added to the list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
test_file_get (void)
88
88
{
89
89
        ConfSource *source;
90
 
        ConfFile   *conf_file, *ptr;
 
90
        ConfFile   *file, *ptr;
91
91
 
92
92
        TEST_FUNCTION ("conf_file_get");
93
93
        source = conf_source_new (NULL, "/tmp", CONF_JOB_DIR);
98
98
         */
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");
102
102
 
103
103
                if (test_alloc_failed) {
104
 
                        TEST_EQ_P (conf_file, NULL);
 
104
                        TEST_EQ_P (file, NULL);
105
105
                        continue;
106
106
                }
107
107
 
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);
115
115
 
116
116
                TEST_EQ_P ((void *)nih_hash_lookup (source->files, "/tmp/foo"),
117
 
                           conf_file);
 
117
                           file);
118
118
 
119
 
                nih_list_free (&conf_file->entry);
 
119
                nih_list_free (&file->entry);
120
120
        }
121
121
 
122
122
 
124
124
         * source, and that the flag is updated to the new value.
125
125
         */
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);
129
129
 
130
130
        TEST_ALLOC_FAIL {
135
135
                        continue;
136
136
                }
137
137
 
138
 
                TEST_EQ_P (ptr, conf_file);
 
138
                TEST_EQ_P (ptr, file);
139
139
 
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);
147
147
 
148
148
                TEST_EQ_P ((void *)nih_hash_lookup (source->files, "/tmp/foo"),
149
 
                           conf_file);
 
149
                           file);
150
150
        }
151
151
 
152
 
        nih_list_free (&conf_file->entry);
 
152
        nih_list_free (&file->entry);
153
153
        nih_list_free (&source->entry);
154
154
}
155
155
 
156
156
void
157
 
test_item_set (void)
 
157
test_item_new (void)
158
158
{
159
159
        ConfSource *source;
160
 
        ConfFile   *conf_file;
161
 
        ConfItem   *item, *ptr;
162
 
        Job        *job1, *job2;
 
160
        ConfFile   *file;
 
161
        ConfItem   *item;
163
162
 
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");
167
166
 
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.
171
170
         */
172
171
        TEST_FEATURE ("with new item");
173
 
        job1 = job_new (NULL, "foo");
174
 
 
175
172
        TEST_ALLOC_FAIL {
176
 
                item = conf_item_set (source, conf_file, "foo", job1);
 
173
                item = conf_item_new (source, file, CONF_JOB);
177
174
 
178
175
                if (test_alloc_failed) {
179
176
                        TEST_EQ_P (item, NULL);
181
178
                }
182
179
 
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);
190
 
 
191
 
                TEST_EQ_P ((void *)nih_hash_lookup (conf_file->items, "foo"),
192
 
                           item);
 
183
                TEST_EQ (item->type, CONF_JOB);
 
184
                TEST_EQ (item->flag, file->flag);
 
185
                TEST_EQ_P (item->data, NULL);
193
186
 
194
187
                nih_list_free (&item->entry);
195
188
        }
196
189
 
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.
199
 
         */
200
 
        TEST_FEATURE ("with existing item");
201
 
        item = conf_item_set (source, conf_file, "foo", job1);
202
 
        source->flag = (! source->flag);
203
 
 
204
 
        job2 = job_new (NULL, "foo");
205
 
 
206
 
        TEST_ALLOC_FAIL {
207
 
                ptr = conf_item_set (source, conf_file, "foo", job2);
208
 
 
209
 
                if (test_alloc_failed) {
210
 
                        TEST_EQ_P (ptr, NULL);
211
 
                        continue;
212
 
                }
213
 
 
214
 
                TEST_EQ_P (ptr, item);
215
 
 
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);
223
 
 
224
 
                TEST_EQ_P ((void *)nih_hash_lookup (conf_file->items, "foo"),
225
 
                           item);
226
 
        }
227
 
 
228
 
        nih_list_free (&conf_file->entry);
 
190
        nih_list_free (&file->entry);
229
191
        nih_list_free (&source->entry);
230
192
}
231
193
 
307
269
{
308
270
        test_source_new ();
309
271
        test_file_get ();
310
 
        test_item_set ();
 
272
        test_item_new ();
 
273
 
311
274
        test_source_reload ();
312
275
 
313
276
        return 0;