LLImageManagerTests.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 log4net.Config;
  32. using Nini.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Packets;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.CoreModules.Agent.TextureSender;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Tests.Common;
  40. using OpenSim.Tests.Common.Mock;
  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. using (
  54. Stream resource
  55. = GetType().Assembly.GetManifestResourceStream(
  56. "OpenSim.Region.ClientStack.LindenUDP.Tests.Resources.4-tile2.jp2"))
  57. {
  58. using (BinaryReader br = new BinaryReader(resource))
  59. {
  60. m_testImageAsset
  61. = new AssetBase(
  62. TestHelpers.ParseTail(0x1),
  63. "Test Image",
  64. (sbyte)AssetType.Texture,
  65. TestHelpers.ParseTail(0x2).ToString());
  66. m_testImageAsset.Data = br.ReadBytes(99999999);
  67. }
  68. }
  69. }
  70. [SetUp]
  71. public void SetUp()
  72. {
  73. UUID userId = TestHelpers.ParseTail(0x3);
  74. J2KDecoderModule j2kdm = new J2KDecoderModule();
  75. SceneHelpers sceneHelpers = new SceneHelpers();
  76. scene = sceneHelpers.SetupScene();
  77. SceneHelpers.SetupSceneModules(scene, j2kdm);
  78. tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene);
  79. llim = new LLImageManager(tc, scene.AssetService, j2kdm);
  80. }
  81. [Test]
  82. public void TestSendImage()
  83. {
  84. TestHelpers.InMethod();
  85. // XmlConfigurator.Configure();
  86. scene.AssetService.Store(m_testImageAsset);
  87. TextureRequestArgs args = new TextureRequestArgs();
  88. args.RequestedAssetID = m_testImageAsset.FullID;
  89. args.DiscardLevel = 0;
  90. args.PacketNumber = 1;
  91. args.Priority = 5;
  92. args.requestSequence = 1;
  93. llim.EnqueueReq(args);
  94. llim.ProcessImageQueue(20);
  95. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(1));
  96. }
  97. [Test]
  98. public void TestDiscardImage()
  99. {
  100. TestHelpers.InMethod();
  101. // XmlConfigurator.Configure();
  102. scene.AssetService.Store(m_testImageAsset);
  103. TextureRequestArgs args = new TextureRequestArgs();
  104. args.RequestedAssetID = m_testImageAsset.FullID;
  105. args.DiscardLevel = 0;
  106. args.PacketNumber = 1;
  107. args.Priority = 5;
  108. args.requestSequence = 1;
  109. llim.EnqueueReq(args);
  110. // Now create a discard request
  111. TextureRequestArgs discardArgs = new TextureRequestArgs();
  112. discardArgs.RequestedAssetID = m_testImageAsset.FullID;
  113. discardArgs.DiscardLevel = -1;
  114. discardArgs.PacketNumber = 1;
  115. discardArgs.Priority = 0;
  116. discardArgs.requestSequence = 2;
  117. llim.EnqueueReq(discardArgs);
  118. llim.ProcessImageQueue(20);
  119. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
  120. }
  121. [Test]
  122. public void TestMissingImage()
  123. {
  124. TestHelpers.InMethod();
  125. // XmlConfigurator.Configure();
  126. TextureRequestArgs args = new TextureRequestArgs();
  127. args.RequestedAssetID = m_testImageAsset.FullID;
  128. args.DiscardLevel = 0;
  129. args.PacketNumber = 1;
  130. args.Priority = 5;
  131. args.requestSequence = 1;
  132. llim.EnqueueReq(args);
  133. llim.ProcessImageQueue(20);
  134. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
  135. Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1));
  136. }
  137. }
  138. }