xmltest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Xml.Schema;
  5. using System.Xml.Serialization;
  6. public class Test
  7. {
  8. static char SEP = Path.DirectorySeparatorChar;
  9. public static void Main ()
  10. {
  11. Console.WriteLine ("Started: " + DateTime.Now.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
  12. RunInvalidTest ("xmltest", false);
  13. RunInvalidTest ("ibm", false);
  14. RunInvalidTest ("sun", true);
  15. RunValidTest ("xmltest", false);
  16. RunValidTest ("ibm", false);
  17. RunValidTest ("sun", true);
  18. RunNotWellFormedTest ("xmltest", false);
  19. RunNotWellFormedTest ("ibm", false);
  20. RunNotWellFormedTest ("sun", true);
  21. RunOASISTest ();
  22. Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
  23. }
  24. static void RunOASISTest ()
  25. {
  26. XmlDocument doc = new XmlDocument ();
  27. foreach (FileInfo fi in
  28. new DirectoryInfo (@"xml-test-suite/xmlconf/oasis").GetFiles ("*.xml")) {
  29. try {
  30. XmlTextReader xtr = new XmlTextReader (fi.FullName);
  31. xtr.Namespaces = false;
  32. xtr.Normalization = true;
  33. while (!xtr.EOF)
  34. xtr.Read ();
  35. if (fi.Name.IndexOf ("fail") >= 0)
  36. Console.WriteLine ("Incorrectly valid: " + fi.FullName);
  37. } catch (Exception ex) {
  38. if (fi.Name.IndexOf ("pass") >= 0)
  39. Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
  40. }
  41. }
  42. }
  43. static void RunNotWellFormedTest (string subdir, bool isSunTest)
  44. {
  45. string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/not-wf";
  46. DirectoryInfo [] dirs = null;
  47. if (isSunTest)
  48. dirs = new DirectoryInfo [] {new DirectoryInfo (basePath)};
  49. else
  50. dirs = new DirectoryInfo (basePath).GetDirectories ();
  51. foreach (DirectoryInfo di in dirs) {
  52. foreach (FileInfo fi in di.GetFiles ("*.xml")) {
  53. try {
  54. XmlTextReader xtr = new XmlTextReader (fi.FullName);
  55. xtr.Namespaces = false;
  56. while (!xtr.EOF)
  57. xtr.Read ();
  58. Console.WriteLine ("Incorrectly wf: " + fi.FullName);
  59. } catch (XmlException) {
  60. // expected
  61. } catch (Exception ex) {
  62. Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + ex.Message);
  63. }
  64. }
  65. }
  66. }
  67. static void RunValidTest (string subdir, bool isSunTest)
  68. {
  69. string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/valid";
  70. DirectoryInfo [] dirs = null;
  71. if (isSunTest)
  72. dirs = new DirectoryInfo [] {new DirectoryInfo (basePath)};
  73. else
  74. dirs = new DirectoryInfo (basePath).GetDirectories ();
  75. foreach (DirectoryInfo di in dirs) {
  76. foreach (FileInfo fi in di.GetFiles ("*.xml")) {
  77. try {
  78. XmlTextReader xtr = new XmlTextReader (fi.FullName);
  79. xtr.Namespaces = false;
  80. xtr.Normalization = true;
  81. XmlReader xr = new XmlValidatingReader (xtr);
  82. while (!xr.EOF)
  83. xr.Read ();
  84. } catch (XmlException ex) {
  85. Console.WriteLine ("Incorrectly not-wf: " + fi.FullName + " " + ex.Message);
  86. } catch (XmlSchemaException ex) {
  87. Console.WriteLine ("Incorrectly invalid: " + fi.FullName + " " + ex.Message);
  88. } catch (Exception ex) {
  89. Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + ex.Message);
  90. }
  91. }
  92. }
  93. }
  94. static void RunInvalidTest (string subdir, bool isSunTest)
  95. {
  96. string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/invalid";
  97. DirectoryInfo [] dirs = null;
  98. if (isSunTest)
  99. dirs = new DirectoryInfo [] {new DirectoryInfo (basePath)};
  100. else
  101. dirs = new DirectoryInfo (basePath).GetDirectories ();
  102. foreach (DirectoryInfo di in dirs) {
  103. foreach (FileInfo fi in di.GetFiles ("*.xml")) {
  104. try {
  105. XmlTextReader xtr = new XmlTextReader (fi.FullName);
  106. xtr.Namespaces = false;
  107. xtr.Normalization = true;
  108. while (!xtr.EOF)
  109. xtr.Read ();
  110. } catch (Exception ex) {
  111. Console.WriteLine ("Incorrectly not-wf: " + fi.FullName + String.Concat ("(", ex.GetType ().Name, ") " + ex.Message));
  112. }
  113. }
  114. }
  115. foreach (DirectoryInfo di in dirs) {
  116. foreach (FileInfo fi in di.GetFiles ("*.xml")) {
  117. try {
  118. XmlTextReader xtr = new XmlTextReader (fi.FullName);
  119. xtr.Namespaces = false;
  120. xtr.Normalization = true;
  121. XmlValidatingReader xr =
  122. new XmlValidatingReader (xtr);
  123. while (!xr.EOF)
  124. xr.Read ();
  125. Console.WriteLine ("Incorrectly valid: " + fi.FullName);
  126. } catch (XmlSchemaException) {
  127. // expected
  128. } catch (Exception ex) {
  129. Console.WriteLine ("Unexpected Error: " + fi.FullName + "\n" + ex.Message);
  130. }
  131. }
  132. }
  133. }
  134. }