TestsCatalog.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // Authors:
  3. // Rafael Mizrahi <[email protected]>
  4. // Erez Lotan <[email protected]>
  5. // Vladimir Krasnov <[email protected]>
  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. namespace MonoTests.stand_alone.WebHarness
  33. {
  34. public class TestInfo
  35. {
  36. private string _url;
  37. private string _name;
  38. public string Url
  39. {
  40. get {return _url;}
  41. set {_url = value;}
  42. }
  43. public string Name
  44. {
  45. get {return _name;}
  46. set {_name = value;}
  47. }
  48. }
  49. public class TestsCatalog : IEnumerator, IEnumerable
  50. {
  51. private XmlDocument _testsListXml = null;
  52. private IEnumerator _tests = null;
  53. public TestsCatalog() : this("")
  54. {
  55. }
  56. public TestsCatalog(string catalogName) : this(catalogName, false)
  57. {
  58. }
  59. public TestsCatalog(string catalogName, bool collectExluded)
  60. {
  61. if (catalogName == "")
  62. {
  63. catalogName = "test_catalog.xml";
  64. }
  65. try
  66. {
  67. _testsListXml = new XmlDocument();
  68. _testsListXml.Load(catalogName);
  69. }
  70. catch(Exception e)
  71. {
  72. throw e;
  73. }
  74. try
  75. {
  76. if (collectExluded)
  77. _tests = _testsListXml.SelectNodes("/TestCases/TestCase").GetEnumerator();
  78. else
  79. _tests = _testsListXml.SelectNodes("/TestCases/TestCase[@Exclude='N']").GetEnumerator();
  80. }
  81. catch(Exception e)
  82. {
  83. throw e;
  84. }
  85. }
  86. public IEnumerator GetEnumerator()
  87. {
  88. return this;
  89. }
  90. public object Current
  91. {
  92. get {return GetCurrentTestInfo();}
  93. }
  94. public bool MoveNext()
  95. {
  96. return _tests.MoveNext();
  97. }
  98. public void Reset()
  99. {
  100. _tests.Reset();
  101. }
  102. private TestInfo GetCurrentTestInfo()
  103. {
  104. XmlNode n = (XmlNode)_tests.Current;
  105. TestInfo ti = new TestInfo();
  106. ti.Name = n.Attributes["name"].Value;
  107. ti.Url = n.Attributes["url"].Value;
  108. return ti;
  109. }
  110. }
  111. }