aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Tests/Common/Helpers
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Tests/Common/Helpers')
-rw-r--r--OpenSim/Tests/Common/Helpers/AssetHelpers.cs168
-rw-r--r--OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs75
-rw-r--r--OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs95
-rw-r--r--OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs123
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs724
-rw-r--r--OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs210
-rw-r--r--OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs160
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs370
8 files changed, 1925 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/AssetHelpers.cs b/OpenSim/Tests/Common/Helpers/AssetHelpers.cs
new file mode 100644
index 0000000..7af8bed
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/AssetHelpers.cs
@@ -0,0 +1,168 @@
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
28using System.Text;
29using OpenMetaverse;
30using OpenMetaverse.Assets;
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Region.Framework.Scenes.Serialization;
34using OpenSim.Services.Interfaces;
35
36namespace OpenSim.Tests.Common
37{
38 public class AssetHelpers
39 {
40 /// <summary>
41 /// Create a notecard asset with a random uuids and dummy text.
42 /// </summary>
43 /// <returns></returns>
44 public static AssetBase CreateNotecardAsset()
45 {
46 return CreateNotecardAsset(UUID.Random());
47 }
48
49 /// <summary>
50 /// Create a notecard asset with dummy text and a random owner.
51 /// </summary>
52 /// <param name="assetId">/param>
53 /// <returns></returns>
54 public static AssetBase CreateNotecardAsset(UUID assetId)
55 {
56 return CreateNotecardAsset(assetId, "hello");
57 }
58
59 /// <summary>
60 /// Create a notecard asset with a random owner.
61 /// </summary>
62 /// <param name="assetId">/param>
63 /// <param name="text"></param>
64 /// <returns></returns>
65 public static AssetBase CreateNotecardAsset(UUID assetId, string text)
66 {
67 return CreateAsset(assetId, AssetType.Notecard, text, UUID.Random());
68 }
69
70// /// <summary>
71// /// Create and store a notecard asset with a random uuid and dummy text.
72// /// </summary>
73// /// <param name="creatorId">/param>
74// /// <returns></returns>
75// public static AssetBase CreateNotecardAsset(Scene scene, UUID creatorId)
76// {
77// AssetBase asset = CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId);
78// scene.AssetService.Store(asset);
79// return asset;
80// }
81
82 /// <summary>
83 /// Create an asset from the given object.
84 /// </summary>
85 /// <param name="assetUuidTail">
86 /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
87 /// will be used.
88 /// </param>
89 /// <param name="sog"></param>
90 /// <returns></returns>
91 public static AssetBase CreateAsset(int assetUuidTail, SceneObjectGroup sog)
92 {
93 return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), sog);
94 }
95
96 /// <summary>
97 /// Create an asset from the given object.
98 /// </summary>
99 /// <param name="assetUuid"></param>
100 /// <param name="sog"></param>
101 /// <returns></returns>
102 public static AssetBase CreateAsset(UUID assetUuid, SceneObjectGroup sog)
103 {
104 return CreateAsset(
105 assetUuid,
106 AssetType.Object,
107 Encoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(sog)),
108 sog.OwnerID);
109 }
110
111 /// <summary>
112 /// Create an asset from the given scene object.
113 /// </summary>
114 /// <param name="assetUuidTail">
115 /// The hexadecimal last part of the UUID for the asset created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
116 /// will be used.
117 /// </param>
118 /// <param name="coa"></param>
119 /// <returns></returns>
120 public static AssetBase CreateAsset(int assetUuidTail, CoalescedSceneObjects coa)
121 {
122 return CreateAsset(new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", assetUuidTail)), coa);
123 }
124
125 /// <summary>
126 /// Create an asset from the given scene object.
127 /// </summary>
128 /// <param name="assetUuid"></param>
129 /// <param name="coa"></param>
130 /// <returns></returns>
131 public static AssetBase CreateAsset(UUID assetUuid, CoalescedSceneObjects coa)
132 {
133 return CreateAsset(
134 assetUuid,
135 AssetType.Object,
136 Encoding.ASCII.GetBytes(CoalescedSceneObjectsSerializer.ToXml(coa)),
137 coa.CreatorId);
138 }
139
140 /// <summary>
141 /// Create an asset from the given data.
142 /// </summary>
143 public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string text, UUID creatorID)
144 {
145 AssetNotecard anc = new AssetNotecard();
146 anc.BodyText = text;
147 anc.Encode();
148
149 return CreateAsset(assetUuid, assetType, anc.AssetData, creatorID);
150 }
151
152 /// <summary>
153 /// Create an asset from the given data.
154 /// </summary>
155 public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID)
156 {
157 AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString());
158 asset.Data = data;
159 return asset;
160 }
161
162 public static string ReadAssetAsString(IAssetService assetService, UUID uuid)
163 {
164 byte[] assetData = assetService.GetData(uuid.ToString());
165 return Encoding.ASCII.GetString(assetData);
166 }
167 }
168}
diff --git a/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
new file mode 100644
index 0000000..82ecf9a
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/BaseRequestHandlerHelpers.cs
@@ -0,0 +1,75 @@
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
28using System;
29using System.Collections.Generic;
30using System.Text;
31using NUnit.Framework;
32using OpenSim.Framework;
33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer;
35
36namespace OpenSim.Tests.Common
37{
38 public class BaseRequestHandlerHelpers
39 {
40 private static string[] m_emptyStringArray = new string[] { };
41
42 public static void BaseTestGetParams(BaseRequestHandler handler, string assetsPath)
43 {
44 Assert.AreEqual(String.Empty, handler.GetParam(null), "Failed on null path.");
45 Assert.AreEqual(String.Empty, handler.GetParam(""), "Failed on empty path.");
46 Assert.AreEqual(String.Empty, handler.GetParam("s"), "Failed on short url.");
47 Assert.AreEqual(String.Empty, handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
48
49 Assert.AreEqual(String.Empty, handler.GetParam(assetsPath));
50 Assert.AreEqual("/", handler.GetParam(assetsPath + "/"));
51 Assert.AreEqual("/a", handler.GetParam(assetsPath + "/a"));
52 Assert.AreEqual("/b/", handler.GetParam(assetsPath + "/b/"));
53 Assert.AreEqual("/c/d", handler.GetParam(assetsPath + "/c/d"));
54 Assert.AreEqual("/e/f/", handler.GetParam(assetsPath + "/e/f/"));
55 }
56
57 public static void BaseTestSplitParams(BaseRequestHandler handler, string assetsPath)
58 {
59 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(null), "Failed on null.");
60 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(""), "Failed on empty path.");
61 Assert.AreEqual(m_emptyStringArray, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
62
63 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath), "Failed on empty params.");
64 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath + "/"), "Failed on single slash.");
65
66 Assert.AreEqual(new string[] { "a" }, handler.SplitParams(assetsPath + "/a"), "Failed on first segment.");
67 Assert.AreEqual(new string[] { "b" }, handler.SplitParams(assetsPath + "/b/"), "Failed on second slash.");
68 Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams(assetsPath + "/c/d"), "Failed on second segment.");
69 Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams(assetsPath + "/e/f/"), "Failed on trailing slash.");
70 }
71
72 public static byte[] EmptyByteArray = new byte[] {};
73
74 }
75}
diff --git a/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
new file mode 100644
index 0000000..33cd8a2
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
@@ -0,0 +1,95 @@
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
28using System;
29using System.Net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenMetaverse.Packets;
33using OpenSim.Framework;
34using OpenSim.Region.ClientStack.LindenUDP;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Tests.Common
38{
39 /// <summary>
40 /// This class adds full UDP client classes and associated scene presence to scene.
41 /// </summary>
42 /// <remarks>
43 /// This is used for testing client stack code. For testing other code, use SceneHelper methods instead since
44 /// they operate without the burden of setting up UDP structures which should be unnecessary for testing scene
45 /// code.
46 /// </remarks>
47 public static class ClientStackHelpers
48 {
49 public static ScenePresence AddChildClient(
50 Scene scene, LLUDPServer udpServer, UUID agentId, UUID sessionId, uint circuitCode)
51 {
52 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
53
54 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
55
56 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
57 = new UseCircuitCodePacket.CircuitCodeBlock();
58 uccpCcBlock.Code = circuitCode;
59 uccpCcBlock.ID = agentId;
60 uccpCcBlock.SessionID = sessionId;
61 uccp.CircuitCode = uccpCcBlock;
62
63 byte[] uccpBytes = uccp.ToBytes();
64 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
65 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
66 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
67
68 AgentCircuitData acd = new AgentCircuitData();
69 acd.AgentID = agentId;
70 acd.SessionID = sessionId;
71
72 scene.AuthenticateHandler.AddNewCircuit(circuitCode, acd);
73
74 udpServer.PacketReceived(upb);
75
76 return scene.GetScenePresence(agentId);
77 }
78
79 public static TestLLUDPServer AddUdpServer(Scene scene)
80 {
81 return AddUdpServer(scene, new IniConfigSource());
82 }
83
84 public static TestLLUDPServer AddUdpServer(Scene scene, IniConfigSource configSource)
85 {
86 uint port = 0;
87 AgentCircuitManager acm = scene.AuthenticateHandler;
88
89 TestLLUDPServer udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
90 udpServer.AddScene(scene);
91
92 return udpServer;
93 }
94 }
95} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
new file mode 100644
index 0000000..cf7583e
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
@@ -0,0 +1,123 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using System.Threading;
35using log4net;
36using Nini.Config;
37using NUnit.Framework;
38using OpenMetaverse;
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Framework.Servers;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Region.CoreModules.Framework;
45using OpenSim.Tests.Common;
46
47namespace OpenSim.Tests.Common
48{
49 public static class EntityTransferHelpers
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 /// <summary>
54 /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the
55 /// viewer to setup a connection with the destination region.
56 /// </summary>
57 /// <param name='tc'></param>
58 /// <param name='neighbourTcs'>
59 /// A list that will be populated with any TestClients set up in response to
60 /// being informed about a destination region.
61 /// </param>
62 public static void SetupInformClientOfNeighbourTriggersNeighbourClientCreate(
63 TestClient tc, List<TestClient> neighbourTcs)
64 {
65 // XXX: Confusingly, this is also used for non-neighbour notification (as in teleports that do not use the
66 // event queue).
67
68 tc.OnTestClientInformClientOfNeighbour += (neighbourHandle, neighbourExternalEndPoint) =>
69 {
70 uint x, y;
71 Util.RegionHandleToRegionLoc(neighbourHandle, out x, out y);
72
73 m_log.DebugFormat(
74 "[TEST CLIENT]: Processing inform client of neighbour located at {0},{1} at {2}",
75 x, y, neighbourExternalEndPoint);
76
77 AgentCircuitData newAgent = tc.RequestClientInfo();
78
79 Scene neighbourScene;
80 SceneManager.Instance.TryGetScene(x, y, out neighbourScene);
81
82 TestClient neighbourTc = new TestClient(newAgent, neighbourScene);
83 neighbourTcs.Add(neighbourTc);
84 neighbourScene.AddNewAgent(neighbourTc, PresenceType.User);
85 };
86 }
87
88 /// <summary>
89 /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the
90 /// viewer to setup a connection with the destination region.
91 /// </summary>
92 /// <param name='tc'></param>
93 /// <param name='neighbourTcs'>
94 /// A list that will be populated with any TestClients set up in response to
95 /// being informed about a destination region.
96 /// </param>
97 public static void SetupSendRegionTeleportTriggersDestinationClientCreateAndCompleteMovement(
98 TestClient client, List<TestClient> destinationClients)
99 {
100 client.OnTestClientSendRegionTeleport
101 += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) =>
102 {
103 uint x, y;
104 Util.RegionHandleToRegionLoc(regionHandle, out x, out y);
105
106 m_log.DebugFormat(
107 "[TEST CLIENT]: Processing send region teleport for destination at {0},{1} at {2}",
108 x, y, regionExternalEndPoint);
109
110 AgentCircuitData newAgent = client.RequestClientInfo();
111
112 Scene destinationScene;
113 SceneManager.Instance.TryGetScene(x, y, out destinationScene);
114
115 TestClient destinationClient = new TestClient(newAgent, destinationScene);
116 destinationClients.Add(destinationClient);
117 destinationScene.AddNewAgent(destinationClient, PresenceType.User);
118
119 ThreadPool.UnsafeQueueUserWorkItem(o => destinationClient.CompleteMovement(), null);
120 };
121 }
122 }
123} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
new file mode 100644
index 0000000..1fb1c5c
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -0,0 +1,724 @@
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
28using System;
29using System.Net;
30using System.Collections.Generic;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Data.Null;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Region.Physics.Manager;
40using OpenSim.Region.Framework;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.CoreModules.Avatar.Gods;
44using OpenSim.Region.CoreModules.Asset;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
46using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
47using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
48using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
49using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
50using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
51using OpenSim.Services.Interfaces;
52using GridRegion = OpenSim.Services.Interfaces.GridRegion;
53
54namespace OpenSim.Tests.Common
55{
56 /// <summary>
57 /// Helpers for setting up scenes.
58 /// </summary>
59 public class SceneHelpers
60 {
61 /// <summary>
62 /// We need a scene manager so that test clients can retrieve a scene when performing teleport tests.
63 /// </summary>
64 public SceneManager SceneManager { get; private set; }
65
66 public ISimulationDataService SimDataService { get; private set; }
67
68 private AgentCircuitManager m_acm = new AgentCircuitManager();
69 private IEstateDataService m_estateDataService = null;
70
71 private LocalAssetServicesConnector m_assetService;
72 private LocalAuthenticationServicesConnector m_authenticationService;
73 private LocalInventoryServicesConnector m_inventoryService;
74 private LocalGridServicesConnector m_gridService;
75 private LocalUserAccountServicesConnector m_userAccountService;
76 private LocalPresenceServicesConnector m_presenceService;
77
78 private CoreAssetCache m_cache;
79
80 public SceneHelpers() : this(null) {}
81
82 public SceneHelpers(CoreAssetCache cache)
83 {
84 SceneManager = new SceneManager();
85
86 m_assetService = StartAssetService(cache);
87 m_authenticationService = StartAuthenticationService();
88 m_inventoryService = StartInventoryService();
89 m_gridService = StartGridService();
90 m_userAccountService = StartUserAccountService();
91 m_presenceService = StartPresenceService();
92
93 m_inventoryService.PostInitialise();
94 m_assetService.PostInitialise();
95 m_userAccountService.PostInitialise();
96 m_presenceService.PostInitialise();
97
98 m_cache = cache;
99
100 SimDataService
101 = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
102 }
103
104 /// <summary>
105 /// Set up a test scene
106 /// </summary>
107 /// <remarks>
108 /// Automatically starts services, as would the normal runtime.
109 /// </remarks>
110 /// <returns></returns>
111 public TestScene SetupScene()
112 {
113 return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
114 }
115
116 public TestScene SetupScene(string name, UUID id, uint x, uint y)
117 {
118 return SetupScene(name, id, x, y, new IniConfigSource());
119 }
120
121 public TestScene SetupScene(string name, UUID id, uint x, uint y, IConfigSource configSource)
122 {
123 return SetupScene(name, id, x, y, Constants.RegionSize, Constants.RegionSize, configSource);
124 }
125
126 /// <summary>
127 /// Set up a scene.
128 /// </summary>
129 /// <param name="name">Name of the region</param>
130 /// <param name="id">ID of the region</param>
131 /// <param name="x">X co-ordinate of the region</param>
132 /// <param name="y">Y co-ordinate of the region</param>
133 /// <param name="sizeX">X size of scene</param>
134 /// <param name="sizeY">Y size of scene</param>
135 /// <param name="configSource"></param>
136 /// <returns></returns>
137 public TestScene SetupScene(
138 string name, UUID id, uint x, uint y, uint sizeX, uint sizeY, IConfigSource configSource)
139 {
140 Console.WriteLine("Setting up test scene {0}", name);
141
142 // We must set up a console otherwise setup of some modules may fail
143 MainConsole.Instance = new MockConsole();
144
145 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
146 regInfo.RegionName = name;
147 regInfo.RegionID = id;
148 regInfo.RegionSizeX = sizeX;
149 regInfo.RegionSizeY = sizeY;
150
151 SceneCommunicationService scs = new SceneCommunicationService();
152
153 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
154 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
155 Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
156 PhysicsScene physicsScene
157 = physicsPluginManager.GetPhysicsScene(
158 "basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
159
160 TestScene testScene = new TestScene(
161 regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null);
162
163 INonSharedRegionModule godsModule = new GodsModule();
164 godsModule.Initialise(new IniConfigSource());
165 godsModule.AddRegion(testScene);
166
167 // Add scene to services
168 m_assetService.AddRegion(testScene);
169
170 if (m_cache != null)
171 {
172 m_cache.AddRegion(testScene);
173 m_cache.RegionLoaded(testScene);
174 testScene.AddRegionModule(m_cache.Name, m_cache);
175 }
176
177 m_assetService.RegionLoaded(testScene);
178 testScene.AddRegionModule(m_assetService.Name, m_assetService);
179
180 m_authenticationService.AddRegion(testScene);
181 m_authenticationService.RegionLoaded(testScene);
182 testScene.AddRegionModule(m_authenticationService.Name, m_authenticationService);
183
184 m_inventoryService.AddRegion(testScene);
185 m_inventoryService.RegionLoaded(testScene);
186 testScene.AddRegionModule(m_inventoryService.Name, m_inventoryService);
187
188 m_gridService.AddRegion(testScene);
189 m_gridService.RegionLoaded(testScene);
190 testScene.AddRegionModule(m_gridService.Name, m_gridService);
191
192 m_userAccountService.AddRegion(testScene);
193 m_userAccountService.RegionLoaded(testScene);
194 testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
195
196 m_presenceService.AddRegion(testScene);
197 m_presenceService.RegionLoaded(testScene);
198 testScene.AddRegionModule(m_presenceService.Name, m_presenceService);
199
200 testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
201 testScene.SetModuleInterfaces();
202
203 testScene.LandChannel = new TestLandChannel(testScene);
204 testScene.LoadWorldMap();
205
206 testScene.RegionInfo.EstateSettings = new EstateSettings();
207 testScene.LoginsEnabled = true;
208 testScene.RegisterRegionWithGrid();
209
210 SceneManager.Add(testScene);
211
212 return testScene;
213 }
214
215 private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
216 {
217 IConfigSource config = new IniConfigSource();
218 config.AddConfig("Modules");
219 config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
220 config.AddConfig("AssetService");
221 config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
222 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
223
224 LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
225 assetService.Initialise(config);
226
227 if (cache != null)
228 {
229 IConfigSource cacheConfig = new IniConfigSource();
230 cacheConfig.AddConfig("Modules");
231 cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
232 cacheConfig.AddConfig("AssetCache");
233
234 cache.Initialise(cacheConfig);
235 }
236
237 return assetService;
238 }
239
240 private static LocalAuthenticationServicesConnector StartAuthenticationService()
241 {
242 IConfigSource config = new IniConfigSource();
243 config.AddConfig("Modules");
244 config.AddConfig("AuthenticationService");
245 config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
246 config.Configs["AuthenticationService"].Set(
247 "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
248 config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
249
250 LocalAuthenticationServicesConnector service = new LocalAuthenticationServicesConnector();
251 service.Initialise(config);
252
253 return service;
254 }
255
256 private static LocalInventoryServicesConnector StartInventoryService()
257 {
258 IConfigSource config = new IniConfigSource();
259 config.AddConfig("Modules");
260 config.AddConfig("InventoryService");
261 config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
262 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
263 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
264
265 LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
266 inventoryService.Initialise(config);
267
268 return inventoryService;
269 }
270
271 private static LocalGridServicesConnector StartGridService()
272 {
273 IConfigSource config = new IniConfigSource();
274 config.AddConfig("Modules");
275 config.AddConfig("GridService");
276 config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
277 config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
278 config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
279 config.Configs["GridService"].Set("ConnectionString", "!static");
280
281 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
282 gridService.Initialise(config);
283
284 return gridService;
285 }
286
287 /// <summary>
288 /// Start a user account service
289 /// </summary>
290 /// <param name="testScene"></param>
291 /// <returns></returns>
292 private static LocalUserAccountServicesConnector StartUserAccountService()
293 {
294 IConfigSource config = new IniConfigSource();
295 config.AddConfig("Modules");
296 config.AddConfig("UserAccountService");
297 config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
298 config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
299 config.Configs["UserAccountService"].Set(
300 "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
301
302 LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
303 userAccountService.Initialise(config);
304
305 return userAccountService;
306 }
307
308 /// <summary>
309 /// Start a presence service
310 /// </summary>
311 /// <param name="testScene"></param>
312 private static LocalPresenceServicesConnector StartPresenceService()
313 {
314 // Unfortunately, some services share data via statics, so we need to null every time to stop interference
315 // between tests.
316 // This is a massive non-obvious pita.
317 NullPresenceData.Instance = null;
318
319 IConfigSource config = new IniConfigSource();
320 config.AddConfig("Modules");
321 config.AddConfig("PresenceService");
322 config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
323 config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
324 config.Configs["PresenceService"].Set(
325 "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
326
327 LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
328 presenceService.Initialise(config);
329
330 return presenceService;
331 }
332
333 /// <summary>
334 /// Setup modules for a scene using their default settings.
335 /// </summary>
336 /// <param name="scene"></param>
337 /// <param name="modules"></param>
338 public static void SetupSceneModules(Scene scene, params object[] modules)
339 {
340 SetupSceneModules(scene, new IniConfigSource(), modules);
341 }
342
343 /// <summary>
344 /// Setup modules for a scene.
345 /// </summary>
346 /// <remarks>
347 /// If called directly, then all the modules must be shared modules.
348 /// </remarks>
349 /// <param name="scenes"></param>
350 /// <param name="config"></param>
351 /// <param name="modules"></param>
352 public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
353 {
354 SetupSceneModules(new Scene[] { scene }, config, modules);
355 }
356
357 /// <summary>
358 /// Setup modules for a scene using their default settings.
359 /// </summary>
360 /// <param name="scenes"></param>
361 /// <param name="modules"></param>
362 public static void SetupSceneModules(Scene[] scenes, params object[] modules)
363 {
364 SetupSceneModules(scenes, new IniConfigSource(), modules);
365 }
366
367 /// <summary>
368 /// Setup modules for scenes.
369 /// </summary>
370 /// <remarks>
371 /// If called directly, then all the modules must be shared modules.
372 ///
373 /// We are emulating here the normal calls made to setup region modules
374 /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
375 /// TODO: Need to reuse normal runtime module code.
376 /// </remarks>
377 /// <param name="scenes"></param>
378 /// <param name="config"></param>
379 /// <param name="modules"></param>
380 public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
381 {
382 List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
383 foreach (object module in modules)
384 {
385 IRegionModuleBase m = (IRegionModuleBase)module;
386// Console.WriteLine("MODULE {0}", m.Name);
387 m.Initialise(config);
388 newModules.Add(m);
389 }
390
391 foreach (IRegionModuleBase module in newModules)
392 {
393 if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
394 }
395
396 foreach (IRegionModuleBase module in newModules)
397 {
398 foreach (Scene scene in scenes)
399 {
400 module.AddRegion(scene);
401 scene.AddRegionModule(module.Name, module);
402 }
403 }
404
405 // RegionLoaded is fired after all modules have been appropriately added to all scenes
406 foreach (IRegionModuleBase module in newModules)
407 foreach (Scene scene in scenes)
408 module.RegionLoaded(scene);
409
410 foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
411 }
412
413 /// <summary>
414 /// Generate some standard agent connection data.
415 /// </summary>
416 /// <param name="agentId"></param>
417 /// <returns></returns>
418 public static AgentCircuitData GenerateAgentData(UUID agentId)
419 {
420 AgentCircuitData acd = GenerateCommonAgentData();
421
422 acd.AgentID = agentId;
423 acd.firstname = "testfirstname";
424 acd.lastname = "testlastname";
425 acd.ServiceURLs = new Dictionary<string, object>();
426
427 return acd;
428 }
429
430 /// <summary>
431 /// Generate some standard agent connection data.
432 /// </summary>
433 /// <param name="agentId"></param>
434 /// <returns></returns>
435 public static AgentCircuitData GenerateAgentData(UserAccount ua)
436 {
437 AgentCircuitData acd = GenerateCommonAgentData();
438
439 acd.AgentID = ua.PrincipalID;
440 acd.firstname = ua.FirstName;
441 acd.lastname = ua.LastName;
442 acd.ServiceURLs = ua.ServiceURLs;
443
444 return acd;
445 }
446
447 private static AgentCircuitData GenerateCommonAgentData()
448 {
449 AgentCircuitData acd = new AgentCircuitData();
450
451 // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
452 acd.SessionID = UUID.Random();
453 acd.SecureSessionID = UUID.Random();
454
455 acd.circuitcode = 123;
456 acd.BaseFolder = UUID.Zero;
457 acd.InventoryFolder = UUID.Zero;
458 acd.startpos = Vector3.Zero;
459 acd.CapsPath = "http://wibble.com";
460 acd.Appearance = new AvatarAppearance();
461
462 return acd;
463 }
464
465 /// <summary>
466 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
467 /// </summary>
468 /// <remarks>
469 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
470 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
471 /// </remarks>
472 /// <param name="scene"></param>
473 /// <param name="agentId"></param>
474 /// <returns></returns>
475 public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
476 {
477 return AddScenePresence(scene, GenerateAgentData(agentId));
478 }
479
480 /// <summary>
481 /// Add a root agent.
482 /// </summary>
483 /// <param name="scene"></param>
484 /// <param name="ua"></param>
485 /// <returns></returns>
486 public static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
487 {
488 return AddScenePresence(scene, GenerateAgentData(ua));
489 }
490
491 /// <summary>
492 /// Add a root agent.
493 /// </summary>
494 /// <remarks>
495 /// This function
496 ///
497 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
498 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
499 /// agent was coming.
500 ///
501 /// 2) Connects the agent with the scene
502 ///
503 /// This function performs actions equivalent with notifying the scene that an agent is
504 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
505 /// </remarks>
506 /// <param name="scene"></param>
507 /// <param name="agentData"></param>
508 /// <returns></returns>
509 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
510 {
511 return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
512 }
513
514 /// <summary>
515 /// Add a root agent.
516 /// </summary>
517 /// <remarks>
518 /// This function
519 ///
520 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
521 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
522 /// agent was coming.
523 ///
524 /// 2) Connects the agent with the scene
525 ///
526 /// This function performs actions equivalent with notifying the scene that an agent is
527 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
528 /// </remarks>
529 /// <param name="scene"></param>
530 /// <param name="agentData"></param>
531 /// <returns></returns>
532 public static ScenePresence AddScenePresence(
533 Scene scene, IClientAPI client, AgentCircuitData agentData)
534 {
535 // We emulate the proper login sequence here by doing things in four stages
536
537 // Stage 0: login
538 // We need to punch through to the underlying service because scene will not, correctly, let us call it
539 // through it's reference to the LPSC
540 LocalPresenceServicesConnector lpsc = (LocalPresenceServicesConnector)scene.PresenceService;
541 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
542
543 // Stages 1 & 2
544 ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
545
546 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
547 sp.CompleteMovement(sp.ControllingClient, true);
548
549 return sp;
550 }
551
552 /// <summary>
553 /// Introduce an agent into the scene by adding a new client.
554 /// </summary>
555 /// <returns>The scene presence added</returns>
556 /// <param name='scene'></param>
557 /// <param name='testClient'></param>
558 /// <param name='agentData'></param>
559 /// <param name='tf'></param>
560 private static ScenePresence IntroduceClientToScene(
561 Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
562 {
563 string reason;
564
565 // Stage 1: tell the scene to expect a new user connection
566 if (!scene.NewUserConnection(agentData, (uint)tf, null, out reason))
567 Console.WriteLine("NewUserConnection failed: " + reason);
568
569 // Stage 2: add the new client as a child agent to the scene
570 scene.AddNewAgent(client, PresenceType.User);
571
572 return scene.GetScenePresence(client.AgentId);
573 }
574
575 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
576 {
577 return AddChildScenePresence(scene, GenerateAgentData(agentId));
578 }
579
580 public static ScenePresence AddChildScenePresence(Scene scene, AgentCircuitData acd)
581 {
582 acd.child = true;
583
584 // XXX: ViaLogin may not be correct for child agents
585 TestClient client = new TestClient(acd, scene);
586 return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
587 }
588
589 /// <summary>
590 /// Add a test object
591 /// </summary>
592 /// <param name="scene"></param>
593 /// <returns></returns>
594 public static SceneObjectGroup AddSceneObject(Scene scene)
595 {
596 return AddSceneObject(scene, "Test Object", UUID.Zero);
597 }
598
599 /// <summary>
600 /// Add a test object
601 /// </summary>
602 /// <param name="scene"></param>
603 /// <param name="name"></param>
604 /// <param name="ownerId"></param>
605 /// <returns></returns>
606 public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
607 {
608 SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
609
610 //part.UpdatePrimFlags(false, false, true);
611 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
612
613 scene.AddNewSceneObject(so, true);
614
615 return so;
616 }
617
618 /// <summary>
619 /// Add a test object
620 /// </summary>
621 /// <param name="scene"></param>
622 /// <param name="parts">
623 /// The number of parts that should be in the scene object
624 /// </param>
625 /// <param name="ownerId"></param>
626 /// <param name="partNamePrefix">
627 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
628 /// (e.g. mynamePart1 for the root part)
629 /// </param>
630 /// <param name="uuidTail">
631 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
632 /// will be given to the root part, and incremented for each part thereafter.
633 /// </param>
634 /// <returns></returns>
635 public static SceneObjectGroup AddSceneObject(Scene scene, int parts, UUID ownerId, string partNamePrefix, int uuidTail)
636 {
637 SceneObjectGroup so = CreateSceneObject(parts, ownerId, partNamePrefix, uuidTail);
638
639 scene.AddNewSceneObject(so, false);
640
641 return so;
642 }
643
644 /// <summary>
645 /// Create a scene object part.
646 /// </summary>
647 /// <param name="name"></param>
648 /// <param name="id"></param>
649 /// <param name="ownerId"></param>
650 /// <returns></returns>
651 public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
652 {
653 return new SceneObjectPart(
654 ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
655 { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
656 }
657
658 /// <summary>
659 /// Create a scene object but do not add it to the scene.
660 /// </summary>
661 /// <remarks>
662 /// UUID always starts at 00000000-0000-0000-0000-000000000001. For some purposes, (e.g. serializing direct
663 /// to another object's inventory) we do not need a scene unique ID. So it would be better to add the
664 /// UUID when we actually add an object to a scene rather than on creation.
665 /// </remarks>
666 /// <param name="parts">The number of parts that should be in the scene object</param>
667 /// <param name="ownerId"></param>
668 /// <returns></returns>
669 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
670 {
671 return CreateSceneObject(parts, ownerId, 0x1);
672 }
673
674 /// <summary>
675 /// Create a scene object but do not add it to the scene.
676 /// </summary>
677 /// <param name="parts">The number of parts that should be in the scene object</param>
678 /// <param name="ownerId"></param>
679 /// <param name="uuidTail">
680 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
681 /// will be given to the root part, and incremented for each part thereafter.
682 /// </param>
683 /// <returns></returns>
684 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
685 {
686 return CreateSceneObject(parts, ownerId, "", uuidTail);
687 }
688
689 /// <summary>
690 /// Create a scene object but do not add it to the scene.
691 /// </summary>
692 /// <param name="parts">
693 /// The number of parts that should be in the scene object
694 /// </param>
695 /// <param name="ownerId"></param>
696 /// <param name="partNamePrefix">
697 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
698 /// (e.g. mynamePart1 for the root part)
699 /// </param>
700 /// <param name="uuidTail">
701 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
702 /// will be given to the root part, and incremented for each part thereafter.
703 /// </param>
704 /// <returns></returns>
705 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
706 {
707 string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
708
709 SceneObjectGroup sog
710 = new SceneObjectGroup(
711 CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
712
713 if (parts > 1)
714 for (int i = 2; i <= parts; i++)
715 sog.AddPart(
716 CreateSceneObjectPart(
717 string.Format("{0}Part{1}", partNamePrefix, i),
718 new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
719 ownerId));
720
721 return sog;
722 }
723 }
724}
diff --git a/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
new file mode 100644
index 0000000..3a3b33a
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
@@ -0,0 +1,210 @@
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
28using System;
29using OpenMetaverse;
30using OpenMetaverse.Assets;
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Tests.Common
36{
37 /// <summary>
38 /// Utility functions for carrying out task inventory tests.
39 /// </summary>
40 ///
41 public static class TaskInventoryHelpers
42 {
43 /// <summary>
44 /// Add a notecard item to the given part.
45 /// </summary>
46 /// <param name="assetService"></param>
47 /// <param name="part"></param>
48 /// <param name="itemName"></param>
49 /// <param name="itemIDFrag">UUID or UUID stem</param>
50 /// <param name="assetIDFrag">UUID or UUID stem</param>
51 /// <param name="text">The tex to put in the notecard.</param>
52 /// <returns>The item that was added</returns>
53 public static TaskInventoryItem AddNotecard(
54 IAssetService assetService, SceneObjectPart part, string itemName, string itemIDStem, string assetIDStem, string text)
55 {
56 return AddNotecard(
57 assetService, part, itemName, TestHelpers.ParseStem(itemIDStem), TestHelpers.ParseStem(assetIDStem), text);
58 }
59
60 /// <summary>
61 /// Add a notecard item to the given part.
62 /// </summary>
63 /// <param name="assetService"></param>
64 /// <param name="part"></param>
65 /// <param name="itemName"></param>
66 /// <param name="itemID"></param>
67 /// <param name="assetID"></param>
68 /// <param name="text">The tex to put in the notecard.</param>
69 /// <returns>The item that was added</returns>
70 public static TaskInventoryItem AddNotecard(
71 IAssetService assetService, SceneObjectPart part, string itemName, UUID itemID, UUID assetID, string text)
72 {
73 AssetNotecard nc = new AssetNotecard();
74 nc.BodyText = text;
75 nc.Encode();
76
77 AssetBase ncAsset
78 = AssetHelpers.CreateAsset(assetID, AssetType.Notecard, nc.AssetData, UUID.Zero);
79 assetService.Store(ncAsset);
80
81 TaskInventoryItem ncItem
82 = new TaskInventoryItem
83 { Name = itemName, AssetID = assetID, ItemID = itemID,
84 Type = (int)AssetType.Notecard, InvType = (int)InventoryType.Notecard };
85 part.Inventory.AddInventoryItem(ncItem, true);
86
87 return ncItem;
88 }
89
90 /// <summary>
91 /// Add a simple script to the given part.
92 /// </summary>
93 /// <remarks>
94 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
95 /// functions more than once in a test.
96 /// </remarks>
97 /// <param name="assetService"></param>
98 /// <param name="part"></param>
99 /// <returns>The item that was added</returns>
100 public static TaskInventoryItem AddScript(IAssetService assetService, SceneObjectPart part)
101 {
102 return AddScript(assetService, part, "scriptItem", "default { state_entry() { llSay(0, \"Hello World\"); } }");
103 }
104
105 /// <summary>
106 /// Add a simple script to the given part.
107 /// </summary>
108 /// <remarks>
109 /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather
110 /// than a random component.
111 /// </remarks>
112 /// <param name="assetService"></param>
113 /// <param name="part"></param>
114 /// <param name="scriptName">Name of the script to add</param>
115 /// <param name="scriptSource">LSL script source</param>
116 /// <returns>The item that was added</returns>
117 public static TaskInventoryItem AddScript(
118 IAssetService assetService, SceneObjectPart part, string scriptName, string scriptSource)
119 {
120 return AddScript(assetService, part, UUID.Random(), UUID.Random(), scriptName, scriptSource);
121 }
122
123 /// <summary>
124 /// Add a simple script to the given part.
125 /// </summary>
126 /// <remarks>
127 /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather
128 /// than a random component.
129 /// </remarks>
130 /// <param name="assetService"></param>
131 /// <param name="part"></param>
132 /// <param name="itemId">Item UUID for the script</param>
133 /// <param name="assetId">Asset UUID for the script</param>
134 /// <param name="scriptName">Name of the script to add</param>
135 /// <param name="scriptSource">LSL script source</param>
136 /// <returns>The item that was added</returns>
137 public static TaskInventoryItem AddScript(
138 IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource)
139 {
140 AssetScriptText ast = new AssetScriptText();
141 ast.Source = scriptSource;
142 ast.Encode();
143
144 AssetBase asset
145 = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero);
146 assetService.Store(asset);
147 TaskInventoryItem item
148 = new TaskInventoryItem
149 { Name = scriptName, AssetID = assetId, ItemID = itemId,
150 Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
151 part.Inventory.AddInventoryItem(item, true);
152
153 return item;
154 }
155
156 /// <summary>
157 /// Add a scene object item to the given part.
158 /// </summary>
159 /// <remarks>
160 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
161 /// functions more than once in a test.
162 /// </remarks>
163 ///
164 /// <param name="assetService"></param>
165 /// <param name="sop"></param>
166 /// <param name="itemName"></param>
167 /// <param name="itemId"></param>
168 /// <param name="soToAdd"></param>
169 /// <param name="soAssetId"></param>
170 public static TaskInventoryItem AddSceneObject(
171 IAssetService assetService, SceneObjectPart sop, string itemName, UUID itemId, SceneObjectGroup soToAdd, UUID soAssetId)
172 {
173 AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(soAssetId, soToAdd);
174 assetService.Store(taskSceneObjectAsset);
175 TaskInventoryItem taskSceneObjectItem
176 = new TaskInventoryItem
177 { Name = itemName,
178 AssetID = taskSceneObjectAsset.FullID,
179 ItemID = itemId,
180 OwnerID = soToAdd.OwnerID,
181 Type = (int)AssetType.Object,
182 InvType = (int)InventoryType.Object };
183 sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
184
185 return taskSceneObjectItem;
186 }
187
188 /// <summary>
189 /// Add a scene object item to the given part.
190 /// </summary>
191 /// <remarks>
192 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
193 /// functions more than once in a test.
194 /// </remarks>
195 ///
196 /// <param name="assetService"></param>
197 /// <param name="sop"></param>
198 /// <param name="itemName"></param>
199 /// <param name="id"></param>
200 /// <param name="userId"></param>
201 public static TaskInventoryItem AddSceneObject(
202 IAssetService assetService, SceneObjectPart sop, string itemName, UUID itemId, UUID userId)
203 {
204 SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, userId);
205
206 return TaskInventoryHelpers.AddSceneObject(
207 assetService, sop, itemName, itemId, taskSceneObject, TestHelpers.ParseTail(0x10));
208 }
209 }
210} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
new file mode 100644
index 0000000..2fbebc4
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/UserAccountHelpers.cs
@@ -0,0 +1,160 @@
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
28using System.Collections.Generic;
29using OpenMetaverse;
30using OpenSim.Framework.Communications;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Tests.Common
35{
36 /// <summary>
37 /// Utility functions for carrying out user profile related tests.
38 /// </summary>
39 public static class UserAccountHelpers
40 {
41// /// <summary>
42// /// Create a test user with a standard inventory
43// /// </summary>
44// /// <param name="commsManager"></param>
45// /// <param name="callback">
46// /// Callback to invoke when inventory has been loaded. This is required because
47// /// loading may be asynchronous, even on standalone
48// /// </param>
49// /// <returns></returns>
50// public static CachedUserInfo CreateUserWithInventory(
51// CommunicationsManager commsManager, OnInventoryReceivedDelegate callback)
52// {
53// UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000099");
54// return CreateUserWithInventory(commsManager, userId, callback);
55// }
56//
57// /// <summary>
58// /// Create a test user with a standard inventory
59// /// </summary>
60// /// <param name="commsManager"></param>
61// /// <param name="userId">User ID</param>
62// /// <param name="callback">
63// /// Callback to invoke when inventory has been loaded. This is required because
64// /// loading may be asynchronous, even on standalone
65// /// </param>
66// /// <returns></returns>
67// public static CachedUserInfo CreateUserWithInventory(
68// CommunicationsManager commsManager, UUID userId, OnInventoryReceivedDelegate callback)
69// {
70// return CreateUserWithInventory(commsManager, "Bill", "Bailey", userId, callback);
71// }
72//
73// /// <summary>
74// /// Create a test user with a standard inventory
75// /// </summary>
76// /// <param name="commsManager"></param>
77// /// <param name="firstName">First name of user</param>
78// /// <param name="lastName">Last name of user</param>
79// /// <param name="userId">User ID</param>
80// /// <param name="callback">
81// /// Callback to invoke when inventory has been loaded. This is required because
82// /// loading may be asynchronous, even on standalone
83// /// </param>
84// /// <returns></returns>
85// public static CachedUserInfo CreateUserWithInventory(
86// CommunicationsManager commsManager, string firstName, string lastName,
87// UUID userId, OnInventoryReceivedDelegate callback)
88// {
89// return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
90// }
91//
92// /// <summary>
93// /// Create a test user with a standard inventory
94// /// </summary>
95// /// <param name="commsManager"></param>
96// /// <param name="firstName">First name of user</param>
97// /// <param name="lastName">Last name of user</param>
98// /// <param name="password">Password</param>
99// /// <param name="userId">User ID</param>
100// /// <param name="callback">
101// /// Callback to invoke when inventory has been loaded. This is required because
102// /// loading may be asynchronous, even on standalone
103// /// </param>
104// /// <returns></returns>
105// public static CachedUserInfo CreateUserWithInventory(
106// CommunicationsManager commsManager, string firstName, string lastName, string password,
107// UUID userId, OnInventoryReceivedDelegate callback)
108// {
109// LocalUserServices lus = (LocalUserServices)commsManager.UserService;
110// lus.AddUser(firstName, lastName, password, "bill@bailey.com", 1000, 1000, userId);
111//
112// CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
113// userInfo.OnInventoryReceived += callback;
114// userInfo.FetchInventory();
115//
116// return userInfo;
117// }
118
119 public static UserAccount CreateUserWithInventory(Scene scene)
120 {
121 return CreateUserWithInventory(scene, TestHelpers.ParseTail(99));
122 }
123
124 public static UserAccount CreateUserWithInventory(Scene scene, UUID userId)
125 {
126 return CreateUserWithInventory(scene, "Bill", "Bailey", userId, "troll");
127 }
128
129 public static UserAccount CreateUserWithInventory(Scene scene, int userId)
130 {
131 return CreateUserWithInventory(scene, "Bill", "Bailey", TestHelpers.ParseTail(userId), "troll");
132 }
133
134 public static UserAccount CreateUserWithInventory(
135 Scene scene, string firstName, string lastName, UUID userId, string pw)
136 {
137 UserAccount ua = new UserAccount(userId) { FirstName = firstName, LastName = lastName };
138 CreateUserWithInventory(scene, ua, pw);
139 return ua;
140 }
141
142 public static UserAccount CreateUserWithInventory(
143 Scene scene, string firstName, string lastName, int userId, string pw)
144 {
145 UserAccount ua
146 = new UserAccount(TestHelpers.ParseTail(userId)) { FirstName = firstName, LastName = lastName };
147 CreateUserWithInventory(scene, ua, pw);
148 return ua;
149 }
150
151 public static void CreateUserWithInventory(Scene scene, UserAccount ua, string pw)
152 {
153 // FIXME: This should really be set up by UserAccount itself
154 ua.ServiceURLs = new Dictionary<string, object>();
155 scene.UserAccountService.StoreUserAccount(ua);
156 scene.InventoryService.CreateUserInventory(ua.PrincipalID);
157 scene.AuthenticationService.SetPassword(ua.PrincipalID, pw);
158 }
159 }
160} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
new file mode 100644
index 0000000..5a36332
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
@@ -0,0 +1,370 @@
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
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
33using OpenSim.Region.Framework.Scenes;
34using OpenSim.Services.Interfaces;
35
36namespace OpenSim.Tests.Common
37{
38 /// <summary>
39 /// Utility functions for carrying out user inventory tests.
40 /// </summary>
41 public static class UserInventoryHelpers
42 {
43 public static readonly string PATH_DELIMITER = "/";
44
45 /// <summary>
46 /// Add an existing scene object as an item in the user's inventory.
47 /// </summary>
48 /// <remarks>
49 /// Will be added to the system Objects folder.
50 /// </remarks>
51 /// <param name='scene'></param>
52 /// <param name='so'></param>
53 /// <param name='inventoryIdTail'></param>
54 /// <param name='assetIdTail'></param>
55 /// <returns>The inventory item created.</returns>
56 public static InventoryItemBase AddInventoryItem(
57 Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail)
58 {
59 return AddInventoryItem(
60 scene,
61 so.Name,
62 TestHelpers.ParseTail(inventoryIdTail),
63 InventoryType.Object,
64 AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
65 so.OwnerID);
66 }
67
68 /// <summary>
69 /// Add an existing scene object as an item in the user's inventory at the given path.
70 /// </summary>
71 /// <param name='scene'></param>
72 /// <param name='so'></param>
73 /// <param name='inventoryIdTail'></param>
74 /// <param name='assetIdTail'></param>
75 /// <returns>The inventory item created.</returns>
76 public static InventoryItemBase AddInventoryItem(
77 Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail, string path)
78 {
79 return AddInventoryItem(
80 scene,
81 so.Name,
82 TestHelpers.ParseTail(inventoryIdTail),
83 InventoryType.Object,
84 AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
85 so.OwnerID,
86 path);
87 }
88
89 /// <summary>
90 /// Adds the given item to the existing system folder for its type (e.g. an object will go in the "Objects"
91 /// folder).
92 /// </summary>
93 /// <param name="scene"></param>
94 /// <param name="itemName"></param>
95 /// <param name="itemId"></param>
96 /// <param name="itemType"></param>
97 /// <param name="asset">The serialized asset for this item</param>
98 /// <param name="userId"></param>
99 /// <returns></returns>
100 private static InventoryItemBase AddInventoryItem(
101 Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId)
102 {
103 return AddInventoryItem(
104 scene, itemName, itemId, itemType, asset, userId,
105 scene.InventoryService.GetFolderForType(userId, (FolderType)asset.Type).Name);
106 }
107
108 /// <summary>
109 /// Adds the given item to an inventory folder
110 /// </summary>
111 /// <param name="scene"></param>
112 /// <param name="itemName"></param>
113 /// <param name="itemId"></param>
114 /// <param name="itemType"></param>
115 /// <param name="asset">The serialized asset for this item</param>
116 /// <param name="userId"></param>
117 /// <param name="path">Existing inventory path at which to add.</param>
118 /// <returns></returns>
119 private static InventoryItemBase AddInventoryItem(
120 Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId, string path)
121 {
122 scene.AssetService.Store(asset);
123
124 InventoryItemBase item = new InventoryItemBase();
125 item.Name = itemName;
126 item.AssetID = asset.FullID;
127 item.ID = itemId;
128 item.Owner = userId;
129 item.AssetType = asset.Type;
130 item.InvType = (int)itemType;
131
132 InventoryFolderBase folder = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, path)[0];
133
134 item.Folder = folder.ID;
135 scene.AddInventoryItem(item);
136
137 return item;
138 }
139
140 /// <summary>
141 /// Creates a notecard in the objects folder and specify an item id.
142 /// </summary>
143 /// <param name="scene"></param>
144 /// <param name="itemName"></param>
145 /// <param name="itemId"></param>
146 /// <param name="userId"></param>
147 /// <returns></returns>
148 public static InventoryItemBase CreateInventoryItem(Scene scene, string itemName, UUID userId)
149 {
150 return CreateInventoryItem(scene, itemName, UUID.Random(), UUID.Random(), userId, InventoryType.Notecard);
151 }
152
153 /// <summary>
154 /// Creates an item of the given type with an accompanying asset.
155 /// </summary>
156 /// <param name="scene"></param>
157 /// <param name="itemName"></param>
158 /// <param name="itemId"></param>
159 /// <param name="userId"></param>
160 /// <param name="type">Type of item to create</param>
161 /// <returns></returns>
162 public static InventoryItemBase CreateInventoryItem(
163 Scene scene, string itemName, UUID userId, InventoryType type)
164 {
165 return CreateInventoryItem(scene, itemName, UUID.Random(), UUID.Random(), userId, type);
166 }
167
168 /// <summary>
169 /// Creates a notecard in the objects folder and specify an item id.
170 /// </summary>
171 /// <param name="scene"></param>
172 /// <param name="itemName"></param>
173 /// <param name="itemId"></param>
174 /// <param name="assetId"></param>
175 /// <param name="userId"></param>
176 /// <param name="type">Type of item to create</param>
177 /// <returns></returns>
178 public static InventoryItemBase CreateInventoryItem(
179 Scene scene, string itemName, UUID itemId, UUID assetId, UUID userId, InventoryType itemType)
180 {
181 AssetBase asset = null;
182
183 if (itemType == InventoryType.Notecard)
184 {
185 asset = AssetHelpers.CreateNotecardAsset();
186 asset.CreatorID = userId.ToString();
187 }
188 else if (itemType == InventoryType.Object)
189 {
190 asset = AssetHelpers.CreateAsset(assetId, SceneHelpers.CreateSceneObject(1, userId));
191 }
192 else
193 {
194 throw new Exception(string.Format("Inventory type {0} not supported", itemType));
195 }
196
197 return AddInventoryItem(scene, itemName, itemId, itemType, asset, userId);
198 }
199
200 /// <summary>
201 /// Create inventory folders starting from the user's root folder.
202 /// </summary>
203 /// <param name="inventoryService"></param>
204 /// <param name="userId"></param>
205 /// <param name="path">
206 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
207 /// </param>
208 /// <param name="useExistingFolders">
209 /// If true, then folders in the path which already the same name are
210 /// used. This applies to the terminal folder as well.
211 /// If false, then all folders in the path are created, even if there is already a folder at a particular
212 /// level with the same name.
213 /// </param>
214 /// <returns>
215 /// The folder created. If the path contains multiple folders then the last one created is returned.
216 /// Will return null if the root folder could not be found.
217 /// </returns>
218 public static InventoryFolderBase CreateInventoryFolder(
219 IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders)
220 {
221 return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
222 }
223
224 /// <summary>
225 /// Create inventory folders starting from the user's root folder.
226 /// </summary>
227 /// <param name="inventoryService"></param>
228 /// <param name="userId"></param>
229 /// <param name="folderId"></param>
230 /// <param name="path">
231 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
232 /// </param>
233 /// <param name="useExistingFolders">
234 /// If true, then folders in the path which already the same name are
235 /// used. This applies to the terminal folder as well.
236 /// If false, then all folders in the path are created, even if there is already a folder at a particular
237 /// level with the same name.
238 /// </param>
239 /// <returns>
240 /// The folder created. If the path contains multiple folders then the last one created is returned.
241 /// Will return null if the root folder could not be found.
242 /// </returns>
243 public static InventoryFolderBase CreateInventoryFolder(
244 IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
245 {
246 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
247
248 if (null == rootFolder)
249 return null;
250
251 return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
252 }
253
254 /// <summary>
255 /// Create inventory folders starting from a given parent folder
256 /// </summary>
257 /// <remarks>
258 /// If any stem of the path names folders that already exist then these are not recreated. This includes the
259 /// final folder.
260 /// TODO: May need to make it an option to create duplicate folders.
261 /// </remarks>
262 /// <param name="inventoryService"></param>
263 /// <param name="folderId">ID of the folder to create</param>
264 /// <param name="parentFolder"></param>
265 /// <param name="path">
266 /// The folder to create.
267 /// </param>
268 /// <param name="useExistingFolders">
269 /// If true, then folders in the path which already the same name are
270 /// used. This applies to the terminal folder as well.
271 /// If false, then all folders in the path are created, even if there is already a folder at a particular
272 /// level with the same name.
273 /// </param>
274 /// <returns>
275 /// The folder created. If the path contains multiple folders then the last one created is returned.
276 /// </returns>
277 public static InventoryFolderBase CreateInventoryFolder(
278 IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
279 {
280 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
281
282 InventoryFolderBase folder = null;
283
284 if (useExistingFolders)
285 folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]);
286
287 if (folder == null)
288 {
289// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name);
290
291 UUID folderIdForCreate;
292
293 if (components.Length > 1)
294 folderIdForCreate = UUID.Random();
295 else
296 folderIdForCreate = folderId;
297
298 folder
299 = new InventoryFolderBase(
300 folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
301
302 inventoryService.AddFolder(folder);
303 }
304// else
305// {
306// Console.WriteLine("Found existing folder {0}", folder.Name);
307// }
308
309 if (components.Length > 1)
310 return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
311 else
312 return folder;
313 }
314
315 /// <summary>
316 /// Get the inventory folder that matches the path name. If there are multiple folders then only the first
317 /// is returned.
318 /// </summary>
319 /// <param name="inventoryService"></param>
320 /// <param name="userId"></param>
321 /// <param name="path"></param>
322 /// <returns>null if no folder matching the path was found</returns>
323 public static InventoryFolderBase GetInventoryFolder(IInventoryService inventoryService, UUID userId, string path)
324 {
325 List<InventoryFolderBase> folders = GetInventoryFolders(inventoryService, userId, path);
326
327 if (folders.Count != 0)
328 return folders[0];
329 else
330 return null;
331 }
332
333 /// <summary>
334 /// Get the inventory folders that match the path name.
335 /// </summary>
336 /// <param name="inventoryService"></param>
337 /// <param name="userId"></param>
338 /// <param name="path"></param>
339 /// <returns>An empty list if no matching folders were found</returns>
340 public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path)
341 {
342 return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path);
343 }
344
345 /// <summary>
346 /// Get the inventory item that matches the path name. If there are multiple items then only the first
347 /// is returned.
348 /// </summary>
349 /// <param name="inventoryService"></param>
350 /// <param name="userId"></param>
351 /// <param name="path"></param>
352 /// <returns>null if no item matching the path was found</returns>
353 public static InventoryItemBase GetInventoryItem(IInventoryService inventoryService, UUID userId, string path)
354 {
355 return InventoryArchiveUtils.FindItemByPath(inventoryService, userId, path);
356 }
357
358 /// <summary>
359 /// Get the inventory items that match the path name.
360 /// </summary>
361 /// <param name="inventoryService"></param>
362 /// <param name="userId"></param>
363 /// <param name="path"></param>
364 /// <returns>An empty list if no matching items were found.</returns>
365 public static List<InventoryItemBase> GetInventoryItems(IInventoryService inventoryService, UUID userId, string path)
366 {
367 return InventoryArchiveUtils.FindItemsByPath(inventoryService, userId, path);
368 }
369 }
370} \ No newline at end of file