aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Tests/MundaneFrameworkTests.cs308
1 files changed, 308 insertions, 0 deletions
diff --git a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
new file mode 100644
index 0000000..3f0a031
--- /dev/null
+++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
@@ -0,0 +1,308 @@
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 NUnit.Framework;
29using OpenSim.Framework;
30using OpenMetaverse;
31using OpenMetaverse.StructuredData;
32using System;
33using System.Globalization;
34using System.Threading;
35using OpenSim.Tests.Common;
36
37namespace OpenSim.Framework.Tests
38{
39 [TestFixture]
40 public class MundaneFrameworkTests : OpenSimTestCase
41 {
42 private bool m_RegionSettingsOnSaveEventFired;
43 private bool m_RegionLightShareDataOnSaveEventFired;
44
45
46 [Test]
47 public void ChildAgentDataUpdate01()
48 {
49 // code coverage
50 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
51 Assert.IsFalse(cadu.alwaysrun, "Default is false");
52 }
53
54 [Test]
55 public void AgentPositionTest01()
56 {
57 UUID AgentId1 = UUID.Random();
58 UUID SessionId1 = UUID.Random();
59 uint CircuitCode1 = uint.MinValue;
60 Vector3 Size1 = Vector3.UnitZ;
61 Vector3 Position1 = Vector3.UnitX;
62 Vector3 LeftAxis1 = Vector3.UnitY;
63 Vector3 UpAxis1 = Vector3.UnitZ;
64 Vector3 AtAxis1 = Vector3.UnitX;
65
66 ulong RegionHandle1 = ulong.MinValue;
67 byte[] Throttles1 = new byte[] {0, 1, 0};
68
69 Vector3 Velocity1 = Vector3.Zero;
70 float Far1 = 256;
71
72 bool ChangedGrid1 = false;
73 Vector3 Center1 = Vector3.Zero;
74
75 AgentPosition position1 = new AgentPosition();
76 position1.AgentID = AgentId1;
77 position1.SessionID = SessionId1;
78 position1.CircuitCode = CircuitCode1;
79 position1.Size = Size1;
80 position1.Position = Position1;
81 position1.LeftAxis = LeftAxis1;
82 position1.UpAxis = UpAxis1;
83 position1.AtAxis = AtAxis1;
84 position1.RegionHandle = RegionHandle1;
85 position1.Throttles = Throttles1;
86 position1.Velocity = Velocity1;
87 position1.Far = Far1;
88 position1.ChangedGrid = ChangedGrid1;
89 position1.Center = Center1;
90
91 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
92 cadu.AgentID = AgentId1.Guid;
93 cadu.ActiveGroupID = UUID.Zero.Guid;
94 cadu.throttles = Throttles1;
95 cadu.drawdistance = Far1;
96 cadu.Position = Position1;
97 cadu.Velocity = Velocity1;
98 cadu.regionHandle = RegionHandle1;
99 cadu.cameraPosition = Center1;
100 cadu.AVHeight = Size1.Z;
101
102 AgentPosition position2 = new AgentPosition();
103 position2.CopyFrom(cadu, position1.SessionID);
104
105 Assert.IsTrue(
106 position2.AgentID == position1.AgentID
107 && position2.Size == position1.Size
108 && position2.Position == position1.Position
109 && position2.Velocity == position1.Velocity
110 && position2.Center == position1.Center
111 && position2.RegionHandle == position1.RegionHandle
112 && position2.Far == position1.Far
113
114 ,"Copy From ChildAgentDataUpdate failed");
115
116 position2 = new AgentPosition();
117
118 Assert.IsFalse(position2.AgentID == position1.AgentID, "Test Error, position2 should be a blank uninitialized AgentPosition");
119 position2.Unpack(position1.Pack(), null);
120
121 Assert.IsTrue(position2.AgentID == position1.AgentID, "Agent ID didn't unpack the same way it packed");
122 Assert.IsTrue(position2.Position == position1.Position, "Position didn't unpack the same way it packed");
123 Assert.IsTrue(position2.Velocity == position1.Velocity, "Velocity didn't unpack the same way it packed");
124 Assert.IsTrue(position2.SessionID == position1.SessionID, "SessionID didn't unpack the same way it packed");
125 Assert.IsTrue(position2.CircuitCode == position1.CircuitCode, "CircuitCode didn't unpack the same way it packed");
126 Assert.IsTrue(position2.LeftAxis == position1.LeftAxis, "LeftAxis didn't unpack the same way it packed");
127 Assert.IsTrue(position2.UpAxis == position1.UpAxis, "UpAxis didn't unpack the same way it packed");
128 Assert.IsTrue(position2.AtAxis == position1.AtAxis, "AtAxis didn't unpack the same way it packed");
129 Assert.IsTrue(position2.RegionHandle == position1.RegionHandle, "RegionHandle didn't unpack the same way it packed");
130 Assert.IsTrue(position2.ChangedGrid == position1.ChangedGrid, "ChangedGrid didn't unpack the same way it packed");
131 Assert.IsTrue(position2.Center == position1.Center, "Center didn't unpack the same way it packed");
132 Assert.IsTrue(position2.Size == position1.Size, "Size didn't unpack the same way it packed");
133
134 }
135
136 [Test]
137 public void RegionSettingsTest01()
138 {
139 RegionSettings settings = new RegionSettings();
140 settings.OnSave += RegionSaveFired;
141 settings.Save();
142 settings.OnSave -= RegionSaveFired;
143
144// string str = settings.LoadedCreationDate;
145// int dt = settings.LoadedCreationDateTime;
146// string id = settings.LoadedCreationID;
147// string time = settings.LoadedCreationTime;
148
149 Assert.That(m_RegionSettingsOnSaveEventFired, "RegionSettings Save Event didn't Fire");
150
151 }
152 public void RegionSaveFired(RegionSettings settings)
153 {
154 m_RegionSettingsOnSaveEventFired = true;
155 }
156
157 [Test]
158 public void InventoryItemBaseConstructorTest01()
159 {
160 InventoryItemBase b1 = new InventoryItemBase();
161 Assert.That(b1.ID == UUID.Zero, "void constructor should create an inventory item with ID = UUID.Zero");
162 Assert.That(b1.Owner == UUID.Zero, "void constructor should create an inventory item with Owner = UUID.Zero");
163
164 UUID ItemID = UUID.Random();
165 UUID OwnerID = UUID.Random();
166
167 InventoryItemBase b2 = new InventoryItemBase(ItemID);
168 Assert.That(b2.ID == ItemID, "ID constructor should create an inventory item with ID = ItemID");
169 Assert.That(b2.Owner == UUID.Zero, "ID constructor should create an inventory item with Owner = UUID.Zero");
170
171 InventoryItemBase b3 = new InventoryItemBase(ItemID,OwnerID);
172 Assert.That(b3.ID == ItemID, "ID,OwnerID constructor should create an inventory item with ID = ItemID");
173 Assert.That(b3.Owner == OwnerID, "ID,OwnerID constructor should create an inventory item with Owner = OwnerID");
174
175 }
176
177 [Test]
178 public void AssetMetaDataNonNullContentTypeTest01()
179 {
180 AssetMetadata assetMetadata = new AssetMetadata();
181 assetMetadata.ContentType = "image/jp2";
182 Assert.That(assetMetadata.Type == (sbyte)AssetType.Texture, "Content type should be AssetType.Texture");
183 Assert.That(assetMetadata.ContentType == "image/jp2", "Text of content type should be image/jp2");
184 UUID rndID = UUID.Random();
185 assetMetadata.ID = rndID.ToString();
186 Assert.That(assetMetadata.ID.ToLower() == rndID.ToString().ToLower(), "assetMetadata.ID Setter/Getter not Consistent");
187 DateTime fixedTime = DateTime.Now;
188 assetMetadata.CreationDate = fixedTime;
189 }
190
191 [Test]
192 public void RegionLightShareDataCloneSaveTest01()
193 {
194 RegionLightShareData rlsd = new RegionLightShareData();
195 rlsd.OnSave += RegionLightShareDataSaveFired;
196 rlsd.Save();
197 rlsd.OnSave -= RegionLightShareDataSaveFired;
198 Assert.IsTrue(m_RegionLightShareDataOnSaveEventFired, "OnSave Event Never Fired");
199
200 object o = rlsd.Clone();
201 RegionLightShareData dupe = (RegionLightShareData) o;
202 Assert.IsTrue(rlsd.sceneGamma == dupe.sceneGamma, "Memberwise Clone of RegionLightShareData failed");
203 }
204 public void RegionLightShareDataSaveFired(RegionLightShareData settings)
205 {
206 m_RegionLightShareDataOnSaveEventFired = true;
207 }
208
209 [Test]
210 public void EstateSettingsMundateTests()
211 {
212 EstateSettings es = new EstateSettings();
213 es.AddBan(null);
214 UUID bannedUserId = UUID.Random();
215 es.AddBan(new EstateBan()
216 { BannedHostAddress = string.Empty,
217 BannedHostIPMask = string.Empty,
218 BannedHostNameMask = string.Empty,
219 BannedUserID = bannedUserId}
220 );
221 Assert.IsTrue(es.IsBanned(bannedUserId), "User Should be banned but is not.");
222 Assert.IsFalse(es.IsBanned(UUID.Zero), "User Should not be banned but is.");
223
224 es.RemoveBan(bannedUserId);
225
226 Assert.IsFalse(es.IsBanned(bannedUserId), "User Should not be banned but is.");
227
228 es.AddEstateManager(UUID.Zero);
229
230 es.AddEstateManager(bannedUserId);
231 Assert.IsTrue(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserId should be EstateManager but isn't.");
232
233 es.RemoveEstateManager(bannedUserId);
234 Assert.IsFalse(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserID is estateManager but shouldn't be");
235
236 Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't");
237
238 es.AddEstateUser(bannedUserId);
239
240 Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
241 es.RemoveEstateUser(bannedUserId);
242
243 es.AddEstateManager(bannedUserId);
244
245 Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
246
247 Assert.That(es.EstateGroups.Length == 0, "No Estate Groups Added.. so the array should be 0 length");
248
249 es.AddEstateGroup(bannedUserId);
250
251 Assert.That(es.EstateGroups.Length == 1, "1 Estate Groups Added.. so the array should be 1 length");
252
253 Assert.That(es.EstateGroups[0] == bannedUserId,"User ID should be in EstateGroups");
254
255 }
256
257 [Test]
258 public void InventoryFolderBaseConstructorTest01()
259 {
260 UUID uuid1 = UUID.Random();
261 UUID uuid2 = UUID.Random();
262
263 InventoryFolderBase fld = new InventoryFolderBase(uuid1);
264 Assert.That(fld.ID == uuid1, "ID constructor failed to save value in ID field.");
265
266 fld = new InventoryFolderBase(uuid1, uuid2);
267 Assert.That(fld.ID == uuid1, "ID,Owner constructor failed to save value in ID field.");
268 Assert.That(fld.Owner == uuid2, "ID,Owner constructor failed to save value in ID field.");
269 }
270
271 [Test]
272 public void AsssetBaseConstructorTest01()
273 {
274 AssetBase abase = new AssetBase();
275 Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
276 UUID itemID = UUID.Random();
277 UUID creatorID = UUID.Random();
278 abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());
279
280 Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
281 Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
282 Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");
283
284
285 abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
286 Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
287 Assert.That(abase.Metadata.Type == -1, "Unknown Type passed to string,string,sbyte,string constructor and was a known type when it came out again");
288
289 AssetMetadata metts = new AssetMetadata();
290 metts.FullID = itemID;
291 metts.ID = string.Empty;
292 metts.Name = "test item";
293 abase.Metadata = metts;
294
295 Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
296 Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
297 }
298
299 [Test]
300 public void CultureSetCultureTest01()
301 {
302 CultureInfo ci = new CultureInfo("en-US", false);
303 Culture.SetCurrentCulture();
304 Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US");
305
306 }
307 }
308} \ No newline at end of file