2013-04-01 12:41:23 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Intel Corporation
|
2025-07-29 15:55:02 +03:00
|
|
|
* Copyright 2025 Collabora, Ltd.
|
2013-04-01 12:41:23 -04:00
|
|
|
*
|
2015-06-11 15:39:40 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2013-04-01 12:41:23 -04:00
|
|
|
*
|
2015-06-11 15:39:40 -07:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
|
* portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2013-04-01 12:41:23 -04:00
|
|
|
*/
|
|
|
|
|
|
2014-04-07 12:40:35 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2015-07-15 19:22:42 -07:00
|
|
|
#include <stdio.h>
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2019-04-04 14:27:31 +03:00
|
|
|
#include <libweston/config-parser.h>
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
#include "weston-test-client-helper.h"
|
|
|
|
|
#include "weston-test-assert.h"
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
static struct weston_config *
|
2015-07-15 19:22:42 -07:00
|
|
|
load_config(const char *text)
|
2013-04-01 12:41:23 -04:00
|
|
|
{
|
2015-07-15 19:22:42 -07:00
|
|
|
struct weston_config *config = NULL;
|
2022-06-25 06:12:50 +01:00
|
|
|
char *content = NULL;
|
|
|
|
|
size_t file_len = 0;
|
|
|
|
|
int write_len;
|
|
|
|
|
FILE *file;
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2022-06-25 06:12:50 +01:00
|
|
|
file = open_memstream(&content, &file_len);
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_ptr_not_null(file);
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2022-06-25 06:12:50 +01:00
|
|
|
write_len = fwrite(text, 1, strlen(text), file);
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq((int)strlen(text), write_len);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(fflush(file), 0);
|
2022-06-25 06:12:50 +01:00
|
|
|
fseek(file, 0L, SEEK_SET);
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2022-06-25 06:12:50 +01:00
|
|
|
config = weston_config_parse_fp(file);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2022-06-25 06:12:50 +01:00
|
|
|
fclose(file);
|
|
|
|
|
free(content);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
static struct weston_config *
|
|
|
|
|
assert_load_config(const char *text)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = load_config(text);
|
|
|
|
|
test_assert_ptr_not_null(config);
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2015-07-15 19:22:42 -07:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
static const char *comment_only_text =
|
|
|
|
|
"# nothing in this file...\n";
|
|
|
|
|
|
|
|
|
|
TEST(comment_only)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(comment_only_text);
|
|
|
|
|
|
2015-07-15 19:22:42 -07:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
/** @todo legit tests should have more descriptive names. */
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
static const char *legit_text =
|
2013-04-01 12:41:23 -04:00
|
|
|
"# comment line here...\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"[foo]\n"
|
|
|
|
|
"a=b\n"
|
|
|
|
|
"name= Roy Batty \n"
|
|
|
|
|
"\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"[bar]\n"
|
|
|
|
|
"# more comments\n"
|
|
|
|
|
"number=5252\n"
|
2016-07-07 14:08:28 -07:00
|
|
|
"zero=0\n"
|
2016-07-14 18:28:04 -07:00
|
|
|
"negative=-42\n"
|
2013-04-01 12:41:23 -04:00
|
|
|
"flag=false\n"
|
2022-03-11 17:05:04 +02:00
|
|
|
"real=4.667\n"
|
|
|
|
|
"negreal=-3.2\n"
|
|
|
|
|
"expval=24.687E+15\n"
|
|
|
|
|
"negexpval=-3e-2\n"
|
|
|
|
|
"notanumber=nan\n"
|
|
|
|
|
"empty=\n"
|
|
|
|
|
"tiny=0.0000000000000000000000000000000000000063548\n"
|
2013-04-01 12:41:23 -04:00
|
|
|
"\n"
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
"[colors]\n"
|
|
|
|
|
"none=0x00000000\n"
|
|
|
|
|
"low=0x11223344\n"
|
|
|
|
|
"high=0xff00ff00\n"
|
|
|
|
|
"oct=01234567\n"
|
|
|
|
|
"dec=12345670\n"
|
|
|
|
|
"short=1234567\n"
|
|
|
|
|
"\n"
|
2013-04-01 12:41:23 -04:00
|
|
|
"[stuff]\n"
|
|
|
|
|
"flag= true \n"
|
|
|
|
|
"\n"
|
|
|
|
|
"[bucket]\n"
|
|
|
|
|
"color=blue \n"
|
|
|
|
|
"contents=live crabs\n"
|
|
|
|
|
"pinchy=true\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"[bucket]\n"
|
|
|
|
|
"material=plastic \n"
|
|
|
|
|
"color=red\n"
|
2025-01-26 13:04:40 +01:00
|
|
|
"contents=sand\n";
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test01)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
2015-07-15 19:22:42 -07:00
|
|
|
struct weston_config_section *section;
|
2025-01-26 13:04:40 +01:00
|
|
|
|
2015-07-15 19:22:42 -07:00
|
|
|
section = weston_config_get_section(config,
|
|
|
|
|
"mollusc", NULL, NULL);
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_ptr_null(section);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test02)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "foo", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_string(section, "a", &s, NULL);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_str_eq("b", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test03)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "foo", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_string(section, "b", &s, NULL);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_ptr_null(s);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test04)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "foo", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_string(section, "name", &s, NULL);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_str_eq("Roy Batty", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test05)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_string(section, "a", &s, "boo");
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_str_eq("boo", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test06)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
int r;
|
|
|
|
|
int32_t n;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_int(section, "number", &n, 600);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_s32_eq(5252, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test07)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
int r;
|
|
|
|
|
int32_t n;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_int(section, "+++", &n, 700);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_s32_eq(700, n);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test08)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t u;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_uint(section, "number", &u, 600);
|
2016-07-07 14:08:28 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(5252, u);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test09)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t u;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_uint(section, "+++", &u, 600);
|
2025-01-26 13:04:40 +01:00
|
|
|
|
|
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_u32_eq(600, u);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test10)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2019-11-26 00:14:24 +00:00
|
|
|
int r;
|
|
|
|
|
bool b;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
2019-11-26 00:14:24 +00:00
|
|
|
r = weston_config_section_get_bool(section, "flag", &b, true);
|
2025-01-26 13:04:40 +01:00
|
|
|
|
|
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_false(b);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test11)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2019-11-26 00:14:24 +00:00
|
|
|
int r;
|
|
|
|
|
bool b;
|
2015-07-15 19:22:42 -07:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "stuff", NULL, NULL);
|
2019-11-26 00:14:24 +00:00
|
|
|
r = weston_config_section_get_bool(section, "flag", &b, false);
|
2025-01-26 13:04:40 +01:00
|
|
|
|
|
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_true(b);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test12)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2019-11-26 00:14:24 +00:00
|
|
|
int r;
|
|
|
|
|
bool b;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "stuff", NULL, NULL);
|
2019-11-26 00:14:24 +00:00
|
|
|
r = weston_config_section_get_bool(section, "bonk", &b, false);
|
2025-01-26 13:04:40 +01:00
|
|
|
|
|
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_false(b);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test13)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config,
|
|
|
|
|
"bucket", "color", "blue");
|
2013-04-01 12:41:23 -04:00
|
|
|
r = weston_config_section_get_string(section, "contents", &s, NULL);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_str_eq("live crabs", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test14)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2015-07-15 19:22:42 -07:00
|
|
|
section = weston_config_get_section(config,
|
|
|
|
|
"bucket", "color", "red");
|
2013-04-01 12:41:23 -04:00
|
|
|
r = weston_config_section_get_string(section, "contents", &s, NULL);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_str_eq("sand", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test15)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
char *s;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config,
|
|
|
|
|
"bucket", "color", "pink");
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_ptr_null(section);
|
2013-04-01 12:41:23 -04:00
|
|
|
r = weston_config_section_get_string(section, "contents", &s, "eels");
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
test_assert_str_eq("eels", s);
|
2015-07-15 19:22:42 -07:00
|
|
|
|
2013-04-01 12:41:23 -04:00
|
|
|
free(s);
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test16)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
static const char *section_names[] = {
|
|
|
|
|
"foo", "bar", "colors", "stuff", "bucket", "bucket"
|
|
|
|
|
};
|
|
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2015-07-15 19:22:42 -07:00
|
|
|
const char *name;
|
|
|
|
|
int i;
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2013-05-26 20:50:53 -04:00
|
|
|
section = NULL;
|
|
|
|
|
i = 0;
|
|
|
|
|
while (weston_config_next_section(config, §ion, &name))
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_str_eq(section_names[i++], name);
|
|
|
|
|
|
|
|
|
|
test_assert_int_eq(6, i);
|
2013-05-26 20:50:53 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test17)
|
2016-07-07 14:08:28 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2016-07-07 14:08:28 -07:00
|
|
|
int r;
|
|
|
|
|
int32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_int(section, "zero", &n, 600);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_s32_eq(0, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2016-07-07 14:08:28 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test18)
|
2016-07-07 14:08:28 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2016-07-07 14:08:28 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_uint(section, "zero", &n, 600);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2016-07-07 14:08:28 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test19)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "none", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0x000000, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test20)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "low", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0x11223344, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test21)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "high", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0xff00ff00, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test22)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
/* Treat colors as hex values even if missing the leading 0x */
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "oct", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0x01234567, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test23)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
/* Treat colors as hex values even if missing the leading 0x */
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "dec", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_u32_eq(0x12345670, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test24)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
/* 7-digit colors are not valid (most likely typos) */
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
section = weston_config_get_section(config, "colors", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "short", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_u32_eq(0xff336699, n);
|
|
|
|
|
test_assert_errno(EINVAL);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test25)
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
/* String color names are unsupported */
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
section = weston_config_get_section(config, "bucket", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_color(section, "color", &n, 0xff336699);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_u32_eq(0xff336699, n);
|
|
|
|
|
test_assert_errno(EINVAL);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
config-parser: Add weston_config_section_get_color
Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.) and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.
However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used. And for colors in particular, it would misparse hex
values if the leading 0x was omitted. E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white. "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.
This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white. It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-14 18:28:03 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test26)
|
2016-07-14 18:28:04 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2016-07-14 18:28:04 -07:00
|
|
|
int r;
|
|
|
|
|
int32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_int(section, "negative", &n, 600);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_s32_eq(-42, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2016-07-14 18:28:04 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(legit_test27)
|
2016-07-14 18:28:04 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2016-07-14 18:28:04 -07:00
|
|
|
int r;
|
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_uint(section, "negative", &n, 600);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_u32_eq(600, n);
|
|
|
|
|
test_assert_errno(ERANGE);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2016-07-14 18:28:04 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_number)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "number", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(5252.0, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_missing)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "+++", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_f64_eq(600.0, n);
|
|
|
|
|
test_assert_errno(ENOENT);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_zero)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "zero", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(n, 0.0);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_negative)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "negative", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(n, -42.0);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_flag)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "flag", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(-1, r);
|
|
|
|
|
test_assert_f64_eq(n, 600.0);
|
|
|
|
|
test_assert_errno(EINVAL);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_real)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "real", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(4.667, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_negreal)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "negreal", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(-3.2, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_expval)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "expval", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(24.687e+15, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_negexpval)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "negexpval", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(-3e-2, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_notanumber)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "notanumber", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_true(isnan(n));
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_empty)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "empty", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(0.0, n);
|
|
|
|
|
test_assert_errno(0);
|
|
|
|
|
|
|
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2022-03-11 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(get_double_tiny)
|
2022-03-11 17:05:04 +02:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct weston_config *config = assert_load_config(legit_text);
|
|
|
|
|
struct weston_config_section *section;
|
2022-03-11 17:05:04 +02:00
|
|
|
int r;
|
|
|
|
|
double n;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
section = weston_config_get_section(config, "bar", NULL, NULL);
|
|
|
|
|
r = weston_config_section_get_double(section, "tiny", &n, 600.0);
|
|
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, r);
|
|
|
|
|
test_assert_f64_eq(6.3548e-39, n);
|
|
|
|
|
test_assert_errno(0);
|
2022-03-11 17:05:04 +02:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
weston_config_destroy(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
struct doesnt_parse_test { char *text; };
|
|
|
|
|
|
|
|
|
|
static const struct doesnt_parse_test doesnt_parse_test_data[] = {
|
|
|
|
|
{
|
|
|
|
|
"# invalid section...\n"
|
|
|
|
|
"[this bracket isn't closed\n",
|
|
|
|
|
}, {
|
|
|
|
|
"# line without = ...\n"
|
|
|
|
|
"[bambam]\n"
|
|
|
|
|
"this line isn't any kind of valid\n",
|
|
|
|
|
}, {
|
|
|
|
|
"# starting with = ...\n"
|
|
|
|
|
"[bambam]\n"
|
|
|
|
|
"=not valid at all\n",
|
|
|
|
|
},
|
|
|
|
|
};
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST_P(doesnt_parse, doesnt_parse_test_data)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2025-01-26 13:04:40 +01:00
|
|
|
struct doesnt_parse_test *test = (struct doesnt_parse_test *) data;
|
|
|
|
|
struct weston_config *config = load_config(test->text);
|
|
|
|
|
test_assert_ptr_null(config);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-04-01 12:41:23 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(destroy_null)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
2013-05-28 15:34:46 -04:00
|
|
|
weston_config_destroy(NULL);
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_int_eq(0, weston_config_next_section(NULL, NULL, NULL));
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2015-07-15 19:22:42 -07:00
|
|
|
}
|
2013-05-28 15:34:46 -04:00
|
|
|
|
2025-01-26 13:04:40 +01:00
|
|
|
TEST(section_from_null)
|
2015-07-15 19:22:42 -07:00
|
|
|
{
|
|
|
|
|
struct weston_config_section *section;
|
2013-05-28 15:34:46 -04:00
|
|
|
section = weston_config_get_section(NULL, "bucket", NULL, NULL);
|
2025-01-26 13:04:40 +01:00
|
|
|
test_assert_ptr_null(section);
|
2025-04-30 14:49:10 +03:00
|
|
|
|
|
|
|
|
return RESULT_OK;
|
2013-04-01 12:41:23 -04:00
|
|
|
}
|
2025-07-29 15:55:02 +03:00
|
|
|
|
|
|
|
|
TEST(parse_comma_separated_list)
|
|
|
|
|
{
|
|
|
|
|
const char *matter;
|
|
|
|
|
struct weston_string_array strarr;
|
|
|
|
|
|
|
|
|
|
matter = "";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 0);
|
|
|
|
|
|
|
|
|
|
matter = " ";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 0);
|
|
|
|
|
|
|
|
|
|
matter = " \t \t \t";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 0);
|
|
|
|
|
|
|
|
|
|
matter = "k";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 1);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "k");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = " k";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 1);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "k");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = "k ";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 1);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "k");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = " k ";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 1);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "k");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = "kissa kassi";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 2);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "kissa");
|
|
|
|
|
test_assert_str_eq(strarr.array[1], "kassi");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = "kissa\tkassi";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 2);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "kissa");
|
|
|
|
|
test_assert_str_eq(strarr.array[1], "kassi");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = " kissa\t kassi";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 2);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "kissa");
|
|
|
|
|
test_assert_str_eq(strarr.array[1], "kassi");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
matter = " 4.556\ra bab c \nkoe\t";
|
|
|
|
|
strarr = weston_parse_space_separated_list(matter);
|
|
|
|
|
test_assert_u64_eq(strarr.len, 5);
|
|
|
|
|
test_assert_str_eq(strarr.array[0], "4.556");
|
|
|
|
|
test_assert_str_eq(strarr.array[1], "a");
|
|
|
|
|
test_assert_str_eq(strarr.array[2], "bab");
|
|
|
|
|
test_assert_str_eq(strarr.array[3], "c");
|
|
|
|
|
test_assert_str_eq(strarr.array[4], "koe");
|
|
|
|
|
weston_string_array_fini(&strarr);
|
|
|
|
|
|
|
|
|
|
return RESULT_OK;
|
|
|
|
|
}
|