1
0

UuidGathererTests.cs 7.1 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.Collections.Generic;
  28. using System.Text;
  29. using NUnit.Framework;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Tests.Common;
  35. namespace OpenSim.Region.Framework.Scenes.Tests
  36. {
  37. [TestFixture]
  38. public class UuidGathererTests : OpenSimTestCase
  39. {
  40. protected IAssetService m_assetService;
  41. protected UuidGatherer m_uuidGatherer;
  42. protected static string noteBase = @"Linden text version 2\n{\nLLEmbeddedItems version 1\n
  43. {\ncount 0\n}\nText length xxx\n"; // len does not matter on this test
  44. [SetUp]
  45. public void Init()
  46. {
  47. // FIXME: We don't need a full scene here - it would be enough to set up the asset service.
  48. Scene scene = new SceneHelpers().SetupScene();
  49. m_assetService = scene.AssetService;
  50. m_uuidGatherer = new UuidGatherer(m_assetService);
  51. }
  52. [Test]
  53. public void TestCorruptAsset()
  54. {
  55. TestHelpers.InMethod();
  56. UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
  57. AssetBase corruptAsset
  58. = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, noteBase + "CORRUPT ASSET", UUID.Zero);
  59. m_assetService.Store(corruptAsset);
  60. m_uuidGatherer.AddForInspection(corruptAssetUuid);
  61. m_uuidGatherer.GatherAll();
  62. // We count the uuid as gathered even if the asset itself is corrupt.
  63. Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(1));
  64. }
  65. /// <summary>
  66. /// Test requests made for non-existent assets while we're gathering
  67. /// </summary>
  68. [Test]
  69. public void TestMissingAsset()
  70. {
  71. TestHelpers.InMethod();
  72. UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
  73. m_uuidGatherer.AddForInspection(missingAssetUuid);
  74. m_uuidGatherer.GatherAll();
  75. Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(0));
  76. }
  77. [Test]
  78. public void TestNotecardAsset()
  79. {
  80. TestHelpers.InMethod();
  81. // TestHelpers.EnableLogging();
  82. UUID ownerId = TestHelpers.ParseTail(0x10);
  83. UUID embeddedId = TestHelpers.ParseTail(0x20);
  84. UUID secondLevelEmbeddedId = TestHelpers.ParseTail(0x21);
  85. UUID missingEmbeddedId = TestHelpers.ParseTail(0x22);
  86. UUID ncAssetId = TestHelpers.ParseTail(0x30);
  87. AssetBase ncAsset
  88. = AssetHelpers.CreateNotecardAsset(
  89. ncAssetId, string.Format("{0}Hello{1}World{2}", noteBase, embeddedId, missingEmbeddedId));
  90. m_assetService.Store(ncAsset);
  91. AssetBase embeddedAsset
  92. = AssetHelpers.CreateNotecardAsset(embeddedId, string.Format("{0}{1} We'll meet again.", noteBase, secondLevelEmbeddedId));
  93. m_assetService.Store(embeddedAsset);
  94. AssetBase secondLevelEmbeddedAsset
  95. = AssetHelpers.CreateNotecardAsset(secondLevelEmbeddedId, noteBase + "Don't know where, don't know when.");
  96. m_assetService.Store(secondLevelEmbeddedAsset);
  97. m_uuidGatherer.AddForInspection(ncAssetId);
  98. m_uuidGatherer.GatherAll();
  99. // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys)
  100. // System.Console.WriteLine("key : {0}", key);
  101. Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(3));
  102. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(ncAssetId));
  103. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(embeddedId));
  104. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(secondLevelEmbeddedId));
  105. }
  106. [Test]
  107. public void TestTaskItems()
  108. {
  109. TestHelpers.InMethod();
  110. // TestHelpers.EnableLogging();
  111. UUID ownerId = TestHelpers.ParseTail(0x10);
  112. SceneObjectGroup soL0 = SceneHelpers.CreateSceneObject(1, ownerId, "l0", 0x20);
  113. SceneObjectGroup soL1 = SceneHelpers.CreateSceneObject(1, ownerId, "l1", 0x21);
  114. SceneObjectGroup soL2 = SceneHelpers.CreateSceneObject(1, ownerId, "l2", 0x22);
  115. TaskInventoryHelpers.AddScript(
  116. m_assetService, soL2.RootPart, TestHelpers.ParseTail(0x33), TestHelpers.ParseTail(0x43), "l3-script", "gibberish");
  117. TaskInventoryHelpers.AddSceneObject(
  118. m_assetService, soL1.RootPart, "l2-item", TestHelpers.ParseTail(0x32), soL2, TestHelpers.ParseTail(0x42));
  119. TaskInventoryHelpers.AddSceneObject(
  120. m_assetService, soL0.RootPart, "l1-item", TestHelpers.ParseTail(0x31), soL1, TestHelpers.ParseTail(0x41));
  121. m_uuidGatherer.AddForInspection(soL0);
  122. m_uuidGatherer.GatherAll();
  123. // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys)
  124. // System.Console.WriteLine("key : {0}", key);
  125. // We expect to see the default prim texture and the assets of the contained task items
  126. Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(4));
  127. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(new UUID(Constants.DefaultTexture)));
  128. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x41)));
  129. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x42)));
  130. Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(TestHelpers.ParseTail(0x43)));
  131. }
  132. }
  133. }