opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | using OpenSim.Tests.Common.Mock; |
||
43 | |||
44 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
||
45 | { |
||
46 | [TestFixture] |
||
47 | public class LLImageManagerTests : OpenSimTestCase |
||
48 | { |
||
49 | private AssetBase m_testImageAsset; |
||
50 | private Scene scene; |
||
51 | private LLImageManager llim; |
||
52 | private TestClient tc; |
||
53 | |||
54 | [TestFixtureSetUp] |
||
55 | public void FixtureInit() |
||
56 | { |
||
57 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
||
58 | Util.FireAndForgetMethod = FireAndForgetMethod.None; |
||
59 | |||
60 | using ( |
||
61 | Stream resource |
||
62 | = GetType().Assembly.GetManifestResourceStream( |
||
63 | "OpenSim.Region.ClientStack.LindenUDP.Tests.Resources.4-tile2.jp2")) |
||
64 | { |
||
65 | using (BinaryReader br = new BinaryReader(resource)) |
||
66 | { |
||
67 | m_testImageAsset |
||
68 | = new AssetBase( |
||
69 | TestHelpers.ParseTail(0x1), |
||
70 | "Test Image", |
||
71 | (sbyte)AssetType.Texture, |
||
72 | TestHelpers.ParseTail(0x2).ToString()); |
||
73 | |||
74 | m_testImageAsset.Data = br.ReadBytes(99999999); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | |||
79 | [TestFixtureTearDown] |
||
80 | public void TearDown() |
||
81 | { |
||
82 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple |
||
83 | // threads. Possibly, later tests should be rewritten not to worry about such things. |
||
84 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
||
85 | } |
||
86 | |||
87 | [SetUp] |
||
88 | public override void SetUp() |
||
89 | { |
||
90 | base.SetUp(); |
||
91 | |||
92 | UUID userId = TestHelpers.ParseTail(0x3); |
||
93 | |||
94 | J2KDecoderModule j2kdm = new J2KDecoderModule(); |
||
95 | |||
96 | SceneHelpers sceneHelpers = new SceneHelpers(); |
||
97 | scene = sceneHelpers.SetupScene(); |
||
98 | SceneHelpers.SetupSceneModules(scene, j2kdm); |
||
99 | |||
100 | tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene); |
||
101 | llim = new LLImageManager(tc, scene.AssetService, j2kdm); |
||
102 | } |
||
103 | |||
104 | [Test] |
||
105 | public void TestSendImage() |
||
106 | { |
||
107 | TestHelpers.InMethod(); |
||
108 | // XmlConfigurator.Configure(); |
||
109 | |||
110 | scene.AssetService.Store(m_testImageAsset); |
||
111 | |||
112 | TextureRequestArgs args = new TextureRequestArgs(); |
||
113 | args.RequestedAssetID = m_testImageAsset.FullID; |
||
114 | args.DiscardLevel = 0; |
||
115 | args.PacketNumber = 1; |
||
116 | args.Priority = 5; |
||
117 | args.requestSequence = 1; |
||
118 | |||
119 | llim.EnqueueReq(args); |
||
120 | llim.ProcessImageQueue(20); |
||
121 | |||
122 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(1)); |
||
123 | } |
||
124 | |||
125 | [Test] |
||
126 | public void TestDiscardImage() |
||
127 | { |
||
128 | TestHelpers.InMethod(); |
||
129 | // XmlConfigurator.Configure(); |
||
130 | |||
131 | scene.AssetService.Store(m_testImageAsset); |
||
132 | |||
133 | TextureRequestArgs args = new TextureRequestArgs(); |
||
134 | args.RequestedAssetID = m_testImageAsset.FullID; |
||
135 | args.DiscardLevel = 0; |
||
136 | args.PacketNumber = 1; |
||
137 | args.Priority = 5; |
||
138 | args.requestSequence = 1; |
||
139 | llim.EnqueueReq(args); |
||
140 | |||
141 | // Now create a discard request |
||
142 | TextureRequestArgs discardArgs = new TextureRequestArgs(); |
||
143 | discardArgs.RequestedAssetID = m_testImageAsset.FullID; |
||
144 | discardArgs.DiscardLevel = -1; |
||
145 | discardArgs.PacketNumber = 1; |
||
146 | discardArgs.Priority = 0; |
||
147 | discardArgs.requestSequence = 2; |
||
148 | llim.EnqueueReq(discardArgs); |
||
149 | |||
150 | llim.ProcessImageQueue(20); |
||
151 | |||
152 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0)); |
||
153 | } |
||
154 | |||
155 | [Test] |
||
156 | public void TestMissingImage() |
||
157 | { |
||
158 | TestHelpers.InMethod(); |
||
159 | // XmlConfigurator.Configure(); |
||
160 | |||
161 | TextureRequestArgs args = new TextureRequestArgs(); |
||
162 | args.RequestedAssetID = m_testImageAsset.FullID; |
||
163 | args.DiscardLevel = 0; |
||
164 | args.PacketNumber = 1; |
||
165 | args.Priority = 5; |
||
166 | args.requestSequence = 1; |
||
167 | |||
168 | llim.EnqueueReq(args); |
||
169 | llim.ProcessImageQueue(20); |
||
170 | |||
171 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0)); |
||
172 | Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1)); |
||
173 | } |
||
174 | } |
||
175 | } |