diff options
author | Justin Clark-Casey (justincc) | 2013-02-16 00:26:21 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-02-16 00:26:21 +0000 |
commit | e9cc22fea48a6d80fccbd624fd9710dfa3830980 (patch) | |
tree | 1298f28b915ce6c0d23a5ac50aea93f8e06fdc19 /OpenSim/Tests | |
parent | Enable one sub-test in TestJsonSetValue() which now works (using identifier w... (diff) | |
download | opensim-SC-e9cc22fea48a6d80fccbd624fd9710dfa3830980.zip opensim-SC-e9cc22fea48a6d80fccbd624fd9710dfa3830980.tar.gz opensim-SC-e9cc22fea48a6d80fccbd624fd9710dfa3830980.tar.bz2 opensim-SC-e9cc22fea48a6d80fccbd624fd9710dfa3830980.tar.xz |
Add regression test TestSaveNonRootFolderToIar
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r-- | OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs | 109 |
1 files changed, 89 insertions, 20 deletions
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs index 87d9410..a1794c9 100644 --- a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs | |||
@@ -45,6 +45,9 @@ namespace OpenSim.Tests.Common | |||
45 | /// <summary> | 45 | /// <summary> |
46 | /// Add an existing scene object as an item in the user's inventory. | 46 | /// Add an existing scene object as an item in the user's inventory. |
47 | /// </summary> | 47 | /// </summary> |
48 | /// <remarks> | ||
49 | /// Will be added to the system Objects folder. | ||
50 | /// </remarks> | ||
48 | /// <param name='scene'></param> | 51 | /// <param name='scene'></param> |
49 | /// <param name='so'></param> | 52 | /// <param name='so'></param> |
50 | /// <param name='inventoryIdTail'></param> | 53 | /// <param name='inventoryIdTail'></param> |
@@ -63,7 +66,29 @@ namespace OpenSim.Tests.Common | |||
63 | } | 66 | } |
64 | 67 | ||
65 | /// <summary> | 68 | /// <summary> |
66 | /// Creates a notecard in the objects folder and specify an item id. | 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). | ||
67 | /// </summary> | 92 | /// </summary> |
68 | /// <param name="scene"></param> | 93 | /// <param name="scene"></param> |
69 | /// <param name="itemName"></param> | 94 | /// <param name="itemName"></param> |
@@ -75,6 +100,25 @@ namespace OpenSim.Tests.Common | |||
75 | private static InventoryItemBase AddInventoryItem( | 100 | private static InventoryItemBase AddInventoryItem( |
76 | Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId) | 101 | Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId) |
77 | { | 102 | { |
103 | return AddInventoryItem( | ||
104 | scene, itemName, itemId, itemType, asset, userId, | ||
105 | scene.InventoryService.GetFolderForType(userId, (AssetType)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 | { | ||
78 | scene.AssetService.Store(asset); | 122 | scene.AssetService.Store(asset); |
79 | 123 | ||
80 | InventoryItemBase item = new InventoryItemBase(); | 124 | InventoryItemBase item = new InventoryItemBase(); |
@@ -85,7 +129,7 @@ namespace OpenSim.Tests.Common | |||
85 | item.AssetType = asset.Type; | 129 | item.AssetType = asset.Type; |
86 | item.InvType = (int)itemType; | 130 | item.InvType = (int)itemType; |
87 | 131 | ||
88 | InventoryFolderBase folder = scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type); | 132 | InventoryFolderBase folder = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, path)[0]; |
89 | 133 | ||
90 | item.Folder = folder.ID; | 134 | item.Folder = folder.ID; |
91 | scene.AddInventoryItem(item); | 135 | scene.AddInventoryItem(item); |
@@ -156,58 +200,83 @@ namespace OpenSim.Tests.Common | |||
156 | /// <summary> | 200 | /// <summary> |
157 | /// Create inventory folders starting from the user's root folder. | 201 | /// Create inventory folders starting from the user's root folder. |
158 | /// </summary> | 202 | /// </summary> |
159 | /// | ||
160 | /// Ignores any existing folders with the same name | ||
161 | /// | ||
162 | /// <param name="inventoryService"></param> | 203 | /// <param name="inventoryService"></param> |
163 | /// <param name="userId"></param> | 204 | /// <param name="userId"></param> |
164 | /// <param name="path"> | 205 | /// <param name="path"> |
165 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER | 206 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER |
166 | /// </param> | 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> | ||
167 | /// <returns> | 214 | /// <returns> |
168 | /// The folder created. If the path contains multiple folders then the last one created is returned. | 215 | /// The folder created. If the path contains multiple folders then the last one created is returned. |
169 | /// Will return null if the root folder could not be found. | 216 | /// Will return null if the root folder could not be found. |
170 | /// </returns> | 217 | /// </returns> |
171 | public static InventoryFolderBase CreateInventoryFolder( | 218 | public static InventoryFolderBase CreateInventoryFolder( |
172 | IInventoryService inventoryService, UUID userId, string path) | 219 | IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders) |
173 | { | 220 | { |
174 | InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); | 221 | InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); |
175 | 222 | ||
176 | if (null == rootFolder) | 223 | if (null == rootFolder) |
177 | return null; | 224 | return null; |
178 | 225 | ||
179 | return CreateInventoryFolder(inventoryService, rootFolder, path); | 226 | return CreateInventoryFolder(inventoryService, rootFolder, path, useExistingFolders); |
180 | } | 227 | } |
181 | 228 | ||
182 | /// <summary> | 229 | /// <summary> |
183 | /// Create inventory folders starting from a given parent folder | 230 | /// Create inventory folders starting from a given parent folder |
184 | /// </summary> | 231 | /// </summary> |
185 | /// | 232 | /// <remarks> |
186 | /// Ignores any existing folders with the same name | 233 | /// If any stem of the path names folders that already exist then these are not recreated. This includes the |
187 | /// | 234 | /// final folder. |
235 | /// TODO: May need to make it an option to create duplicate folders. | ||
236 | /// </remarks> | ||
188 | /// <param name="inventoryService"></param> | 237 | /// <param name="inventoryService"></param> |
189 | /// <param name="parentFolder"></param> | 238 | /// <param name="parentFolder"></param> |
190 | /// <param name="path"> | 239 | /// <param name="path"> |
191 | /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER | 240 | /// The folder to create. |
241 | /// </param> | ||
242 | /// <param name="useExistingFolders"> | ||
243 | /// If true, then folders in the path which already the same name are | ||
244 | /// used. This applies to the terminal folder as well. | ||
245 | /// If false, then all folders in the path are created, even if there is already a folder at a particular | ||
246 | /// level with the same name. | ||
192 | /// </param> | 247 | /// </param> |
193 | /// <returns> | 248 | /// <returns> |
194 | /// The folder created. If the path contains multiple folders then the last one created is returned. | 249 | /// The folder created. If the path contains multiple folders then the last one created is returned. |
195 | /// </returns> | 250 | /// </returns> |
196 | public static InventoryFolderBase CreateInventoryFolder( | 251 | public static InventoryFolderBase CreateInventoryFolder( |
197 | IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) | 252 | IInventoryService inventoryService, InventoryFolderBase parentFolder, string path, bool useExistingFolders) |
198 | { | 253 | { |
199 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | 254 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); |
200 | 255 | ||
201 | InventoryFolderBase newFolder | 256 | InventoryFolderBase folder = null; |
202 | = new InventoryFolderBase( | 257 | |
203 | UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); | 258 | if (useExistingFolders) |
204 | 259 | folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]); | |
205 | inventoryService.AddFolder(newFolder); | 260 | |
261 | if (folder == null) | ||
262 | { | ||
263 | // Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name); | ||
264 | |||
265 | folder | ||
266 | = new InventoryFolderBase( | ||
267 | UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); | ||
268 | |||
269 | inventoryService.AddFolder(folder); | ||
270 | } | ||
271 | // else | ||
272 | // { | ||
273 | // Console.WriteLine("Found existing folder {0}", folder.Name); | ||
274 | // } | ||
206 | 275 | ||
207 | if (components.Length > 1) | 276 | if (components.Length > 1) |
208 | return CreateInventoryFolder(inventoryService, newFolder, components[1]); | 277 | return CreateInventoryFolder(inventoryService, folder, components[1], useExistingFolders); |
209 | else | 278 | else |
210 | return newFolder; | 279 | return folder; |
211 | } | 280 | } |
212 | 281 | ||
213 | /// <summary> | 282 | /// <summary> |
@@ -237,7 +306,7 @@ namespace OpenSim.Tests.Common | |||
237 | /// <returns>An empty list if no matching folders were found</returns> | 306 | /// <returns>An empty list if no matching folders were found</returns> |
238 | public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) | 307 | public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) |
239 | { | 308 | { |
240 | return InventoryArchiveUtils.FindFolderByPath(inventoryService, userId, path); | 309 | return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path); |
241 | } | 310 | } |
242 | 311 | ||
243 | /// <summary> | 312 | /// <summary> |