1
0

LLImageManagerTests.cs 6.3 KB

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