OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LSL_ApiAvatarTests.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.Region.ScriptEngine.Shared.ScriptBase;
46 using OpenSim.Services.Interfaces;
47 using OpenSim.Tests.Common;
50 
51 namespace OpenSim.Region.ScriptEngine.Shared.Tests
52 {
56  [TestFixture]
58  {
59  protected Scene m_scene;
61 
62  [SetUp]
63  public override void SetUp()
64  {
65  base.SetUp();
66 
67  IConfigSource initConfigSource = new IniConfigSource();
68  IConfig config = initConfigSource.AddConfig("XEngine");
69  config.Set("Enabled", "true");
70 
71  m_scene = new SceneHelpers().SetupScene();
72  SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
73 
74  m_engine = new XEngine.XEngine();
75  m_engine.Initialise(initConfigSource);
76  m_engine.AddRegion(m_scene);
77  }
78 
86  [Test]
88  {
89 /* siting avatars position changed
90  TestHelpers.InMethod();
91 // TestHelpers.EnableLogging();
92 
93  UUID userId = TestHelpers.ParseTail(0x1);
94 
95  SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
96  part.RotationOffset = new Quaternion(0.7071068f, 0, 0, 0.7071068f);
97 
98  LSL_Api apiGrp1 = new LSL_Api();
99  apiGrp1.Initialize(m_engine, part, null);
100 
101  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
102 
103  // sp has to be less than 10 meters away from 0, 0, 0 (default part position)
104  Vector3 startPos = new Vector3(3, 2, 1);
105  sp.AbsolutePosition = startPos;
106 
107  sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero);
108 
109  int entityUpdates = 0;
110  ((TestClient)sp.ControllingClient).OnReceivedEntityUpdate += (entity, flags) => { if (entity is ScenePresence) { entityUpdates++; }};
111 
112  // Test position
113  {
114  Vector3 newPos = new Vector3(1, 2, 3);
115  apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
116 
117  Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
118 
119  m_scene.Update(1);
120  Assert.That(entityUpdates, Is.EqualTo(1));
121  }
122 
123  // Test small reposition
124  {
125  Vector3 newPos = new Vector3(1.001f, 2, 3);
126  apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
127 
128  Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
129 
130  m_scene.Update(1);
131  Assert.That(entityUpdates, Is.EqualTo(2));
132  }
133 
134  // Test world rotation
135  {
136  Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
137  apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROTATION, newRot));
138 
139  Assert.That(
140  sp.Rotation, new QuaternionToleranceConstraint(part.GetWorldRotation() * newRot, 0.000001));
141 
142  m_scene.Update(1);
143  Assert.That(entityUpdates, Is.EqualTo(3));
144  }
145 
146  // Test local rotation
147  {
148  Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
149  apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROT_LOCAL, newRot));
150 
151  Assert.That(
152  sp.Rotation, new QuaternionToleranceConstraint(newRot, 0.000001));
153 
154  m_scene.Update(1);
155  Assert.That(entityUpdates, Is.EqualTo(4));
156  }
157 */
158  }
159  }
160 }
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: CM_Api.cs:51
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: CM_Api.cs:49
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
void TestllSetLinkPrimitiveParamsForAgent()
Test llSetLinkPrimtiveParams for agents.
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSLInteger
Definition: CM_Constants.cs:31