aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-26 11:36:55 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-26 11:36:55 +0000
commitcd9b9360032268cf65bed067b9acbf13e3269282 (patch)
treef783082deacab896613dd3775a3461298a113fcc /tests
parenttest: config: add test_uint32() utility function (diff)
test: config: add test_double() utility function
Diffstat (limited to 'tests')
-rw-r--r--tests/test-config.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test-config.c b/tests/test-config.c
index 7cde7408..2ba2795b 100644
--- a/tests/test-config.c
+++ b/tests/test-config.c
@@ -220,6 +220,43 @@ test_uint32(struct context *ctx, bool (*parse_fun)(struct context *ctx),
}
static void
+test_double(struct context *ctx, bool (*parse_fun)(struct context *ctx),
+ const char *key, const float *conf_ptr)
+{
+ ctx->key = key;
+
+ static const struct {
+ const char *option_string;
+ float value;
+ bool invalid;
+ } input[] = {
+ {"0", 0}, {"0.1", 0.1}, {"1e10", 1e10}, {"-10.7", -10.7},
+ {"abc", 0, true}, {"true", 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);
+ }
+ if (*conf_ptr != input[i].value) {
+ BUG("[%s].%s=%s: set value (%f) not the expected one (%f)",
+ ctx->section, ctx->key, ctx->value,
+ *conf_ptr, input[i].value);
+ }
+ }
+ }
+}
+
+static void
test_pt_or_px(struct context *ctx, bool (*parse_fun)(struct context *ctx),
const char *key, const struct pt_or_px *conf_ptr)
{