OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LLImageManagerTests.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.IO;
30 using System.Net;
31 using System.Reflection;
32 using System.Threading;
33 using log4net.Config;
34 using Nini.Config;
35 using NUnit.Framework;
36 using OpenMetaverse;
37 using OpenMetaverse.Packets;
38 using OpenSim.Framework;
39 using OpenSim.Region.CoreModules.Agent.TextureSender;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Tests.Common;
42 
43 namespace OpenSim.Region.ClientStack.LindenUDP.Tests
44 {
45  [TestFixture]
47  {
48  private AssetBase m_testImageAsset;
49  private Scene scene;
50  private LLImageManager llim;
51  private TestClient tc;
52 
53  [TestFixtureSetUp]
54  public void FixtureInit()
55  {
56  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
57  Util.FireAndForgetMethod = FireAndForgetMethod.None;
58 
59  using (
60  Stream resource
61  = GetType().Assembly.GetManifestResourceStream(
62  "OpenSim.Region.ClientStack.LindenUDP.Tests.Resources.4-tile2.jp2"))
63  {
64  using (BinaryReader br = new BinaryReader(resource))
65  {
66  m_testImageAsset
67  = new AssetBase(
69  "Test Image",
70  (sbyte)AssetType.Texture,
71  TestHelpers.ParseTail(0x2).ToString());
72 
73  m_testImageAsset.Data = br.ReadBytes(99999999);
74  }
75  }
76  }
77 
78  [TestFixtureTearDown]
79  public void TearDown()
80  {
81  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
82  // threads. Possibly, later tests should be rewritten not to worry about such things.
83  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
84  }
85 
86  [SetUp]
87  public override void SetUp()
88  {
89  base.SetUp();
90 
91  UUID userId = TestHelpers.ParseTail(0x3);
92 
93  J2KDecoderModule j2kdm = new J2KDecoderModule();
94 
95  SceneHelpers sceneHelpers = new SceneHelpers();
96  scene = sceneHelpers.SetupScene();
97  SceneHelpers.SetupSceneModules(scene, j2kdm);
98 
99  tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene);
100  llim = new LLImageManager(tc, scene.AssetService, j2kdm);
101  }
102 
103  [Test]
104  public void TestSendImage()
105  {
106  TestHelpers.InMethod();
107 // XmlConfigurator.Configure();
108 
109  scene.AssetService.Store(m_testImageAsset);
110 
112  args.RequestedAssetID = m_testImageAsset.FullID;
113  args.DiscardLevel = 0;
114  args.PacketNumber = 1;
115  args.Priority = 5;
116  args.requestSequence = 1;
117 
118  llim.EnqueueReq(args);
119  llim.ProcessImageQueue(20);
120 
121  Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(1));
122  }
123 
124  [Test]
125  public void TestDiscardImage()
126  {
127  TestHelpers.InMethod();
128 // XmlConfigurator.Configure();
129 
130  scene.AssetService.Store(m_testImageAsset);
131 
133  args.RequestedAssetID = m_testImageAsset.FullID;
134  args.DiscardLevel = 0;
135  args.PacketNumber = 1;
136  args.Priority = 5;
137  args.requestSequence = 1;
138  llim.EnqueueReq(args);
139 
140  // Now create a discard request
141  TextureRequestArgs discardArgs = new TextureRequestArgs();
142  discardArgs.RequestedAssetID = m_testImageAsset.FullID;
143  discardArgs.DiscardLevel = -1;
144  discardArgs.PacketNumber = 1;
145  discardArgs.Priority = 0;
146  discardArgs.requestSequence = 2;
147  llim.EnqueueReq(discardArgs);
148 
149  llim.ProcessImageQueue(20);
150 
151  Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
152  }
153 
154  [Test]
155  public void TestMissingImage()
156  {
157  TestHelpers.InMethod();
158 // XmlConfigurator.Configure();
159 
161  args.RequestedAssetID = m_testImageAsset.FullID;
162  args.DiscardLevel = 0;
163  args.PacketNumber = 1;
164  args.Priority = 5;
165  args.requestSequence = 1;
166 
167  llim.EnqueueReq(args);
168  llim.ProcessImageQueue(20);
169 
170  Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
171  Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1));
172  }
173  }
174 }
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
static AgentCircuitData GenerateAgentData(UUID agentId)
Generate some standard agent connection data.
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
This class handles UDP texture requests.