2 using System.Collections;
6 using System.Xml.XPath;
13 static bool reportDetails;
14 static bool reportAsXml;
15 static bool useDomStyle;
16 static bool useDomInstance;
17 static bool generateOutput;
18 static bool whitespaceStyle;
19 static bool whitespaceInstance;
20 static bool stopImmediately;
21 static bool outputAll;
22 static readonly ArrayList skipTargets;
23 static string explicitTarget;
24 static TextWriter reportOutput = Console.Out;
25 static XmlTextWriter reportXmlWriter;
29 skipTargets = new ArrayList (new string [] {
32 "namespace23.xsl", // under .NET, XPathDocument behavior is different from dom
40 // output22,77: not-supported encoding, but MS passes...?
41 // output72.xsl: should not pass
50 Console.WriteLine (@"mono xslttest.exe [options] [targetFileMatch] -report:reportfile
53 --details : Output detailed output differences.
54 --dom : use XmlDocument for both stylesheet and input source.
55 --domxsl : use XmlDocument for stylesheet.
56 --domsrc : use XmlDocument for input source.
57 --generate : generate output files specified in catalog.
58 Use this feature only when you want to update
60 --outall : Output fine results as OK (omitted by default).
61 --stoponerror : stops the test process and throw detailed
63 --ws : preserve spaces for both stylesheet and input source.
64 --wsxsl : preserve spaces for stylesheet.
65 --wssrc : preserve spaces for input source.
66 --xml : report into xml output.
67 --report : write reports into specified file.
70 arbitrary string that specifies part of file name.
75 public static void Main (string [] args)
79 } catch (Exception ex) {
80 reportOutput.WriteLine (ex);
82 reportOutput.Close ();
86 static void RunMain (string [] args)
88 foreach (string arg in args) {
95 useDomInstance = true;
101 useDomInstance = true;
104 reportDetails = true;
107 generateOutput = true;
112 case "--stoponerror":
113 stopImmediately = true;
116 whitespaceStyle = true;
117 whitespaceInstance = true;
120 whitespaceStyle = true;
123 whitespaceInstance = true;
129 if (arg.StartsWith ("--report:")) {
130 string reportFile = arg.Substring (9);
131 if (reportFile.Length < 0) {
133 Console.WriteLine ("Error: --report option requires filename.");
136 reportOutput = new StreamWriter (reportFile);
139 if (arg.StartsWith ("--")) {
143 explicitTarget = arg;
149 reportXmlWriter = new XmlTextWriter (reportOutput);
150 reportXmlWriter.Formatting = Formatting.Indented;
151 reportXmlWriter.WriteStartElement ("test-results");
154 if (explicitTarget != null)
155 Console.WriteLine ("The specified target is "
158 XmlDocument whole = new XmlDocument ();
159 whole.Load (@"testsuite/TESTS/Xalan_Conformance_Tests/catalog.xml");
161 Console.WriteLine ("Started: " +
162 DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
164 foreach (XmlElement testCase in whole.SelectNodes (
165 "test-suite/test-catalog/test-case")) {
166 string stylesheetBase = null;
168 string filePath = testCase.SelectSingleNode ("file-path").InnerText;
169 string path = @"testsuite/TESTS/Xalan_Conformance_Tests/" + filePath + "/";
170 foreach (XmlElement scenario in
171 testCase.SelectNodes ("scenario")) {
172 RunTest (scenario, path, stylesheetBase);
174 } catch (Exception ex) {
175 if (skipTargets.Contains (stylesheetBase))
179 Report (testCase, "Exception: " + testCase.GetAttribute ("id") + ": " + ex.Message);
182 Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
185 reportXmlWriter.WriteEndElement (); // test-results
188 static void RunTest (XmlElement scenario, string path, string stylesheetBase)
190 XslTransform trans = new XslTransform ();
191 stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
192 string stylesheet = path + stylesheetBase;
193 string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
195 if (explicitTarget != null && stylesheetBase.IndexOf (explicitTarget) < 0)
197 if (skipTargets.Contains (stylesheetBase))
200 XmlTextReader stylextr = new XmlTextReader (stylesheet);
201 XmlValidatingReader stylexvr = new XmlValidatingReader (stylextr);
203 XmlDocument styledoc = new XmlDocument ();
205 styledoc.PreserveWhitespace = true;
206 styledoc.Load (stylesheet);
207 trans.Load (styledoc);
209 trans.Load (new XPathDocument (
211 whitespaceStyle ? XmlSpace.Preserve :
214 string outfile = path + scenario.SelectSingleNode ("output-file[@role='principal']").InnerText;
216 XmlTextReader xtr = new XmlTextReader (srcxml);
217 XmlValidatingReader xvr = new XmlValidatingReader (xtr);
218 xvr.ValidationType = ValidationType.None;
219 IXPathNavigable input = null;
220 if (useDomInstance) {
221 XmlDocument dom = new XmlDocument ();
222 if (whitespaceInstance)
223 dom.PreserveWhitespace = true;
227 input = new XPathDocument (xvr,
228 whitespaceStyle ? XmlSpace.Preserve :
231 StringWriter sw = new StringWriter ();
232 trans.Transform (input, null, sw);
233 if (generateOutput) {
234 StreamWriter fw = new StreamWriter (outfile,
235 false, Encoding.UTF8);
236 fw.Write (sw.ToString ());
238 // ... and don't run comparison
242 if (!File.Exists (outfile)) {
243 // Reference output file does not exist.
246 StreamReader sr = new StreamReader (outfile);
247 string reference_out = sr.ReadToEnd ();
248 string actual_out = sw.ToString ();
249 if (reference_out != actual_out)
250 Report (scenario.ParentNode as XmlElement,
251 reference_out, actual_out);
253 Report (scenario.ParentNode as XmlElement,
257 static void Report (XmlElement testcase, string message)
260 reportXmlWriter.WriteStartElement ("testcase");
261 reportXmlWriter.WriteAttributeString ("id",
262 testcase.GetAttribute ("id"));
263 reportXmlWriter.WriteString (message);
264 reportXmlWriter.WriteEndElement ();
267 reportOutput.WriteLine (message);
270 static void Report (XmlElement testCase,
271 string reference_out, string actual_out)
273 string baseMessage = reportAsXml ? "Different." :
274 "Different: " + testCase.GetAttribute ("id");
276 Report (testCase, baseMessage);
278 Report (testCase, baseMessage +
281 "\n-------------------\nReference*****\n" +