OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
UuidGathererTests.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.Collections.Generic;
29 using System.Text;
30 using NUnit.Framework;
31 using OpenMetaverse;
32 using OpenSim.Framework;
33 using OpenSim.Region.Framework.Scenes;
34 using OpenSim.Services.Interfaces;
35 using OpenSim.Tests.Common;
36 
37 namespace OpenSim.Region.Framework.Scenes.Tests
38 {
39  [TestFixture]
41  {
44 
45  [SetUp]
46  public void Init()
47  {
48  // FIXME: We don't need a full scene here - it would be enough to set up the asset service.
49  Scene scene = new SceneHelpers().SetupScene();
50  m_assetService = scene.AssetService;
51  m_uuidGatherer = new UuidGatherer(m_assetService);
52  }
53 
54  [Test]
55  public void TestCorruptAsset()
56  {
57  TestHelpers.InMethod();
58 
59  UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
60  AssetBase corruptAsset
61  = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, "CORRUPT ASSET", UUID.Zero);
62  m_assetService.Store(corruptAsset);
63 
64  m_uuidGatherer.AddForInspection(corruptAssetUuid);
65  m_uuidGatherer.GatherAll();
66 
67  // We count the uuid as gathered even if the asset itself is corrupt.
68  Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(1));
69  }
70 
74  [Test]
75  public void TestMissingAsset()
76  {
77  TestHelpers.InMethod();
78 
79  UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
80 
81  m_uuidGatherer.AddForInspection(missingAssetUuid);
82  m_uuidGatherer.GatherAll();
83 
84  Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(0));
85  }
86 
87  [Test]
88  public void TestNotecardAsset()
89  {
90  TestHelpers.InMethod();
91 // TestHelpers.EnableLogging();
92 
93  UUID ownerId = TestHelpers.ParseTail(0x10);
94  UUID embeddedId = TestHelpers.ParseTail(0x20);
95  UUID secondLevelEmbeddedId = TestHelpers.ParseTail(0x21);
96  UUID missingEmbeddedId = TestHelpers.ParseTail(0x22);
97  UUID ncAssetId = TestHelpers.ParseTail(0x30);
98 
99  AssetBase ncAsset
100  = AssetHelpers.CreateNotecardAsset(
101  ncAssetId, string.Format("Hello{0}World{1}", embeddedId, missingEmbeddedId));
102  m_assetService.Store(ncAsset);
103 
104  AssetBase embeddedAsset
105  = AssetHelpers.CreateNotecardAsset(embeddedId, string.Format("{0} We'll meet again.", secondLevelEmbeddedId));
106  m_assetService.Store(embeddedAsset);
107 
108  AssetBase secondLevelEmbeddedAsset
109  = AssetHelpers.CreateNotecardAsset(secondLevelEmbeddedId, "Don't know where, don't know when.");
110  m_assetService.Store(secondLevelEmbeddedAsset);
111 
112  m_uuidGatherer.AddForInspection(ncAssetId);
113  m_uuidGatherer.GatherAll();
114 
115 // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys)
116 // System.Console.WriteLine("key : {0}", key);
117 
118  Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(3));
119  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(ncAssetId));
120  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(embeddedId));
121  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(secondLevelEmbeddedId));
122  }
123 
124  [Test]
125  public void TestTaskItems()
126  {
127  TestHelpers.InMethod();
128 // TestHelpers.EnableLogging();
129 
130  UUID ownerId = TestHelpers.ParseTail(0x10);
131 
132  SceneObjectGroup soL0 = SceneHelpers.CreateSceneObject(1, ownerId, "l0", 0x20);
133  SceneObjectGroup soL1 = SceneHelpers.CreateSceneObject(1, ownerId, "l1", 0x21);
134  SceneObjectGroup soL2 = SceneHelpers.CreateSceneObject(1, ownerId, "l2", 0x22);
135 
136  TaskInventoryHelpers.AddScript(
137  m_assetService, soL2.RootPart, TestHelpers.ParseTail(0x33), TestHelpers.ParseTail(0x43), "l3-script", "gibberish");
138 
139  TaskInventoryHelpers.AddSceneObject(
140  m_assetService, soL1.RootPart, "l2-item", TestHelpers.ParseTail(0x32), soL2, TestHelpers.ParseTail(0x42));
141  TaskInventoryHelpers.AddSceneObject(
142  m_assetService, soL0.RootPart, "l1-item", TestHelpers.ParseTail(0x31), soL1, TestHelpers.ParseTail(0x41));
143 
144  m_uuidGatherer.AddForInspection(soL0);
145  m_uuidGatherer.GatherAll();
146 
147 // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys)
148 // System.Console.WriteLine("key : {0}", key);
149 
150  // We expect to see the default prim texture and the assets of the contained task items
151  Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(4));
152  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(new UUID(Constants.DefaultTexture)));
153  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x41)));
154  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x42)));
155  Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x43)));
156  }
157  }
158 }
void TestMissingAsset()
Test requests made for non-existent assets while we're gathering
Gather uuids for a given entity.
Definition: UuidGatherer.cs:54
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
static UUID ParseTail(int tail)
Parse tail section into full UUID.
Definition: TestHelpers.cs:140
const string DefaultTexture
Definition: Constants.cs:45
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60