Blob Blame History Raw
From 043c763822b5198c692750fda290385e93caee27 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Thu, 11 Sep 2014 15:32:38 +0200
Subject: [LIBREPORT PATCH 63/93] testsuite: add test for xstrdup_between(src,
 open, close)

Related to rhbz#1140224

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 tests/Makefile.am  |  3 ++-
 tests/testsuite.at |  1 +
 tests/xfuncs.at    | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 tests/xfuncs.at

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 750fa16..664c43f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,7 +39,8 @@ TESTSUITE_AT = \
   make_description.at \
   libreport_types.at \
   xml_definition.at \
-  report_python.at
+  report_python.at \
+  xfuncs.at
 
 EXTRA_DIST += $(TESTSUITE_AT)
 TESTSUITE = $(srcdir)/testsuite
diff --git a/tests/testsuite.at b/tests/testsuite.at
index a569457..92129d8 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -1,6 +1,7 @@
 # Test suite for abrt.
 # See http://www.gnu.org/software/hello/manual/autoconf/Writing-Testsuites.html
 
+m4_include([xfuncs.at])
 m4_include([strbuf.at])
 m4_include([osrelease.at])
 m4_include([osinfo.at])
diff --git a/tests/xfuncs.at b/tests/xfuncs.at
new file mode 100644
index 0000000..d7e947a
--- /dev/null
+++ b/tests/xfuncs.at
@@ -0,0 +1,56 @@
+# -*- Autotest -*-
+
+AT_BANNER([xfuncs])
+
+## --------------- ##
+## xstrdup_between ##
+## --------------- ##
+
+AT_TESTFUN([xstrdup_between],
+[[#include "internal_libreport.h"
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#define DEBUG_PRINT(e, r, o, c, s) \
+        fprintf(stderr, "Expected: '%s'\nFound:    '%s'\nOpen:     '%s'\nClose:    '%s'\nSource:   '%s'\n", e, r, o, c, s)
+
+void test(const char *src, const char *open, const char *close, const char *exp)
+{
+    char *res = xstrdup_between(src, open, close);
+
+    if (exp == NULL && res != NULL)
+    {
+        DEBUG_PRINT("NULL", res, open, close, src);
+        assert(!"Found non-existing section.");
+    }
+    else if (exp != NULL && res == NULL)
+    {
+        DEBUG_PRINT(exp, "NULL", open, close, src);
+        assert(!"Didn't find section.");
+    }
+    else if (exp == NULL && res == NULL)
+        return;
+    else if (strcmp(res, exp) != 0)
+    {
+        DEBUG_PRINT(exp, res, open, close, src);
+        assert(!"Invalid selection.");
+    }
+
+    free(res);
+}
+
+
+int main(void)
+{
+    g_verbose=3;
+
+    test("<a>foo blah</a>", "<?>", "</a>", NULL);
+    test("<a>foo blah</a>", "<a>", "</?>", NULL);
+    test("<a></a>", "<a>", "</a>", "");
+    test("@.$.@GOOD.$.", "@.$.@", ".$.", "GOOD");
+
+    return 0;
+}
+
+]])
-- 
1.8.3.1