diff options
author | Sean Dague | 2009-01-14 19:34:14 +0000 |
---|---|---|
committer | Sean Dague | 2009-01-14 19:34:14 +0000 |
commit | 7934094cf304a180e20201379fa2825570ad8ad3 (patch) | |
tree | 3d3b806bdcc29abe650a31b14b1682ea7b210c2f | |
parent | * Remove absolute position and authentication handler addition for incoming '... (diff) | |
download | opensim-SC_OLD-7934094cf304a180e20201379fa2825570ad8ad3.zip opensim-SC_OLD-7934094cf304a180e20201379fa2825570ad8ad3.tar.gz opensim-SC_OLD-7934094cf304a180e20201379fa2825570ad8ad3.tar.bz2 opensim-SC_OLD-7934094cf304a180e20201379fa2825570ad8ad3.tar.xz |
* Added MySQL Grid unit tests
From: Arthur Rodrigo S Valadares <arthursv@linux.vnet.ibm.com>
-rw-r--r-- | OpenSim/Data/MySQL/Tests/MySQLGridTest.cs | 83 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicGridTest.cs | 265 |
2 files changed, 348 insertions, 0 deletions
diff --git a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs b/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs new file mode 100644 index 0000000..e6df085 --- /dev/null +++ b/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs | |||
@@ -0,0 +1,83 @@ | |||
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 OpenSim 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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Collections.Generic; | ||
31 | using NUnit.Framework; | ||
32 | using NUnit.Framework.SyntaxHelpers; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Data.Tests; | ||
35 | using OpenSim.Data.MySQL; | ||
36 | using OpenSim.Region.Environment.Scenes; | ||
37 | using OpenMetaverse; | ||
38 | |||
39 | namespace OpenSim.Data.MySQL.Tests | ||
40 | { | ||
41 | [TestFixture] | ||
42 | public class MySQLGridTest : BasicGridTest | ||
43 | { | ||
44 | public string file; | ||
45 | public MySQLManager database; | ||
46 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | ||
47 | |||
48 | [TestFixtureSetUp] | ||
49 | public void Init() | ||
50 | { | ||
51 | SuperInit(); | ||
52 | // If we manage to connect to the database with the user | ||
53 | // and password above it is our test database, and run | ||
54 | // these tests. If anything goes wrong, ignore these | ||
55 | // tests. | ||
56 | try | ||
57 | { | ||
58 | database = new MySQLManager(connect); | ||
59 | db = new MySQLGridData(); | ||
60 | db.Initialise(connect); | ||
61 | } | ||
62 | catch (Exception e) | ||
63 | { | ||
64 | System.Console.WriteLine("Exception {0}", e); | ||
65 | Assert.Ignore(); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | [TestFixtureTearDown] | ||
70 | public void Cleanup() | ||
71 | { | ||
72 | if (db != null) | ||
73 | { | ||
74 | db.Dispose(); | ||
75 | } | ||
76 | // if a new table is added, it has to be dropped here | ||
77 | if (database != null) | ||
78 | { | ||
79 | database.ExecuteSql("drop table regions"); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs new file mode 100644 index 0000000..b9cf4cf --- /dev/null +++ b/OpenSim/Data/Tests/BasicGridTest.cs | |||
@@ -0,0 +1,265 @@ | |||
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 OpenSim 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using NUnit.Framework; | ||
32 | using NUnit.Framework.SyntaxHelpers; | ||
33 | using OpenSim.Data; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.Environment.Scenes; | ||
36 | using OpenMetaverse; | ||
37 | |||
38 | namespace OpenSim.Data.Tests | ||
39 | { | ||
40 | public class BasicGridTest | ||
41 | { | ||
42 | public GridDataBase db; | ||
43 | public UUID region1, region2, region3; | ||
44 | public UUID zero = UUID.Zero; | ||
45 | public static Random random; | ||
46 | |||
47 | |||
48 | public void SuperInit() | ||
49 | { | ||
50 | try | ||
51 | { | ||
52 | log4net.Config.XmlConfigurator.Configure(); | ||
53 | } | ||
54 | catch (Exception) | ||
55 | { | ||
56 | // I don't care, just leave log4net off | ||
57 | } | ||
58 | region1 = UUID.Random(); | ||
59 | region2 = UUID.Random(); | ||
60 | region3 = UUID.Random(); | ||
61 | random = new Random(); | ||
62 | } | ||
63 | |||
64 | [Test] | ||
65 | public void T001_LoadEmpty() | ||
66 | { | ||
67 | Assert.That(db.GetProfileByUUID(region1),Is.Null); | ||
68 | Assert.That(db.GetProfileByUUID(region2),Is.Null); | ||
69 | Assert.That(db.GetProfileByUUID(region3),Is.Null); | ||
70 | Assert.That(db.GetProfileByUUID(zero),Is.Null); | ||
71 | } | ||
72 | |||
73 | [Test] | ||
74 | public void T999_StillNull() | ||
75 | { | ||
76 | Assert.That(db.GetProfileByUUID(zero),Is.Null); | ||
77 | } | ||
78 | |||
79 | [Test] | ||
80 | public void T010_SimpleAddRetrieveProfile() | ||
81 | { | ||
82 | RegionProfileData reg = new RegionProfileData(); | ||
83 | reg.Uuid = region1; | ||
84 | reg.RegionName = "My new Region"; | ||
85 | reg.RegionHandle = (ulong) random.Next(); | ||
86 | reg.RegionLocX = 1000; | ||
87 | reg.RegionLocY = 1000; | ||
88 | reg.RegionLocZ = 0; | ||
89 | |||
90 | db.AddProfile(reg); | ||
91 | |||
92 | RegionProfileData retreg = db.GetProfileByUUID(region1); | ||
93 | |||
94 | Assert.That(retreg.RegionName, Is.EqualTo("My new Region")); | ||
95 | Assert.That(retreg.Uuid, Is.EqualTo(region1)); | ||
96 | } | ||
97 | |||
98 | [Test] | ||
99 | public void T011_AddRetrieveCompleteTest() | ||
100 | { | ||
101 | string regionname = "|<Goth@m Ci1y>|"; | ||
102 | ulong regionhandle = (ulong) random.Next(); | ||
103 | uint regionlocx = (uint) random.Next(); | ||
104 | uint regionlocy = (uint) random.Next(); | ||
105 | uint regionlocz = (uint) random.Next(); | ||
106 | string regionsendkey = RandomName(); | ||
107 | string regionrecvkey = RandomName(); | ||
108 | string regionsecret = RandomName(); | ||
109 | bool regiononline = false; | ||
110 | string serverip = RandomName(); | ||
111 | uint serverport = (uint) random.Next(); | ||
112 | string serveruri = RandomName(); | ||
113 | uint serverhttpport = (uint) random.Next(); | ||
114 | uint serverremotingport = (uint) random.Next(); | ||
115 | ulong northovrhandle = (ulong) random.Next(); | ||
116 | ulong southovrhandle = (ulong) random.Next(); | ||
117 | ulong eastovrhandle = (ulong) random.Next(); | ||
118 | ulong westovrhandle = (ulong) random.Next(); | ||
119 | string regiondatauri = RandomName(); | ||
120 | string regionasseturi = RandomName(); | ||
121 | string regionassetsendkey = RandomName(); | ||
122 | string regionassetrcvkey = RandomName(); | ||
123 | string regionuseruri = RandomName(); | ||
124 | string regionusersendkey = RandomName(); | ||
125 | string regionuserrcvkey = RandomName(); | ||
126 | UUID regionmaptextureid = UUID.Random(); | ||
127 | UUID owner_uuid = UUID.Random(); | ||
128 | UUID originuuid = UUID.Random(); | ||
129 | |||
130 | |||
131 | RegionProfileData reg = new RegionProfileData(); | ||
132 | reg.Uuid = region2; | ||
133 | reg.RegionName = regionname; | ||
134 | reg.RegionHandle = regionhandle; | ||
135 | reg.RegionLocX = regionlocx; | ||
136 | reg.RegionLocY = regionlocy; | ||
137 | reg.RegionLocZ = regionlocz; | ||
138 | reg.RegionSendKey = regionsendkey; | ||
139 | reg.RegionRecvKey = regionrecvkey; | ||
140 | reg.RegionSecret = regionsecret; | ||
141 | reg.RegionOnline = regiononline; | ||
142 | reg.OriginUUID = originuuid; | ||
143 | reg.ServerIP = serverip; | ||
144 | reg.ServerPort = serverport; | ||
145 | reg.ServerURI = serveruri; | ||
146 | reg.ServerHttpPort = serverhttpport; | ||
147 | reg.ServerRemotingPort = serverremotingport; | ||
148 | reg.NorthOverrideHandle = northovrhandle; | ||
149 | reg.SouthOverrideHandle = southovrhandle; | ||
150 | reg.EastOverrideHandle = eastovrhandle; | ||
151 | reg.WestOverrideHandle = westovrhandle; | ||
152 | reg.RegionDataURI = regiondatauri; | ||
153 | reg.RegionAssetURI = regionasseturi; | ||
154 | reg.RegionAssetSendKey = regionassetsendkey; | ||
155 | reg.RegionAssetRecvKey = regionassetrcvkey; | ||
156 | reg.RegionUserURI = regionuseruri; | ||
157 | reg.RegionUserSendKey = regionusersendkey; | ||
158 | reg.RegionUserRecvKey = regionuserrcvkey; | ||
159 | reg.RegionMapTextureID = regionmaptextureid; | ||
160 | reg.Owner_uuid = owner_uuid; | ||
161 | reg.OriginUUID = originuuid; | ||
162 | |||
163 | db.AddProfile(reg); | ||
164 | |||
165 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
166 | |||
167 | Assert.That(retreg.RegionName, Is.EqualTo(regionname)); | ||
168 | Assert.That(retreg.Uuid, Is.EqualTo(region2)); | ||
169 | Assert.That(retreg.RegionHandle, Is.EqualTo(regionhandle)); | ||
170 | Assert.That(retreg.RegionLocX, Is.EqualTo(regionlocx)); | ||
171 | Assert.That(retreg.RegionLocY, Is.EqualTo(regionlocy)); | ||
172 | Assert.That(retreg.RegionLocZ, Is.EqualTo(regionlocz)); | ||
173 | Assert.That(retreg.RegionSendKey, Is.EqualTo(regionsendkey)); | ||
174 | Assert.That(retreg.RegionRecvKey, Is.EqualTo(regionrecvkey)); | ||
175 | Assert.That(retreg.RegionSecret, Is.EqualTo(regionsecret)); | ||
176 | Assert.That(retreg.RegionOnline, Is.EqualTo(regiononline)); | ||
177 | Assert.That(retreg.OriginUUID, Is.EqualTo(originuuid)); | ||
178 | Assert.That(retreg.ServerIP, Is.EqualTo(serverip)); | ||
179 | Assert.That(retreg.ServerPort, Is.EqualTo(serverport)); | ||
180 | Assert.That(retreg.ServerURI, Is.EqualTo(serveruri)); | ||
181 | Assert.That(retreg.ServerHttpPort, Is.EqualTo(serverhttpport)); | ||
182 | Assert.That(retreg.ServerRemotingPort, Is.EqualTo(serverremotingport)); | ||
183 | Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(northovrhandle)); | ||
184 | Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(southovrhandle)); | ||
185 | Assert.That(retreg.EastOverrideHandle, Is.EqualTo(eastovrhandle)); | ||
186 | Assert.That(retreg.WestOverrideHandle, Is.EqualTo(westovrhandle)); | ||
187 | Assert.That(retreg.RegionDataURI, Is.EqualTo(regiondatauri)); | ||
188 | Assert.That(retreg.RegionAssetURI, Is.EqualTo(regionasseturi)); | ||
189 | Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(regionassetsendkey)); | ||
190 | Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(regionassetrcvkey)); | ||
191 | Assert.That(retreg.RegionUserURI, Is.EqualTo(regionuseruri)); | ||
192 | Assert.That(retreg.RegionUserSendKey, Is.EqualTo(regionusersendkey)); | ||
193 | Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(regionuserrcvkey)); | ||
194 | Assert.That(retreg.RegionMapTextureID, Is.EqualTo(regionmaptextureid)); | ||
195 | Assert.That(retreg.Owner_uuid, Is.EqualTo(owner_uuid)); | ||
196 | Assert.That(retreg.OriginUUID, Is.EqualTo(originuuid)); | ||
197 | |||
198 | retreg = db.GetProfileByHandle(regionhandle); | ||
199 | Assert.That(retreg.Uuid, Is.EqualTo(region2)); | ||
200 | |||
201 | retreg = db.GetProfileByString(regionname); | ||
202 | Assert.That(retreg.Uuid, Is.EqualTo(region2)); | ||
203 | |||
204 | RegionProfileData[] retregs = db.GetProfilesInRange(regionlocx,regionlocy,regionlocx,regionlocy); | ||
205 | Assert.That(retregs[0].Uuid, Is.EqualTo(region2)); | ||
206 | } | ||
207 | |||
208 | [Test] | ||
209 | public void T012_DeleteProfile() | ||
210 | { | ||
211 | db.DeleteProfile(region1.ToString()); | ||
212 | RegionProfileData retreg = db.GetProfileByUUID(region1); | ||
213 | Assert.That(retreg,Is.Null); | ||
214 | } | ||
215 | |||
216 | [Test] | ||
217 | public void T013_UpdateProfile() | ||
218 | { | ||
219 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
220 | retreg.regionName = "Gotham City"; | ||
221 | |||
222 | db.UpdateProfile(retreg); | ||
223 | |||
224 | retreg = db.GetProfileByUUID(region2); | ||
225 | Assert.That(retreg.RegionName, Is.EqualTo("Gotham City")); | ||
226 | } | ||
227 | |||
228 | [Test] | ||
229 | public void T014_RegionList() | ||
230 | { | ||
231 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
232 | retreg.RegionName = "Gotham Town"; | ||
233 | retreg.Uuid = region1; | ||
234 | |||
235 | db.AddProfile(retreg); | ||
236 | |||
237 | retreg = db.GetProfileByUUID(region2); | ||
238 | retreg.RegionName = "Gothan Town"; | ||
239 | retreg.Uuid = region3; | ||
240 | |||
241 | db.AddProfile(retreg); | ||
242 | |||
243 | List<RegionProfileData> listreg = db.GetRegionsByName("Gotham",10); | ||
244 | |||
245 | Assert.That(listreg.Count,Is.EqualTo(2)); | ||
246 | Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid)); | ||
247 | Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2)); | ||
248 | Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2)); | ||
249 | } | ||
250 | |||
251 | [Test] | ||
252 | public static string RandomName() | ||
253 | { | ||
254 | StringBuilder name = new StringBuilder(); | ||
255 | int size = random.Next(5,12); | ||
256 | char ch ; | ||
257 | for (int i=0; i<size; i++) | ||
258 | { | ||
259 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
260 | name.Append(ch); | ||
261 | } | ||
262 | return name.ToString(); | ||
263 | } | ||
264 | } | ||
265 | } | ||