aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs')
-rw-r--r--OpenSim/Tests/Common/Helpers/TaskInventoryHelpers.cs210
1 files changed, 210 insertions, 0 deletions
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