2006-09-10 Mikael Hallendal <micke@imendio.com>
* configure.ac:
* loudmouth/Makefile.am:
* tests/Makefile.am:
* tests/parser-tests/*:
* tests/test-parser.c:
- Some more work on unit tests for the parser.
--- a/ChangeLog Fri Sep 08 12:29:54 2006 +0000
+++ b/ChangeLog Sun Sep 10 12:24:09 2006 +0000
@@ -1,3 +1,12 @@
+2006-09-10 Mikael Hallendal <micke@imendio.com>
+
+ * configure.ac:
+ * loudmouth/Makefile.am:
+ * tests/Makefile.am:
+ * tests/parser-tests/*:
+ * tests/test-parser.c:
+ - Some more work on unit tests for the parser.
+
2006-09-08 Mikael Hallendal <micke@imendio.com>
* tests/Makefile.am:
--- a/configure.ac Fri Sep 08 12:29:54 2006 +0000
+++ b/configure.ac Sun Sep 10 12:24:09 2006 +0000
@@ -214,36 +214,6 @@
AC_SUBST(LOUDMOUTH_CFLAGS)
AC_SUBST(LOUDMOUTH_LIBS)
-
-dnl +--------------------------------------+
-dnl | Check if we shoudl build C# bindings |-------------------
-dnl +--------------------------------------+
-
-dnl --------------
-dnl | mono setup |--------------------------------------------
-dnl --------------
-dnl AC_ARG_ENABLE(mono, [ --enable-mono build mono bindings [default=auto]], enable_mono="$enableval", enable_mono=auto)
-
-dnl if test "x$enable_mono" != "xno"; then
-dnl PKG_CHECK_MODULES(,gtk-sharp,have_mono=yes,have_mono=no)
-
-dnl if test "x$have_mono" = "xyes"; then
-dnl AC_PATH_PROG(MCS, mcs, no)
-dnl AC_PATH_PROG(MONO, mono, no)
-dnl fi
-dnl else
-dnl have_mono=no
-dnl fi
-
-dnl if test "x$enable_mono" = "xyes"; then
-dnl AC_MSG_CHECKING(for mono environment)
-dnl if test "x$have_mono" = "xno"; then
-dnl AC_MSG_ERROR([not found])
-dnl fi
-dnl fi
-
-dnl AM_CONDITIONAL(HAVE_MONO, test x$have_mono = xyes)
-
AC_OUTPUT([
Makefile
docs/Makefile
@@ -251,6 +221,7 @@
loudmouth/Makefile
examples/Makefile
tests/Makefile
+tests/parser-tests/Makefile
loudmouth-1.0.pc
loudmouth.spec])
--- a/loudmouth/Makefile.am Fri Sep 08 12:29:54 2006 +0000
+++ b/loudmouth/Makefile.am Sun Sep 10 12:24:09 2006 +0000
@@ -1,12 +1,14 @@
NULL=
-AM_CPPFLAGS = \
- -I. \
- -I$(top_srcdir) \
- $(LOUDMOUTH_CFLAGS) \
- $(LIBIDN_CFLAGS) \
- -DLM_COMPILATION \
- -DRUNTIME_ENDIAN \
+TEST_DIR=$(top_srcdir)/
+
+AM_CPPFLAGS = \
+ -I. \
+ -I$(top_srcdir) \
+ $(LOUDMOUTH_CFLAGS) \
+ $(LIBIDN_CFLAGS) \
+ -DLM_COMPILATION \
+ -DRUNTIME_ENDIAN \
$(NULL)
lib_LTLIBRARIES = libloudmouth-1.la
--- a/tests/Makefile.am Fri Sep 08 12:29:54 2006 +0000
+++ b/tests/Makefile.am Sun Sep 10 12:24:09 2006 +0000
@@ -1,3 +1,5 @@
+SUBDIRS = parser-tests
+
TESTS = \
test-objects \
test-parser
@@ -18,11 +20,12 @@
-I$(top_srcdir) \
-DLM_COMPILATION \
-DRUNTIME_ENDIAN \
- $(LM_CFLAGS) \
+ $(LOUDMOUTH_CFLAGS) \
+ -DPARSER_TEST_DIR="\"$(top_srcdir)/tests/parser-tests\"" \
@CHECK_CFLAGS@
LIBS = \
- $(LM_LIBS) \
+ $(LOUDMOUTH_LIBS) \
@CHECK_LIBS@ \
$(top_builddir)/loudmouth/libloudmouth-1.la
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/.cvsignore Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/Makefile.am Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,6 @@
+EXTRA_DIST = \
+ valid-1.xml \
+ valid-2.xml \
+ valid-3.xml \
+ invalid-1.xml
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/invalid-1.xml Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,9 @@
+<stream:stream from='example.com'
+ id='someid'
+ xmlns='jabber:client'
+ xmlns:stream='http://etherx.jabber.org/streams'
+ version='1.0'>
+ <message xml:lang='en'>
+ <body>Bad XML, no closing body tag!
+ </message>
+</stream:stream>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/valid-1.xml Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,14 @@
+<stream:stream
+ from='example.com'
+ id='someid'
+ xmlns='jabber:client'
+ xmlns:stream='http://etherx.jabber.org/streams'
+ version='1.0'>
+
+ <message from='romeo@example.net'
+ to='juliet@example.com'
+ xml:lang='en'>
+ <body>Neither, fair saint, if either thee dislike.</body>
+ </message>
+</stream:stream>
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/valid-2.xml Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,14 @@
+<stream:stream
+ from='example.com'
+ id='someid'
+ xmlns='jabber:client'
+ xmlns:stream='http://etherx.jabber.org/streams'
+ version='1.0'>
+
+ <message from='romeo@example.net'
+ to='juliet@example.com'
+ xml:lang='en'>
+ <body>Neither, fair saint, if either thee dislike.</body>
+ </message>
+</stream:stream>
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/parser-tests/valid-3.xml Sun Sep 10 12:24:09 2006 +0000
@@ -0,0 +1,14 @@
+<stream:stream
+ from='example.com'
+ id='someid'
+ xmlns='jabber:client'
+ xmlns:stream='http://etherx.jabber.org/streams'
+ version='1.0'>
+
+ <message from='romeo@example.net'
+ to='juliet@example.com'
+ xml:lang='en'>
+ <body>the printout is: name:'.00BD2.A52?'</body>
+ </message>
+</stream:stream>
+
--- a/tests/test-parser.c Fri Sep 08 12:29:54 2006 +0000
+++ b/tests/test-parser.c Sun Sep 10 12:24:09 2006 +0000
@@ -19,15 +19,107 @@
*/
#include <stdlib.h>
-#include <check.h>
+#include <check.h>
+#include <glib.h>
+
+#include "loudmouth/lm-parser.h"
+
+static GSList *
+get_files (const gchar *prefix)
+{
+ GSList *list = NULL;
+ GError *error = NULL;
+ GDir *dir;
+ const gchar *name;
+
+ dir = g_dir_open (PARSER_TEST_DIR, 0, &error);
+
+ if (!dir) {
+ g_error ("Failed to open test file directory '%s' due to: %s",
+ PARSER_TEST_DIR, error->message);
+ g_clear_error (&error);
+
+ return NULL;
+ }
+
+
+ while ((name = g_dir_read_name (dir))) {
+ /* Find *.xml */
+
+ if (g_str_has_prefix (name, prefix) &&
+ g_str_has_suffix (name, ".xml")) {
+ gchar *file_path;
+
+ file_path = g_strconcat (PARSER_TEST_DIR, "/", name,
+ NULL);
+
+ list = g_slist_prepend (list, file_path);
+ }
+ }
+
+ g_dir_close (dir);
+ g_clear_error (&error);
+
+ return list;
+}
+
+static void
+test_parser_with_file (const gchar *file_path, gboolean is_valid)
+{
+ LmParser *parser;
+ gchar *file_contents;
+ GError *error = NULL;
+ gsize length;
+
+ parser = lm_parser_new (NULL, NULL, NULL);
+ if (!g_file_get_contents (file_path,
+ &file_contents, &length,
+ &error)) {
+ g_error ("Couldn't read file '%s': %s",
+ file_path, error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ lm_parser_parse (parser, file_contents);
+ lm_parser_free (parser);
+ g_free (file_contents);
+}
static Suite *
-create_lm_parser_suite ()
+create_lm_parser_valid_suite ()
{
- Suite *suite;
+ Suite *suite;
+ GSList *list, *l;
suite = suite_create ("LmParser");
+ list = get_files ("valid");
+ for (l = list; l; l = l->next) {
+ g_print ("VALID: %s\n", (const gchar *) l->data);
+ test_parser_with_file ((const gchar *) l->data, TRUE);
+ g_free (l->data);
+ }
+ g_slist_free (list);
+
+ return suite;
+}
+
+static Suite *
+create_lm_parser_invalid_suite ()
+{
+ Suite *suite;
+ GSList *list, *l;
+
+ suite = suite_create ("LmParser");
+
+ list = get_files ("invalid");
+ for (l = list; l; l = l->next) {
+ g_print ("INVALID: %s\n", (const gchar *) l->data);
+ g_free (l->data);
+ }
+ g_slist_free (list);
+
return suite;
}
@@ -37,7 +129,9 @@
SRunner *srunner;
int nf;
- srunner = srunner_create (create_lm_parser_suite ());
+ srunner = srunner_create (create_lm_parser_valid_suite ());
+
+ srunner_add_suite (srunner, create_lm_parser_invalid_suite ());
srunner_run_all (srunner, CK_NORMAL);
nf = srunner_ntests_failed (srunner);