MundaneFrameworkTests.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. position2.Unpack(position1.Pack(), null);
  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 RegionLightShareDataCloneSaveTest01()
  165. {
  166. RegionLightShareData rlsd = new RegionLightShareData();
  167. rlsd.OnSave += RegionLightShareDataSaveFired;
  168. rlsd.Save();
  169. rlsd.OnSave -= RegionLightShareDataSaveFired;
  170. Assert.IsTrue(m_RegionLightShareDataOnSaveEventFired, "OnSave Event Never Fired");
  171. object o = rlsd.Clone();
  172. RegionLightShareData dupe = (RegionLightShareData) o;
  173. Assert.IsTrue(rlsd.sceneGamma == dupe.sceneGamma, "Memberwise Clone of RegionLightShareData failed");
  174. }
  175. public void RegionLightShareDataSaveFired(RegionLightShareData settings)
  176. {
  177. m_RegionLightShareDataOnSaveEventFired = true;
  178. }
  179. [Test]
  180. public void EstateSettingsMundateTests()
  181. {
  182. EstateSettings es = new EstateSettings();
  183. es.AddBan(null);
  184. UUID bannedUserId = UUID.Random();
  185. es.AddBan(new EstateBan()
  186. { BannedHostAddress = string.Empty,
  187. BannedHostIPMask = string.Empty,
  188. BannedHostNameMask = string.Empty,
  189. BannedUserID = bannedUserId}
  190. );
  191. Assert.IsTrue(es.IsBanned(bannedUserId), "User Should be banned but is not.");
  192. Assert.IsFalse(es.IsBanned(UUID.Zero), "User Should not be banned but is.");
  193. es.RemoveBan(bannedUserId);
  194. Assert.IsFalse(es.IsBanned(bannedUserId), "User Should not be banned but is.");
  195. es.AddEstateManager(UUID.Zero);
  196. es.AddEstateManager(bannedUserId);
  197. Assert.IsTrue(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserId should be EstateManager but isn't.");
  198. es.RemoveEstateManager(bannedUserId);
  199. Assert.IsFalse(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserID is estateManager but shouldn't be");
  200. Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't");
  201. es.AddEstateUser(bannedUserId);
  202. Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
  203. es.RemoveEstateUser(bannedUserId);
  204. es.AddEstateManager(bannedUserId);
  205. Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
  206. Assert.That(es.EstateGroups.Length == 0, "No Estate Groups Added.. so the array should be 0 length");
  207. es.AddEstateGroup(bannedUserId);
  208. Assert.That(es.EstateGroups.Length == 1, "1 Estate Groups Added.. so the array should be 1 length");
  209. Assert.That(es.EstateGroups[0] == bannedUserId,"User ID should be in EstateGroups");
  210. }
  211. [Test]
  212. public void InventoryFolderBaseConstructorTest01()
  213. {
  214. UUID uuid1 = UUID.Random();
  215. UUID uuid2 = UUID.Random();
  216. InventoryFolderBase fld = new InventoryFolderBase(uuid1);
  217. Assert.That(fld.ID == uuid1, "ID constructor failed to save value in ID field.");
  218. fld = new InventoryFolderBase(uuid1, uuid2);
  219. Assert.That(fld.ID == uuid1, "ID,Owner constructor failed to save value in ID field.");
  220. Assert.That(fld.Owner == uuid2, "ID,Owner constructor failed to save value in ID field.");
  221. }
  222. [Test]
  223. public void AsssetBaseConstructorTest01()
  224. {
  225. AssetBase abase = new AssetBase();
  226. Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
  227. UUID itemID = UUID.Random();
  228. UUID creatorID = UUID.Random();
  229. abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());
  230. Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
  231. Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
  232. Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");
  233. abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
  234. Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
  235. 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");
  236. AssetMetadata metts = new AssetMetadata();
  237. metts.FullID = itemID;
  238. metts.ID = string.Empty;
  239. metts.Name = "test item";
  240. abase.Metadata = metts;
  241. Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
  242. Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
  243. }
  244. [Test]
  245. public void CultureSetCultureTest01()
  246. {
  247. CultureInfo ci = new CultureInfo("en-US", false);
  248. Culture.SetCurrentCulture();
  249. Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US");
  250. }
  251. }
  252. }