SceneTestUtils.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 OpenSim 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 System.Net;
  28. using Nini.Config;
  29. using OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Communications;
  32. using OpenSim.Framework.Communications.Cache;
  33. using OpenSim.Framework.Servers;
  34. using OpenSim.Region.Physics.Manager;
  35. using OpenSim.Region.Environment;
  36. using OpenSim.Region.Environment.Scenes;
  37. using OpenSim.Tests.Common.Mock;
  38. namespace OpenSim.Region.Environment.Scenes.Tests
  39. {
  40. /// <summary>
  41. /// Utilities for constructing and performing operations upon scenes.
  42. /// </summary>
  43. public class SceneTestUtils
  44. {
  45. /// <summary>
  46. /// Set up a test scene
  47. /// </summary>
  48. /// <returns></returns>
  49. public static TestScene SetupScene()
  50. {
  51. return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager());
  52. }
  53. /// <summary>
  54. /// Set up a test scene
  55. /// </summary>
  56. /// <param name="name">Name of the region</param>
  57. /// <param name="id">ID of the region</param>
  58. /// <param name="x">X co-ordinate of the region</param>
  59. /// <param name="y">Y co-ordinate of the region</param>
  60. /// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
  61. /// <returns></returns>
  62. public static TestScene SetupScene(string name, UUID id, uint x, uint y, CommunicationsManager cm)
  63. {
  64. RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
  65. regInfo.RegionName = name;
  66. regInfo.RegionID = id;
  67. AgentCircuitManager acm = new AgentCircuitManager();
  68. SceneCommunicationService scs = new SceneCommunicationService(cm);
  69. SQLAssetServer assetService = new SQLAssetServer(new TestAssetDataPlugin());
  70. AssetCache ac = new AssetCache(assetService);
  71. StorageManager sm = new StorageManager("OpenSim.Data.Null.dll", "", "");
  72. IConfigSource configSource = new IniConfigSource();
  73. TestScene testScene = new TestScene(
  74. regInfo, acm, cm, scs, ac, sm, null, false, false, false, configSource, null);
  75. testScene.LandChannel = new TestLandChannel();
  76. testScene.LoadWorldMap();
  77. PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
  78. physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
  79. testScene.PhysicsScene
  80. = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test");
  81. return testScene;
  82. }
  83. /// <summary>
  84. /// Add a root agent
  85. /// </summary>
  86. /// <param name="scene"></param>
  87. /// <param name="agentId"></param>
  88. /// <returns></returns>
  89. public static TestClient AddRootAgent(Scene scene, UUID agentId)
  90. {
  91. string firstName = "testfirstname";
  92. AgentCircuitData agent = new AgentCircuitData();
  93. agent.AgentID = agentId;
  94. agent.firstname = firstName;
  95. agent.lastname = "testlastname";
  96. agent.SessionID = UUID.Zero;
  97. agent.SecureSessionID = UUID.Zero;
  98. agent.circuitcode = 123;
  99. agent.BaseFolder = UUID.Zero;
  100. agent.InventoryFolder = UUID.Zero;
  101. agent.startpos = Vector3.Zero;
  102. agent.CapsPath = "http://wibble.com";
  103. // We emulate the proper login sequence here by doing things in three stages
  104. // Stage 1: simulate login by telling the scene to expect a new user connection
  105. scene.NewUserConnection(agent);
  106. // Stage 2: add the new client as a child agent to the scene
  107. TestClient client = new TestClient(agent, scene);
  108. scene.AddNewClient(client);
  109. // Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance,
  110. // inventory, etc.)
  111. scene.AgentCrossing(agent.AgentID, new Vector3(90, 90, 90), false);
  112. return client;
  113. }
  114. /// <summary>
  115. /// Add a test object
  116. /// </summary>
  117. /// <param name="scene"></param>
  118. /// <returns></returns>
  119. public static SceneObjectPart AddSceneObject(Scene scene)
  120. {
  121. return AddSceneObject(scene, null);
  122. }
  123. /// <summary>
  124. /// Add a test object
  125. /// </summary>
  126. /// <param name="scene"></param>
  127. /// <param name="name"></param>
  128. /// <returns></returns>
  129. public static SceneObjectPart AddSceneObject(Scene scene, string name)
  130. {
  131. SceneObjectGroup sceneObject = new SceneObjectGroup();
  132. SceneObjectPart part
  133. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
  134. if (name != null)
  135. part.Name = name;
  136. //part.UpdatePrimFlags(false, false, true);
  137. part.ObjectFlags |= (uint)PrimFlags.Phantom;
  138. sceneObject.SetRootPart(part);
  139. scene.AddNewSceneObject(sceneObject, false);
  140. return part;
  141. }
  142. /// <summary>
  143. /// Delete a scene object asynchronously
  144. /// </summary>
  145. /// <param name="scene"></param>
  146. /// <param name="part"></param>
  147. /// <param name="action"></param>
  148. /// <param name="destinationId"></param>
  149. /// <param name="client"></param>
  150. public static void DeleteSceneObjectAsync(
  151. TestScene scene, SceneObjectPart part, DeRezAction action, UUID destinationId, IClientAPI client)
  152. {
  153. // Turn off the timer on the async sog deleter - we'll crank it by hand within a unit test
  154. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  155. sogd.Enabled = false;
  156. scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId);
  157. sogd.InventoryDeQueueAndDelete();
  158. }
  159. }
  160. }