aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMarck2010-08-11 16:31:26 +0200
committerJustin Clark-Casey (justincc)2010-08-13 23:59:33 +0100
commitfcc83f2305f6da6fc93b6f94ef7dbd4a1737568a (patch)
tree32b79064d9c1062654f9b6b92ce66e4ce471b498
parentConfiguration files can read include files from relative paths. (diff)
downloadopensim-SC_OLD-fcc83f2305f6da6fc93b6f94ef7dbd4a1737568a.zip
opensim-SC_OLD-fcc83f2305f6da6fc93b6f94ef7dbd4a1737568a.tar.gz
opensim-SC_OLD-fcc83f2305f6da6fc93b6f94ef7dbd4a1737568a.tar.bz2
opensim-SC_OLD-fcc83f2305f6da6fc93b6f94ef7dbd4a1737568a.tar.xz
Unit test for ConfigurationLoader.
Adds a new test assembly for OpenSim.
-rw-r--r--.nant/local.include11
-rw-r--r--OpenSim/Tests/ConfigurationLoaderTest.cs143
-rw-r--r--prebuild.xml22
3 files changed, 176 insertions, 0 deletions
diff --git a/.nant/local.include b/.nant/local.include
index 0279f25..97c0c0f 100644
--- a/.nant/local.include
+++ b/.nant/local.include
@@ -91,6 +91,11 @@
91 the assembly here as an exec, and you add the fail clause later. 91 the assembly here as an exec, and you add the fail clause later.
92 This lets all the unit tests run and tells you if they fail at the 92 This lets all the unit tests run and tells you if they fail at the
93 end, instead of stopping short --> 93 end, instead of stopping short -->
94 <exec program="${nunitcmd}" failonerror="true" resultproperty="testresult.opensim.tests">
95 <arg value="./bin/OpenSim.Tests.dll" />
96 </exec>
97 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.tests)==0}" />
98
94 <exec program="${nunitcmd}" failonerror="true" resultproperty="testresult.opensim.framework.tests"> 99 <exec program="${nunitcmd}" failonerror="true" resultproperty="testresult.opensim.framework.tests">
95 <arg value="./bin/OpenSim.Framework.Tests.dll" /> 100 <arg value="./bin/OpenSim.Framework.Tests.dll" />
96 </exec> 101 </exec>
@@ -256,6 +261,11 @@
256 261
257 <mkdir dir="test-results" failonerror="false" /> 262 <mkdir dir="test-results" failonerror="false" />
258 <!-- Unit Test Assembly --> 263 <!-- Unit Test Assembly -->
264 <exec program="${nunitcmd}" failonerror="false" resultproperty="testresult.opensim.tests">
265 <arg value="./bin/OpenSim.Tests.dll" />
266 <arg value="-xml=test-results/OpenSim.Tests.dll-Results.xml" />
267 </exec>
268
259 <exec program="${nunitcmd}" failonerror="false" resultproperty="testresult.opensim.framework.tests"> 269 <exec program="${nunitcmd}" failonerror="false" resultproperty="testresult.opensim.framework.tests">
260 <arg value="./bin/OpenSim.Framework.Tests.dll" /> 270 <arg value="./bin/OpenSim.Framework.Tests.dll" />
261 <arg value="-xml=test-results/OpenSim.Framework.Tests.dll-Results.xml" /> 271 <arg value="-xml=test-results/OpenSim.Framework.Tests.dll-Results.xml" />
@@ -298,6 +308,7 @@
298 <arg value="-xml=test-results/OpenSim.Data.Tests.dll-Results.xml" /> 308 <arg value="-xml=test-results/OpenSim.Data.Tests.dll-Results.xml" />
299 </exec> 309 </exec>
300 310
311 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.tests)==0}" />
301 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.framework.tests)==0}" /> 312 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.framework.tests)==0}" />
302 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.framework.servers.tests)==0}" /> 313 <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.framework.servers.tests)==0}" />
303<!-- <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.region.clientstack.lindenudp.tests)==0}" /> --> 314<!-- <fail message="Failures reported in unit tests." unless="${int::parse(testresult.opensim.region.clientstack.lindenudp.tests)==0}" /> -->
diff --git a/OpenSim/Tests/ConfigurationLoaderTest.cs b/OpenSim/Tests/ConfigurationLoaderTest.cs
new file mode 100644
index 0000000..4262c95
--- /dev/null
+++ b/OpenSim/Tests/ConfigurationLoaderTest.cs
@@ -0,0 +1,143 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.IO;
29using Nini.Config;
30using NUnit.Framework;
31using OpenSim.Framework;
32
33namespace OpenSim.Tests
34{
35 [TestFixture]
36 public class ConfigurationLoaderTests
37 {
38 private const string m_testSubdirectory = "test";
39 private string m_basePath;
40 private string m_workingDirectory;
41 private IConfigSource m_config;
42
43 /// <summary>
44 /// Set up a test directory.
45 /// </summary>
46 [SetUp]
47 public void SetUp()
48 {
49 m_basePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
50 string path = Path.Combine(m_basePath, m_testSubdirectory);
51 Directory.CreateDirectory(path);
52 m_workingDirectory = Directory.GetCurrentDirectory();
53 Directory.SetCurrentDirectory(path);
54 }
55
56 /// <summary>
57 /// Remove the test directory.
58 /// </summary>
59 [TearDown]
60 public void TearDown()
61 {
62 Directory.SetCurrentDirectory(m_workingDirectory);
63 Directory.Delete(m_basePath, true);
64 }
65
66 /// <summary>
67 /// Test the including of ini files with absolute and relative paths.
68 /// </summary>
69 [Test]
70 public void IncludeTests()
71 {
72 const string mainIniFile = "OpenSim.ini";
73 m_config = new IniConfigSource();
74
75 // Create ini files in a directory structure
76 IniConfigSource ini;
77 IConfig config;
78
79 ini = new IniConfigSource();
80 config = ini.AddConfig("IncludeTest");
81 config.Set("Include-absolute", "absolute/*/config/*.ini");
82 config.Set("Include-relative", "../" + m_testSubdirectory + "/relative/*/config/*.ini");
83 CreateIni(mainIniFile, ini);
84
85 ini = new IniConfigSource();
86 ini.AddConfig("Absolute1").Set("name1", "value1");
87 CreateIni("absolute/one/config/setting.ini", ini);
88
89 ini = new IniConfigSource();
90 ini.AddConfig("Absolute2").Set("name2", 2.3);
91 CreateIni("absolute/two/config/setting1.ini", ini);
92
93 ini = new IniConfigSource();
94 ini.AddConfig("Absolute2").Set("name3", "value3");
95 CreateIni("absolute/two/config/setting2.ini", ini);
96
97 ini = new IniConfigSource();
98 ini.AddConfig("Relative1").Set("name4", "value4");
99 CreateIni("relative/one/config/setting.ini", ini);
100
101 ini = new IniConfigSource();
102 ini.AddConfig("Relative2").Set("name5", true);
103 CreateIni("relative/two/config/setting1.ini", ini);
104
105 ini = new IniConfigSource();
106 ini.AddConfig("Relative2").Set("name6", 6);
107 CreateIni("relative/two/config/setting2.ini", ini);
108
109 // Prepare call to ConfigurationLoader.LoadConfigSettings()
110 ConfigurationLoader cl = new ConfigurationLoader();
111 IConfigSource argvSource = new IniConfigSource();
112 argvSource.AddConfig("Startup").Set("inifile", mainIniFile);
113 ConfigSettings configSettings;
114 NetworkServersInfo networkInfo;
115
116 OpenSimConfigSource source = cl.LoadConfigSettings(argvSource, out configSettings, out networkInfo);
117
118 // Remove default config
119 config = source.Source.Configs["Startup"];
120 source.Source.Configs.Remove(config);
121 config = source.Source.Configs["Network"];
122 source.Source.Configs.Remove(config);
123
124 // Finally, we are able to check the result
125 Assert.AreEqual(m_config.ToString(), source.Source.ToString(),
126 "Configuration with includes does not contain all settings.");
127 // The following would be preferable but fails due to a type mismatch which I am not able to resolve
128 //CollectionAssert.AreEquivalent(m_config.Configs, source.Source.Configs,
129 // String.Format("Configuration with includes does not contain all settings.\nAll settings:\n{0}\nSettings read:\n{1}", m_config, source.Source));
130 }
131
132 private void CreateIni(string filepath, IniConfigSource source)
133 {
134 string path = Path.GetDirectoryName(filepath);
135 if (path != string.Empty)
136 {
137 Directory.CreateDirectory(path);
138 }
139 source.Save(filepath);
140 m_config.Merge(source);
141 }
142 }
143}
diff --git a/prebuild.xml b/prebuild.xml
index 8407797..fdd024a 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -2770,6 +2770,28 @@
2770 </Files> 2770 </Files>
2771 </Project> 2771 </Project>
2772 2772
2773 <Project frameworkVersion="v3_5" name="OpenSim.Tests" path="OpenSim/Tests" type="Library">
2774 <Configuration name="Debug">
2775 <Options>
2776 <OutputPath>../../bin/</OutputPath>
2777 </Options>
2778 </Configuration>
2779 <Configuration name="Release">
2780 <Options>
2781 <OutputPath>../../bin/</OutputPath>
2782 </Options>
2783 </Configuration>
2784
2785 <ReferencePath>../../bin/</ReferencePath>
2786 <Reference name="OpenSim.Framework"/>
2787 <Reference name="Nini.dll" />
2788 <Reference name="nunit.framework.dll" />
2789 <Reference name="OpenSim" />
2790 <Files>
2791 <Match pattern="*.cs" recurse="false"/>
2792 </Files>
2793 </Project>
2794
2773 <Project frameworkVersion="v3_5" name="OpenSim.Data.Tests" path="OpenSim/Data/Tests" type="Library"> 2795 <Project frameworkVersion="v3_5" name="OpenSim.Data.Tests" path="OpenSim/Data/Tests" type="Library">
2774 <Configuration name="Debug"> 2796 <Configuration name="Debug">
2775 <Options> 2797 <Options>