LP#1709710: write unit tests for osrfXmlEscapingLength()
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 8 Sep 2017 19:34:29 +0000 (15:34 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 11 Sep 2017 13:30:09 +0000 (09:30 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
tests/Makefile.am
tests/check_osrf_utils.c [new file with mode: 0644]

index 107872d..4e6b3ad 100644 (file)
@@ -3,9 +3,9 @@ OSRF_INC = $(top_srcdir)/include/opensrf
 AM_LDFLAGS = $(DEF_LDFLAGS) -R $(libdir)
 
 TESTS = check_osrf_message check_osrf_json_object check_osrf_list check_osrf_stack check_transport_client \
 AM_LDFLAGS = $(DEF_LDFLAGS) -R $(libdir)
 
 TESTS = check_osrf_message check_osrf_json_object check_osrf_list check_osrf_stack check_transport_client \
-               check_transport_message
+               check_transport_message check_osrf_utils
 check_PROGRAMS = check_osrf_message check_osrf_json_object check_osrf_list check_osrf_stack check_transport_client \
 check_PROGRAMS = check_osrf_message check_osrf_json_object check_osrf_list check_osrf_stack check_transport_client \
-                                check_transport_message
+                                check_transport_message check_osrf_utils
 
 check_osrf_message_SOURCES = $(COMMON) $(OSRF_INC)/osrf_message.h check_osrf_message.c
 check_osrf_message_CFLAGS = @CHECK_CFLAGS@ $(DEF_CFLAGS)
 
 check_osrf_message_SOURCES = $(COMMON) $(OSRF_INC)/osrf_message.h check_osrf_message.c
 check_osrf_message_CFLAGS = @CHECK_CFLAGS@ $(DEF_CFLAGS)
@@ -30,3 +30,7 @@ check_transport_client_LDADD = @CHECK_LIBS@ $(top_builddir)/src/libopensrf/libop
 check_transport_message_SOURCES = $(COMMON) $(OSRF_INC)/transport_message.h check_transport_message.c
 check_transport_message_CFLAGS = @CHECK_CFLAGS@ $(DEF_CFLAGS)
 check_transport_message_LDADD = @CHECK_LIBS@ $(top_builddir)/src/libopensrf/libopensrf.la
 check_transport_message_SOURCES = $(COMMON) $(OSRF_INC)/transport_message.h check_transport_message.c
 check_transport_message_CFLAGS = @CHECK_CFLAGS@ $(DEF_CFLAGS)
 check_transport_message_LDADD = @CHECK_LIBS@ $(top_builddir)/src/libopensrf/libopensrf.la
+
+check_osrf_utils_SOURCES = $(COMMON) $(OSRF_INC)/utils.h check_osrf_utils.c
+check_osrf_utils_CFLAGS = @CHECK_CFLAGS@ $(DEF_CFLAGS)
+check_osrf_utils_LDADD = @CHECK_LIBS@ $(top_builddir)/src/libopensrf/libopensrf.la
diff --git a/tests/check_osrf_utils.c b/tests/check_osrf_utils.c
new file mode 100644 (file)
index 0000000..b0a3a6d
--- /dev/null
@@ -0,0 +1,43 @@
+#include <check.h>
+#include "opensrf/utils.h"
+
+
+
+//Set up the test fixture
+void setup(void){
+}
+
+//Clean up the test fixture
+void teardown(void){
+}
+
+// BEGIN TESTS
+
+START_TEST(test_osrfXmlEscapingLength)
+  const char* ordinary = "12345";
+  fail_unless(osrfXmlEscapingLength(ordinary) == 0,
+      "osrfXmlEscapingLength should return 0 if string has no special characters");
+  const char* special = "<tag attr=\"attribute value\">a &amp; b</tag>";
+  ck_assert_int_eq(osrfXmlEscapingLength(special), 38);
+END_TEST
+
+//END TESTS
+
+Suite *osrf_utils_suite(void) {
+  //Create test suite, test case, initialize fixture
+  Suite *s = suite_create("osrf_utils");
+  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_osrfXmlEscapingLength);
+
+  //Add test case to test suite
+  suite_add_tcase(s, tc_core);
+
+  return s;
+}
+
+void run_tests(SRunner *sr) {
+  srunner_add_suite(sr, osrf_utils_suite());
+}