at work
This commit is contained in:
57
tests/cfparser_test.c
Normal file
57
tests/cfparser_test.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user