Blame SOURCES/0063-testsuite-add-test-for-xstrdup_between-src-open-clos.patch

0c9110
From 043c763822b5198c692750fda290385e93caee27 Mon Sep 17 00:00:00 2001
0c9110
From: Jakub Filak <jfilak@redhat.com>
0c9110
Date: Thu, 11 Sep 2014 15:32:38 +0200
0c9110
Subject: [LIBREPORT PATCH 63/93] testsuite: add test for xstrdup_between(src,
0c9110
 open, close)
0c9110
0c9110
Related to rhbz#1140224
0c9110
0c9110
Signed-off-by: Jakub Filak <jfilak@redhat.com>
0c9110
---
0c9110
 tests/Makefile.am  |  3 ++-
0c9110
 tests/testsuite.at |  1 +
0c9110
 tests/xfuncs.at    | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
0c9110
 3 files changed, 59 insertions(+), 1 deletion(-)
0c9110
 create mode 100644 tests/xfuncs.at
0c9110
0c9110
diff --git a/tests/Makefile.am b/tests/Makefile.am
0c9110
index 750fa16..664c43f 100644
0c9110
--- a/tests/Makefile.am
0c9110
+++ b/tests/Makefile.am
0c9110
@@ -39,7 +39,8 @@ TESTSUITE_AT = \
0c9110
   make_description.at \
0c9110
   libreport_types.at \
0c9110
   xml_definition.at \
0c9110
-  report_python.at
0c9110
+  report_python.at \
0c9110
+  xfuncs.at
0c9110
 
0c9110
 EXTRA_DIST += $(TESTSUITE_AT)
0c9110
 TESTSUITE = $(srcdir)/testsuite
0c9110
diff --git a/tests/testsuite.at b/tests/testsuite.at
0c9110
index a569457..92129d8 100644
0c9110
--- a/tests/testsuite.at
0c9110
+++ b/tests/testsuite.at
0c9110
@@ -1,6 +1,7 @@
0c9110
 # Test suite for abrt.
0c9110
 # See http://www.gnu.org/software/hello/manual/autoconf/Writing-Testsuites.html
0c9110
 
0c9110
+m4_include([xfuncs.at])
0c9110
 m4_include([strbuf.at])
0c9110
 m4_include([osrelease.at])
0c9110
 m4_include([osinfo.at])
0c9110
diff --git a/tests/xfuncs.at b/tests/xfuncs.at
0c9110
new file mode 100644
0c9110
index 0000000..d7e947a
0c9110
--- /dev/null
0c9110
+++ b/tests/xfuncs.at
0c9110
@@ -0,0 +1,56 @@
0c9110
+# -*- Autotest -*-
0c9110
+
0c9110
+AT_BANNER([xfuncs])
0c9110
+
0c9110
+## --------------- ##
0c9110
+## xstrdup_between ##
0c9110
+## --------------- ##
0c9110
+
0c9110
+AT_TESTFUN([xstrdup_between],
0c9110
+[[#include "internal_libreport.h"
0c9110
+#include <assert.h>
0c9110
+#include <string.h>
0c9110
+#include <stdio.h>
0c9110
+
0c9110
+#define DEBUG_PRINT(e, r, o, c, s) \
0c9110
+        fprintf(stderr, "Expected: '%s'\nFound:    '%s'\nOpen:     '%s'\nClose:    '%s'\nSource:   '%s'\n", e, r, o, c, s)
0c9110
+
0c9110
+void test(const char *src, const char *open, const char *close, const char *exp)
0c9110
+{
0c9110
+    char *res = xstrdup_between(src, open, close);
0c9110
+
0c9110
+    if (exp == NULL && res != NULL)
0c9110
+    {
0c9110
+        DEBUG_PRINT("NULL", res, open, close, src);
0c9110
+        assert(!"Found non-existing section.");
0c9110
+    }
0c9110
+    else if (exp != NULL && res == NULL)
0c9110
+    {
0c9110
+        DEBUG_PRINT(exp, "NULL", open, close, src);
0c9110
+        assert(!"Didn't find section.");
0c9110
+    }
0c9110
+    else if (exp == NULL && res == NULL)
0c9110
+        return;
0c9110
+    else if (strcmp(res, exp) != 0)
0c9110
+    {
0c9110
+        DEBUG_PRINT(exp, res, open, close, src);
0c9110
+        assert(!"Invalid selection.");
0c9110
+    }
0c9110
+
0c9110
+    free(res);
0c9110
+}
0c9110
+
0c9110
+
0c9110
+int main(void)
0c9110
+{
0c9110
+    g_verbose=3;
0c9110
+
0c9110
+    test("foo blah", "", "", NULL);
0c9110
+    test("foo blah", "", "</?>", NULL);
0c9110
+    test("", "", "", "");
0c9110
+    test("@.$.@GOOD.$.", "@.$.@", ".$.", "GOOD");
0c9110
+
0c9110
+    return 0;
0c9110
+}
0c9110
+
0c9110
+]])
0c9110
-- 
0c9110
1.8.3.1
0c9110