C unit test examples for Evergreen
authorJason Etheridge <jason@esilibrary.com>
Tue, 25 Jun 2013 20:54:45 +0000 (16:54 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 1 Aug 2013 15:22:09 +0000 (11:22 -0400)
Building off of Kevin Beswick's work in OpenSRF

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/c-apps/Makefile.am
Open-ILS/src/c-apps/tests/Makefile.am [new file with mode: 0644]
Open-ILS/src/c-apps/tests/check_idl.c [new file with mode: 0644]
Open-ILS/src/c-apps/tests/check_util.c [new file with mode: 0644]
Open-ILS/src/c-apps/tests/testsuite.c [new file with mode: 0644]
Open-ILS/src/c-apps/tests/testsuite.h [new file with mode: 0644]
configure.ac

index 003b5ef..3006373 100644 (file)
@@ -4,6 +4,8 @@
 # Process this file with automake to generate Makefile.in
 #-----------------------------------------------------------
 
 # 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
 
 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 (file)
index 0000000..df9439f
--- /dev/null
@@ -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 (file)
index 0000000..65f6d39
--- /dev/null
@@ -0,0 +1,46 @@
+#include <check.h>
+#include <ctype.h>
+#include <limits.h>
+#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 (file)
index 0000000..f7342a3
--- /dev/null
@@ -0,0 +1,46 @@
+#include <check.h>
+#include <ctype.h>
+#include <limits.h>
+#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 (file)
index 0000000..e3fcae0
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+#include <check.h>
+#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 (file)
index 0000000..b6ef586
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef __OPENSRF_CHECK_H__
+#define __OPENSRF_CHECK_H__
+
+#endif /* __OPENSRF_CHECK_H__ */
index d8ac271..99370e4 100644 (file)
@@ -342,6 +342,7 @@ if test "x$openils_core" = "xtrue"; then
 
     AC_CONFIG_FILES([Open-ILS/examples/Makefile
              Open-ILS/src/c-apps/Makefile
 
     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])
              Open-ILS/src/extras/Makefile
              Open-ILS/src/java/Makefile
              Open-ILS/src/python/Makefile])