diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-12-29 18:43:01 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-12-29 18:43:01 +0000 |
| commit | 7938b9e811c76fe32b7ed5177c931a729003cc0c (patch) | |
| tree | 0a91a593bba981d0ce107d1b317b0a44ef0009da /tests | |
| parent | test: config: test csd section (diff) | |
test: config: add test_color() utility function
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-config.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test-config.c b/tests/test-config.c index e7a4477f..388066b0 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -364,6 +364,40 @@ test_enum(struct context *ctx, bool (*parse_fun)(struct context *ctx), } } + +static void +test_color(struct context *ctx, bool (*parse_fun)(struct context *ctx), + const char *key, bool alpha_allowed, uint32_t *ptr) +{ + ctx->key = key; + + const struct { + const char *option_string; + uint32_t color; + bool invalid; + } input[] = { + {"000000", 0}, + {"ffffff", 0xffffff}, + {"ffffffff", 0xffffffff, !alpha_allowed}, + {"unittest-invalid-color", 0, true}, + }; + + for (size_t i = 0; i < ALEN(input); i++) { + ctx->value = input[i].option_string; + if (input[i].invalid) { + if (parse_fun(ctx)) { + BUG("[%s].%s=%s: did not fail to parse as expected", + ctx->section, ctx->key, ctx->value); + } + } else { + if (!parse_fun(ctx)) { + BUG("[%s].%s=%s: failed to parse", + ctx->section, ctx->key, ctx->value); + } + } + } +} + static void test_section_main(void) { |
