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