[Expat-checkins] CVS: expat/tests runtests.c,1.9,1.10
Fred L. Drake
fdrake@users.sourceforge.net
Fri Apr 19 14:00:02 2002
Update of /cvsroot/expat/expat/tests
In directory usw-pr-cvs1:/tmp/cvs-serv20546/tests
Modified Files:
runtests.c
Log Message:
Added a test for SF bug #231864.
Index: runtests.c
===================================================================
RCS file: /cvsroot/expat/expat/tests/runtests.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** runtests.c 19 Apr 2002 19:18:35 -0000 1.9
--- runtests.c 19 Apr 2002 20:59:01 -0000 1.10
***************
*** 347,350 ****
--- 347,422 ----
+ /*
+ * Namespaces tests.
+ */
+
+ static void
+ namespace_setup(void)
+ {
+ parser = XML_ParserCreateNS(NULL, ' ');
+ if (parser == NULL)
+ fail("Parser not created.");
+ }
+
+ static void
+ namespace_teardown(void)
+ {
+ basic_teardown();
+ }
+
+ /* Check that an element name and attribute name match the expected values.
+ * The expected values are passed as an array reference of string pointers
+ * provided as the userData argument; the first is the expected
+ * element name, and the second is the expected attribute name.
+ */
+ static void
+ triplet_start_checker(void *userData, const XML_Char *name,
+ const XML_Char **atts)
+ {
+ char **elemstr = (char **)userData;
+ char buffer[1024];
+ if (strcmp(elemstr[0], name) != 0) {
+ sprintf(buffer, "unexpected start string: '%s'", name);
+ fail(buffer);
+ }
+ if (strcmp(elemstr[1], atts[0]) != 0) {
+ sprintf(buffer, "unexpected attribute string: '%s'", atts[0]);
+ fail(buffer);
+ }
+ }
+
+ /* Check that the element name passed to the end-element handler matches
+ * the expected value. The expected value is passed as the first element
+ * in an array of strings passed as the userData argument.
+ */
+ static void
+ triplet_end_checker(void *userData, const XML_Char *name)
+ {
+ char **elemstr = (char **)userData;
+ if (strcmp(elemstr[0], name) != 0) {
+ char buffer[1024];
+ sprintf(buffer, "unexpected end string: '%s'", name);
+ fail(buffer);
+ }
+ }
+
+ START_TEST(test_return_ns_triplet)
+ {
+ char *text =
+ "<foo:e xmlns:foo='http://expat.sf.net/' bar:a='12'\n"
+ " xmlns:bar='http://expat.sf.net/'></foo:e>";
+ char *elemstr[] = {
+ "http://expat.sf.net/ e foo",
+ "http://expat.sf.net/ a bar"
+ };
+ XML_SetReturnNSTriplet(parser, 1);
+ XML_SetUserData(parser, elemstr);
+ XML_SetElementHandler(parser, triplet_start_checker, triplet_end_checker);
+ if (!XML_Parse(parser, text, strlen(text), 1))
+ xml_failure();
+ }
+ END_TEST
+
+
static Suite *
make_basic_suite(void)
***************
*** 354,357 ****
--- 426,430 ----
TCase *tc_attrs = tcase_create("attributes");
TCase *tc_xmldecl = tcase_create("XML declaration");
+ TCase *tc_namespace = tcase_create("XML namespaces");
suite_add_tcase(s, tc_chars);
***************
*** 378,381 ****
--- 451,459 ----
tcase_add_checked_fixture(tc_xmldecl, basic_setup, basic_teardown);
tcase_add_test(tc_xmldecl, test_xmldecl_misplaced);
+
+ suite_add_tcase(s, tc_namespace);
+ tcase_add_checked_fixture(tc_namespace,
+ namespace_setup, namespace_teardown);
+ tcase_add_test(tc_namespace, test_return_ns_triplet);
return s;