xmltest.cs 4.8 KB

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