Files
cworker/cfparser_test.c
2023-08-13 23:30:26 +02:00

53 lines
1015 B
C

/*
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <cflexer.h>
#include <cfparser.h>
#include <massert.h>
#include <rcache.h>
int main(void) {
int fd = open("test.conf", O_RDONLY);
MASSERT(fd > 0);
rcache_t cache;
rcache_init(&cache, fd);
cflexer_t lexer;
cflexer_init(&lexer, &cache);
cfparser_t parser;
cfparser_init(&parser, &lexer);
if (cfparser_parse(&parser)) {
printf("parse args error\n");
return 1;
}
int64_t id = 0;
cfparser_bind(&parser, CFVALTYPE_INT, "id", (void *)&id);
char* name = "";
cfparser_bind(&parser, CFVALTYPE_STR, "name", (void *)&name);
cfparser_destroy(&parser);
cflexer_destroy(&lexer);
MASSERT(id == -123);
MASSERT(strcmp(name, "qwerty\"567") == 0);
printf("id = %ld\n", id);
printf("name = %s\n", name);
return 0;
}