Merge branch 'patch-1' of https://github.com/ReubenBond/mono into ReubenBond-patch-1
[mono.git] / mcs / class / System.XML / Test / System.Xml.Xsl / standalone_tests / generate.cs
1 using System;
2 using System.Collections;
3 using System.IO;
4 using System.Text;
5 using System.Xml;
6
7 namespace MonoTests.oasis_xslt {
8         public class Generator: IDisposable
9         {
10                 #region test list fields
11                 ArrayList skipTargets = new ArrayList ();
12                 StreamWriter resultExceptionsWriter;
13                 #endregion
14
15                 #region IDisposable Members
16                 public void Dispose()
17                 {
18                         if (resultExceptionsWriter!=null)
19                                 resultExceptionsWriter.Close ();
20                         resultExceptionsWriter = null;
21                 }
22
23                 #endregion
24
25                 public static int Main (string [] args) {
26                         using (Generator test = new Generator (args)) {
27                                 test.Run ();
28                         }
29                         return 0;
30                 }
31
32                 string [] _args;
33
34                 Generator (string [] args)
35                 {
36                         _args = args;
37                 }
38
39                 void Run ()
40                 {
41                         string resultExceptionsFilename = Path.Combine (EnvOptions.OutputDir, "res-exceptions.lst");
42
43                         if (Directory.Exists (EnvOptions.OutputDir))
44                                 Directory.Delete (EnvOptions.OutputDir, true);
45                         Directory.CreateDirectory (EnvOptions.OutputDir);
46
47                         Helpers.ReadStrings (skipTargets, "ignore.lst");
48
49                         resultExceptionsWriter = new StreamWriter (resultExceptionsFilename);
50
51                         XmlDocument catalog = new XmlDocument ();
52                         catalog.Load (@"testsuite/TESTS/catalog-fixed.xml");
53
54                         foreach (XmlElement testCase in catalog.SelectNodes ("test-suite/test-catalog/test-case")) {
55                                 ProcessTestCase (testCase);
56                         }
57                 }
58                 
59                 void ProcessTestCase (XmlElement testCase) {
60                         string testid = testCase.GetAttribute ("id");
61                         Console.Out.WriteLine (testid);
62                         if (skipTargets.Contains (testid))
63                                 return;
64
65                         CatalogTestCase ctc = new CatalogTestCase(EnvOptions.OutputDir, testCase);
66                         if (!ctc.Process ())
67                                 return;
68
69                         SingleTestTransform stt = new SingleTestTransform (ctc);
70                         stt.RunTest ();
71                         if (stt.Succeeded)
72                                 using (StreamWriter fw = new StreamWriter (ctc.OutFile, false, Encoding.UTF8))
73                                         fw.Write (stt.Result);
74                         else
75                                 resultExceptionsWriter.WriteLine ("{0}\t{1}", testid, stt.Exception.GetType ().ToString ());
76                 }
77
78         }
79 }