In gmcs:
[mono.git] / mcs / class / System.Web / Test / mainsoft / MainsoftWebTest / TestsCatalog.cs
1 //
2 // Authors:
3 //   Rafael Mizrahi   <rafim@mainsoft.com>
4 //   Erez Lotan       <erezl@mainsoft.com>
5 //   Vladimir Krasnov <vladimirk@mainsoft.com>
6 //   
7 // 
8 // Copyright (c) 2002-2005 Mainsoft Corporation.
9 // 
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 using System;
30 using System.Collections;
31 using System.Xml;
32
33 namespace MonoTests.stand_alone.WebHarness
34 {
35         public class TestInfo
36         {
37                 private string _url;
38                 private string _name;
39
40                 public string Url
41                 {
42                         get {return _url;}
43                         set {_url = value;}
44                 }
45                 public string Name
46                 {
47                         get {return _name;}
48                         set {_name = value;}
49                 }
50         }
51
52         public class TestsCatalog : IEnumerator, IEnumerable
53         {
54                 private XmlDocument _testsListXml = null;
55                 private IEnumerator _tests = null;
56
57                 public TestsCatalog() : this("")
58                 {
59                 }
60                 public TestsCatalog(string catalogName) : this(catalogName, false)
61                 {
62                 }
63
64                 public TestsCatalog(string catalogName, bool collectExluded)
65                 {
66                         if (catalogName == "")
67                         {
68                                 catalogName = "test_catalog.xml";
69                         }
70
71                         try
72                         {
73                                 _testsListXml = new XmlDocument();
74                                 _testsListXml.Load(catalogName);
75                         }
76                         catch(Exception e)
77                         {
78                                 throw e;
79                         }
80
81                         try
82                         {
83                                 if (collectExluded)
84                                         _tests = _testsListXml.SelectNodes("/TestCases/TestCase").GetEnumerator();
85                                 else
86                                         _tests = _testsListXml.SelectNodes("/TestCases/TestCase[@Exclude='N']").GetEnumerator();
87                         }
88                         catch(Exception e)
89                         {
90                                 throw e;
91                         }
92                 }
93
94                 public IEnumerator GetEnumerator()
95                 {
96                         return this;
97                 }
98
99                 public object Current
100                 {
101                         get {return GetCurrentTestInfo();}
102                 }
103
104                 public bool MoveNext()
105                 {
106                         return _tests.MoveNext();
107                 }
108
109                 public void Reset()
110                 {
111                         _tests.Reset();
112                 }
113
114                 private TestInfo GetCurrentTestInfo()
115                 {
116                         XmlNode n = (XmlNode)_tests.Current;
117                         TestInfo ti = new TestInfo();
118                         ti.Name = n.Attributes["name"].Value;
119                         ti.Url = n.Attributes["url"].Value;
120                         return ti;
121                 }
122         }
123 }