3 // Rafael Mizrahi <rafim@mainsoft.com>
4 // Erez Lotan <erezl@mainsoft.com>
5 // Vladimir Krasnov <vladimirk@mainsoft.com>
8 // Copyright (c) 2002-2005 Mainsoft Corporation.
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using System.Configuration;
32 using System.Collections;
36 using NUnit.Framework;
40 namespace MonoTests.stand_alone.WebHarness
44 static string _ignoreListFile = "";
45 static string _catalogFile = "";
46 static string _outputPath = "";
47 static string _baseUrlExp = "";
48 static string _baseUrlTst = "";
49 static bool _disableAlmost = false;
50 static bool _runExcluded = false;
52 static void Main(string[] args)
54 ParseCommandLineAgrs(args);
56 if (_baseUrlExp != "")
58 //baseUrl = "http://localhost:80/System_Web_dll";
59 CreateExpectedResults(_baseUrlExp);
62 if (_baseUrlTst != "")
64 //baseUrl = "http://localhost:8080/System_Web_dll";
65 RunTests(_baseUrlTst);
71 static public TestSuite Suite
77 TestSuite suite = new TestSuite ("SystemWebTests");
78 TestsCatalog tc = new TestsCatalog();
79 foreach (TestInfo ti in tc)
81 suite.Add(new SingleWebTest(ti, _baseUrlTst));
91 static string GetParameterByName(string name, string[] args)
93 int i = Array.IndexOf(args, name);
96 if (i < args.Length - 1)
104 static bool IsParameterSet(string name, string[] args)
106 int i = Array.IndexOf(args, name);
110 static void ParseAppConfigFile()
112 _disableAlmost = Convert.ToBoolean(ConfigurationSettings.AppSettings["DisableAlmost"]);
113 _runExcluded = Convert.ToBoolean(ConfigurationSettings.AppSettings["RunExcluded"]);
114 _ignoreListFile = ConfigurationSettings.AppSettings["AlmostList"];
115 _catalogFile = ConfigurationSettings.AppSettings["TestCatalog"];
116 _outputPath = ConfigurationSettings.AppSettings["OutputDir"];
117 if ((!_outputPath.EndsWith("\\")) && (!_outputPath.EndsWith("/")))
119 _outputPath += Path.DirectorySeparatorChar;
122 _baseUrlExp = ConfigurationSettings.AppSettings["ExpResBaseUrl"];
123 _baseUrlTst = ConfigurationSettings.AppSettings["TestBaseUrl"];
126 static void ParseCommandLineAgrs(string [] args)
128 _disableAlmost = IsParameterSet("-na", args);
129 _runExcluded = IsParameterSet("-x", args);
131 // specifies the almost config xml file
132 // default is almost_config.xml in current folder
133 _ignoreListFile = GetParameterByName("-i", args);
134 if (_ignoreListFile == "")
136 _ignoreListFile = "almost_config.xml";
139 // specifies tests catalog xml file
140 // default is test_catalog.xml in current folder
141 _catalogFile = GetParameterByName("-c", args);
142 if (_catalogFile == "")
144 _catalogFile = "test_catalog.xml";
147 // specifies the folder where expected results will be stored
148 // by default is current folder
149 _outputPath = GetParameterByName("-o", args);
150 if (_outputPath != "")
152 if ((!_outputPath.EndsWith("\\")) && (!_outputPath.EndsWith("/")))
154 _outputPath += Path.DirectorySeparatorChar;
158 // specifies the base url for all tests
160 _baseUrlExp = GetParameterByName("-e", args);
161 _baseUrlTst = GetParameterByName("-t", args);
165 #region "Tests run routines"
167 static void CreateExpectedResults(string baseUrl)
169 TestsCatalog tc = new TestsCatalog(_catalogFile, _runExcluded);
170 HtmlDiff wt = new HtmlDiff();
171 wt.TestsBaseUrl = baseUrl;
172 wt.IgnoreListFile = _ignoreListFile;
174 if ((_outputPath != "") && (!Directory.Exists(_outputPath)))
176 Directory.CreateDirectory(_outputPath);
179 Console.WriteLine("Running expected results...");
180 foreach (TestInfo ti in tc)
182 Console.WriteLine("Running... " + ti.Url);
183 XmlDocument d = wt.GetTestXml( ti );
184 d.Save(_outputPath + ti.Url.Replace("/", "_") + ".xml");
188 static void RunTests(string baseUrl)
190 TestsCatalog tc = new TestsCatalog(_catalogFile, _runExcluded);
191 foreach (TestInfo ti in tc)
194 RunSingleTest(baseUrl, ti);
196 catch (Exception e) {
197 Console.WriteLine(e.Message);
202 public static bool RunSingleTest(string baseUrl, TestInfo ti)
204 HtmlDiff wt = new HtmlDiff();
205 wt.TestsBaseUrl = baseUrl;
206 wt.IgnoreListFile = _ignoreListFile;
208 XmlDocument d1 = new XmlDocument();
209 d1.Load(_outputPath + ti.Url.Replace("/", "_") + ".xml");
211 XmlDocument d2 = wt.GetTestXml( ti );
212 bool fp = wt.XmlCompare(d1, d2, _disableAlmost);
214 throw new Exception("Url: " + ti.Url + "\nCompare failed:\n" + wt.CompareStatus + "\n");
225 public class SingleWebTest : NUnit.Core.TestCase
227 TestInfo _testInfo = null;
228 string _baseUrl = "";
229 public SingleWebTest (TestInfo testInfo, string baseUrl) : base (null, testInfo.Url)
231 _testInfo = testInfo;
235 public override void Run (TestCaseResult res)
239 Harness.RunSingleTest(_baseUrl, _testInfo);
243 res.Failure(e.Message, null);