From 33b6b485aff2b89312b9f6c3cb7f39e4857e2551 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Tue, 25 Jun 2013 16:54:45 -0400 Subject: [PATCH] C unit test examples for Evergreen Building off of Kevin Beswick's work in OpenSRF Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander --- Open-ILS/src/c-apps/Makefile.am | 2 ++ Open-ILS/src/c-apps/tests/Makefile.am | 21 ++++++++++++ Open-ILS/src/c-apps/tests/check_idl.c | 46 ++++++++++++++++++++++++++ Open-ILS/src/c-apps/tests/check_util.c | 46 ++++++++++++++++++++++++++ Open-ILS/src/c-apps/tests/testsuite.c | 15 +++++++++ Open-ILS/src/c-apps/tests/testsuite.h | 4 +++ configure.ac | 1 + 7 files changed, 135 insertions(+) create mode 100644 Open-ILS/src/c-apps/tests/Makefile.am create mode 100644 Open-ILS/src/c-apps/tests/check_idl.c create mode 100644 Open-ILS/src/c-apps/tests/check_util.c create mode 100644 Open-ILS/src/c-apps/tests/testsuite.c create mode 100644 Open-ILS/src/c-apps/tests/testsuite.h diff --git a/Open-ILS/src/c-apps/Makefile.am b/Open-ILS/src/c-apps/Makefile.am index 003b5efc59..3006373ffb 100644 --- a/Open-ILS/src/c-apps/Makefile.am +++ b/Open-ILS/src/c-apps/Makefile.am @@ -4,6 +4,8 @@ # Process this file with automake to generate Makefile.in #----------------------------------------------------------- +SUBDIRS = tests + AM_CFLAGS = $(DEF_CFLAGS) -DOSRF_LOG_PARAMS -I@top_srcdir@/include/ AM_LDFLAGS = $(DEF_LDFLAGS) -L$(DBI_LIBS) -lopensrf diff --git a/Open-ILS/src/c-apps/tests/Makefile.am b/Open-ILS/src/c-apps/tests/Makefile.am new file mode 100644 index 0000000000..df9439f6f7 --- /dev/null +++ b/Open-ILS/src/c-apps/tests/Makefile.am @@ -0,0 +1,21 @@ +export DEF_LDFLAGS = -L. -L$(TMP) -L$(OPENSRF_LIBS) +export DEF_CFLAGS = -D_LARGEFILE64_SOURCE -pipe -g -Wall -O2 -fPIC -I@top_srcdir@/include -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS) -I$(APR_HEADERS) -I$(LIBXML2_HEADERS)/libxml -I$(TMP) -I$(OPENSRF_HEADERS) +export DEF_LDLIBS = -lopensrf + +COMMON = testsuite.c +AM_CFLAGS = $(DEF_CFLAGS) -DOSRF_LOG_PARAMS +AM_LDFLAGS = $(DEF_LDLIBS) -L$(DBI_LIBS) + +TESTS = check_util check_idl +check_PROGRAMS = check_util check_idl + +check_util_SOURCES = $(COMMON) check_util.c +check_util_CFLAGS = $(AM_CFLAGS) +check_util_LDFLAGS = $(AM_LDFLAGS) -loils_idl -loils_utils -lcheck +check_util_DEPENDENCIES = ../liboils_idl.la ../liboils_utils.la + +check_idl_SOURCES = $(COMMON) check_idl.c +check_idl_CFLAGS = $(AM_CFLAGS) +check_idl_LDFLAGS = $(AM_LDFLAGS) -loils_idl -loils_utils -lcheck +check_idl_DEPENDENCIES = ../liboils_idl.la ../liboils_utils.la + diff --git a/Open-ILS/src/c-apps/tests/check_idl.c b/Open-ILS/src/c-apps/tests/check_idl.c new file mode 100644 index 0000000000..65f6d39432 --- /dev/null +++ b/Open-ILS/src/c-apps/tests/check_idl.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include "openils/oils_utils.h" +#include "openils/oils_idl.h" + +osrfHash * my_idl; + +//Set up the test fixture +void setup (void) { + my_idl = oilsInitIDL("../../../examples/fm_IDL.xml"); +} + +//Clean up the test fixture +void teardown (void) { + free(my_idl); +} + +//Tests + +START_TEST (test_loading_idl) +{ + ck_assert(my_idl); +} +END_TEST + +//END Tests + +Suite *idl_suite (void) { + //Create test suite, test case, initialize fixture + Suite *s = suite_create("idl"); + TCase *tc_core = tcase_create("Core"); + tcase_add_checked_fixture(tc_core, setup, teardown); + + //Add tests to test case + tcase_add_test(tc_core, test_loading_idl); + + //Add test case to test suite + suite_add_tcase(s, tc_core); + + return s; +} + +void run_tests (SRunner *sr) { + srunner_add_suite (sr, idl_suite()); +} diff --git a/Open-ILS/src/c-apps/tests/check_util.c b/Open-ILS/src/c-apps/tests/check_util.c new file mode 100644 index 0000000000..f7342a37f1 --- /dev/null +++ b/Open-ILS/src/c-apps/tests/check_util.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include "openils/oils_utils.h" +#include "openils/oils_idl.h" + +//Set up the test fixture +void setup (void) { +} + +//Clean up the test fixture +void teardown (void) { +} + +//Tests + +START_TEST (test_oilsUtilsIsDBTrue) +{ + ck_assert_msg( ! oilsUtilsIsDBTrue("0"), "oilsUtilIsDBTrue() should be false when passed '0'"); + ck_assert_msg( oilsUtilsIsDBTrue("1"), "oilsUtilIsDBTrue() should be true when passed '1'"); + ck_assert_msg( oilsUtilsIsDBTrue("-1"), "oilsUtilIsDBTrue() should be true when passed '-1'"); + ck_assert_msg( oilsUtilsIsDBTrue("a"), "oilsUtilIsDBTrue() should be true when passed 'a'"); + ck_assert_msg( ! oilsUtilsIsDBTrue("f"), "oilsUtilIsDBTrue() should be false when passed 'f'"); +} +END_TEST + +//END Tests + +Suite *util_suite (void) { + //Create test suite, test case, initialize fixture + Suite *s = suite_create("util"); + TCase *tc_core = tcase_create("Core"); + tcase_add_checked_fixture(tc_core, setup, teardown); + + //Add tests to test case + tcase_add_test(tc_core, test_oilsUtilsIsDBTrue); + + //Add test case to test suite + suite_add_tcase(s, tc_core); + + return s; +} + +void run_tests (SRunner *sr) { + srunner_add_suite (sr, util_suite()); +} diff --git a/Open-ILS/src/c-apps/tests/testsuite.c b/Open-ILS/src/c-apps/tests/testsuite.c new file mode 100644 index 0000000000..e3fcae0c24 --- /dev/null +++ b/Open-ILS/src/c-apps/tests/testsuite.c @@ -0,0 +1,15 @@ +#include +#include +#include "testsuite.h" + +extern void run_tests(SRunner *sr); + +int main (int argc, char **argv) +{ + SRunner *sr = srunner_create(NULL); + run_tests(sr); + srunner_run_all(sr, CK_NORMAL); + int failed = srunner_ntests_failed(sr); + srunner_free(sr); + return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/Open-ILS/src/c-apps/tests/testsuite.h b/Open-ILS/src/c-apps/tests/testsuite.h new file mode 100644 index 0000000000..b6ef586ac6 --- /dev/null +++ b/Open-ILS/src/c-apps/tests/testsuite.h @@ -0,0 +1,4 @@ +#ifndef __OPENSRF_CHECK_H__ +#define __OPENSRF_CHECK_H__ + +#endif /* __OPENSRF_CHECK_H__ */ diff --git a/configure.ac b/configure.ac index d8ac271bd5..99370e4f2e 100644 --- a/configure.ac +++ b/configure.ac @@ -342,6 +342,7 @@ if test "x$openils_core" = "xtrue"; then AC_CONFIG_FILES([Open-ILS/examples/Makefile Open-ILS/src/c-apps/Makefile + Open-ILS/src/c-apps/tests/Makefile Open-ILS/src/extras/Makefile Open-ILS/src/java/Makefile Open-ILS/src/python/Makefile]) -- 2.43.2