2 using System.Collections;
6 using System.Xml.XPath;
14 static bool noExclude;
15 static bool reportDetails;
16 static bool reportAsXml;
17 static bool useDomStyle;
18 static bool useDomInstance;
19 static bool generateOutput;
20 static bool listOutput;
21 static bool whitespaceStyle;
22 static bool whitespaceInstance;
23 static bool stopImmediately;
24 static bool outputAll;
25 static readonly ArrayList skipTargets;
26 static readonly ArrayList knownFailures = new ArrayList (new string [] { });
27 static string explicitTarget;
28 static TextWriter reportOutput = Console.Out;
29 static XmlTextWriter reportXmlWriter;
30 static StreamWriter missingFiles = new StreamWriter ("missing.lst");
31 static StreamWriter failedTests = new StreamWriter ("failed.lst");
36 skipTargets = new ArrayList (new string [] {
43 mono xslttest.exe [options] [targetFileMatch] -report:reportfile
46 --details Output detailed output differences.
47 --dom Use XmlDocument for both stylesheet and input source.
48 --domxsl Use XmlDocument for stylesheet.
49 --domsrc Use XmlDocument for input source.
50 --generate Generate output files specified in catalog.
51 Use this feature only when you want to update
53 --list Print output list to console.
54 --noExclude Don't exclude meaningless comparison testcases.
55 --outall Output fine results as OK (omitted by default).
56 --stoponerror Stops the test process and throw detailed
58 --ws Preserve spaces for both stylesheet and input source.
59 --wsxsl Preserve spaces for stylesheet.
60 --wssrc Preserve spaces for input source.
61 --xml Report into xml output.
62 --report Write reports into specified file.
65 arbitrary string that specifies part of file name.
70 public static void Main (string [] args)
74 } catch (Exception ex) {
75 reportOutput.WriteLine (ex);
77 reportOutput.Close ();
81 static void ParseOptions (string [] args)
83 foreach (string arg in args) {
90 useDomInstance = true;
96 useDomInstance = true;
102 generateOutput = true;
113 case "--stoponerror":
114 stopImmediately = true;
117 whitespaceStyle = true;
118 whitespaceInstance = true;
121 whitespaceStyle = true;
124 whitespaceInstance = true;
130 if (arg.StartsWith ("--report:")) {
131 string reportFile = arg.Substring (9);
132 if (reportFile.Length < 0) {
134 Console.WriteLine ("Error: --report option requires filename.");
137 reportOutput = new StreamWriter (reportFile);
140 if (arg.StartsWith ("--")) {
144 explicitTarget = arg;
150 static void RunMain (string [] args)
154 foreach (string s_ in new StreamReader ("ignore.lst").ReadToEnd ()
155 .Split ("\n".ToCharArray ())) {
156 string s = s_.Trim ();
163 reportXmlWriter = new XmlTextWriter (reportOutput);
164 reportXmlWriter.Formatting = Formatting.Indented;
165 reportXmlWriter.WriteStartElement ("test-results");
168 if (explicitTarget != null)
169 Console.WriteLine ("The specified target is "
172 XmlDocument whole = new XmlDocument ();
173 whole.Load (@"testsuite/TESTS/catalog-fixed.xml");
176 Console.Error.WriteLine ("Started: "
177 + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
179 foreach (XmlElement testCase in whole.SelectNodes ("test-suite/test-catalog/test-case"))
180 ProcessTestCase (testCase);
183 Console.WriteLine ("Finished: "
184 + DateTime.Now.ToString ("yyyyMMdd-HHmmss.fff"));
187 reportXmlWriter.WriteEndElement (); // test-results
190 static void ProcessTestCase (XmlElement testCase)
192 string stylesheetBase = null;
193 string testid = testCase.GetAttribute ("id");
194 if (skipTargets.Contains (testid))
197 string submitter = testCase.SelectSingleNode ("./parent::test-catalog/@submitter")
199 string filePath = testCase.SelectSingleNode ("file-path").InnerText;
200 string testAuthorDir;
201 if (submitter == "Lotus")
202 testAuthorDir = "Xalan_Conformance_Tests";
203 else if (submitter == "Microsoft")
204 testAuthorDir = "MSFT_Conformance_Tests";
206 return; //unknown directory
208 string path = @"testsuite/TESTS/" + testAuthorDir + "/" + filePath + "/";
209 foreach (XmlElement scenario in
210 testCase.SelectNodes ("scenario[@operation='standard']")) {
211 RunTest (testid, scenario, path, stylesheetBase);
213 } catch (Exception ex) {
216 Report (false, testid, "Exception: " + ex.Message);
220 static void RunTest (string testid, XmlElement scenario, string path, string stylesheetBase)
222 stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
223 string stylesheet = path + stylesheetBase;
225 if (!File.Exists (stylesheet)) {
226 missingFiles.WriteLine (stylesheet);
227 missingFiles.Flush ();
229 string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
230 XmlNode outputNode = scenario.SelectSingleNode ("output-file[@role='principal']");
231 string outfile = outputNode != null ? path + outputNode.InnerText : null;
235 Console.WriteLine (outfile);
239 XslTransform trans = new XslTransform ();
241 if (explicitTarget != null && testid.IndexOf (explicitTarget) < 0)
243 if (skipTargets.Contains (stylesheetBase))
247 XmlDocument styledoc = new XmlDocument ();
249 styledoc.PreserveWhitespace = true;
250 styledoc.Load (stylesheet);
251 trans.Load (styledoc, null, null);
253 trans.Load (new XPathDocument (
255 whitespaceStyle ? XmlSpace.Preserve :
259 XmlTextReader xtr = new XmlTextReader (srcxml);
260 XmlValidatingReader xvr = new XmlValidatingReader (xtr);
261 xvr.ValidationType = ValidationType.None;
262 IXPathNavigable input = null;
263 if (useDomInstance) {
264 XmlDocument dom = new XmlDocument ();
265 if (whitespaceInstance)
266 dom.PreserveWhitespace = true;
270 input = new XPathDocument (xvr,
271 whitespaceStyle ? XmlSpace.Preserve :
274 StringWriter sw = new StringWriter ();
275 trans.Transform (input, null, sw, null);
276 if (generateOutput) {
277 StreamWriter fw = new StreamWriter (outfile,
278 false, Encoding.UTF8);
279 fw.Write (sw.ToString ());
281 // ... and don't run comparison
285 if (!File.Exists (outfile)) {
286 // Reference output file does not exist.
287 Report (true, testid, "No reference file found");
290 StreamReader sr = new StreamReader (outfile);
291 string reference_out = sr.ReadToEnd ();
292 string actual_out = sw.ToString ();
293 if (reference_out != actual_out)
294 Report (false, testid, reference_out, actual_out);
296 Report (true, testid, "OK");
299 static void Report (bool passed, string testid, string message)
302 Console.Error.Write (".");
305 failedTests.WriteLine (testid + "\t" + message);
306 failedTests.Flush ();
308 reportXmlWriter.WriteStartElement ("testcase");
309 reportXmlWriter.WriteAttributeString ("id", testid);
310 reportXmlWriter.WriteString (message);
311 reportXmlWriter.WriteEndElement ();
312 if (knownFailures.Contains (testid))
313 Console.Error.Write ("k");
315 Console.Error.Write ("E");
318 reportOutput.WriteLine (message);
321 static void Report (bool passed, string testid, string reference_out, string actual_out)
323 string baseMessage = reportAsXml ? "Different." : "Different: " + testid;
325 Report (passed, testid, baseMessage);
327 Report (passed, testid, baseMessage +
330 "\n-------------------\nReference*****\n" +