diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -86,14 +86,13 @@ EXTRA_DIST = etc/distrendaemon.conf.in \ # tests -TESTS=test/check_execio test/check_asprintf test/check_csv -check_PROGRAMS=$(TESTS) +TESTS = test/check +check_PROGRAMS = $(TESTS) -#check_execio_LIBS = $(CHECK_LIBS) -#check_asprintf_LIBS = $(CHECK_LIBS) -test_check_csv_LDADD = $(CHECK_LIBS) libdistrencommon.la -test_check_execio_LDADD = $(CHECK_LIBS) libdistrencommon.la -test_check_asprintf_LDADD = $(CHECK_LIBS) libdistrencommon.la -test_check_csv_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) -test_check_execio_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) -test_check_asprintf_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) +test_check_LDADD = $(CHECK_LIBS) libdistrencommon.la +test_check_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) +test_check_SOURCES = \ + test/check.c \ + test/check_asprintf.c test/check_asprintf.h \ + test/check_csv.c test/check_csv.h \ + test/check_execio.c test/check_execio.h diff --git a/test/check.c b/test/check.c new file mode 100644 --- /dev/null +++ b/test/check.c @@ -0,0 +1,66 @@ +/* + * Copyright 2010 Nathan Phillip Brink + * + * This file is a part of DistRen. + * + * DistRen is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DistRen is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with DistRen. If not, see . + */ + +#include +#include +#include + +#include "check_asprintf.h" +#include "check_csv.h" +#include "check_execio.h" + +/** + * \brief + * Use libcheck to run our full testsuite. + */ +int main(int argc, char *argv[]) +{ + int number_failed; + size_t test_num; + + Suite *s; + SRunner *sr; + + Suite *(*suites[])() = + { + &asprintf_suite, + &csv_suite, + &execio_suite, + NULL + }; + + number_failed = 0; + + for (test_num = 0; suites[test_num]; test_num ++) + { + s = (*suites[test_num])(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + number_failed += srunner_ntests_failed(sr); + srunner_free(sr); + } + + if (number_failed) + { + fprintf(stderr, "total tests failed: %d\n", number_failed); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/test/check_asprintf.c b/test/check_asprintf.c --- a/test/check_asprintf.c +++ b/test/check_asprintf.c @@ -17,6 +17,8 @@ along with DistRen. If not, see . */ +#include "check_asprintf.h" + #include "common/asprintf.h" #include @@ -35,9 +37,16 @@ START_TEST (check_asprintf) } END_TEST -int main(int argc, char *argv[]) +Suite *asprintf_suite() { - return 0; - /* see http://check.sourceforge.net/doc/check.html/check_6.html#SEC6 */ + Suite *s; + TCase *tc; + + s = suite_create("asprintf"); + + tc = tcase_create("core"); + tcase_add_test(tc, check_asprintf); + suite_add_tcase(s, tc); + + return s; } - diff --git a/test/check_asprintf.h b/test/check_asprintf.h new file mode 100644 --- /dev/null +++ b/test/check_asprintf.h @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Nathan Phillip Brink + * + * This file is a part of DistRen. + * + * DistRen is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DistRen is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with DistRen. If not, see . + */ + +#ifndef _DISTREN_CHECK_ASPRINTF_H +#define _DISTREN_CHECK_ASPRINTF_H + +#include + +/** + * \brief + * Return a suite with a set of tests for the common/asprintf + * functionality + */ +Suite *asprintf_suite(); + +#endif /* _DISTREN_CHECK_ASPRINTF_H */ diff --git a/test/check_csv.c b/test/check_csv.c --- a/test/check_csv.c +++ b/test/check_csv.c @@ -17,6 +17,8 @@ * along with DistRen. If not, see . */ +#include "check_csv.h" + #include "common/csv.h" #include @@ -110,7 +112,7 @@ d,f,ss,e\n", vals.num_cols); } END_TEST -static Suite *csv_suite() +Suite *csv_suite() { Suite *s; TCase *tc; @@ -123,21 +125,3 @@ static Suite *csv_suite() return s; } - -int main(int argc, char *argv[]) -{ - int number_failed; - Suite *s; - SRunner *sr; - - s = csv_suite(); - sr = srunner_create(s); - - srunner_run_all(sr, CK_NORMAL); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - if (number_failed) - return EXIT_FAILURE; - return EXIT_SUCCESS; -} diff --git a/test/check_csv.h b/test/check_csv.h new file mode 100644 --- /dev/null +++ b/test/check_csv.h @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Nathan Phillip Brink + * + * This file is a part of DistRen. + * + * DistRen is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DistRen is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with DistRen. If not, see . + */ + +#ifndef _DISTREN_CHECK_CSV_H +#define _DISTREN_CHECK_CSV_H + +#include + +/** + * \brief + * Return a suite with a set of tests for the common/csv + * functionality. + */ +Suite *csv_suite(); + +#endif /* _DISTREN_CHECK_CSV_H */ diff --git a/test/check_execio.c b/test/check_execio.c --- a/test/check_execio.c +++ b/test/check_execio.c @@ -1,25 +1,28 @@ /* - Copyright 2010 Nathan Phillip Brink, Ethan Zonca - - This file is a part of DistRen. + * Copyright 2010 Nathan Phillip Brink, Ethan Zonca + * + * This file is a part of DistRen. + * + * DistRen is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DistRen is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with DistRen. If not, see . + */ - DistRen is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DistRen is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with DistRen. If not, see . -*/ +#include "check_execio.h" #include "common/execio.h" #include +#include START_TEST (check_execio) { @@ -32,21 +35,46 @@ START_TEST (check_execio) char inbuf[20]; size_t bytesread; - + size_t pos; + + pos = 1; + fail_unless(execio_open(&eio, echoargv[0], echoargv) == 0, "execio_open failed"); fail_unless(execio_read(eio, inbuf, sizeof(inbuf) - 1, &bytesread) == 0, "error using execio_read\n"); - + pos += bytesread; + + while (bytesread && pos < (sizeof(inbuf) - 1)) + { + execio_read(eio, &inbuf[pos], sizeof(inbuf) - 1 - pos, &bytesread); + pos += bytesread; + } + + fail_if (pos > 10, + "I read more than 10 bytes from the command ``echo test'' when I expected only 5 or 6 bytes"); + + inbuf[sizeof(inbuf) - 1] = '\0'; + fail_if (strncmp(inbuf, "test", 4), + "Expecting ``test''; got ``%s''", + inbuf); + fail_unless(execio_close(eio) == 0, "error using execio_close\n"); } END_TEST -int main(int argc, char *argv[]) +Suite *execio_suite() { - return 0; - /* see http://check.sourceforge.net/doc/check.html/check_6.html#SEC6 */ + Suite *s; + TCase *tc; + + s = suite_create("execio"); + + tc = tcase_create("core"); + tcase_add_test(tc, check_execio); + suite_add_tcase(s, tc); + + return s; } - diff --git a/test/check_execio.h b/test/check_execio.h new file mode 100644 --- /dev/null +++ b/test/check_execio.h @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Nathan Phillip Brink + * + * This file is a part of DistRen. + * + * DistRen is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DistRen is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with DistRen. If not, see . + */ + +#ifndef _DISTREN_CHECK_EXECIO_H +#define _DISTREN_CHECK_EXECIO_H + +#include + +/** + * \brief + * Return a suite with a set of tests for the common/csv + * functionality. + */ +Suite *execio_suite(); + +#endif /* _DISTREN_CHECK_EXECIO_H */