xslttest.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Text;
  5. using System.Xml;
  6. using System.Xml.Xsl;
  7. namespace XsltTest
  8. {
  9. public class XsltTest
  10. {
  11. public static void Main ()
  12. {
  13. // output22,77: not-supported encoding, but MS passes...?
  14. // output72.xsl: should not pass
  15. ArrayList expectedExceptions = new ArrayList
  16. (new string [] {"lre12.xsl", "namespace40.xsl", "namespace42.xsl", "namespace43.xsl",
  17. "namespace48.xsl", "namespace60.xsl", "namespace73.xsl", "namespace106.xsl",
  18. "output22.xsl", "output72.xsl", "output77.xsl"});
  19. XmlDocument whole = new XmlDocument ();
  20. whole.Load (@"testsuite/TESTS/Xalan_Conformance_Tests/catalog.xml");
  21. Console.WriteLine ("Started: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
  22. foreach (XmlElement testCase in whole.SelectNodes ("test-suite/test-catalog/test-case")) {
  23. string stylesheetBase = null;
  24. try {
  25. string filePath = testCase.SelectSingleNode ("file-path").InnerText;
  26. string path = @"testsuite/TESTS/Xalan_Conformance_Tests/" + filePath + "/";
  27. foreach (XmlElement scenario in testCase.SelectNodes ("scenario")) {
  28. XslTransform trans = new XslTransform ();
  29. stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
  30. string stylesheet = path + stylesheetBase;
  31. string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
  32. //if (srcxml.IndexOf ("attribset") < 0)
  33. // continue;
  34. if (expectedExceptions.Contains (stylesheetBase))
  35. continue;
  36. XmlTextReader stylextr = new XmlTextReader (stylesheet);
  37. XmlValidatingReader stylexvr = new XmlValidatingReader (stylextr);
  38. XmlDocument styledoc = new XmlDocument ();
  39. styledoc.Load (stylesheet);
  40. trans.Load (stylesheet);
  41. // trans.Load (styledoc);
  42. XmlTextReader xtr = new XmlTextReader (srcxml);
  43. XmlValidatingReader xvr = new XmlValidatingReader (xtr);
  44. xvr.ValidationType = ValidationType.None;
  45. XmlDocument input = new XmlDocument ();
  46. input.Load (xvr);
  47. // input.Load (xtr);
  48. // XPathDocument input = new XPathDocument (xtr);
  49. StringWriter sw = new StringWriter ();
  50. trans.Transform (input, null, sw);
  51. string outfile = path + scenario.SelectSingleNode ("output-file[@role='principal']").InnerText;
  52. if (!File.Exists (outfile)) {
  53. // Console.WriteLine ("Reference output file does not exist.");
  54. continue;
  55. }
  56. StreamReader sr = new StreamReader (outfile);
  57. string reference_out = sr.ReadToEnd ();
  58. string actual_out = sw.ToString ();
  59. if (reference_out != actual_out)
  60. #if false
  61. Console.WriteLine ("Different: " + testCase.GetAttribute ("id"));
  62. #else
  63. Console.WriteLine ("Different: " +
  64. testCase.GetAttribute ("id") +
  65. "\n" +
  66. actual_out + "\n-------------------\n" + reference_out + "\n");
  67. #endif
  68. }
  69. // } catch (NotSupportedException ex) {
  70. } catch (Exception ex) {
  71. if (expectedExceptions.Contains (stylesheetBase))
  72. continue;
  73. Console.WriteLine ("Exception: " + testCase.GetAttribute ("id") + ": " + ex.Message);
  74. }
  75. }
  76. Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
  77. }
  78. }
  79. }