1
0

LLImageManagerTests.cs 6.3 KB

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