diff --git a/lfile.c b/lfile.c index 4635346..920c91c 100644 --- a/lfile.c +++ b/lfile.c @@ -1,6 +1,6 @@ /* Parse UNIX /etc configuration files like /etc/protocols and /etc/services * - * Copyright (c) 2015 Joachim Nilsson + * Copyright (c) 2015-2016 Joachim Nilsson * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -187,47 +187,8 @@ int fgetint(char *file, char *sep, char *key) return val; } -#ifdef UNITTEST -int main(void) -{ - int val; - lfile_t lf; - - val = fgetint("/etc/protocols", " \n\t", "udp"); - if (val == -1) { - perror("Failed locating 'udp' protocol"); - return 1; - } - printf("udp has proto %d\n", val); - - val = fgetint("/etc/services", " /\n\t", "ftp"); - if (val == -1) { - perror("Failed locating 'ftp' service"); - return 1; - } - printf("ftp is inet port %d\n", val); - - val = fgetint("/etc/group", "x:\n", "utmp"); - if (val == -1) { - perror("Failed locating group 'utmp'"); - return 1; - } - printf("utmp is gid %d\n", val); - - val = fgetint("/etc/passwd", "x:\n", "nobody"); - if (val == -1) { - perror("Failed locating user 'nobody'"); - return 1; - } - printf("nobody is uid %d\n", val); - - return 0; -} -#endif - /** * Local Variables: - * compile-command: "make V=1 -f lfile.mk" * indent-tabs-mode: t * c-file-style: "linux" * End: diff --git a/lfile.mk b/lfile.mk deleted file mode 100644 index 91fadb8..0000000 --- a/lfile.mk +++ /dev/null @@ -1,4 +0,0 @@ -OBJS = -TARGET = lfile.test clean - -include rules.mk diff --git a/tests/.gitignore b/tests/.gitignore index e5fbc6e..f8c7922 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,5 +1,7 @@ *.log *.trs +lfile makepath pidfile +tempfile tree diff --git a/tests/Makefile.am b/tests/Makefile.am index 82edab1..be35a07 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = check.h CLEANFILES = *~ *.trs *.log TESTS = +TESTS += lfile TESTS += makepath TESTS += pidfile TESTS += tempfile diff --git a/tests/lfile.c b/tests/lfile.c new file mode 100644 index 0000000..dd82628 --- /dev/null +++ b/tests/lfile.c @@ -0,0 +1,37 @@ +#include +#include "check.h" + +int main(void) +{ + int val; + + val = fgetint("/etc/protocols", " \n\t", "udp"); + if (val == -1) { + perror("Failed locating 'udp' protocol"); + return 1; + } + printf("udp has proto %d\n", val); + + val = fgetint("/etc/services", " /\n\t", "ftp"); + if (val == -1) { + perror("Failed locating 'ftp' service"); + return 1; + } + printf("ftp is inet port %d\n", val); + + val = fgetint("/etc/group", "x:\n", "utmp"); + if (val == -1) { + perror("Failed locating group 'utmp'"); + return 1; + } + printf("utmp is gid %d\n", val); + + val = fgetint("/etc/passwd", "x:\n", "nobody"); + if (val == -1) { + perror("Failed locating user 'nobody'"); + return 1; + } + printf("nobody is uid %d\n", val); + + return 0; +}