Browse Source

* update test: build in release config

master
Alex 'AdUser' Z 9 years ago
parent
commit
d804f15906
  1. 40
      t/t_config_param.c
  2. 2
      t/t_filters.c
  3. 22
      t/t_ipaddr.c
  4. 44
      t/t_logfile.c

40
t/t_config_param.c

@ -4,32 +4,46 @@
int main() {
f2b_config_param_t *param = NULL;
assert(f2b_config_param_create("") == NULL);
assert(f2b_config_param_create("#") == NULL);
assert(f2b_config_param_create("=") == NULL);
assert(f2b_config_param_create("key=") == NULL);
assert(f2b_config_param_create("key =") == NULL);
assert(f2b_config_param_create("key = ") == NULL);
assert(f2b_config_param_create( "=value") == NULL);
assert(f2b_config_param_create( "= value") == NULL);
assert(f2b_config_param_create(" = value") == NULL);
assert(param == NULL);
f2b_config_param_create("");
assert(param == NULL);
f2b_config_param_create("#");
assert(param == NULL);
f2b_config_param_create("=");
assert(param == NULL);
f2b_config_param_create("key=");
assert(param == NULL);
f2b_config_param_create("key =");
assert(param == NULL);
f2b_config_param_create("key = ");
assert(param == NULL);
f2b_config_param_create( "=value");
assert(param == NULL);
f2b_config_param_create( "= value");
assert(param == NULL);
f2b_config_param_create(" = value");
assert(param == NULL);
assert((param = f2b_config_param_create("key=value")) != NULL);
param = f2b_config_param_create("key=value");
assert(param != NULL);
assert(strcmp(param->name, "key") == 0);
assert(strcmp(param->value, "value") == 0);
free(param);
assert((param = f2b_config_param_create("key = value")) != NULL);
param = f2b_config_param_create("key = value");
assert(param != NULL);
assert(strcmp(param->name, "key") == 0);
assert(strcmp(param->value, "value") == 0);
free(param);
assert((param = f2b_config_param_create("key=value #comment")) != NULL);
param = f2b_config_param_create("key=value #comment");
assert(param != NULL);
assert(strcmp(param->name, "key") == 0);
assert(strcmp(param->value, "value") == 0);
free(param);
assert((param = f2b_config_param_create("key=value#compose")) != NULL);
param = f2b_config_param_create("key=value#compose");
assert(param != NULL);
assert(strcmp(param->name, "key") == 0);
assert(strcmp(param->value, "value#compose") == 0);
free(param);

2
t/t_filters.c

@ -8,6 +8,8 @@ int main() {
char matchbuf[IPADDR_MAX] = "";
bool result = false;
UNUSED(result);
filter = create("test");
assert(filter != NULL);

22
t/t_ipaddr.c

@ -2,13 +2,21 @@
#include "../src/ipaddr.h"
int main() {
bool res = false;
f2b_ipaddr_t *list = NULL;
f2b_ipaddr_t *addr = NULL;
assert(f2b_addrlist_lookup(list, "127.0.0.1") == NULL);
UNUSED(res);
UNUSED(addr);
UNUSED(list);
assert((addr = f2b_ipaddr_create("400.400.400.400", 15)) == NULL);
assert((addr = f2b_ipaddr_create("127.0.0.1", 15)) != NULL);
addr = f2b_addrlist_lookup(list, "127.0.0.1");
assert(addr == NULL);
addr = f2b_ipaddr_create("400.400.400.400", 15);
assert(addr == NULL);
addr = f2b_ipaddr_create("127.0.0.1", 15);
assert(addr != NULL);
assert(addr->type == AF_INET);
assert(addr->next == NULL);
@ -17,12 +25,14 @@ int main() {
assert(addr->matches.max == 15);
assert(addr->matches.used == 0);
assert((list = f2b_addrlist_append(list, addr)) != NULL);
list = f2b_addrlist_append(list, addr);
assert(list != NULL);
assert(f2b_addrlist_lookup(list, "127.0.0.1") != NULL);
assert(list == addr);
assert((list = f2b_addrlist_remove(list, "127.4.4.4")) != NULL);
assert((list = f2b_addrlist_remove(list, "127.0.0.1")) == NULL);
list = f2b_addrlist_remove(list, "127.4.4.4");
assert(list != NULL);
list = f2b_addrlist_remove(list, "127.0.0.1");
assert(list == NULL);
assert((addr = f2b_ipaddr_create("127.0.0.1", 15)) != NULL);

44
t/t_logfile.c

@ -5,32 +5,50 @@ int main() {
f2b_logfile_t file;
char filename[] = "/tmp/f2b-test.XXXXXX";
int fd = 0;
int ret;
bool res;
FILE *wfd = NULL;
char buf[2048];
assert((fd = mkstemp(filename)) > 0);
assert((wfd = fdopen(fd, "a")) != NULL);
assert(fputs("test1\n", wfd) > 0);
assert(fflush(wfd) == 0);
UNUSED(res);
UNUSED(ret);
assert(f2b_logfile_open(&file, filename) == true);
assert(f2b_logfile_getline(&file, buf, sizeof(buf)) == false);
fd = mkstemp(filename);
assert(fd > 0);
wfd = fdopen(fd, "a");
assert(wfd != NULL);
ret = fputs("test1\n", wfd);
assert(ret > 0);
ret = fflush(wfd);
assert(ret == 0);
assert(fputs("test2\n", wfd) > 0);
assert(fflush(wfd) == 0);
res = f2b_logfile_open(&file, filename);
assert(res == true);
res = f2b_logfile_getline(&file, buf, sizeof(buf));
assert(res == false);
assert(f2b_logfile_getline(&file, buf, sizeof(buf)) == true);
assert(strncmp(buf, "test2\n", sizeof(buf)) == 0);
ret = fputs("test2\n", wfd);
assert(ret > 0);
ret = fflush(wfd);
assert(ret == 0);
assert(f2b_logfile_getline(&file, buf, sizeof(buf)) == false);
res = f2b_logfile_getline(&file, buf, sizeof(buf));
assert(res == true);
ret = strncmp(buf, "test2\n", sizeof(buf));
assert(ret == 0);
res = f2b_logfile_getline(&file, buf, sizeof(buf));
assert(res == false);
fclose(wfd);
close(fd);
unlink(filename);
assert((wfd = fopen(filename, "a")) != 0);
wfd = fopen(filename, "a");
assert(wfd != NULL);
assert(f2b_logfile_rotated(&file) == true);
res = f2b_logfile_rotated(&file);
assert(res == true);
f2b_logfile_close(&file);
fclose(wfd);

Loading…
Cancel
Save