2 using System.Collections;
6 using System.Xml.XPath;
13 static bool noExclude;
14 static bool reportDetails;
15 static bool reportAsXml;
16 static bool useDomStyle;
17 static bool useDomInstance;
18 static bool generateOutput;
19 static bool listOutput;
20 static bool whitespaceStyle;
21 static bool whitespaceInstance;
22 static bool stopImmediately;
23 static bool outputAll;
24 static readonly ArrayList skipTargets;
25 static string explicitTarget;
26 static TextWriter reportOutput = Console.Out;
27 static XmlTextWriter reportXmlWriter;
31 skipTargets = new ArrayList (new string [] {
38 mono xslttest.exe [options] [targetFileMatch] -report:reportfile
41 --details Output detailed output differences.
42 --dom Use XmlDocument for both stylesheet and input source.
43 --domxsl Use XmlDocument for stylesheet.
44 --domsrc Use XmlDocument for input source.
45 --generate Generate output files specified in catalog.
46 Use this feature only when you want to update
48 --list Print output list to console.
49 --noExclude Don't exclude meaningless comparison testcases.
50 --outall Output fine results as OK (omitted by default).
51 --stoponerror Stops the test process and throw detailed
53 --ws Preserve spaces for both stylesheet and input source.
54 --wsxsl Preserve spaces for stylesheet.
55 --wssrc Preserve spaces for input source.
56 --xml Report into xml output.
57 --report Write reports into specified file.
60 arbitrary string that specifies part of file name.
65 public static void Main (string [] args)
69 } catch (Exception ex) {
70 reportOutput.WriteLine (ex);
72 reportOutput.Close ();
76 static void RunMain (string [] args)
78 foreach (string arg in args) {
85 useDomInstance = true;
91 useDomInstance = true;
97 generateOutput = true;
108 case "--stoponerror":
109 stopImmediately = true;
112 whitespaceStyle = true;
113 whitespaceInstance = true;
116 whitespaceStyle = true;
119 whitespaceInstance = true;
125 if (arg.StartsWith ("--report:")) {
126 string reportFile = arg.Substring (9);
127 if (reportFile.Length < 0) {
129 Console.WriteLine ("Error: --report option requires filename.");
132 reportOutput = new StreamWriter (reportFile);
135 if (arg.StartsWith ("--")) {
139 explicitTarget = arg;
145 foreach (string s_ in new StreamReader ("ignore.lst").ReadToEnd ().Split ("\n".ToCharArray ())) {
146 string s = s_.Trim ();
153 reportXmlWriter = new XmlTextWriter (reportOutput);
154 reportXmlWriter.Formatting = Formatting.Indented;
155 reportXmlWriter.WriteStartElement ("test-results");
158 if (explicitTarget != null)
159 Console.WriteLine ("The specified target is "
162 XmlDocument whole = new XmlDocument ();
163 whole.Load (@"testsuite/TESTS/catalog.xml");
166 Console.WriteLine ("Started: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
168 foreach (XmlElement testCase in whole.SelectNodes (
169 "test-suite/test-catalog/test-case")) {
170 string stylesheetBase = null;
171 string testid = testCase.GetAttribute ("id");
172 if (skipTargets.Contains (testid))
175 string filePath = testCase.SelectSingleNode ("file-path").InnerText;
177 string testAuthorDir =
178 filePath [0] >= 'a' ?
179 "Xalan_Conformance_Tests" :
180 "MSFT_Conformance_Tests";
181 string path = @"testsuite/TESTS/" + testAuthorDir + "/" + filePath + "/";
182 foreach (XmlElement scenario in
183 testCase.SelectNodes ("scenario")) {
184 RunTest (scenario, path, stylesheetBase);
186 } catch (Exception ex) {
189 Report (testCase, "Exception: " + testCase.GetAttribute ("id") + ": " + ex.Message);
193 Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
196 reportXmlWriter.WriteEndElement (); // test-results
199 static void RunTest (XmlElement scenario, string path, string stylesheetBase)
201 stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
202 string id = scenario.ParentNode.Attributes ["id"].Value;
203 string stylesheet = path + stylesheetBase;
204 string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
205 XmlNode outputNode = scenario.SelectSingleNode ("output-file[@role='principal']");
206 string outfile = outputNode != null ? path + outputNode.InnerText : null;
210 Console.WriteLine (outfile);
214 XslTransform trans = new XslTransform ();
216 if (explicitTarget != null && id.IndexOf (explicitTarget) < 0)
218 if (skipTargets.Contains (stylesheetBase))
221 XmlTextReader stylextr = new XmlTextReader (stylesheet);
222 XmlValidatingReader stylexvr = new XmlValidatingReader (stylextr);
224 XmlDocument styledoc = new XmlDocument ();
226 styledoc.PreserveWhitespace = true;
227 styledoc.Load (stylesheet);
228 trans.Load (styledoc);
230 trans.Load (new XPathDocument (
232 whitespaceStyle ? XmlSpace.Preserve :
235 XmlTextReader xtr = new XmlTextReader (srcxml);
236 XmlValidatingReader xvr = new XmlValidatingReader (xtr);
237 xvr.ValidationType = ValidationType.None;
238 IXPathNavigable input = null;
239 if (useDomInstance) {
240 XmlDocument dom = new XmlDocument ();
241 if (whitespaceInstance)
242 dom.PreserveWhitespace = true;
246 input = new XPathDocument (xvr,
247 whitespaceStyle ? XmlSpace.Preserve :
250 StringWriter sw = new StringWriter ();
251 trans.Transform (input, null, sw);
252 if (generateOutput) {
253 StreamWriter fw = new StreamWriter (outfile,
254 false, Encoding.UTF8);
255 fw.Write (sw.ToString ());
257 // ... and don't run comparison
261 if (!File.Exists (outfile)) {
262 // Reference output file does not exist.
265 StreamReader sr = new StreamReader (outfile);
266 string reference_out = sr.ReadToEnd ();
267 string actual_out = sw.ToString ();
268 if (reference_out != actual_out)
269 Report (scenario.ParentNode as XmlElement,
270 reference_out, actual_out);
272 Report (scenario.ParentNode as XmlElement,
276 static void Report (XmlElement testcase, string message)
279 reportXmlWriter.WriteStartElement ("testcase");
280 reportXmlWriter.WriteAttributeString ("id",
281 testcase.GetAttribute ("id"));
282 reportXmlWriter.WriteString (message);
283 reportXmlWriter.WriteEndElement ();
286 reportOutput.WriteLine (message);
289 static void Report (XmlElement testCase,
290 string reference_out, string actual_out)
292 string baseMessage = reportAsXml ? "Different." :
293 "Different: " + testCase.GetAttribute ("id");
295 Report (testCase, baseMessage);
297 Report (testCase, baseMessage +
300 "\n-------------------\nReference*****\n" +