OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
MundaneFrameworkTests.cs
Go to the documentation of this file.
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 
28 using NUnit.Framework;
29 using OpenSim.Framework;
30 using OpenMetaverse;
31 using OpenMetaverse.StructuredData;
32 using System;
33 using System.Globalization;
34 using System.Threading;
35 using OpenSim.Tests.Common;
36 
37 namespace OpenSim.Framework.Tests
38 {
39  [TestFixture]
41  {
42  private bool m_RegionSettingsOnSaveEventFired;
43  private bool m_RegionLightShareDataOnSaveEventFired;
44 
45 
46  [Test]
47  public void ChildAgentDataUpdate01()
48  {
49  // code coverage
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 
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");
120  position2.Unpack(position1.Pack(ctx), null, ctx);
121 
122  Assert.IsTrue(position2.AgentID == position1.AgentID, "Agent ID didn't unpack the same way it packed");
123  Assert.IsTrue(position2.Position == position1.Position, "Position didn't unpack the same way it packed");
124  Assert.IsTrue(position2.Velocity == position1.Velocity, "Velocity didn't unpack the same way it packed");
125  Assert.IsTrue(position2.SessionID == position1.SessionID, "SessionID didn't unpack the same way it packed");
126  Assert.IsTrue(position2.CircuitCode == position1.CircuitCode, "CircuitCode didn't unpack the same way it packed");
127  Assert.IsTrue(position2.LeftAxis == position1.LeftAxis, "LeftAxis didn't unpack the same way it packed");
128  Assert.IsTrue(position2.UpAxis == position1.UpAxis, "UpAxis didn't unpack the same way it packed");
129  Assert.IsTrue(position2.AtAxis == position1.AtAxis, "AtAxis didn't unpack the same way it packed");
130  Assert.IsTrue(position2.RegionHandle == position1.RegionHandle, "RegionHandle didn't unpack the same way it packed");
131  Assert.IsTrue(position2.ChangedGrid == position1.ChangedGrid, "ChangedGrid didn't unpack the same way it packed");
132  Assert.IsTrue(position2.Center == position1.Center, "Center didn't unpack the same way it packed");
133  Assert.IsTrue(position2.Size == position1.Size, "Size didn't unpack the same way it packed");
134 
135  }
136 
137  [Test]
138  public void RegionSettingsTest01()
139  {
140  RegionSettings settings = new RegionSettings();
141  settings.OnSave += RegionSaveFired;
142  settings.Save();
143  settings.OnSave -= RegionSaveFired;
144 
145 // string str = settings.LoadedCreationDate;
146 // int dt = settings.LoadedCreationDateTime;
147 // string id = settings.LoadedCreationID;
148 // string time = settings.LoadedCreationTime;
149 
150  Assert.That(m_RegionSettingsOnSaveEventFired, "RegionSettings Save Event didn't Fire");
151 
152  }
153  public void RegionSaveFired(RegionSettings settings)
154  {
155  m_RegionSettingsOnSaveEventFired = true;
156  }
157 
158  [Test]
160  {
162  Assert.That(b1.ID == UUID.Zero, "void constructor should create an inventory item with ID = UUID.Zero");
163  Assert.That(b1.Owner == UUID.Zero, "void constructor should create an inventory item with Owner = UUID.Zero");
164 
165  UUID ItemID = UUID.Random();
166  UUID OwnerID = UUID.Random();
167 
168  InventoryItemBase b2 = new InventoryItemBase(ItemID);
169  Assert.That(b2.ID == ItemID, "ID constructor should create an inventory item with ID = ItemID");
170  Assert.That(b2.Owner == UUID.Zero, "ID constructor should create an inventory item with Owner = UUID.Zero");
171 
172  InventoryItemBase b3 = new InventoryItemBase(ItemID,OwnerID);
173  Assert.That(b3.ID == ItemID, "ID,OwnerID constructor should create an inventory item with ID = ItemID");
174  Assert.That(b3.Owner == OwnerID, "ID,OwnerID constructor should create an inventory item with Owner = OwnerID");
175 
176  }
177 
178  [Test]
180  {
181  AssetMetadata assetMetadata = new AssetMetadata();
182  assetMetadata.ContentType = "image/jp2";
183  Assert.That(assetMetadata.Type == (sbyte)AssetType.Texture, "Content type should be AssetType.Texture");
184  Assert.That(assetMetadata.ContentType == "image/jp2", "Text of content type should be image/jp2");
185  UUID rndID = UUID.Random();
186  assetMetadata.ID = rndID.ToString();
187  Assert.That(assetMetadata.ID.ToLower() == rndID.ToString().ToLower(), "assetMetadata.ID Setter/Getter not Consistent");
188  DateTime fixedTime = DateTime.Now;
189  assetMetadata.CreationDate = fixedTime;
190  }
191 
192  [Test]
194  {
196  rlsd.OnSave += RegionLightShareDataSaveFired;
197  rlsd.Save();
198  rlsd.OnSave -= RegionLightShareDataSaveFired;
199  Assert.IsTrue(m_RegionLightShareDataOnSaveEventFired, "OnSave Event Never Fired");
200 
201  object o = rlsd.Clone();
203  Assert.IsTrue(rlsd.sceneGamma == dupe.sceneGamma, "Memberwise Clone of RegionLightShareData failed");
204  }
206  {
207  m_RegionLightShareDataOnSaveEventFired = true;
208  }
209 
210  [Test]
212  {
213  EstateSettings es = new EstateSettings();
214  es.AddBan(null);
215  UUID bannedUserId = UUID.Random();
216  es.AddBan(new EstateBan()
217  { BannedHostAddress = string.Empty,
218  BannedHostIPMask = string.Empty,
219  BannedHostNameMask = string.Empty,
220  BannedUserID = bannedUserId}
221  );
222  Assert.IsTrue(es.IsBanned(bannedUserId, 32), "User Should be banned but is not.");
223  Assert.IsFalse(es.IsBanned(UUID.Zero, 32), "User Should not be banned but is.");
224 
225  es.RemoveBan(bannedUserId);
226 
227  Assert.IsFalse(es.IsBanned(bannedUserId, 32), "User Should not be banned but is.");
228 
229  es.AddEstateManager(UUID.Zero);
230 
231  es.AddEstateManager(bannedUserId);
232  Assert.IsTrue(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserId should be EstateManager but isn't.");
233 
234  es.RemoveEstateManager(bannedUserId);
235  Assert.IsFalse(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserID is estateManager but shouldn't be");
236 
237  Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't");
238 
239  es.AddEstateUser(bannedUserId);
240 
241  Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
242  es.RemoveEstateUser(bannedUserId);
243 
244  es.AddEstateManager(bannedUserId);
245 
246  Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
247 
248  Assert.That(es.EstateGroups.Length == 0, "No Estate Groups Added.. so the array should be 0 length");
249 
250  es.AddEstateGroup(bannedUserId);
251 
252  Assert.That(es.EstateGroups.Length == 1, "1 Estate Groups Added.. so the array should be 1 length");
253 
254  Assert.That(es.EstateGroups[0] == bannedUserId,"User ID should be in EstateGroups");
255 
256  }
257 
258  [Test]
260  {
261  UUID uuid1 = UUID.Random();
262  UUID uuid2 = UUID.Random();
263 
264  InventoryFolderBase fld = new InventoryFolderBase(uuid1);
265  Assert.That(fld.ID == uuid1, "ID constructor failed to save value in ID field.");
266 
267  fld = new InventoryFolderBase(uuid1, uuid2);
268  Assert.That(fld.ID == uuid1, "ID,Owner constructor failed to save value in ID field.");
269  Assert.That(fld.Owner == uuid2, "ID,Owner constructor failed to save value in ID field.");
270  }
271 
272  [Test]
274  {
275  AssetBase abase = new AssetBase();
276  Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
277  UUID itemID = UUID.Random();
278  UUID creatorID = UUID.Random();
279  abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());
280 
281  Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
282  Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
283  Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");
284 
285 
286  abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
287  Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
288  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");
289 
290  AssetMetadata metts = new AssetMetadata();
291  metts.FullID = itemID;
292  metts.ID = string.Empty;
293  metts.Name = "test item";
294  abase.Metadata = metts;
295 
296  Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
297  Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
298  }
299 
300  [Test]
302  {
303  CultureInfo ci = new CultureInfo("en-US", false);
304  Culture.SetCurrentCulture();
305  Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US");
306 
307  }
308  }
309 }
OpenSim.Framework.RegionSettings RegionSettings
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
Inventory Item - contains all the properties associated with an individual inventory piece...
void RegionLightShareDataSaveFired(RegionLightShareData settings)
Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.