Added a boolean return value from LmParser::parse to be able to check whether it was successful
authorMikael Hallendal <micke@imendio.com>
Sat, 07 Jun 2008 11:22:19 +0200
changeset 399 b5ebdc9d8152
parent 398 d81f80894575
child 400 5a4f3a49212a
Added a boolean return value from LmParser::parse to be able to check whether it was successful
loudmouth/lm-parser.c
loudmouth/lm-parser.h
tests/test-parser.c
--- a/loudmouth/lm-parser.c	Sat Jun 07 11:21:42 2008 +0200
+++ b/loudmouth/lm-parser.c	Sat Jun 07 11:22:19 2008 +0200
@@ -239,10 +239,10 @@
 	return parser;
 }
 
-void
+gboolean
 lm_parser_parse (LmParser *parser, const gchar *string)
 {
-	g_return_if_fail (parser != NULL);
+	g_return_val_if_fail (parser != NULL, FALSE);
 	
         if (!parser->context) {
                 parser->context = g_markup_parse_context_new (parser->m_parser, 0,
@@ -250,10 +250,12 @@
         }
         
         if (g_markup_parse_context_parse (parser->context, string, 
-                                          (gssize)strlen (string), NULL)) {
+					  (gssize)strlen (string), NULL)) {
+		return TRUE;
         } else {
 		g_markup_parse_context_free (parser->context);
 		parser->context = NULL;
+		return FALSE;
         }
 }
 
--- a/loudmouth/lm-parser.h	Sat Jun 07 11:21:42 2008 +0200
+++ b/loudmouth/lm-parser.h	Sat Jun 07 11:22:19 2008 +0200
@@ -33,7 +33,7 @@
 LmParser *   lm_parser_new       (LmParserMessageFunction  function,
 				  gpointer                 user_data,
 				  GDestroyNotify           notify);
-void         lm_parser_parse     (LmParser                *parser,
+gboolean     lm_parser_parse     (LmParser                *parser,
 				  const gchar             *string);
 void         lm_parser_free      (LmParser                *parser);
 
--- a/tests/test-parser.c	Sat Jun 07 11:21:42 2008 +0200
+++ b/tests/test-parser.c	Sat Jun 07 11:22:19 2008 +0200
@@ -80,7 +80,7 @@
 		return;
 	}
 	    
-	lm_parser_parse (parser, file_contents);
+	g_assert (lm_parser_parse (parser, file_contents) == is_valid);
 	lm_parser_free (parser);
 	g_free (file_contents);
 }
@@ -107,6 +107,7 @@
 	list = get_files ("invalid");
 	for (l = list; l; l = l->next) {
 		g_print ("INVALID: %s\n", (const gchar *) l->data);
+		test_parser_with_file ((const gchar *) l->data, FALSE);
 		g_free (l->data);
 	}
 	g_slist_free (list);