Bläddra i källkod

2004-01-14 Atsushi Enomoto <[email protected]>

	* README, Makefile, xmltest.cs : Initial checkin.

svn path=/trunk/mcs/; revision=22054
Atsushi Eno 22 år sedan
förälder
incheckning
8577b699e3

+ 3 - 0
mcs/class/System.XML/Test/System.Xml/standalone_tests/ChangeLog

@@ -0,0 +1,3 @@
+2004-01-14  Atsushi Enomoto  <[email protected]>
+
+	* README, Makefile, xmltest.cs : Initial checkin.

+ 24 - 0
mcs/class/System.XML/Test/System.Xml/standalone_tests/Makefile

@@ -0,0 +1,24 @@
+RUNTIME = mono
+MCS_RUNTIME =
+MCS = mcs
+TESTS = xsd-test-suite/suntest/SunTestsAll/xsiType1.xsd
+TEST_ARCHIVE = xmlts20031210.zip
+
+xmltest.exe : xmltest.cs $(TESTS)
+	$(MCS_RUNTIME) $(MCS) xmltest.cs
+
+$(TESTS) : $(TEST_ARCHIVE) xml-test-suite
+	cd xml-test-suite; unzip -n ../$(TEST_ARCHIVE); cd ..
+
+$(TEST_ARCHIVE) :
+	wget http://www.w3.org/XML/Test/xmlts20031210.zip
+
+xml-test-suite:
+	mkdir xml-test-suite
+
+test :
+	$(RUNTIME) xmltest.exe
+
+# be careful to use it. This removes ALL files in xml-test-suite!
+# clean:
+#	rm -rf xml-test-suite

+ 13 - 0
mcs/class/System.XML/Test/System.Xml/standalone_tests/README

@@ -0,0 +1,13 @@
+
+Small XML test system::
+
+This is a small standalone test system using W3C XML test collection.
+http://www.w3.org/XML/Test/
+
+"make" will do what you need (downloading test archive, expanding,
+compiling test runner).
+
+"make test" will do the actual tests.
+
+Atsushi Eno <[email protected]>
+

+ 140 - 0
mcs/class/System.XML/Test/System.Xml/standalone_tests/xmltest.cs

@@ -0,0 +1,140 @@
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+
+public class Test
+{
+	static char SEP = Path.DirectorySeparatorChar;
+
+	public static void Main ()
+	{
+		RunInvalidTest ("xmltest", false);
+		RunInvalidTest ("ibm", false);
+		RunInvalidTest ("sun", true);
+
+		RunValidTest ("xmltest", false);
+		RunValidTest ("ibm", false);
+		RunValidTest ("sun", true);
+
+		RunNotWellFormedTest ("xmltest", false);
+		RunNotWellFormedTest ("ibm", false);
+		RunNotWellFormedTest ("sun", true);
+
+		RunOASISTest ();
+	}
+
+	static void RunOASISTest ()
+	{
+		XmlDocument doc = new XmlDocument ();
+		foreach (FileInfo fi in
+			new DirectoryInfo (@"XML-Test-Suite/xmlconf/oasis").GetFiles ("*.xml")) {
+			try {
+				XmlTextReader xtr = new XmlTextReader (fi.FullName);
+				xtr.Namespaces = false;
+				xtr.Normalization = true;
+				doc.RemoveAll ();
+				doc.Load (xtr);
+				if (fi.Name.IndexOf ("fail") >= 0)
+					Console.WriteLine ("Incorrectly valid: " + fi.FullName);
+			} catch (Exception ex) {
+				if (fi.Name.IndexOf ("pass") >= 0)
+					Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
+			}
+		}
+	}
+
+	static void RunNotWellFormedTest (string subdir, bool isSunTest)
+	{
+		string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/not-wf";
+		DirectoryInfo [] dirs = null;
+		if (isSunTest)
+			dirs =  new DirectoryInfo [] {new DirectoryInfo (basePath)};
+		else
+			dirs = new DirectoryInfo (basePath).GetDirectories ();
+
+		XmlDocument doc = new XmlDocument ();
+		foreach (DirectoryInfo di in dirs) {
+			foreach (FileInfo fi in di.GetFiles ("*.xml")) {
+				try {
+					XmlTextReader xtr = new XmlTextReader (fi.FullName);
+					xtr.Namespaces = false;
+					doc.RemoveAll ();
+					doc.Load (xtr);
+					Console.WriteLine ("Incorrectly wf: " + fi.FullName);
+				} catch (Exception ex) {
+					Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
+				}
+			}
+		}
+	}
+
+	static void RunValidTest (string subdir, bool isSunTest)
+	{
+		string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/invalid";
+		DirectoryInfo [] dirs = null;
+		if (isSunTest)
+			dirs =  new DirectoryInfo [] {new DirectoryInfo (basePath)};
+		else
+			dirs = new DirectoryInfo (basePath).GetDirectories ();
+
+		XmlDocument doc = new XmlDocument ();
+		foreach (DirectoryInfo di in dirs) {
+			foreach (FileInfo fi in di.GetFiles ("*.xml")) {
+				try {
+					XmlTextReader xtr = new XmlTextReader (fi.FullName);
+					xtr.Namespaces = false;
+					xtr.Normalization = true;
+					XmlReader xr = new XmlValidatingReader (xtr);
+					while (!xr.EOF)
+						xr.Read ();
+				} catch (XmlException ex) {
+					Console.WriteLine ("Incorrectly not-wf: " + fi.FullName + " " + ex.Message);
+				} catch (XmlSchemaException ex) {
+					Console.WriteLine ("Incorrectly invalid: " + fi.FullName + " " + ex.Message);
+				}
+			}
+		}
+	}
+
+	static void RunInvalidTest (string subdir, bool isSunTest)
+	{
+		string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/invalid";
+		DirectoryInfo [] dirs = null;
+		if (isSunTest)
+			dirs =  new DirectoryInfo [] {new DirectoryInfo (basePath)};
+		else
+			dirs = new DirectoryInfo (basePath).GetDirectories ();
+
+		XmlDocument doc = new XmlDocument ();
+		foreach (DirectoryInfo di in dirs) {
+			foreach (FileInfo fi in di.GetFiles ("*.xml")) {
+				try {
+					XmlTextReader xtr = new XmlTextReader (fi.FullName);
+					xtr.Namespaces = false;
+					xtr.Normalization = true;
+					doc.RemoveAll ();
+					while (!xtr.EOF)
+						xtr.Read ();
+				} catch (Exception ex) {
+					Console.WriteLine ("Incorrectly not-wf: " + fi.FullName + String.Concat ("(", ex.GetType ().Name, ") " + ex.Message));
+				}
+			}
+		}
+
+		foreach (DirectoryInfo di in dirs) {
+			foreach (FileInfo fi in di.GetFiles ("*.xml")) {
+				try {
+					XmlTextReader xtr = new XmlTextReader (fi.FullName);
+					xtr.Namespaces = false;
+					xtr.Normalization = true;
+					doc.RemoveAll ();
+					doc.Load (new XmlValidatingReader (xtr));
+					Console.WriteLine ("Incorrectly valid: " + fi.FullName);
+				} catch (Exception ex) {
+				}
+			}
+		}
+	}
+}