Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 4 | * 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øgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 12 | * 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øgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 28 | #include <stdlib.h> |
| 29 | #include <stdint.h> |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 30 | #include <stdio.h> |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 31 | #include <string.h> |
| 32 | #include <assert.h> |
| 33 | #include <errno.h> |
Kristian Høgsberg | ac3a8b8 | 2013-07-08 19:06:06 -0400 | [diff] [blame] | 34 | #include <unistd.h> |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 35 | |
| 36 | #include "config-parser.h" |
| 37 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 38 | #include "shared/helpers.h" |
| 39 | #include "zunitc/zunitc.h" |
| 40 | |
| 41 | struct fixture_data { |
| 42 | const char *text; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 43 | struct weston_config *config; |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | static struct weston_config * |
| 47 | load_config(const char *text) |
| 48 | { |
| 49 | struct weston_config *config = NULL; |
| 50 | int len = 0; |
| 51 | int fd = -1; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 52 | char file[] = "/tmp/weston-config-parser-test-XXXXXX"; |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 53 | |
| 54 | ZUC_ASSERTG_NOT_NULL(text, out); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 55 | |
| 56 | fd = mkstemp(file); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 57 | ZUC_ASSERTG_NE(-1, fd, out); |
| 58 | |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 59 | len = write(fd, text, strlen(text)); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 60 | ZUC_ASSERTG_EQ((int)strlen(text), len, out_close); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 61 | |
Kristian Høgsberg | 1abe048 | 2013-09-21 23:02:31 -0700 | [diff] [blame] | 62 | config = weston_config_parse(file); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 63 | |
| 64 | out_close: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 65 | close(fd); |
| 66 | unlink(file); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 67 | out: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 68 | return config; |
| 69 | } |
| 70 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 71 | static void * |
| 72 | setup_test_config(void *data) |
| 73 | { |
| 74 | struct weston_config *config = load_config(data); |
| 75 | ZUC_ASSERTG_NOT_NULL(config, out); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 76 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 77 | out: |
| 78 | return config; |
| 79 | } |
| 80 | |
| 81 | static void * |
| 82 | setup_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; |
| 88 | err_free: |
| 89 | weston_config_destroy(config); |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | cleanup_test_config(void *data) |
| 95 | { |
| 96 | struct weston_config *config = data; |
| 97 | ZUC_ASSERT_NOT_NULL(config); |
| 98 | weston_config_destroy(config); |
| 99 | } |
| 100 | |
| 101 | static 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 | |
| 107 | static struct zuc_fixture config_test_t1 = { |
| 108 | .data = |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 109 | "# 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 Harrington | cbc0537 | 2016-07-07 14:08:28 -0700 | [diff] [blame] | 119 | "zero=0\n" |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 120 | "flag=false\n" |
| 121 | "\n" |
| 122 | "[stuff]\n" |
| 123 | "flag= true \n" |
| 124 | "\n" |
| 125 | "[bucket]\n" |
| 126 | "color=blue \n" |
| 127 | "contents=live crabs\n" |
| 128 | "pinchy=true\n" |
| 129 | "\n" |
| 130 | "[bucket]\n" |
| 131 | "material=plastic \n" |
| 132 | "color=red\n" |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 133 | "contents=sand\n", |
| 134 | .set_up = setup_test_config, |
| 135 | .tear_down = cleanup_test_config |
| 136 | }; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 137 | |
Kristian Høgsberg | f73f316 | 2013-05-26 20:50:53 -0400 | [diff] [blame] | 138 | static const char *section_names[] = { |
| 139 | "foo", "bar", "stuff", "bucket", "bucket" |
| 140 | }; |
| 141 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 142 | /* |
| 143 | * Since these next few won't parse, we don't add the tear_down to |
| 144 | * attempt cleanup. |
| 145 | */ |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 146 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 147 | static struct zuc_fixture config_test_t2 = { |
| 148 | .data = |
| 149 | "# invalid section...\n" |
| 150 | "[this bracket isn't closed\n", |
| 151 | .set_up = setup_test_config_failing, |
| 152 | }; |
| 153 | |
| 154 | static struct zuc_fixture config_test_t3 = { |
| 155 | .data = |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 156 | "# line without = ...\n" |
| 157 | "[bambam]\n" |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 158 | "this line isn't any kind of valid\n", |
| 159 | .set_up = setup_test_config_failing, |
| 160 | }; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 161 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 162 | static struct zuc_fixture config_test_t4 = { |
| 163 | .data = |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 164 | "# starting with = ...\n" |
| 165 | "[bambam]\n" |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 166 | "=not valid at all\n", |
| 167 | .set_up = setup_test_config_failing, |
| 168 | }; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 169 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 170 | ZUC_TEST_F(config_test_t0, comment_only, data) |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 171 | { |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 172 | struct weston_config *config = data; |
| 173 | ZUC_ASSERT_NOT_NULL(config); |
| 174 | } |
| 175 | |
| 176 | /** @todo individual t1 tests should have more descriptive names. */ |
| 177 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 178 | ZUC_TEST_F(config_test_t1, test001, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 179 | { |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 180 | struct weston_config_section *section; |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 181 | struct weston_config *config = data; |
| 182 | ZUC_ASSERT_NOT_NULL(config); |
| 183 | section = weston_config_get_section(config, |
| 184 | "mollusc", NULL, NULL); |
| 185 | ZUC_ASSERT_NULL(section); |
| 186 | } |
| 187 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 188 | ZUC_TEST_F(config_test_t1, test002, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 189 | { |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 190 | char *s; |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 191 | int r; |
| 192 | struct weston_config_section *section; |
| 193 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 194 | |
| 195 | section = weston_config_get_section(config, "foo", NULL, NULL); |
| 196 | r = weston_config_section_get_string(section, "a", &s, NULL); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 197 | |
| 198 | ZUC_ASSERTG_EQ(0, r, out_free); |
| 199 | ZUC_ASSERTG_STREQ("b", s, out_free); |
| 200 | |
| 201 | out_free: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 202 | free(s); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 205 | ZUC_TEST_F(config_test_t1, test003, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 206 | { |
| 207 | char *s; |
| 208 | int r; |
| 209 | struct weston_config_section *section; |
| 210 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 211 | |
| 212 | section = weston_config_get_section(config, "foo", NULL, NULL); |
| 213 | r = weston_config_section_get_string(section, "b", &s, NULL); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 214 | |
| 215 | ZUC_ASSERT_EQ(-1, r); |
| 216 | ZUC_ASSERT_EQ(ENOENT, errno); |
| 217 | ZUC_ASSERT_NULL(s); |
| 218 | } |
| 219 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 220 | ZUC_TEST_F(config_test_t1, test004, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 221 | { |
| 222 | char *s; |
| 223 | int r; |
| 224 | struct weston_config_section *section; |
| 225 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 226 | |
| 227 | section = weston_config_get_section(config, "foo", NULL, NULL); |
| 228 | r = weston_config_section_get_string(section, "name", &s, NULL); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 229 | |
| 230 | ZUC_ASSERTG_EQ(0, r, out_free); |
| 231 | ZUC_ASSERTG_STREQ("Roy Batty", s, out_free); |
| 232 | |
| 233 | out_free: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 234 | free(s); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 237 | ZUC_TEST_F(config_test_t1, test005, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 238 | { |
| 239 | char *s; |
| 240 | int r; |
| 241 | struct weston_config_section *section; |
| 242 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 243 | |
| 244 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 245 | r = weston_config_section_get_string(section, "a", &s, "boo"); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 246 | |
| 247 | ZUC_ASSERTG_EQ(-1, r, out_free); |
| 248 | ZUC_ASSERTG_EQ(ENOENT, errno, out_free); |
| 249 | ZUC_ASSERTG_STREQ("boo", s, out_free); |
| 250 | |
| 251 | out_free: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 252 | free(s); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 255 | ZUC_TEST_F(config_test_t1, test006, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 256 | { |
| 257 | int r; |
| 258 | int32_t n; |
| 259 | struct weston_config_section *section; |
| 260 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 261 | |
| 262 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 263 | r = weston_config_section_get_int(section, "number", &n, 600); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 264 | |
| 265 | ZUC_ASSERT_EQ(0, r); |
| 266 | ZUC_ASSERT_EQ(5252, n); |
Bryce Harrington | cbc0537 | 2016-07-07 14:08:28 -0700 | [diff] [blame] | 267 | ZUC_ASSERT_EQ(0, errno); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 270 | ZUC_TEST_F(config_test_t1, test007, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 271 | { |
| 272 | int r; |
| 273 | int32_t n; |
| 274 | struct weston_config_section *section; |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 275 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 276 | |
| 277 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 278 | r = weston_config_section_get_int(section, "+++", &n, 700); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 279 | |
| 280 | ZUC_ASSERT_EQ(-1, r); |
| 281 | ZUC_ASSERT_EQ(ENOENT, errno); |
| 282 | ZUC_ASSERT_EQ(700, n); |
| 283 | } |
| 284 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 285 | ZUC_TEST_F(config_test_t1, test008, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 286 | { |
| 287 | int r; |
| 288 | uint32_t u; |
| 289 | struct weston_config_section *section; |
| 290 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 291 | |
| 292 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 293 | r = weston_config_section_get_uint(section, "number", &u, 600); |
Bryce Harrington | cbc0537 | 2016-07-07 14:08:28 -0700 | [diff] [blame] | 294 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 295 | ZUC_ASSERT_EQ(0, r); |
| 296 | ZUC_ASSERT_EQ(5252, u); |
Bryce Harrington | cbc0537 | 2016-07-07 14:08:28 -0700 | [diff] [blame] | 297 | ZUC_ASSERT_EQ(0, errno); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 300 | ZUC_TEST_F(config_test_t1, test009, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 301 | { |
| 302 | int r; |
| 303 | uint32_t u; |
| 304 | struct weston_config_section *section; |
| 305 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 306 | |
| 307 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 308 | r = weston_config_section_get_uint(section, "+++", &u, 600); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 309 | ZUC_ASSERT_EQ(-1, r); |
| 310 | ZUC_ASSERT_EQ(ENOENT, errno); |
| 311 | ZUC_ASSERT_EQ(600, u); |
| 312 | } |
| 313 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 314 | ZUC_TEST_F(config_test_t1, test010, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 315 | { |
| 316 | int r, b; |
| 317 | struct weston_config_section *section; |
| 318 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 319 | |
| 320 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 321 | r = weston_config_section_get_bool(section, "flag", &b, 600); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 322 | ZUC_ASSERT_EQ(0, r); |
| 323 | ZUC_ASSERT_EQ(0, b); |
| 324 | } |
| 325 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 326 | ZUC_TEST_F(config_test_t1, test011, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 327 | { |
| 328 | int r, b; |
| 329 | struct weston_config_section *section; |
| 330 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 331 | |
| 332 | section = weston_config_get_section(config, "stuff", NULL, NULL); |
| 333 | r = weston_config_section_get_bool(section, "flag", &b, -1); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 334 | ZUC_ASSERT_EQ(0, r); |
| 335 | ZUC_ASSERT_EQ(1, b); |
| 336 | } |
| 337 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 338 | ZUC_TEST_F(config_test_t1, test012, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 339 | { |
| 340 | int r, b; |
| 341 | struct weston_config_section *section; |
| 342 | struct weston_config *config = data; |
| 343 | |
| 344 | section = weston_config_get_section(config, "stuff", NULL, NULL); |
| 345 | r = weston_config_section_get_bool(section, "flag", &b, -1); |
| 346 | ZUC_ASSERT_EQ(0, r); |
| 347 | ZUC_ASSERT_EQ(1, b); |
| 348 | } |
| 349 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 350 | ZUC_TEST_F(config_test_t1, test013, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 351 | { |
| 352 | int r, b; |
| 353 | struct weston_config_section *section; |
| 354 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 355 | |
| 356 | section = weston_config_get_section(config, "stuff", NULL, NULL); |
| 357 | r = weston_config_section_get_bool(section, "bonk", &b, -1); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 358 | ZUC_ASSERT_EQ(-1, r); |
| 359 | ZUC_ASSERT_EQ(ENOENT, errno); |
| 360 | ZUC_ASSERT_EQ(-1, b); |
| 361 | } |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 362 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 363 | ZUC_TEST_F(config_test_t1, test014, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 364 | { |
| 365 | char *s; |
| 366 | int r; |
| 367 | struct weston_config_section *section; |
| 368 | struct weston_config *config = data; |
| 369 | |
| 370 | section = weston_config_get_section(config, |
| 371 | "bucket", "color", "blue"); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 372 | r = weston_config_section_get_string(section, "contents", &s, NULL); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 373 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 374 | ZUC_ASSERTG_EQ(0, r, out_free); |
| 375 | ZUC_ASSERTG_STREQ("live crabs", s, out_free); |
| 376 | |
| 377 | out_free: |
| 378 | free(s); |
| 379 | } |
| 380 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 381 | ZUC_TEST_F(config_test_t1, test015, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 382 | { |
| 383 | char *s; |
| 384 | int r; |
| 385 | struct weston_config_section *section; |
| 386 | struct weston_config *config = data; |
| 387 | |
| 388 | section = weston_config_get_section(config, |
| 389 | "bucket", "color", "red"); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 390 | r = weston_config_section_get_string(section, "contents", &s, NULL); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 391 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 392 | ZUC_ASSERTG_EQ(0, r, out_free); |
| 393 | ZUC_ASSERTG_STREQ("sand", s, out_free); |
| 394 | |
| 395 | out_free: |
| 396 | free(s); |
| 397 | } |
| 398 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 399 | ZUC_TEST_F(config_test_t1, test016, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 400 | { |
| 401 | char *s; |
| 402 | int r; |
| 403 | struct weston_config_section *section; |
| 404 | struct weston_config *config = data; |
| 405 | |
| 406 | section = weston_config_get_section(config, |
| 407 | "bucket", "color", "pink"); |
| 408 | ZUC_ASSERT_NULL(section); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 409 | r = weston_config_section_get_string(section, "contents", &s, "eels"); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 410 | |
| 411 | ZUC_ASSERTG_EQ(-1, r, out_free); |
| 412 | ZUC_ASSERTG_EQ(ENOENT, errno, out_free); |
| 413 | ZUC_ASSERTG_STREQ("eels", s, out_free); |
| 414 | |
| 415 | out_free: |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 416 | free(s); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 419 | ZUC_TEST_F(config_test_t1, test017, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 420 | { |
| 421 | const char *name; |
| 422 | int i; |
| 423 | struct weston_config_section *section; |
| 424 | struct weston_config *config = data; |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 425 | |
Kristian Høgsberg | f73f316 | 2013-05-26 20:50:53 -0400 | [diff] [blame] | 426 | section = NULL; |
| 427 | i = 0; |
| 428 | while (weston_config_next_section(config, §ion, &name)) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 429 | ZUC_ASSERT_STREQ(section_names[i++], name); |
Kristian Høgsberg | f73f316 | 2013-05-26 20:50:53 -0400 | [diff] [blame] | 430 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 431 | ZUC_ASSERT_EQ(5, i); |
| 432 | } |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 433 | |
Bryce Harrington | cbc0537 | 2016-07-07 14:08:28 -0700 | [diff] [blame] | 434 | ZUC_TEST_F(config_test_t1, test018, data) |
| 435 | { |
| 436 | int r; |
| 437 | int32_t n; |
| 438 | struct weston_config_section *section; |
| 439 | struct weston_config *config = data; |
| 440 | |
| 441 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 442 | r = weston_config_section_get_int(section, "zero", &n, 600); |
| 443 | |
| 444 | ZUC_ASSERT_EQ(0, r); |
| 445 | ZUC_ASSERT_EQ(0, n); |
| 446 | ZUC_ASSERT_EQ(0, errno); |
| 447 | } |
| 448 | |
| 449 | ZUC_TEST_F(config_test_t1, test019, data) |
| 450 | { |
| 451 | int r; |
| 452 | uint32_t n; |
| 453 | struct weston_config_section *section; |
| 454 | struct weston_config *config = data; |
| 455 | |
| 456 | section = weston_config_get_section(config, "bar", NULL, NULL); |
| 457 | r = weston_config_section_get_uint(section, "zero", &n, 600); |
| 458 | |
| 459 | ZUC_ASSERT_EQ(0, r); |
| 460 | ZUC_ASSERT_EQ(0, n); |
| 461 | ZUC_ASSERT_EQ(0, errno); |
| 462 | } |
| 463 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 464 | ZUC_TEST_F(config_test_t2, doesnt_parse, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 465 | { |
| 466 | struct weston_config *config = data; |
| 467 | ZUC_ASSERT_NULL(config); |
| 468 | } |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 469 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 470 | ZUC_TEST_F(config_test_t3, doesnt_parse, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 471 | { |
| 472 | struct weston_config *config = data; |
| 473 | ZUC_ASSERT_NULL(config); |
| 474 | } |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 475 | |
Jon Cruz | ecf819b | 2015-10-22 21:11:12 -0700 | [diff] [blame] | 476 | ZUC_TEST_F(config_test_t4, doesnt_parse, data) |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 477 | { |
| 478 | struct weston_config *config = data; |
| 479 | ZUC_ASSERT_NULL(config); |
| 480 | } |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 481 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 482 | ZUC_TEST(config_test, destroy_null) |
| 483 | { |
Kristian Høgsberg | 82189f7 | 2013-05-28 15:34:46 -0400 | [diff] [blame] | 484 | weston_config_destroy(NULL); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 485 | ZUC_ASSERT_EQ(0, weston_config_next_section(NULL, NULL, NULL)); |
| 486 | } |
Kristian Høgsberg | 82189f7 | 2013-05-28 15:34:46 -0400 | [diff] [blame] | 487 | |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 488 | ZUC_TEST(config_test, section_from_null) |
| 489 | { |
| 490 | struct weston_config_section *section; |
Kristian Høgsberg | 82189f7 | 2013-05-28 15:34:46 -0400 | [diff] [blame] | 491 | section = weston_config_get_section(NULL, "bucket", NULL, NULL); |
Jon A. Cruz | a67c541 | 2015-07-15 19:22:42 -0700 | [diff] [blame] | 492 | ZUC_ASSERT_NULL(section); |
Kristian Høgsberg | 7327471 | 2013-04-01 12:41:23 -0400 | [diff] [blame] | 493 | } |