aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs174
1 files changed, 174 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
new file mode 100644
index 0000000..6c57e6d
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
@@ -0,0 +1,174 @@
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
28using System;
29using System.IO;
30using System.Net;
31using System.Reflection;
32using System.Threading;
33using log4net.Config;
34using Nini.Config;
35using NUnit.Framework;
36using OpenMetaverse;
37using OpenMetaverse.Packets;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Agent.TextureSender;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Tests.Common;
42
43namespace OpenSim.Region.ClientStack.LindenUDP.Tests
44{
45 [TestFixture]
46 public class LLImageManagerTests : OpenSimTestCase
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(
68 TestHelpers.ParseTail(0x1),
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
111 TextureRequestArgs args = new TextureRequestArgs();
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
132 TextureRequestArgs args = new TextureRequestArgs();
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
160 TextureRequestArgs args = new TextureRequestArgs();
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} \ No newline at end of file