OSSL_ApiAppearanceTest.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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.Services.Interfaces;
  44. using OpenSim.Tests.Common;
  45. using OpenSim.Tests.Common.Mock;
  46. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  47. {
  48. /// <summary>
  49. /// Tests for OSSL_Api
  50. /// </summary>
  51. [TestFixture]
  52. public class OSSL_ApiAppearanceTest
  53. {
  54. protected Scene m_scene;
  55. protected XEngine.XEngine m_engine;
  56. [SetUp]
  57. public void SetUp()
  58. {
  59. IConfigSource initConfigSource = new IniConfigSource();
  60. IConfig config = initConfigSource.AddConfig("XEngine");
  61. config.Set("Enabled", "true");
  62. config.Set("AllowOSFunctions", "true");
  63. config.Set("OSFunctionThreatLevel", "Severe");
  64. config = initConfigSource.AddConfig("NPC");
  65. config.Set("Enabled", "true");
  66. m_scene = new SceneHelpers().SetupScene();
  67. SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
  68. m_engine = new XEngine.XEngine();
  69. m_engine.Initialise(initConfigSource);
  70. m_engine.AddRegion(m_scene);
  71. }
  72. /// <summary>
  73. /// Test creation of an NPC where the appearance data comes from a notecard
  74. /// </summary>
  75. [Test]
  76. public void TestOsNpcCreateUsingAppearanceFromNotecard()
  77. {
  78. TestHelpers.InMethod();
  79. // log4net.Config.XmlConfigurator.Configure();
  80. // Store an avatar with a different height from default in a notecard.
  81. UUID userId = TestHelpers.ParseTail(0x1);
  82. float newHeight = 1.9f;
  83. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  84. sp.Appearance.AvatarHeight = newHeight;
  85. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
  86. SceneObjectPart part = so.RootPart;
  87. m_scene.AddSceneObject(so);
  88. OSSL_Api osslApi = new OSSL_Api();
  89. osslApi.Initialize(m_engine, part, null);
  90. string notecardName = "appearanceNc";
  91. osslApi.osOwnerSaveAppearance(notecardName);
  92. // Try creating a bot using the appearance in the notecard.
  93. string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName);
  94. Assert.That(npcRaw, Is.Not.Null);
  95. UUID npcId = new UUID(npcRaw);
  96. ScenePresence npc = m_scene.GetScenePresence(npcId);
  97. Assert.That(npc, Is.Not.Null);
  98. Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
  99. }
  100. /// <summary>
  101. /// Test creation of an NPC where the appearance data comes from an avatar already in the region.
  102. /// </summary>
  103. [Test]
  104. public void TestOsNpcCreateUsingAppearanceFromAvatar()
  105. {
  106. TestHelpers.InMethod();
  107. // TestHelpers.EnableLogging();
  108. // Store an avatar with a different height from default in a notecard.
  109. UUID userId = TestHelpers.ParseTail(0x1);
  110. float newHeight = 1.9f;
  111. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  112. sp.Appearance.AvatarHeight = newHeight;
  113. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
  114. SceneObjectPart part = so.RootPart;
  115. m_scene.AddSceneObject(so);
  116. OSSL_Api osslApi = new OSSL_Api();
  117. osslApi.Initialize(m_engine, part, null);
  118. string notecardName = "appearanceNc";
  119. osslApi.osOwnerSaveAppearance(notecardName);
  120. // Try creating a bot using the existing avatar's appearance
  121. string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString());
  122. Assert.That(npcRaw, Is.Not.Null);
  123. UUID npcId = new UUID(npcRaw);
  124. ScenePresence npc = m_scene.GetScenePresence(npcId);
  125. Assert.That(npc, Is.Not.Null);
  126. Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
  127. }
  128. [Test]
  129. public void TestOsOwnerSaveAppearance()
  130. {
  131. TestHelpers.InMethod();
  132. // log4net.Config.XmlConfigurator.Configure();
  133. UUID userId = TestHelpers.ParseTail(0x1);
  134. float newHeight = 1.9f;
  135. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  136. sp.Appearance.AvatarHeight = newHeight;
  137. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
  138. SceneObjectPart part = so.RootPart;
  139. m_scene.AddSceneObject(so);
  140. OSSL_Api osslApi = new OSSL_Api();
  141. osslApi.Initialize(m_engine, part, null);
  142. string notecardName = "appearanceNc";
  143. osslApi.osOwnerSaveAppearance(notecardName);
  144. IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
  145. Assert.That(items.Count, Is.EqualTo(1));
  146. TaskInventoryItem ncItem = items[0];
  147. Assert.That(ncItem.Name, Is.EqualTo(notecardName));
  148. AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
  149. Assert.That(ncAsset, Is.Not.Null);
  150. AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
  151. anc.Decode();
  152. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
  153. AvatarAppearance savedAppearance = new AvatarAppearance();
  154. savedAppearance.Unpack(appearanceOsd);
  155. Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
  156. }
  157. [Test]
  158. public void TestOsAgentSaveAppearance()
  159. {
  160. TestHelpers.InMethod();
  161. // log4net.Config.XmlConfigurator.Configure();
  162. UUID ownerId = TestHelpers.ParseTail(0x1);
  163. UUID nonOwnerId = TestHelpers.ParseTail(0x2);
  164. float newHeight = 1.9f;
  165. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId);
  166. sp.Appearance.AvatarHeight = newHeight;
  167. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId, 0x10);
  168. SceneObjectPart part = so.RootPart;
  169. m_scene.AddSceneObject(so);
  170. OSSL_Api osslApi = new OSSL_Api();
  171. osslApi.Initialize(m_engine, part, null);
  172. string notecardName = "appearanceNc";
  173. osslApi.osAgentSaveAppearance(new LSL_Types.LSLString(nonOwnerId.ToString()), notecardName);
  174. IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
  175. Assert.That(items.Count, Is.EqualTo(1));
  176. TaskInventoryItem ncItem = items[0];
  177. Assert.That(ncItem.Name, Is.EqualTo(notecardName));
  178. AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
  179. Assert.That(ncAsset, Is.Not.Null);
  180. AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
  181. anc.Decode();
  182. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
  183. AvatarAppearance savedAppearance = new AvatarAppearance();
  184. savedAppearance.Unpack(appearanceOsd);
  185. Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
  186. }
  187. }
  188. }