MundaneFrameworkTests.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. namespace OpenSim.Framework.Tests
  35. {
  36. [TestFixture]
  37. public class MundaneFrameworkTests
  38. {
  39. private bool m_RegionSettingsOnSaveEventFired;
  40. private bool m_RegionLightShareDataOnSaveEventFired;
  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);
  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. position2.Unpack(position1.Pack());
  104. Assert.IsTrue(position2.AgentID == position1.AgentID, "Agent ID didn't unpack the same way it packed");
  105. Assert.IsTrue(position2.Position == position1.Position, "Position didn't unpack the same way it packed");
  106. Assert.IsTrue(position2.Velocity == position1.Velocity, "Velocity didn't unpack the same way it packed");
  107. Assert.IsTrue(position2.SessionID == position1.SessionID, "SessionID didn't unpack the same way it packed");
  108. Assert.IsTrue(position2.CircuitCode == position1.CircuitCode, "CircuitCode didn't unpack the same way it packed");
  109. Assert.IsTrue(position2.LeftAxis == position1.LeftAxis, "LeftAxis didn't unpack the same way it packed");
  110. Assert.IsTrue(position2.UpAxis == position1.UpAxis, "UpAxis didn't unpack the same way it packed");
  111. Assert.IsTrue(position2.AtAxis == position1.AtAxis, "AtAxis didn't unpack the same way it packed");
  112. Assert.IsTrue(position2.RegionHandle == position1.RegionHandle, "RegionHandle didn't unpack the same way it packed");
  113. Assert.IsTrue(position2.ChangedGrid == position1.ChangedGrid, "ChangedGrid didn't unpack the same way it packed");
  114. Assert.IsTrue(position2.Center == position1.Center, "Center didn't unpack the same way it packed");
  115. Assert.IsTrue(position2.Size == position1.Size, "Size didn't unpack the same way it packed");
  116. }
  117. [Test]
  118. public void RegionSettingsTest01()
  119. {
  120. RegionSettings settings = new RegionSettings();
  121. settings.OnSave += RegionSaveFired;
  122. settings.Save();
  123. settings.OnSave -= RegionSaveFired;
  124. // string str = settings.LoadedCreationDate;
  125. // int dt = settings.LoadedCreationDateTime;
  126. // string id = settings.LoadedCreationID;
  127. // string time = settings.LoadedCreationTime;
  128. Assert.That(m_RegionSettingsOnSaveEventFired, "RegionSettings Save Event didn't Fire");
  129. }
  130. public void RegionSaveFired(RegionSettings settings)
  131. {
  132. m_RegionSettingsOnSaveEventFired = true;
  133. }
  134. [Test]
  135. public void InventoryItemBaseConstructorTest01()
  136. {
  137. InventoryItemBase b1 = new InventoryItemBase();
  138. Assert.That(b1.ID == UUID.Zero, "void constructor should create an inventory item with ID = UUID.Zero");
  139. Assert.That(b1.Owner == UUID.Zero, "void constructor should create an inventory item with Owner = UUID.Zero");
  140. UUID ItemID = UUID.Random();
  141. UUID OwnerID = UUID.Random();
  142. InventoryItemBase b2 = new InventoryItemBase(ItemID);
  143. Assert.That(b2.ID == ItemID, "ID constructor should create an inventory item with ID = ItemID");
  144. Assert.That(b2.Owner == UUID.Zero, "ID constructor should create an inventory item with Owner = UUID.Zero");
  145. InventoryItemBase b3 = new InventoryItemBase(ItemID,OwnerID);
  146. Assert.That(b3.ID == ItemID, "ID,OwnerID constructor should create an inventory item with ID = ItemID");
  147. Assert.That(b3.Owner == OwnerID, "ID,OwnerID constructor should create an inventory item with Owner = OwnerID");
  148. }
  149. [Test]
  150. public void AssetMetaDataNonNullContentTypeTest01()
  151. {
  152. AssetMetadata assetMetadata = new AssetMetadata();
  153. assetMetadata.ContentType = "image/jp2";
  154. Assert.That(assetMetadata.Type == (sbyte)AssetType.Texture, "Content type should be AssetType.Texture");
  155. Assert.That(assetMetadata.ContentType == "image/jp2", "Text of content type should be image/jp2");
  156. UUID rndID = UUID.Random();
  157. assetMetadata.ID = rndID.ToString();
  158. Assert.That(assetMetadata.ID.ToLower() == rndID.ToString().ToLower(), "assetMetadata.ID Setter/Getter not Consistent");
  159. DateTime fixedTime = DateTime.Now;
  160. assetMetadata.CreationDate = fixedTime;
  161. }
  162. [Test]
  163. public void RegionLightShareDataCloneSaveTest01()
  164. {
  165. RegionLightShareData rlsd = new RegionLightShareData();
  166. rlsd.OnSave += RegionLightShareDataSaveFired;
  167. rlsd.Save();
  168. rlsd.OnSave -= RegionLightShareDataSaveFired;
  169. Assert.IsTrue(m_RegionLightShareDataOnSaveEventFired, "OnSave Event Never Fired");
  170. object o = rlsd.Clone();
  171. RegionLightShareData dupe = (RegionLightShareData) o;
  172. Assert.IsTrue(rlsd.sceneGamma == dupe.sceneGamma, "Memberwise Clone of RegionLightShareData failed");
  173. }
  174. public void RegionLightShareDataSaveFired(RegionLightShareData settings)
  175. {
  176. m_RegionLightShareDataOnSaveEventFired = true;
  177. }
  178. [Test]
  179. public void EstateSettingsMundateTests()
  180. {
  181. EstateSettings es = new EstateSettings();
  182. es.AddBan(null);
  183. UUID bannedUserId = UUID.Random();
  184. es.AddBan(new EstateBan()
  185. { BannedHostAddress = string.Empty,
  186. BannedHostIPMask = string.Empty,
  187. BannedHostNameMask = string.Empty,
  188. BannedUserID = bannedUserId}
  189. );
  190. Assert.IsTrue(es.IsBanned(bannedUserId), "User Should be banned but is not.");
  191. Assert.IsFalse(es.IsBanned(UUID.Zero), "User Should not be banned but is.");
  192. es.RemoveBan(bannedUserId);
  193. Assert.IsFalse(es.IsBanned(bannedUserId), "User Should not be banned but is.");
  194. es.AddEstateManager(UUID.Zero);
  195. es.AddEstateManager(bannedUserId);
  196. Assert.IsTrue(es.IsEstateManager(bannedUserId), "bannedUserId should be EstateManager but isn't.");
  197. es.RemoveEstateManager(bannedUserId);
  198. Assert.IsFalse(es.IsEstateManager(bannedUserId), "bannedUserID is estateManager but shouldn't be");
  199. Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't");
  200. es.AddEstateUser(bannedUserId);
  201. Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
  202. es.RemoveEstateUser(bannedUserId);
  203. es.AddEstateManager(bannedUserId);
  204. Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
  205. Assert.That(es.EstateGroups.Length == 0, "No Estate Groups Added.. so the array should be 0 length");
  206. es.AddEstateGroup(bannedUserId);
  207. Assert.That(es.EstateGroups.Length == 1, "1 Estate Groups Added.. so the array should be 1 length");
  208. Assert.That(es.EstateGroups[0] == bannedUserId,"User ID should be in EstateGroups");
  209. }
  210. [Test]
  211. public void InventoryFolderBaseConstructorTest01()
  212. {
  213. UUID uuid1 = UUID.Random();
  214. UUID uuid2 = UUID.Random();
  215. InventoryFolderBase fld = new InventoryFolderBase(uuid1);
  216. Assert.That(fld.ID == uuid1, "ID constructor failed to save value in ID field.");
  217. fld = new InventoryFolderBase(uuid1, uuid2);
  218. Assert.That(fld.ID == uuid1, "ID,Owner constructor failed to save value in ID field.");
  219. Assert.That(fld.Owner == uuid2, "ID,Owner constructor failed to save value in ID field.");
  220. }
  221. [Test]
  222. public void AsssetBaseConstructorTest01()
  223. {
  224. AssetBase abase = new AssetBase();
  225. Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
  226. UUID itemID = UUID.Random();
  227. UUID creatorID = UUID.Random();
  228. abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());
  229. Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
  230. Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
  231. Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");
  232. abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
  233. Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
  234. 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");
  235. AssetMetadata metts = new AssetMetadata();
  236. metts.FullID = itemID;
  237. metts.ID = string.Empty;
  238. metts.Name = "test item";
  239. abase.Metadata = metts;
  240. Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
  241. Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
  242. }
  243. [Test]
  244. public void CultureSetCultureTest01()
  245. {
  246. CultureInfo ci = new CultureInfo("en-US", false);
  247. Culture.SetCurrentCulture();
  248. Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US");
  249. }
  250. }
  251. }