1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
}
|