1
0

MundaneFrameworkTests.cs 14 KB

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