OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
OSSL_ApiAppearanceTest.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Text;
32 using log4net;
33 using Nini.Config;
34 using NUnit.Framework;
35 using OpenMetaverse;
36 using OpenMetaverse.Assets;
37 using OpenMetaverse.StructuredData;
38 using OpenSim.Framework;
39 using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40 using OpenSim.Region.OptionalModules.World.NPC;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.ScriptEngine.Shared;
43 using OpenSim.Region.ScriptEngine.Shared.Api;
44 using OpenSim.Region.ScriptEngine.Shared.Instance;
45 using OpenSim.Services.Interfaces;
46 using OpenSim.Tests.Common;
47 
48 namespace OpenSim.Region.ScriptEngine.Shared.Tests
49 {
53  [TestFixture]
55  {
56  protected Scene m_scene;
58 
59  [SetUp]
60  public override void SetUp()
61  {
62  base.SetUp();
63 
64  IConfigSource initConfigSource = new IniConfigSource();
65  IConfig config = initConfigSource.AddConfig("XEngine");
66  config.Set("Enabled", "true");
67  config.Set("AllowOSFunctions", "true");
68  config.Set("OSFunctionThreatLevel", "Severe");
69  config = initConfigSource.AddConfig("NPC");
70  config.Set("Enabled", "true");
71 
72  m_scene = new SceneHelpers().SetupScene();
73  SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
74 
75  m_engine = new XEngine.XEngine();
76  m_engine.Initialise(initConfigSource);
77  m_engine.AddRegion(m_scene);
78  }
79 
80  [Test]
82  {
83  TestHelpers.InMethod();
84 // log4net.Config.XmlConfigurator.Configure();
85 
86  UUID userId = TestHelpers.ParseTail(0x1);
87  float newHeight = 1.9f;
88 
89  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
90  sp.Appearance.AvatarHeight = newHeight;
91  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
92  SceneObjectPart part = so.RootPart;
93  m_scene.AddSceneObject(so);
94 
95  OSSL_Api osslApi = new OSSL_Api();
96  osslApi.Initialize(m_engine, part, null);
97 
98  string notecardName = "appearanceNc";
99 
100  osslApi.osOwnerSaveAppearance(notecardName);
101 
102  IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
103  Assert.That(items.Count, Is.EqualTo(1));
104 
105  TaskInventoryItem ncItem = items[0];
106  Assert.That(ncItem.Name, Is.EqualTo(notecardName));
107 
108  AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
109  Assert.That(ncAsset, Is.Not.Null);
110 
111  AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
112  anc.Decode();
113  OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
114  AvatarAppearance savedAppearance = new AvatarAppearance();
115  savedAppearance.Unpack(appearanceOsd);
116 
117  Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
118  }
119 
120  [Test]
122  {
123  TestHelpers.InMethod();
124 // log4net.Config.XmlConfigurator.Configure();
125 
126  UUID ownerId = TestHelpers.ParseTail(0x1);
127  UUID nonOwnerId = TestHelpers.ParseTail(0x2);
128  float newHeight = 1.9f;
129 
130  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId);
131  sp.Appearance.AvatarHeight = newHeight;
132  SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId, 0x10);
133  SceneObjectPart part = so.RootPart;
134  m_scene.AddSceneObject(so);
135 
136  OSSL_Api osslApi = new OSSL_Api();
137  osslApi.Initialize(m_engine, part, null);
138 
139  string notecardName = "appearanceNc";
140 
141  osslApi.osAgentSaveAppearance(new LSL_Types.LSLString(nonOwnerId.ToString()), notecardName);
142 
143  IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
144  Assert.That(items.Count, Is.EqualTo(1));
145 
146  TaskInventoryItem ncItem = items[0];
147  Assert.That(ncItem.Name, Is.EqualTo(notecardName));
148 
149  AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
150  Assert.That(ncAsset, Is.Not.Null);
151 
152  AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
153  anc.Decode();
154  OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
155  AvatarAppearance savedAppearance = new AvatarAppearance();
156  savedAppearance.Unpack(appearanceOsd);
157 
158  Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
159  }
160  }
161 }
Contains the Avatar's Appearance and methods to manipulate the appearance.
OpenMetaverse.StructuredData.OSDMap OSDMap
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60