[PATCH weston 2/2] config-parser-test: test support for more color formats
Eric Engestrom
eric at engestrom.ch
Wed Oct 19 22:08:30 UTC 2016
Test for all the possible lengths (up to 8), specifying which are
expected to be valid and how they should be interpreted.
Sprinkle some `#` and `0x` around randomly to make sure those work at
any length too.
Signed-off-by: Eric Engestrom <eric at engestrom.ch>
---
tests/config-parser-test.c | 160 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 160 insertions(+)
diff --git a/tests/config-parser-test.c b/tests/config-parser-test.c
index 1cdffff..a1038e5 100644
--- a/tests/config-parser-test.c
+++ b/tests/config-parser-test.c
@@ -127,6 +127,16 @@ static struct zuc_fixture config_test_t1 = {
"oct=01234567\n"
"dec=12345670\n"
"short=1234567\n"
+ "hash=#12345678\n"
+ "zerox=0x12345678\n"
+ "one=0x1\n"
+ "two=0x12\n"
+ "three=123\n"
+ "four=#1234\n"
+ "five=#12345\n"
+ "six=0x123456\n"
+ "seven=1234567\n"
+ "eight=12345678\n"
"\n"
"[stuff]\n"
"flag= true \n"
@@ -609,6 +619,156 @@ ZUC_TEST_F(config_test_t1, test028, data)
ZUC_ASSERT_EQ(ERANGE, errno);
}
+ZUC_TEST_F(config_test_t1, test029, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "hash", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x12345678, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test030, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "zerox", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x12345678, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test031, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "one", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0xff111111, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test032, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "two", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0xff121212, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test033, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "three", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0xff112233, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test034, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "four", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x11223344, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test035, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "five", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(-1, r);
+ ZUC_ASSERT_EQ(0xff336699, n);
+ ZUC_ASSERT_EQ(EINVAL, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test036, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "six", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0xff123456, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test037, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "seven", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(-1, r);
+ ZUC_ASSERT_EQ(0xff336699, n);
+ ZUC_ASSERT_EQ(EINVAL, errno);
+}
+
+ZUC_TEST_F(config_test_t1, test038, data)
+{
+ int r;
+ uint32_t n;
+ struct weston_config_section *section;
+ struct weston_config *config = data;
+
+ section = weston_config_get_section(config, "colors", NULL, NULL);
+ r = weston_config_section_get_color(section, "eight", &n, 0xff336699);
+
+ ZUC_ASSERT_EQ(0, r);
+ ZUC_ASSERT_EQ(0x12345678, n);
+ ZUC_ASSERT_EQ(0, errno);
+}
+
ZUC_TEST_F(config_test_t2, doesnt_parse, data)
{
struct weston_config *config = data;
--
Cheers,
Eric
More information about the wayland-devel
mailing list