OSSL_ApiNpcTests.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 System.Text;
  31. using log4net;
  32. using Nini.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Assets;
  36. using OpenMetaverse.StructuredData;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
  39. using OpenSim.Region.OptionalModules.World.NPC;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.ScriptEngine.Shared;
  42. using OpenSim.Region.ScriptEngine.Shared.Api;
  43. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Tests.Common;
  46. using OpenSim.Tests.Common.Mock;
  47. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  48. {
  49. /// <summary>
  50. /// Tests for OSSL NPC API
  51. /// </summary>
  52. [TestFixture]
  53. public class OSSL_NpcApiAppearanceTest : OpenSimTestCase
  54. {
  55. protected Scene m_scene;
  56. protected XEngine.XEngine m_engine;
  57. [SetUp]
  58. public override void SetUp()
  59. {
  60. base.SetUp();
  61. IConfigSource initConfigSource = new IniConfigSource();
  62. IConfig config = initConfigSource.AddConfig("XEngine");
  63. config.Set("Enabled", "true");
  64. config.Set("AllowOSFunctions", "true");
  65. config.Set("OSFunctionThreatLevel", "Severe");
  66. config = initConfigSource.AddConfig("NPC");
  67. config.Set("Enabled", "true");
  68. m_scene = new SceneHelpers().SetupScene();
  69. SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
  70. m_engine = new XEngine.XEngine();
  71. m_engine.Initialise(initConfigSource);
  72. m_engine.AddRegion(m_scene);
  73. }
  74. /// <summary>
  75. /// Test removal of an owned NPC.
  76. /// </summary>
  77. [Test]
  78. public void TestOsNpcRemoveOwned()
  79. {
  80. TestHelpers.InMethod();
  81. // log4net.Config.XmlConfigurator.Configure();
  82. // Store an avatar with a different height from default in a notecard.
  83. UUID userId = TestHelpers.ParseTail(0x1);
  84. UUID otherUserId = TestHelpers.ParseTail(0x2);
  85. float newHeight = 1.9f;
  86. SceneHelpers.AddScenePresence(m_scene, otherUserId);
  87. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  88. sp.Appearance.AvatarHeight = newHeight;
  89. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
  90. SceneObjectPart part = so.RootPart;
  91. m_scene.AddSceneObject(so);
  92. SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId, 0x20);
  93. SceneObjectPart otherPart = otherSo.RootPart;
  94. m_scene.AddSceneObject(otherSo);
  95. OSSL_Api osslApi = new OSSL_Api();
  96. osslApi.Initialize(m_engine, part, null);
  97. OSSL_Api otherOsslApi = new OSSL_Api();
  98. otherOsslApi.Initialize(m_engine, otherPart, null);
  99. string notecardName = "appearanceNc";
  100. osslApi.osOwnerSaveAppearance(notecardName);
  101. string npcRaw
  102. = osslApi.osNpcCreate(
  103. "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED);
  104. otherOsslApi.osNpcRemove(npcRaw);
  105. // Should still be around
  106. UUID npcId = new UUID(npcRaw);
  107. ScenePresence npc = m_scene.GetScenePresence(npcId);
  108. Assert.That(npc, Is.Not.Null);
  109. osslApi.osNpcRemove(npcRaw);
  110. npc = m_scene.GetScenePresence(npcId);
  111. // Now the owner deleted it and it's gone
  112. Assert.That(npc, Is.Null);
  113. }
  114. /// <summary>
  115. /// Test removal of an unowned NPC.
  116. /// </summary>
  117. [Test]
  118. public void TestOsNpcRemoveUnowned()
  119. {
  120. TestHelpers.InMethod();
  121. // log4net.Config.XmlConfigurator.Configure();
  122. // Store an avatar with a different height from default in a notecard.
  123. UUID userId = TestHelpers.ParseTail(0x1);
  124. float newHeight = 1.9f;
  125. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  126. sp.Appearance.AvatarHeight = newHeight;
  127. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
  128. SceneObjectPart part = so.RootPart;
  129. m_scene.AddSceneObject(so);
  130. OSSL_Api osslApi = new OSSL_Api();
  131. osslApi.Initialize(m_engine, part, null);
  132. string notecardName = "appearanceNc";
  133. osslApi.osOwnerSaveAppearance(notecardName);
  134. string npcRaw
  135. = osslApi.osNpcCreate(
  136. "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED);
  137. osslApi.osNpcRemove(npcRaw);
  138. UUID npcId = new UUID(npcRaw);
  139. ScenePresence npc = m_scene.GetScenePresence(npcId);
  140. Assert.That(npc, Is.Null);
  141. }
  142. }
  143. }