blob: 5a5a380b3bc6ffc8ccbbeca9a1b07ae6aafdd7f6 [file] [log] [blame]
Kristian Høgsberg73274712013-04-01 12:41:23 -04001/*
2 * Copyright © 2013 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Kristian Høgsberg73274712013-04-01 12:41:23 -040011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Kristian Høgsberg73274712013-04-01 12:41:23 -040024 */
25
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010026#include "config.h"
27
Kristian Høgsberg73274712013-04-01 12:41:23 -040028#include <stdlib.h>
29#include <stdint.h>
Jon A. Cruza67c5412015-07-15 19:22:42 -070030#include <stdio.h>
Kristian Høgsberg73274712013-04-01 12:41:23 -040031#include <string.h>
32#include <assert.h>
33#include <errno.h>
Kristian Høgsbergac3a8b82013-07-08 19:06:06 -040034#include <unistd.h>
Kristian Høgsberg73274712013-04-01 12:41:23 -040035
36#include "config-parser.h"
37
Jon A. Cruza67c5412015-07-15 19:22:42 -070038#include "shared/helpers.h"
39#include "zunitc/zunitc.h"
40
41struct fixture_data {
42 const char *text;
Kristian Høgsberg73274712013-04-01 12:41:23 -040043 struct weston_config *config;
Jon A. Cruza67c5412015-07-15 19:22:42 -070044};
45
46static struct weston_config *
47load_config(const char *text)
48{
49 struct weston_config *config = NULL;
50 int len = 0;
51 int fd = -1;
Kristian Høgsberg73274712013-04-01 12:41:23 -040052 char file[] = "/tmp/weston-config-parser-test-XXXXXX";
Jon A. Cruza67c5412015-07-15 19:22:42 -070053
54 ZUC_ASSERTG_NOT_NULL(text, out);
Kristian Høgsberg73274712013-04-01 12:41:23 -040055
56 fd = mkstemp(file);
Jon A. Cruza67c5412015-07-15 19:22:42 -070057 ZUC_ASSERTG_NE(-1, fd, out);
58
Kristian Høgsberg73274712013-04-01 12:41:23 -040059 len = write(fd, text, strlen(text));
Jon A. Cruza67c5412015-07-15 19:22:42 -070060 ZUC_ASSERTG_EQ((int)strlen(text), len, out_close);
Kristian Høgsberg73274712013-04-01 12:41:23 -040061
Kristian Høgsberg1abe0482013-09-21 23:02:31 -070062 config = weston_config_parse(file);
Jon A. Cruza67c5412015-07-15 19:22:42 -070063
64out_close:
Kristian Høgsberg73274712013-04-01 12:41:23 -040065 close(fd);
66 unlink(file);
Jon A. Cruza67c5412015-07-15 19:22:42 -070067out:
Kristian Høgsberg73274712013-04-01 12:41:23 -040068 return config;
69}
70
Jon A. Cruza67c5412015-07-15 19:22:42 -070071static void *
72setup_test_config(void *data)
73{
74 struct weston_config *config = load_config(data);
75 ZUC_ASSERTG_NOT_NULL(config, out);
Kristian Høgsberg73274712013-04-01 12:41:23 -040076
Jon A. Cruza67c5412015-07-15 19:22:42 -070077out:
78 return config;
79}
80
81static void *
82setup_test_config_failing(void *data)
83{
84 struct weston_config *config = load_config(data);
85 ZUC_ASSERTG_NULL(config, err_free);
86
87 return config;
88err_free:
89 weston_config_destroy(config);
90 return NULL;
91}
92
93static void
94cleanup_test_config(void *data)
95{
96 struct weston_config *config = data;
97 ZUC_ASSERT_NOT_NULL(config);
98 weston_config_destroy(config);
99}
100
101static struct zuc_fixture config_test_t0 = {
102 .data = "# nothing in this file...\n",
103 .set_up = setup_test_config,
104 .tear_down = cleanup_test_config
105};
106
107static struct zuc_fixture config_test_t1 = {
108 .data =
Kristian Høgsberg73274712013-04-01 12:41:23 -0400109 "# comment line here...\n"
110 "\n"
111 "[foo]\n"
112 "a=b\n"
113 "name= Roy Batty \n"
114 "\n"
115 "\n"
116 "[bar]\n"
117 "# more comments\n"
118 "number=5252\n"
Bryce Harringtoncbc05372016-07-07 14:08:28 -0700119 "zero=0\n"
Kristian Høgsberg73274712013-04-01 12:41:23 -0400120 "flag=false\n"
121 "\n"
Bryce Harringtone776f2a2016-07-14 18:28:03 -0700122 "[colors]\n"
123 "none=0x00000000\n"
124 "low=0x11223344\n"
125 "high=0xff00ff00\n"
126 "oct=01234567\n"
127 "dec=12345670\n"
128 "short=1234567\n"
129 "\n"
Kristian Høgsberg73274712013-04-01 12:41:23 -0400130 "[stuff]\n"
131 "flag= true \n"
132 "\n"
133 "[bucket]\n"
134 "color=blue \n"
135 "contents=live crabs\n"
136 "pinchy=true\n"
137 "\n"
138 "[bucket]\n"
139 "material=plastic \n"
140 "color=red\n"
Jon A. Cruza67c5412015-07-15 19:22:42 -0700141 "contents=sand\n",
142 .set_up = setup_test_config,
143 .tear_down = cleanup_test_config
144};
Kristian Høgsberg73274712013-04-01 12:41:23 -0400145
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400146static const char *section_names[] = {
Bryce Harringtone776f2a2016-07-14 18:28:03 -0700147 "foo", "bar", "colors", "stuff", "bucket", "bucket"
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400148};
149
Jon A. Cruza67c5412015-07-15 19:22:42 -0700150/*
151 * Since these next few won't parse, we don't add the tear_down to
152 * attempt cleanup.
153 */
Kristian Høgsberg73274712013-04-01 12:41:23 -0400154
Jon A. Cruza67c5412015-07-15 19:22:42 -0700155static struct zuc_fixture config_test_t2 = {
156 .data =
157 "# invalid section...\n"
158 "[this bracket isn't closed\n",
159 .set_up = setup_test_config_failing,
160};
161
162static struct zuc_fixture config_test_t3 = {
163 .data =
Kristian Høgsberg73274712013-04-01 12:41:23 -0400164 "# line without = ...\n"
165 "[bambam]\n"
Jon A. Cruza67c5412015-07-15 19:22:42 -0700166 "this line isn't any kind of valid\n",
167 .set_up = setup_test_config_failing,
168};
Kristian Høgsberg73274712013-04-01 12:41:23 -0400169
Jon A. Cruza67c5412015-07-15 19:22:42 -0700170static struct zuc_fixture config_test_t4 = {
171 .data =
Kristian Høgsberg73274712013-04-01 12:41:23 -0400172 "# starting with = ...\n"
173 "[bambam]\n"
Jon A. Cruza67c5412015-07-15 19:22:42 -0700174 "=not valid at all\n",
175 .set_up = setup_test_config_failing,
176};
Kristian Høgsberg73274712013-04-01 12:41:23 -0400177
Jon Cruzecf819b2015-10-22 21:11:12 -0700178ZUC_TEST_F(config_test_t0, comment_only, data)
Kristian Høgsberg73274712013-04-01 12:41:23 -0400179{
Jon A. Cruza67c5412015-07-15 19:22:42 -0700180 struct weston_config *config = data;
181 ZUC_ASSERT_NOT_NULL(config);
182}
183
184/** @todo individual t1 tests should have more descriptive names. */
185
Jon Cruzecf819b2015-10-22 21:11:12 -0700186ZUC_TEST_F(config_test_t1, test001, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700187{
Kristian Høgsberg73274712013-04-01 12:41:23 -0400188 struct weston_config_section *section;
Jon A. Cruza67c5412015-07-15 19:22:42 -0700189 struct weston_config *config = data;
190 ZUC_ASSERT_NOT_NULL(config);
191 section = weston_config_get_section(config,
192 "mollusc", NULL, NULL);
193 ZUC_ASSERT_NULL(section);
194}
195
Jon Cruzecf819b2015-10-22 21:11:12 -0700196ZUC_TEST_F(config_test_t1, test002, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700197{
Kristian Høgsberg73274712013-04-01 12:41:23 -0400198 char *s;
Jon A. Cruza67c5412015-07-15 19:22:42 -0700199 int r;
200 struct weston_config_section *section;
201 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400202
203 section = weston_config_get_section(config, "foo", NULL, NULL);
204 r = weston_config_section_get_string(section, "a", &s, NULL);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700205
206 ZUC_ASSERTG_EQ(0, r, out_free);
207 ZUC_ASSERTG_STREQ("b", s, out_free);
208
209out_free:
Kristian Høgsberg73274712013-04-01 12:41:23 -0400210 free(s);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700211}
212
Jon Cruzecf819b2015-10-22 21:11:12 -0700213ZUC_TEST_F(config_test_t1, test003, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700214{
215 char *s;
216 int r;
217 struct weston_config_section *section;
218 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400219
220 section = weston_config_get_section(config, "foo", NULL, NULL);
221 r = weston_config_section_get_string(section, "b", &s, NULL);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700222
223 ZUC_ASSERT_EQ(-1, r);
224 ZUC_ASSERT_EQ(ENOENT, errno);
225 ZUC_ASSERT_NULL(s);
226}
227
Jon Cruzecf819b2015-10-22 21:11:12 -0700228ZUC_TEST_F(config_test_t1, test004, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700229{
230 char *s;
231 int r;
232 struct weston_config_section *section;
233 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400234
235 section = weston_config_get_section(config, "foo", NULL, NULL);
236 r = weston_config_section_get_string(section, "name", &s, NULL);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700237
238 ZUC_ASSERTG_EQ(0, r, out_free);
239 ZUC_ASSERTG_STREQ("Roy Batty", s, out_free);
240
241out_free:
Kristian Høgsberg73274712013-04-01 12:41:23 -0400242 free(s);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700243}
244
Jon Cruzecf819b2015-10-22 21:11:12 -0700245ZUC_TEST_F(config_test_t1, test005, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700246{
247 char *s;
248 int r;
249 struct weston_config_section *section;
250 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400251
252 section = weston_config_get_section(config, "bar", NULL, NULL);
253 r = weston_config_section_get_string(section, "a", &s, "boo");
Jon A. Cruza67c5412015-07-15 19:22:42 -0700254
255 ZUC_ASSERTG_EQ(-1, r, out_free);
256 ZUC_ASSERTG_EQ(ENOENT, errno, out_free);
257 ZUC_ASSERTG_STREQ("boo", s, out_free);
258
259out_free:
Kristian Høgsberg73274712013-04-01 12:41:23 -0400260 free(s);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700261}
262
Jon Cruzecf819b2015-10-22 21:11:12 -0700263ZUC_TEST_F(config_test_t1, test006, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700264{
265 int r;
266 int32_t n;
267 struct weston_config_section *section;
268 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400269
270 section = weston_config_get_section(config, "bar", NULL, NULL);
271 r = weston_config_section_get_int(section, "number", &n, 600);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700272
273 ZUC_ASSERT_EQ(0, r);
274 ZUC_ASSERT_EQ(5252, n);
Bryce Harringtoncbc05372016-07-07 14:08:28 -0700275 ZUC_ASSERT_EQ(0, errno);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700276}
277
Jon Cruzecf819b2015-10-22 21:11:12 -0700278ZUC_TEST_F(config_test_t1, test007, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700279{
280 int r;
281 int32_t n;
282 struct weston_config_section *section;
Derek Foremanbdc8c722015-10-07 11:51:29 -0500283 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400284
285 section = weston_config_get_section(config, "bar", NULL, NULL);
286 r = weston_config_section_get_int(section, "+++", &n, 700);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700287
288 ZUC_ASSERT_EQ(-1, r);
289 ZUC_ASSERT_EQ(ENOENT, errno);
290 ZUC_ASSERT_EQ(700, n);
291}
292
Jon Cruzecf819b2015-10-22 21:11:12 -0700293ZUC_TEST_F(config_test_t1, test008, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700294{
295 int r;
296 uint32_t u;
297 struct weston_config_section *section;
298 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400299
300 section = weston_config_get_section(config, "bar", NULL, NULL);
301 r = weston_config_section_get_uint(section, "number", &u, 600);
Bryce Harringtoncbc05372016-07-07 14:08:28 -0700302
Jon A. Cruza67c5412015-07-15 19:22:42 -0700303 ZUC_ASSERT_EQ(0, r);
304 ZUC_ASSERT_EQ(5252, u);
Bryce Harringtoncbc05372016-07-07 14:08:28 -0700305 ZUC_ASSERT_EQ(0, errno);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700306}
307
Jon Cruzecf819b2015-10-22 21:11:12 -0700308ZUC_TEST_F(config_test_t1, test009, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700309{
310 int r;
311 uint32_t u;
312 struct weston_config_section *section;
313 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400314
315 section = weston_config_get_section(config, "bar", NULL, NULL);
316 r = weston_config_section_get_uint(section, "+++", &u, 600);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700317 ZUC_ASSERT_EQ(-1, r);
318 ZUC_ASSERT_EQ(ENOENT, errno);
319 ZUC_ASSERT_EQ(600, u);
320}
321
Jon Cruzecf819b2015-10-22 21:11:12 -0700322ZUC_TEST_F(config_test_t1, test010, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700323{
324 int r, b;
325 struct weston_config_section *section;
326 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400327
328 section = weston_config_get_section(config, "bar", NULL, NULL);
329 r = weston_config_section_get_bool(section, "flag", &b, 600);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700330 ZUC_ASSERT_EQ(0, r);
331 ZUC_ASSERT_EQ(0, b);
332}
333
Jon Cruzecf819b2015-10-22 21:11:12 -0700334ZUC_TEST_F(config_test_t1, test011, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700335{
336 int r, b;
337 struct weston_config_section *section;
338 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400339
340 section = weston_config_get_section(config, "stuff", NULL, NULL);
341 r = weston_config_section_get_bool(section, "flag", &b, -1);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700342 ZUC_ASSERT_EQ(0, r);
343 ZUC_ASSERT_EQ(1, b);
344}
345
Jon Cruzecf819b2015-10-22 21:11:12 -0700346ZUC_TEST_F(config_test_t1, test012, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700347{
348 int r, b;
349 struct weston_config_section *section;
350 struct weston_config *config = data;
351
352 section = weston_config_get_section(config, "stuff", NULL, NULL);
353 r = weston_config_section_get_bool(section, "flag", &b, -1);
354 ZUC_ASSERT_EQ(0, r);
355 ZUC_ASSERT_EQ(1, b);
356}
357
Jon Cruzecf819b2015-10-22 21:11:12 -0700358ZUC_TEST_F(config_test_t1, test013, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700359{
360 int r, b;
361 struct weston_config_section *section;
362 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400363
364 section = weston_config_get_section(config, "stuff", NULL, NULL);
365 r = weston_config_section_get_bool(section, "bonk", &b, -1);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700366 ZUC_ASSERT_EQ(-1, r);
367 ZUC_ASSERT_EQ(ENOENT, errno);
368 ZUC_ASSERT_EQ(-1, b);
369}
Kristian Høgsberg73274712013-04-01 12:41:23 -0400370
Jon Cruzecf819b2015-10-22 21:11:12 -0700371ZUC_TEST_F(config_test_t1, test014, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700372{
373 char *s;
374 int r;
375 struct weston_config_section *section;
376 struct weston_config *config = data;
377
378 section = weston_config_get_section(config,
379 "bucket", "color", "blue");
Kristian Høgsberg73274712013-04-01 12:41:23 -0400380 r = weston_config_section_get_string(section, "contents", &s, NULL);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400381
Jon A. Cruza67c5412015-07-15 19:22:42 -0700382 ZUC_ASSERTG_EQ(0, r, out_free);
383 ZUC_ASSERTG_STREQ("live crabs", s, out_free);
384
385out_free:
386 free(s);
387}
388
Jon Cruzecf819b2015-10-22 21:11:12 -0700389ZUC_TEST_F(config_test_t1, test015, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700390{
391 char *s;
392 int r;
393 struct weston_config_section *section;
394 struct weston_config *config = data;
395
396 section = weston_config_get_section(config,
397 "bucket", "color", "red");
Kristian Høgsberg73274712013-04-01 12:41:23 -0400398 r = weston_config_section_get_string(section, "contents", &s, NULL);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400399
Jon A. Cruza67c5412015-07-15 19:22:42 -0700400 ZUC_ASSERTG_EQ(0, r, out_free);
401 ZUC_ASSERTG_STREQ("sand", s, out_free);
402
403out_free:
404 free(s);
405}
406
Jon Cruzecf819b2015-10-22 21:11:12 -0700407ZUC_TEST_F(config_test_t1, test016, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700408{
409 char *s;
410 int r;
411 struct weston_config_section *section;
412 struct weston_config *config = data;
413
414 section = weston_config_get_section(config,
415 "bucket", "color", "pink");
416 ZUC_ASSERT_NULL(section);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400417 r = weston_config_section_get_string(section, "contents", &s, "eels");
Jon A. Cruza67c5412015-07-15 19:22:42 -0700418
419 ZUC_ASSERTG_EQ(-1, r, out_free);
420 ZUC_ASSERTG_EQ(ENOENT, errno, out_free);
421 ZUC_ASSERTG_STREQ("eels", s, out_free);
422
423out_free:
Kristian Høgsberg73274712013-04-01 12:41:23 -0400424 free(s);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700425}
426
Jon Cruzecf819b2015-10-22 21:11:12 -0700427ZUC_TEST_F(config_test_t1, test017, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700428{
429 const char *name;
430 int i;
431 struct weston_config_section *section;
432 struct weston_config *config = data;
Kristian Høgsberg73274712013-04-01 12:41:23 -0400433
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400434 section = NULL;
435 i = 0;
436 while (weston_config_next_section(config, &section, &name))
Jon A. Cruza67c5412015-07-15 19:22:42 -0700437 ZUC_ASSERT_STREQ(section_names[i++], name);
Kristian Høgsbergf73f3162013-05-26 20:50:53 -0400438
Bryce Harringtone776f2a2016-07-14 18:28:03 -0700439 ZUC_ASSERT_EQ(6, i);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700440}
Kristian Høgsberg73274712013-04-01 12:41:23 -0400441
Bryce Harringtoncbc05372016-07-07 14:08:28 -0700442ZUC_TEST_F(config_test_t1, test018, data)
443{
444 int r;
445 int32_t n;
446 struct weston_config_section *section;
447 struct weston_config *config = data;
448
449 section = weston_config_get_section(config, "bar", NULL, NULL);
450 r = weston_config_section_get_int(section, "zero", &n, 600);
451
452 ZUC_ASSERT_EQ(0, r);
453 ZUC_ASSERT_EQ(0, n);
454 ZUC_ASSERT_EQ(0, errno);
455}
456
457ZUC_TEST_F(config_test_t1, test019, data)
458{
459 int r;
460 uint32_t n;
461 struct weston_config_section *section;
462 struct weston_config *config = data;
463
464 section = weston_config_get_section(config, "bar", NULL, NULL);
465 r = weston_config_section_get_uint(section, "zero", &n, 600);
466
467 ZUC_ASSERT_EQ(0, r);
468 ZUC_ASSERT_EQ(0, n);
469 ZUC_ASSERT_EQ(0, errno);
470}
471
Bryce Harringtone776f2a2016-07-14 18:28:03 -0700472ZUC_TEST_F(config_test_t1, test020, data)
473{
474 int r;
475 uint32_t n;
476 struct weston_config_section *section;
477 struct weston_config *config = data;
478
479 section = weston_config_get_section(config, "colors", NULL, NULL);
480 r = weston_config_section_get_color(section, "none", &n, 0xff336699);
481
482 ZUC_ASSERT_EQ(0, r);
483 ZUC_ASSERT_EQ(0x000000, n);
484 ZUC_ASSERT_EQ(0, errno);
485}
486
487ZUC_TEST_F(config_test_t1, test021, data)
488{
489 int r;
490 uint32_t n;
491 struct weston_config_section *section;
492 struct weston_config *config = data;
493
494 section = weston_config_get_section(config, "colors", NULL, NULL);
495 r = weston_config_section_get_color(section, "low", &n, 0xff336699);
496
497 ZUC_ASSERT_EQ(0, r);
498 ZUC_ASSERT_EQ(0x11223344, n);
499 ZUC_ASSERT_EQ(0, errno);
500}
501
502ZUC_TEST_F(config_test_t1, test022, data)
503{
504 int r;
505 uint32_t n;
506 struct weston_config_section *section;
507 struct weston_config *config = data;
508
509 section = weston_config_get_section(config, "colors", NULL, NULL);
510 r = weston_config_section_get_color(section, "high", &n, 0xff336699);
511
512 ZUC_ASSERT_EQ(0, r);
513 ZUC_ASSERT_EQ(0xff00ff00, n);
514 ZUC_ASSERT_EQ(0, errno);
515}
516
517ZUC_TEST_F(config_test_t1, test023, data)
518{
519 int r;
520 uint32_t n;
521 struct weston_config_section *section;
522 struct weston_config *config = data;
523
524 // Treat colors as hex values even if missing the leading 0x
525 section = weston_config_get_section(config, "colors", NULL, NULL);
526 r = weston_config_section_get_color(section, "oct", &n, 0xff336699);
527
528 ZUC_ASSERT_EQ(0, r);
529 ZUC_ASSERT_EQ(0x01234567, n);
530 ZUC_ASSERT_EQ(0, errno);
531}
532
533ZUC_TEST_F(config_test_t1, test024, data)
534{
535 int r;
536 uint32_t n;
537 struct weston_config_section *section;
538 struct weston_config *config = data;
539
540 // Treat colors as hex values even if missing the leading 0x
541 section = weston_config_get_section(config, "colors", NULL, NULL);
542 r = weston_config_section_get_color(section, "dec", &n, 0xff336699);
543
544 ZUC_ASSERT_EQ(0, r);
545 ZUC_ASSERT_EQ(0x12345670, n);
546 ZUC_ASSERT_EQ(0, errno);
547}
548
549ZUC_TEST_F(config_test_t1, test025, data)
550{
551 int r;
552 uint32_t n;
553 struct weston_config_section *section;
554 struct weston_config *config = data;
555
556 // 7-digit colors are not valid (most likely typos)
557 section = weston_config_get_section(config, "colors", NULL, NULL);
558 r = weston_config_section_get_color(section, "short", &n, 0xff336699);
559
560 ZUC_ASSERT_EQ(-1, r);
561 ZUC_ASSERT_EQ(0xff336699, n);
562 ZUC_ASSERT_EQ(EINVAL, errno);
563}
564
565ZUC_TEST_F(config_test_t1, test026, data)
566{
567 int r;
568 uint32_t n;
569 struct weston_config_section *section;
570 struct weston_config *config = data;
571
572 // String color names are unsupported
573 section = weston_config_get_section(config, "bucket", NULL, NULL);
574 r = weston_config_section_get_color(section, "color", &n, 0xff336699);
575
576 ZUC_ASSERT_EQ(-1, r);
577 ZUC_ASSERT_EQ(0xff336699, n);
578 ZUC_ASSERT_EQ(EINVAL, errno);
579}
580
Jon Cruzecf819b2015-10-22 21:11:12 -0700581ZUC_TEST_F(config_test_t2, doesnt_parse, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700582{
583 struct weston_config *config = data;
584 ZUC_ASSERT_NULL(config);
585}
Kristian Høgsberg73274712013-04-01 12:41:23 -0400586
Jon Cruzecf819b2015-10-22 21:11:12 -0700587ZUC_TEST_F(config_test_t3, doesnt_parse, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700588{
589 struct weston_config *config = data;
590 ZUC_ASSERT_NULL(config);
591}
Kristian Høgsberg73274712013-04-01 12:41:23 -0400592
Jon Cruzecf819b2015-10-22 21:11:12 -0700593ZUC_TEST_F(config_test_t4, doesnt_parse, data)
Jon A. Cruza67c5412015-07-15 19:22:42 -0700594{
595 struct weston_config *config = data;
596 ZUC_ASSERT_NULL(config);
597}
Kristian Høgsberg73274712013-04-01 12:41:23 -0400598
Jon A. Cruza67c5412015-07-15 19:22:42 -0700599ZUC_TEST(config_test, destroy_null)
600{
Kristian Høgsberg82189f72013-05-28 15:34:46 -0400601 weston_config_destroy(NULL);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700602 ZUC_ASSERT_EQ(0, weston_config_next_section(NULL, NULL, NULL));
603}
Kristian Høgsberg82189f72013-05-28 15:34:46 -0400604
Jon A. Cruza67c5412015-07-15 19:22:42 -0700605ZUC_TEST(config_test, section_from_null)
606{
607 struct weston_config_section *section;
Kristian Høgsberg82189f72013-05-28 15:34:46 -0400608 section = weston_config_get_section(NULL, "bucket", NULL, NULL);
Jon A. Cruza67c5412015-07-15 19:22:42 -0700609 ZUC_ASSERT_NULL(section);
Kristian Høgsberg73274712013-04-01 12:41:23 -0400610}