MundaneFrameworkTests.cs 13 KB

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