Files
cworker/cfparser_test.c
Олег Бородин 42ad1c0f93 at work
2023-08-15 14:39:09 +02:00

58 lines
1.2 KiB
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;
cflexer_t lexer;
cfparser_t parser;
rcache_init(&cache, fd);
cflexer_init(&lexer, &cache);
cfparser_init(&parser, &lexer);
if (cfparser_parse(&parser)) {
printf("parse args error\n");
return 1;
}
int64_t id = 0;
char* name = "";
bool debug = false;
cfparser_bind(&parser, CFVALTYPE_BOOL, "debug", (void *)&debug);
cfparser_bind(&parser, CFVALTYPE_INT, "id", (void *)&id);
cfparser_bind(&parser, CFVALTYPE_STR, "name", (void *)&name);
cfparser_destroy(&parser);
cflexer_destroy(&lexer);
rcache_destroy(&cache);
MASSERT(id == -123);
MASSERT(strcmp(name, "qwerty\"567") == 0);
MASSERT(debug == true);
printf("id = %ld\n", id);
printf("name = %s\n", name);
printf("debug = %d\n", debug);
return 0;
}