2 using System.Collections;
6 using System.Xml.XPath;
11 namespace MonoTests.oasis_xslt {
12 public class SuiteBuilder {
13 #region test list fields
14 IDictionary expectedExceptions = new Hashtable ();
15 ArrayList skipTargets = new ArrayList ();
16 ArrayList knownFailures = new ArrayList ();
17 ArrayList fixmeList = new ArrayList ();
21 SuiteBuilder (TestSuite suite)
28 string exceptionsFilename = Path.Combine (EnvOptions.OutputDir, "res-exceptions.lst");
30 Helpers.ReadStrings (skipTargets, "ignore.lst");
32 Helpers.ReadStrings (knownFailures, "knownFailures.jvm.lst");
34 Helpers.ReadStrings (knownFailures, "knownFailures.lst");
36 Helpers.ReadStrings (fixmeList, "fixme.lst");
37 ArrayList exceptionsArray = new ArrayList();
38 Helpers.ReadStrings (exceptionsArray, exceptionsFilename);
39 foreach (string s in exceptionsArray) {
40 string [] halves = s.Split ('\t');
41 expectedExceptions [halves[0]] = halves[1];
47 // if (Environment.GetEnvironmentVariables().Contains("START_DEBUG"))
48 // System.Diagnostics.Debugger.Launch ();
50 XmlDocument whole = new XmlDocument ();
51 whole.Load (@"testsuite/TESTS/catalog-fixed.xml");
53 foreach (XmlElement testCase in whole.SelectNodes ("test-suite/test-catalog/test-case")) {
54 string testid = testCase.GetAttribute ("id");
56 if (skipTargets.Contains (testid))
59 CatalogTestCase ctc = new CatalogTestCase(EnvOptions.OutputDir, testCase);
63 SingleTestTransform stt = new SingleTestTransform (ctc);
65 string expectedException = (string) expectedExceptions[testid];
66 bool isKnownFailure = knownFailures.Contains (testid) || fixmeList.Contains (testid);
68 _suite.Add (new TestFromCatalog (testid, stt, expectedException,
69 EnvOptions.InverseResults, isKnownFailure));
74 public static TestSuite Suite {
76 TestSuite suite = new TestSuite ("MonoTests.oasis_xslt.SuiteBuilder");
77 SuiteBuilder builder = new SuiteBuilder (suite);
84 class TestFromCatalog: NUnit.Core.TestCase {
87 string _expectedException;
88 SingleTestTransform _transform;
90 public TestFromCatalog (string testid, SingleTestTransform transform,
91 string expectedException, bool inverseResult, bool isKnownFailure)
95 _expectedException = expectedException;
96 _transform = transform;
97 _inverseResult = inverseResult;
99 ArrayList arr = new ArrayList ();
100 if (isKnownFailure) {
101 arr.Add ("KnownFailures");
102 this.IsExplicit = true;
109 static string EscapeString (string res)
111 MemoryStream s = new MemoryStream ();
112 XmlTextWriter w = new XmlTextWriter (s, System.Text.Encoding.ASCII);
116 StringBuilder sb = new StringBuilder (res.Length);
117 byte [] arr = s.ToArray ();
118 foreach (byte b in arr)
119 sb.Append (Convert.ToChar (b));
121 return sb.ToString ();
124 string CompareResult (string actual, string expected, CatalogTestCase.CompareType compare)
126 //TODO: add html comparison
127 if (compare== CatalogTestCase.CompareType.XML) {
129 XmlDocument actDoc = new XmlDocument();
130 XmlDocument expDoc = new XmlDocument();
131 actDoc.LoadXml (actual);
132 expDoc.LoadXml (expected);
133 XmlCompare.XmlCompare cmp = new XmlCompare.XmlCompare(XmlCompare.XmlCompare.Flags.IgnoreAttribOrder);
134 if (cmp.AreEqual (actDoc, expDoc)) {
138 catch (Exception ex) {
139 //could not compare as xml, fallback to text
140 if (actual == expected)
145 if (actual == expected)
148 string res = "Different.\nActual*****\n"+actual+"\nReference*****\n"+expected;
149 return EscapeString (res);
152 string CompareException (Exception actual, string testid)
154 if (_expectedException == null)
155 return "Unexpected exception: " + actual.ToString ();
157 string actualType = actual.GetType ().ToString ();
158 if (actualType != _expectedException)
159 return "Different exception thrown.\nActual*****\n"+actualType+
160 "\nReference*****\n"+_expectedException;
165 void ReportResult (string failureMessage, string stackTrace, TestCaseResult res)
167 if (_inverseResult) {
168 if (failureMessage != null)
171 res.Failure ("The following test was FIXED: "+_testid, null);
174 if (failureMessage != null)
175 res.Failure (failureMessage, stackTrace);
181 public override void Run (TestCaseResult res)
183 _transform.RunTest ();
185 string failureMessage;
186 string stackTrace = null;
187 if (_transform.Succeeded) {
189 using (StreamReader sr = new StreamReader (_transform.TestCase.OutFile))
190 failureMessage = CompareResult (_transform.Result, sr.ReadToEnd ().Replace ("\r\n", "\n"), _transform.TestCase.Compare);
193 //if there is no reference result because of expectedException, we
194 //are OK, otherwise, rethrow
195 if (_expectedException!=null)
196 failureMessage = null;
198 Console.WriteLine (_transform.TestCase.OutFile);
199 Console.WriteLine ("ERROR: No reference result, and no expected exception.");
205 failureMessage = CompareException (_transform.Exception, _testid);
206 stackTrace = _transform.Exception.StackTrace;
209 ReportResult (failureMessage, stackTrace, res);