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

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