| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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 ()
- {
- Console.WriteLine ("Started: " + DateTime.Now.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
- 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 ();
- Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
- }
- 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;
- while (!xtr.EOF)
- xtr.Read ();
- 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 ();
- foreach (DirectoryInfo di in dirs) {
- foreach (FileInfo fi in di.GetFiles ("*.xml")) {
- try {
- XmlTextReader xtr = new XmlTextReader (fi.FullName);
- xtr.Namespaces = false;
- while (!xtr.EOF)
- xtr.Read ();
- Console.WriteLine ("Incorrectly wf: " + fi.FullName);
- } catch (XmlException) {
- // expected
- } catch (Exception ex) {
- Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + ex.Message);
- }
- }
- }
- }
- static void RunValidTest (string subdir, bool isSunTest)
- {
- string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/valid";
- DirectoryInfo [] dirs = null;
- if (isSunTest)
- dirs = new DirectoryInfo [] {new DirectoryInfo (basePath)};
- else
- dirs = new DirectoryInfo (basePath).GetDirectories ();
- 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);
- } catch (Exception ex) {
- Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + 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 ();
- 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;
- 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;
- XmlValidatingReader xr =
- new XmlValidatingReader (xtr);
- while (!xr.EOF)
- xr.Read ();
- Console.WriteLine ("Incorrectly valid: " + fi.FullName);
- } catch (XmlSchemaException) {
- // expected
- } catch (Exception ex) {
- Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + ex.Message);
- }
- }
- }
- }
- }
|