diff options
author | Justin Clarke Casey | 2009-01-23 17:32:38 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-01-23 17:32:38 +0000 |
commit | ee3c61247e61d03ee252f373144d5c6bfecb9d6f (patch) | |
tree | 2ef31475b79dcfdcf034e3ff3404425ac8aecb15 /OpenSim/Tests | |
parent | * minor: remove serialization and deserializationg sog log messages for now (diff) | |
download | opensim-SC_OLD-ee3c61247e61d03ee252f373144d5c6bfecb9d6f.zip opensim-SC_OLD-ee3c61247e61d03ee252f373144d5c6bfecb9d6f.tar.gz opensim-SC_OLD-ee3c61247e61d03ee252f373144d5c6bfecb9d6f.tar.bz2 opensim-SC_OLD-ee3c61247e61d03ee252f373144d5c6bfecb9d6f.tar.xz |
* refactor: move scene setup code into common test code assembly
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r-- | OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs new file mode 100644 index 0000000..11ebc86 --- /dev/null +++ b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs | |||
@@ -0,0 +1,224 @@ | |||
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 | |||
28 | using System.Net; | ||
29 | using Nini.Config; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Framework.Communications; | ||
33 | using OpenSim.Framework.Communications.Cache; | ||
34 | using OpenSim.Framework.Servers; | ||
35 | using OpenSim.Region.Physics.Manager; | ||
36 | using OpenSim.Region.Environment; | ||
37 | using OpenSim.Region.Environment.Interfaces; | ||
38 | using OpenSim.Region.Environment.Modules.Agent.Capabilities; | ||
39 | using OpenSim.Region.Environment.Scenes; | ||
40 | using OpenSim.Tests.Common.Mock; | ||
41 | |||
42 | namespace OpenSim.Tests.Common.Setup | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Helpers for setting up scenes. | ||
46 | /// </summary> | ||
47 | public class SceneSetupHelpers | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// Set up a test scene | ||
51 | /// </summary> | ||
52 | /// <returns></returns> | ||
53 | public static TestScene SetupScene() | ||
54 | { | ||
55 | return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager()); | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Set up a test scene | ||
60 | /// </summary> | ||
61 | /// <param name="name">Name of the region</param> | ||
62 | /// <param name="id">ID of the region</param> | ||
63 | /// <param name="x">X co-ordinate of the region</param> | ||
64 | /// <param name="y">Y co-ordinate of the region</param> | ||
65 | /// <param name="cm">This should be the same if simulating two scenes within a standalone</param> | ||
66 | /// <returns></returns> | ||
67 | public static TestScene SetupScene(string name, UUID id, uint x, uint y, CommunicationsManager cm) | ||
68 | { | ||
69 | RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); | ||
70 | regInfo.RegionName = name; | ||
71 | regInfo.RegionID = id; | ||
72 | |||
73 | AgentCircuitManager acm = new AgentCircuitManager(); | ||
74 | SceneCommunicationService scs = new SceneCommunicationService(cm); | ||
75 | |||
76 | SQLAssetServer assetService = new SQLAssetServer(new TestAssetDataPlugin()); | ||
77 | AssetCache ac = new AssetCache(assetService); | ||
78 | |||
79 | StorageManager sm = new StorageManager("OpenSim.Data.Null.dll", "", ""); | ||
80 | IConfigSource configSource = new IniConfigSource(); | ||
81 | |||
82 | TestScene testScene = new TestScene( | ||
83 | regInfo, acm, cm, scs, ac, sm, null, false, false, false, configSource, null); | ||
84 | |||
85 | IRegionModule capsModule = new CapabilitiesModule(); | ||
86 | capsModule.Initialise(testScene, new IniConfigSource()); | ||
87 | testScene.AddModule(capsModule.Name, capsModule); | ||
88 | testScene.SetModuleInterfaces(); | ||
89 | |||
90 | testScene.LandChannel = new TestLandChannel(); | ||
91 | testScene.LoadWorldMap(); | ||
92 | |||
93 | PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); | ||
94 | physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); | ||
95 | testScene.PhysicsScene | ||
96 | = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); | ||
97 | |||
98 | return testScene; | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Generate some standard agent connection data. | ||
103 | /// </summary> | ||
104 | /// <param name="agentId"></param> | ||
105 | /// <returns></returns> | ||
106 | public static AgentCircuitData GenerateAgentData(UUID agentId) | ||
107 | { | ||
108 | string firstName = "testfirstname"; | ||
109 | |||
110 | AgentCircuitData agentData = new AgentCircuitData(); | ||
111 | agentData.AgentID = agentId; | ||
112 | agentData.firstname = firstName; | ||
113 | agentData.lastname = "testlastname"; | ||
114 | agentData.SessionID = UUID.Zero; | ||
115 | agentData.SecureSessionID = UUID.Zero; | ||
116 | agentData.circuitcode = 123; | ||
117 | agentData.BaseFolder = UUID.Zero; | ||
118 | agentData.InventoryFolder = UUID.Zero; | ||
119 | agentData.startpos = Vector3.Zero; | ||
120 | agentData.CapsPath = "http://wibble.com"; | ||
121 | |||
122 | return agentData; | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test | ||
127 | /// </summary> | ||
128 | /// <param name="scene"></param> | ||
129 | /// <param name="agentId"></param> | ||
130 | /// <returns></returns> | ||
131 | public static TestClient AddRootAgent(Scene scene, UUID agentId) | ||
132 | { | ||
133 | return AddRootAgent(scene, GenerateAgentData(agentId)); | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Add a root agent. | ||
138 | /// </summary> | ||
139 | /// | ||
140 | /// This function | ||
141 | /// | ||
142 | /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the | ||
143 | /// userserver if grid) would give initial login data back to the client and separately tell the scene that the | ||
144 | /// agent was coming. | ||
145 | /// | ||
146 | /// 2) Connects the agent with the scene | ||
147 | /// | ||
148 | /// This function performs actions equivalent with notifying the scene that an agent is | ||
149 | /// coming and then actually connecting the agent to the scene. The one step missed out is the very first | ||
150 | /// | ||
151 | /// <param name="scene"></param> | ||
152 | /// <param name="agentData"></param> | ||
153 | /// <returns></returns> | ||
154 | public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData) | ||
155 | { | ||
156 | // We emulate the proper login sequence here by doing things in three stages | ||
157 | // Stage 1: simulate login by telling the scene to expect a new user connection | ||
158 | scene.NewUserConnection(agentData); | ||
159 | |||
160 | // Stage 2: add the new client as a child agent to the scene | ||
161 | TestClient client = new TestClient(agentData, scene); | ||
162 | scene.AddNewClient(client); | ||
163 | |||
164 | // Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance, | ||
165 | // inventory, etc.) | ||
166 | scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); | ||
167 | |||
168 | return client; | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// Add a test object | ||
173 | /// </summary> | ||
174 | /// <param name="scene"></param> | ||
175 | /// <returns></returns> | ||
176 | public static SceneObjectPart AddSceneObject(Scene scene) | ||
177 | { | ||
178 | return AddSceneObject(scene, null); | ||
179 | } | ||
180 | |||
181 | /// <summary> | ||
182 | /// Add a test object | ||
183 | /// </summary> | ||
184 | /// <param name="scene"></param> | ||
185 | /// <param name="name"></param> | ||
186 | /// <returns></returns> | ||
187 | public static SceneObjectPart AddSceneObject(Scene scene, string name) | ||
188 | { | ||
189 | SceneObjectGroup sceneObject = new SceneObjectGroup(); | ||
190 | SceneObjectPart part | ||
191 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); | ||
192 | |||
193 | if (name != null) | ||
194 | part.Name = name; | ||
195 | |||
196 | //part.UpdatePrimFlags(false, false, true); | ||
197 | part.ObjectFlags |= (uint)PrimFlags.Phantom; | ||
198 | sceneObject.SetRootPart(part); | ||
199 | |||
200 | scene.AddNewSceneObject(sceneObject, false); | ||
201 | |||
202 | return part; | ||
203 | } | ||
204 | |||
205 | /// <summary> | ||
206 | /// Delete a scene object asynchronously | ||
207 | /// </summary> | ||
208 | /// <param name="scene"></param> | ||
209 | /// <param name="part"></param> | ||
210 | /// <param name="action"></param> | ||
211 | /// <param name="destinationId"></param> | ||
212 | /// <param name="client"></param> | ||
213 | public static void DeleteSceneObjectAsync( | ||
214 | TestScene scene, SceneObjectPart part, DeRezAction action, UUID destinationId, IClientAPI client) | ||
215 | { | ||
216 | // Turn off the timer on the async sog deleter - we'll crank it by hand within a unit test | ||
217 | AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; | ||
218 | sogd.Enabled = false; | ||
219 | |||
220 | scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId); | ||
221 | sogd.InventoryDeQueueAndDelete(); | ||
222 | } | ||
223 | } | ||
224 | } | ||