[Expat-CVS] expat/tests runtests.c,1.30,1.31

Fred L. Drake fdrake@users.sourceforge.net
Thu Aug 22 20:36:02 2002


Update of /cvsroot/expat/expat/tests
In directory usw-pr-cvs1:/tmp/cvs-serv9010

Modified Files:
	runtests.c 
Log Message:
Factor out some error reporting code used when the parser is expected
to report an error, and either doesn't report an error at all or
reports the wrong error.


Index: runtests.c
===================================================================
RCS file: /cvsroot/expat/expat/tests/runtests.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- runtests.c	23 Aug 2002 03:14:01 -0000	1.30
+++ runtests.c	23 Aug 2002 03:35:40 -0000	1.31
@@ -45,6 +45,20 @@
 
 #define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__)
 
+static void
+_expect_failure(char *text, enum XML_Error errorCode, char *errorMessage,
+                char *file, int lineno)
+{
+    if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK)
+        fail(errorMessage);
+    if (XML_GetErrorCode(parser) != errorCode)
+        _xml_failure(parser, file, lineno);
+}
+
+#define expect_failure(text, errorCode, errorMessage) \
+        _expect_failure((text), (errorCode), (errorMessage), \
+                        __FILE__, __LINE__)
+
 
 /*
  * Character & encoding tests.
@@ -65,13 +79,10 @@
 
 START_TEST(test_u0000_char)
 {
-    char *text = "<doc>&#0;</doc>";
-
     /* test that a NUL byte (in US-ASCII data) is an error */
-    if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK)
-        fail("Parser did not report error on NUL-byte.");
-    if (XML_GetErrorCode(parser) != XML_ERROR_BAD_CHAR_REF)
-        xml_failure(parser);
+    expect_failure("<doc>&#0;</doc>",
+                   XML_ERROR_BAD_CHAR_REF,
+                   "Parser did not report error on NUL-byte.");
 }
 END_TEST
 
@@ -464,18 +475,11 @@
 
 START_TEST(test_xmldecl_misplaced)
 {
-    char *text =
-        "\n"
-        "<?xml version='1.0'?>\n"
-        "<a>&eee;</a>";
-
-    if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) {
-        if (XML_GetErrorCode(parser) != XML_ERROR_MISPLACED_XML_PI)
-            xml_failure(parser);
-    }
-    else {
-        fail("expected XML_ERROR_MISPLACED_XML_PI with misplaced XML decl");
-    }
+    expect_failure("\n"
+                   "<?xml version='1.0'?>\n"
+                   "<a/>",
+                   XML_ERROR_MISPLACED_XML_PI,
+                   "failed to report misplaced XML declaration");
 }
 END_TEST
 
@@ -525,12 +529,9 @@
    have an external subset.
 */
 START_TEST(test_wfc_undeclared_entity_no_external_subset) {
-    char *text = "<doc>&entity;</doc>";
-
-    if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK)
-        fail("Parser did not report error on undefined entity w/out a DTD.");
-    if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY)
-        xml_failure(parser);
+    expect_failure("<doc>&entity;</doc>",
+                   XML_ERROR_UNDEFINED_ENTITY,
+                   "Parser did not report undefined entity w/out a DTD.");
 }
 END_TEST
 
@@ -543,10 +544,9 @@
         "<!DOCTYPE doc SYSTEM 'foo'>\n"
         "<doc>&entity;</doc>";
 
-    if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK)
-        fail("Parser did not report error on undefined entity (standalone).");
-    if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY)
-        xml_failure(parser);
+    expect_failure(text,
+                   XML_ERROR_UNDEFINED_ENTITY,
+                   "Parser did not report undefined entity (standalone).");
 }
 END_TEST