LP#1709710: write unit tests for osrfXmlEscapingLength()
[opensrf-equinox.git] / tests / check_osrf_utils.c
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());
+}