clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using OpenMetaverse;
30 using OpenMetaverse.Assets;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Services.Interfaces;
34  
35 namespace 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="scene"></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 Scene scene, SceneObjectPart part, string itemName, string itemIDStem, string assetIDStem, string text)
55 {
56 return AddNotecard(
57 scene, 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="scene"></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 Scene scene, 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 scene.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="scene"></param>
98 /// <param name="part"></param>
99 /// <returns>The item that was added</returns>
100 public static TaskInventoryItem AddScript(Scene scene, SceneObjectPart part)
101 {
102 return AddScript(scene, 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="scene"></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 Scene scene, SceneObjectPart part, string scriptName, string scriptSource)
119 {
120 AssetScriptText ast = new AssetScriptText();
121 ast.Source = scriptSource;
122 ast.Encode();
123  
124 UUID assetUuid = UUID.Random();
125 UUID itemUuid = UUID.Random();
126  
127 AssetBase asset
128 = AssetHelpers.CreateAsset(assetUuid, AssetType.LSLText, ast.AssetData, UUID.Zero);
129 scene.AssetService.Store(asset);
130 TaskInventoryItem item
131 = new TaskInventoryItem
132 { Name = scriptName, AssetID = assetUuid, ItemID = itemUuid,
133 Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
134 part.Inventory.AddInventoryItem(item, true);
135  
136 return item;
137 }
138  
139 /// <summary>
140 /// Add a scene object item to the given part.
141 /// </summary>
142 /// <remarks>
143 /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
144 /// functions more than once in a test.
145 /// </remarks>
146 ///
147 /// <param name="scene"></param>
148 /// <param name="sop"></param>
149 /// <param name="itemName"></param>
150 /// <param name="id"></param>
151 /// <param name="userId"></param>
152 public static TaskInventoryItem AddSceneObject(
153 Scene scene, SceneObjectPart sop, string itemName, UUID id, UUID userId)
154 {
155 SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, UUID.Zero);
156 AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(0x10, taskSceneObject);
157 scene.AssetService.Store(taskSceneObjectAsset);
158 TaskInventoryItem taskSceneObjectItem
159 = new TaskInventoryItem
160 { Name = itemName,
161 AssetID = taskSceneObjectAsset.FullID,
162 ItemID = id,
163 OwnerID = userId,
164 Type = (int)AssetType.Object,
165 InvType = (int)InventoryType.Object };
166 sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
167  
168 return taskSceneObjectItem;
169 }
170 }
171 }