[LIBREPORT PATCH] test: added unit test for parse_list
Jiri Moskovcak
jmoskovc at redhat.com
Fri Jul 19 18:30:22 UTC 2013
---
tests/glib_helpers.at | 40 ++++++++++++++++++++++++++++++++++++++++
tests/testsuite.at | 1 +
2 files changed, 41 insertions(+)
create mode 100644 tests/glib_helpers.at
diff --git a/tests/glib_helpers.at b/tests/glib_helpers.at
new file mode 100644
index 0000000..e118819
--- /dev/null
+++ b/tests/glib_helpers.at
@@ -0,0 +1,40 @@
+# -*- Autotest -*-
+
+AT_BANNER([glib helpers])
+
+## -------------------------- ##
+## parse comma separated list ##
+## -------------------------- ##
+
+AT_TESTFUN([parse_list],
+[[
+#include "internal_libreport.h"
+#include <assert.h>
+
+/* Test parsing different release strings */
+int test(const char *list, const char *strings[])
+{
+ GList *l = parse_list(list);
+ char **tmp = (char **)strings;
+ int retval = 0;
+
+ while(l != NULL) {
+ log("is: '%s'", (char *)l->data);
+ log("should be: '%s'", *tmp);
+ retval |= strcmp((char *)l->data, *(tmp++)) != 0;
+ if (retval)
+ break; // no need to continue further
+ l = g_list_next(l);
+ }
+
+ return retval;
+}
+
+int main(void)
+{
+ const char *string_list = "hello,world,fedora,redhat";
+ const char *strings[] = {"hello", "world", "fedora", "redhat"};
+
+ assert(test(string_list, strings) == 0);
+}
+]])
diff --git a/tests/testsuite.at b/tests/testsuite.at
index a67b7d9..596854d 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -6,3 +6,4 @@ m4_include([osrelease.at])
m4_include([osinfo.at])
m4_include([is_text_file.at])
m4_include([taghyperlinks.at])
+m4_include([glib_helpers.at])
--
1.8.3.1
More information about the Crash-catcher
mailing list