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