summaryrefslogtreecommitdiff
path: root/tests/test_config.c
diff options
context:
space:
mode:
authorinfo@mode42.com <info@mode42.com>2026-08-08 03:54:55 +0000
committerinfo@mode42.com <info@mode42.com>2026-08-08 03:54:55 +0000
commit20cb29c2f8c5c87bc590896854a20b1473ceb358 (patch)
tree2857f41513a56ad41af97b57362639298aa7f033 /tests/test_config.c
#2
Diffstat (limited to 'tests/test_config.c')
-rw-r--r--tests/test_config.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_config.c b/tests/test_config.c
new file mode 100644
index 0000000..006d6b5
--- /dev/null
+++ b/tests/test_config.c
@@ -0,0 +1,60 @@
+#include "hybbx/config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static unsigned g_failures;
+
+static void check_str(const char *label, const char *got, const char *want)
+{
+ if (got == NULL || want == NULL || strcmp(got, want) != 0) {
+ fprintf(stderr, "FAIL %s: got '%s' want '%s'\n",
+ label, got != NULL ? got : "(null)", want);
+ g_failures++;
+ }
+}
+
+int main(void)
+{
+ hybbx_config_t cfg;
+ const char *path = "hybbx_test_config.ini";
+ FILE *fp;
+
+ fp = fopen(path, "w");
+ if (fp == NULL) {
+ fprintf(stderr, "FAIL fopen\n");
+ return 1;
+ }
+
+ fputs("[log]\n", fp);
+ fputs("dir = logs ; relative to install root\n", fp);
+ fputs("level = info # debug level\n", fp);
+ fputs("[quoted]\n", fp);
+ fputs("path = \"data;keep\" ; trailing comment\n", fp);
+ fclose(fp);
+
+ if (hybbx_config_load(&cfg, path) != HYBBX_OK) {
+ fprintf(stderr, "FAIL config load\n");
+ remove(path);
+ return 1;
+ }
+
+ check_str("inline semicolon", hybbx_config_get(&cfg, "log", "dir", NULL),
+ "logs");
+ check_str("inline hash", hybbx_config_get(&cfg, "log", "level", NULL),
+ "info");
+ check_str("quoted semicolon",
+ hybbx_config_get(&cfg, "quoted", "path", NULL), "data;keep");
+
+ hybbx_config_free(&cfg);
+ remove(path);
+
+ if (g_failures != 0) {
+ fprintf(stderr, "%u failure(s)\n", g_failures);
+ return 1;
+ }
+
+ puts("test_config: ok");
+ return 0;
+}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com