Просмотр исходного кода

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

	* README, Makefile, test-masters.tar.gz, xsdtest.cs : Initial checkin.

svn path=/trunk/mcs/; revision=21708
Atsushi Eno 22 лет назад
Родитель
Сommit
2a9e30eeb4

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

@@ -0,0 +1,3 @@
+2004-01-05  Atsushi Enomoto  <[email protected]>
+
+	* README, Makefile, test-masters.tar.gz, xsdtest.cs : Initial checkin.

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

@@ -0,0 +1,29 @@
+RUNTIME = mono
+MCS_RUNTIME =
+MCS = mcs
+TESTS = xsd-test-suite/suntest/SunTestsAll/xsiType1.xsd
+MASTERS = xsd-test-suite/suntest/tests-all.xml
+TEST_ARCHIVE = XSTC-20020116.tar.gz
+MASTER_ARCHIVE = test-masters.tar.gz
+
+xsdtest.exe : xsdtest.cs $(TESTS)
+	$(MCS_RUNTIME) $(MCS) xsdtest.cs
+
+$(MASTERS) : $(MASTER_ARCHIVE) xsd-test-suite
+	cd xsd-test-suite; tar zxvf ../$(MASTER_ARCHIVE); cd ..
+
+$(TESTS) : $(TEST_ARCHIVE) $(MASTERS) xsd-test-suite
+	cd xsd-test-suite; tar zxvf ../$(TEST_ARCHIVE); cd ..
+
+$(TEST_ARCHIVE) :
+	wget http://www.w3.org/2001/05/xmlschema-test-collection/XSTC-20020116.tar.gz
+
+xsd-test-suite:
+	mkdir xsd-test-suite
+
+test :
+	$(RUNTIME) xsdtest.exe
+
+# be careful to use it. This removes ALL files in xsd-test-suite!
+# clean:
+#	rm -rf xsd-test-suite

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

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

BIN
mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests/test-masters.tar.gz


+ 74 - 0
mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests/xsdtest.cs

@@ -0,0 +1,74 @@
+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 ()
+	{
+		RunTest ("msxsdtest");
+		RunTest ("nisttest");
+		RunTest ("suntest");
+	}
+	
+	static void RunTest (string subdir)
+	{
+Console.WriteLine ("Started:  " + DateTime.Now);
+		string basePath = @"Xsd-Test-Suite" + SEP;
+		XmlDocument doc = new XmlDocument ();
+		doc.Load (basePath + subdir + SEP + "tests-all.xml");
+		foreach (XmlElement test in doc.SelectNodes ("/tests/test")) {
+			// Test schema
+			string schemaFile = test.SelectSingleNode ("@schema").InnerText;
+			if (schemaFile.Length > 2)
+				schemaFile = schemaFile.Substring (2);
+			bool isValidSchema = test.SelectSingleNode ("@out_s").InnerText == "1";
+			XmlSchema schema = null;
+			try {
+				XmlTextReader sxr = new XmlTextReader (basePath + schemaFile);
+Console.WriteLine ("BaseURI: " + sxr.BaseURI);
+				schema = XmlSchema.Read (sxr, null);
+				sxr.Close ();
+				schema.Compile (null);
+				if (!isValidSchema) {
+					Console.WriteLine ("Incorrectly Valid   schema  : " + schemaFile);
+					continue;
+				}
+			} catch (XmlSchemaException ex) {
+				if (isValidSchema) {
+					Console.WriteLine ("Incorrectly Invalid schema  : " + schemaFile + " " + ex);
+					continue;
+				}
+			} catch (Exception ex) {
+				Console.WriteLine ("Unexpected Exception on schema: " + schemaFile + " " + ex);
+				continue;
+			}
+			// Test instances
+			string instanceFile = test.SelectSingleNode ("@instance").InnerText;
+			if (instanceFile.Length == 0)
+				continue;
+			else if (instanceFile.StartsWith ("./"))
+				instanceFile = instanceFile.Substring (2);
+			bool isValidInstance = test.SelectSingleNode ("@out_x").InnerText == "1";
+			try {
+				XmlValidatingReader xvr = new XmlValidatingReader (new XmlTextReader (basePath + "\\" + instanceFile));
+				xvr.Schemas.Add (schema);
+				while (!xvr.EOF)
+					xvr.Read ();
+				if (!isValidInstance)
+					Console.WriteLine ("Incorrectly Valid   instance: " + schemaFile);
+				xvr.Close ();
+			} catch (XmlSchemaException ex) {
+				if (isValidInstance)
+					Console.WriteLine ("Incorrectly Invalid instance: " + schemaFile + " " + ex);
+			} catch (Exception ex) {
+				Console.WriteLine ("Unexpected Exception on instance: " + schemaFile + " " + ex);
+			}
+		}
+Console.WriteLine ("Finished: " + DateTime.Now);
+	}
+}