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