LLImageManagerTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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
  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. scene = SceneHelpers.SetupScene();
  76. SceneHelpers.SetupSceneModules(scene, j2kdm);
  77. tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene);
  78. llim = new LLImageManager(tc, scene.AssetService, j2kdm);
  79. }
  80. [Test]
  81. public void TestSendImage()
  82. {
  83. TestHelpers.InMethod();
  84. // XmlConfigurator.Configure();
  85. scene.AssetService.Store(m_testImageAsset);
  86. TextureRequestArgs args = new TextureRequestArgs();
  87. args.RequestedAssetID = m_testImageAsset.FullID;
  88. args.DiscardLevel = 0;
  89. args.PacketNumber = 1;
  90. args.Priority = 5;
  91. args.requestSequence = 1;
  92. llim.EnqueueReq(args);
  93. llim.ProcessImageQueue(20);
  94. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(1));
  95. }
  96. [Test]
  97. public void TestDiscardImage()
  98. {
  99. TestHelpers.InMethod();
  100. // XmlConfigurator.Configure();
  101. scene.AssetService.Store(m_testImageAsset);
  102. TextureRequestArgs args = new TextureRequestArgs();
  103. args.RequestedAssetID = m_testImageAsset.FullID;
  104. args.DiscardLevel = 0;
  105. args.PacketNumber = 1;
  106. args.Priority = 5;
  107. args.requestSequence = 1;
  108. llim.EnqueueReq(args);
  109. // Now create a discard request
  110. TextureRequestArgs discardArgs = new TextureRequestArgs();
  111. discardArgs.RequestedAssetID = m_testImageAsset.FullID;
  112. discardArgs.DiscardLevel = -1;
  113. discardArgs.PacketNumber = 1;
  114. discardArgs.Priority = 0;
  115. discardArgs.requestSequence = 2;
  116. llim.EnqueueReq(discardArgs);
  117. llim.ProcessImageQueue(20);
  118. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
  119. }
  120. [Test]
  121. public void TestMissingImage()
  122. {
  123. TestHelpers.InMethod();
  124. // XmlConfigurator.Configure();
  125. TextureRequestArgs args = new TextureRequestArgs();
  126. args.RequestedAssetID = m_testImageAsset.FullID;
  127. args.DiscardLevel = 0;
  128. args.PacketNumber = 1;
  129. args.Priority = 5;
  130. args.requestSequence = 1;
  131. llim.EnqueueReq(args);
  132. llim.ProcessImageQueue(20);
  133. Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
  134. Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1));
  135. }
  136. }
  137. }