OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
InventoryArchiveTestCase.cs
Go to the documentation of this file.
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 System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using System.Threading;
33 using NUnit.Framework;
34 using OpenMetaverse;
35 using OpenSim.Data;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Serialization;
38 using OpenSim.Framework.Serialization.External;
39 using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
40 using OpenSim.Region.CoreModules.World.Serialiser;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.Framework.Scenes.Serialization;
43 using OpenSim.Services.Interfaces;
44 using OpenSim.Tests.Common;
45 
46 namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
47 {
48  [TestFixture]
50  {
51  protected ManualResetEvent mre = new ManualResetEvent(false);
52 
56  protected byte[] m_iarStreamBytes;
57 
61  protected MemoryStream m_iarStream;
62 
63  protected UserAccount m_uaMT
64  = new UserAccount {
65  PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"),
66  FirstName = "Mr",
67  LastName = "Tiddles" };
68 
69  protected UserAccount m_uaLL1
70  = new UserAccount {
71  PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"),
72  FirstName = "Lord",
73  LastName = "Lucan" };
74 
75  protected UserAccount m_uaLL2
76  = new UserAccount {
77  PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000777"),
78  FirstName = "Lord",
79  LastName = "Lucan" };
80 
81  protected string m_item1Name = "Ray Gun Item";
82  protected string m_coaItemName = "Coalesced Item";
83 
84  [TestFixtureSetUp]
85  public void FixtureSetup()
86  {
87  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
88  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
89 
90  ConstructDefaultIarBytesForTestLoad();
91  }
92 
93  [TestFixtureTearDown]
94  public void TearDown()
95  {
96  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
97  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
98  // tests really shouldn't).
99  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
100  }
101 
102  [SetUp]
103  public override void SetUp()
104  {
105  base.SetUp();
106  m_iarStream = new MemoryStream(m_iarStreamBytes);
107  }
108 
110  {
111 // log4net.Config.XmlConfigurator.Configure();
112 
113  InventoryArchiverModule archiverModule = new InventoryArchiverModule();
114  Scene scene = new SceneHelpers().SetupScene();
115  SceneHelpers.SetupSceneModules(scene, archiverModule);
116 
117  UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire");
118 
119  MemoryStream archiveWriteStream = new MemoryStream();
120 
121  // Create scene object asset
122  UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
123  SceneObjectGroup object1 = SceneHelpers.CreateSceneObject(1, ownerId, "Ray Gun Object", 0x50);
124 
125  UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
126  AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
127  scene.AssetService.Store(asset1);
128 
129  // Create scene object item
130  InventoryItemBase item1 = new InventoryItemBase();
131  item1.Name = m_item1Name;
132  item1.ID = UUID.Parse("00000000-0000-0000-0000-000000000020");
133  item1.AssetID = asset1.FullID;
134  item1.GroupID = UUID.Random();
135  item1.CreatorId = m_uaLL1.PrincipalID.ToString();
136  item1.Owner = m_uaLL1.PrincipalID;
137  item1.Folder = scene.InventoryService.GetRootFolder(m_uaLL1.PrincipalID).ID;
138  scene.AddInventoryItem(item1);
139 
140  // Create coalesced objects asset
141  SceneObjectGroup cobj1 = SceneHelpers.CreateSceneObject(1, m_uaLL1.PrincipalID, "Object1", 0x120);
142  cobj1.AbsolutePosition = new Vector3(15, 30, 45);
143 
144  SceneObjectGroup cobj2 = SceneHelpers.CreateSceneObject(1, m_uaLL1.PrincipalID, "Object2", 0x140);
145  cobj2.AbsolutePosition = new Vector3(25, 50, 75);
146 
147  CoalescedSceneObjects coa = new CoalescedSceneObjects(m_uaLL1.PrincipalID, cobj1, cobj2);
148 
149  AssetBase coaAsset = AssetHelpers.CreateAsset(0x160, coa);
150  scene.AssetService.Store(coaAsset);
151 
152  // Create coalesced objects inventory item
153  InventoryItemBase coaItem = new InventoryItemBase();
154  coaItem.Name = m_coaItemName;
155  coaItem.ID = UUID.Parse("00000000-0000-0000-0000-000000000180");
156  coaItem.AssetID = coaAsset.FullID;
157  coaItem.GroupID = UUID.Random();
158  coaItem.CreatorId = m_uaLL1.PrincipalID.ToString();
159  coaItem.Owner = m_uaLL1.PrincipalID;
160  coaItem.Folder = scene.InventoryService.GetRootFolder(m_uaLL1.PrincipalID).ID;
161  scene.AddInventoryItem(coaItem);
162 
163  archiverModule.ArchiveInventory(
164  UUID.Random(), m_uaLL1.FirstName, m_uaLL1.LastName, "/*", "hampshire", archiveWriteStream);
165 
166  m_iarStreamBytes = archiveWriteStream.ToArray();
167  }
168 
169  protected void SaveCompleted(
170  UUID id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream,
171  Exception reportedException, int SaveCount, int FilterCount)
172  {
173  mre.Set();
174  }
175  }
176 }
void SaveCompleted(UUID id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, Exception reportedException, int SaveCount, int FilterCount)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
MemoryStream m_iarStream
Stream of data representing a common IAR for load tests.
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
This module loads and saves OpenSimulator inventory archives
byte[] m_iarStreamBytes
A raw array of bytes that we'll use to create an IAR memory stream suitable for isolated use in each ...
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Represents a coalescene of scene objects. A coalescence occurs when objects that are not in the same ...