SceneObjectDeRezTests.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.Collections.Generic;
  29. using System.Reflection;
  30. using Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Region.CoreModules.World.Permissions;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Tests.Common;
  38. using OpenSim.Tests.Common.Mock;
  39. namespace OpenSim.Region.Framework.Scenes.Tests
  40. {
  41. /// <summary>
  42. /// Tests derez of scene objects by users.
  43. /// </summary>
  44. /// <remarks>
  45. /// This is at a level above the SceneObjectBasicTests, which act on the scene directly.
  46. /// TODO: These tests are very incomplete - they only test for a few conditions.
  47. /// </remarks>
  48. [TestFixture]
  49. public class SceneObjectDeRezTests
  50. {
  51. /// <summary>
  52. /// Test deleting an object from a scene.
  53. /// </summary>
  54. [Test]
  55. public void TestDeRezSceneObject()
  56. {
  57. TestHelpers.InMethod();
  58. // log4net.Config.XmlConfigurator.Configure();
  59. UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
  60. TestScene scene = SceneHelpers.SetupScene();
  61. IConfigSource configSource = new IniConfigSource();
  62. IConfig config = configSource.AddConfig("Startup");
  63. config.Set("serverside_object_permissions", true);
  64. SceneHelpers.SetupSceneModules(scene, configSource, new object[] { new PermissionsModule() });
  65. IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
  66. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  67. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  68. sogd.Enabled = false;
  69. SceneObjectPart part
  70. = new SceneObjectPart(userId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
  71. part.Name = "obj1";
  72. scene.AddNewSceneObject(new SceneObjectGroup(part), false);
  73. List<uint> localIds = new List<uint>();
  74. localIds.Add(part.LocalId);
  75. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  76. sogd.InventoryDeQueueAndDelete();
  77. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  78. Assert.That(retrievedPart, Is.Null);
  79. }
  80. /// <summary>
  81. /// Test deleting an object from a scene where the deleter is not the owner
  82. /// </summary>
  83. ///
  84. /// This test assumes that the deleter is not a god.
  85. [Test]
  86. public void TestDeRezSceneObjectNotOwner()
  87. {
  88. TestHelpers.InMethod();
  89. // log4net.Config.XmlConfigurator.Configure();
  90. UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
  91. UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001");
  92. TestScene scene = SceneHelpers.SetupScene();
  93. IConfigSource configSource = new IniConfigSource();
  94. IConfig config = configSource.AddConfig("Startup");
  95. config.Set("serverside_object_permissions", true);
  96. SceneHelpers.SetupSceneModules(scene, configSource, new object[] { new PermissionsModule() });
  97. IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
  98. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  99. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  100. sogd.Enabled = false;
  101. SceneObjectPart part
  102. = new SceneObjectPart(objectOwnerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
  103. part.Name = "obj1";
  104. scene.AddNewSceneObject(new SceneObjectGroup(part), false);
  105. List<uint> localIds = new List<uint>();
  106. localIds.Add(part.LocalId);
  107. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.Delete, UUID.Zero);
  108. sogd.InventoryDeQueueAndDelete();
  109. // Object should still be in the scene.
  110. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
  111. Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID));
  112. }
  113. }
  114. }