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 [] {
42 mono xslttest.exe [options] [targetFileMatch] -report:reportfile
45 --details Output detailed output differences.
46 --dom Use XmlDocument for both stylesheet and input source.
47 --domxsl Use XmlDocument for stylesheet.
48 --domsrc Use XmlDocument for input source.
49 --generate Generate output files specified in catalog.
50 Use this feature only when you want to update
52 --list Print output list to console.
53 --noExclude Don't exclude meaningless comparison testcases.
54 --outall Output fine results as OK (omitted by default).
55 --stoponerror Stops the test process and throw detailed
57 --ws Preserve spaces for both stylesheet and input source.
58 --wsxsl Preserve spaces for stylesheet.
59 --wssrc Preserve spaces for input source.
60 --xml Report into xml output.
61 --report Write reports into specified file.
64 arbitrary string that specifies part of file name.
69 public static void Main (string [] args)
73 } catch (Exception ex) {
74 reportOutput.WriteLine (ex);
76 reportOutput.Close ();
80 static void RunMain (string [] args)
82 foreach (string arg in args) {
89 useDomInstance = true;
95 useDomInstance = true;
101 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 foreach (string s_ in new StreamReader ("ignore.lst").ReadToEnd ().Split ("\n".ToCharArray ())) {
150 string s = s_.Trim ();
157 reportXmlWriter = new XmlTextWriter (reportOutput);
158 reportXmlWriter.Formatting = Formatting.Indented;
159 reportXmlWriter.WriteStartElement ("test-results");
162 if (explicitTarget != null)
163 Console.WriteLine ("The specified target is "
166 XmlDocument whole = new XmlDocument ();
167 whole.Load (@"testsuite/TESTS/catalog.xml");
170 Console.WriteLine ("Started: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
172 foreach (XmlElement testCase in whole.SelectNodes (
173 "test-suite/test-catalog/test-case")) {
174 string stylesheetBase = null;
175 string testid = testCase.GetAttribute ("id");
176 if (skipTargets.Contains (testid))
179 string filePath = testCase.SelectSingleNode ("file-path").InnerText;
181 string testAuthorDir =
182 filePath [0] >= 'a' ?
183 "Xalan_Conformance_Tests" :
184 "MSFT_Conformance_Tests";
185 string path = @"testsuite/TESTS/" + testAuthorDir + "/" + filePath + "/";
186 foreach (XmlElement scenario in
187 testCase.SelectNodes ("scenario")) {
188 RunTest (scenario, path, stylesheetBase);
190 } catch (Exception ex) {
193 Report (testCase, "Exception: " + testCase.GetAttribute ("id") + ": " + ex.Message);
197 Console.WriteLine ("Finished: " + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
200 reportXmlWriter.WriteEndElement (); // test-results
203 static void RunTest (XmlElement scenario, string path, string stylesheetBase)
205 stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
206 string id = scenario.ParentNode.Attributes ["id"].Value;
207 string stylesheet = path + stylesheetBase;
208 string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
209 XmlNode outputNode = scenario.SelectSingleNode ("output-file[@role='principal']");
210 string outfile = outputNode != null ? path + outputNode.InnerText : null;
214 Console.WriteLine (outfile);
218 XslTransform trans = new XslTransform ();
220 if (explicitTarget != null && id.IndexOf (explicitTarget) < 0)
222 if (skipTargets.Contains (stylesheetBase))
225 XmlTextReader stylextr = new XmlTextReader (stylesheet);
226 XmlValidatingReader stylexvr = new XmlValidatingReader (stylextr);
228 XmlDocument styledoc = new XmlDocument ();
230 styledoc.PreserveWhitespace = true;
231 styledoc.Load (stylesheet);
232 trans.Load (styledoc);
234 trans.Load (new XPathDocument (
236 whitespaceStyle ? XmlSpace.Preserve :
239 XmlTextReader xtr = new XmlTextReader (srcxml);
240 XmlValidatingReader xvr = new XmlValidatingReader (xtr);
241 xvr.ValidationType = ValidationType.None;
242 IXPathNavigable input = null;
243 if (useDomInstance) {
244 XmlDocument dom = new XmlDocument ();
245 if (whitespaceInstance)
246 dom.PreserveWhitespace = true;
250 input = new XPathDocument (xvr,
251 whitespaceStyle ? XmlSpace.Preserve :
254 StringWriter sw = new StringWriter ();
255 trans.Transform (input, null, sw);
256 if (generateOutput) {
257 StreamWriter fw = new StreamWriter (outfile,
258 false, Encoding.UTF8);
259 fw.Write (sw.ToString ());
261 // ... and don't run comparison
265 if (!File.Exists (outfile)) {
266 // Reference output file does not exist.
269 StreamReader sr = new StreamReader (outfile);
270 string reference_out = sr.ReadToEnd ();
271 string actual_out = sw.ToString ();
272 if (reference_out != actual_out)
273 Report (scenario.ParentNode as XmlElement,
274 reference_out, actual_out);
276 Report (scenario.ParentNode as XmlElement,
280 static void Report (XmlElement testcase, string message)
283 reportXmlWriter.WriteStartElement ("testcase");
284 reportXmlWriter.WriteAttributeString ("id",
285 testcase.GetAttribute ("id"));
286 reportXmlWriter.WriteString (message);
287 reportXmlWriter.WriteEndElement ();
290 reportOutput.WriteLine (message);
293 static void Report (XmlElement testCase,
294 string reference_out, string actual_out)
296 string baseMessage = reportAsXml ? "Different." :
297 "Different: " + testCase.GetAttribute ("id");
299 Report (testCase, baseMessage);
301 Report (testCase, baseMessage +
304 "\n-------------------\nReference*****\n" +