UuidGathererTests.cs 7.0 KB

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