aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-29 18:03:36 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-29 18:03:36 +0000
commita7c489980e71484e0dcfed6d406c99bc011e998e (patch)
tree0222ee80f069f806a50c36047446895696cf557a
parentrender: csd: scale border width when rendering the CSD border’s visible part (diff)
test: config: add test_enum() utility function
-rw-r--r--tests/test-config.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test-config.c b/tests/test-config.c
index 9c69c054..892b3915 100644
--- a/tests/test-config.c
+++ b/tests/test-config.c
@@ -338,6 +338,33 @@ test_spawn_template(struct context *ctx, bool (*parse_fun)(struct context *ctx),
}
static void
+test_enum(struct context *ctx, bool (*parse_fun)(struct context *ctx),
+ const char *key, size_t count, const char *enum_strings[static count],
+ int enum_values[static count], int *ptr)
+{
+ ctx->key = key;
+
+ for (size_t i = 0; i < count; i++) {
+ ctx->value = enum_strings[i];
+ if (!parse_fun(ctx)) {
+ BUG("[%s].%s=%s: failed to parse",
+ ctx->section, ctx->key, ctx->value);
+ }
+
+ if (*ptr != enum_values[i]) {
+ BUG("[%s].%s=%s: set value not the expected one: expected %d, got %d",
+ ctx->section, ctx->key, ctx->value, enum_values[i], *ptr);
+ }
+ }
+
+ ctx->value = "invalid-enum-value";
+ if (parse_fun(ctx)) {
+ BUG("[%s].%s=%s: did not fail to parse as expeced",
+ ctx->section, ctx->key, ctx->value);
+ }
+}
+
+static void
test_section_main(void)
{
struct config conf = {0};