aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs158
1 files changed, 158 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs
new file mode 100644
index 0000000..af1da7c
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiAvatarTests.cs
@@ -0,0 +1,158 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
45using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
46using OpenSim.Services.Interfaces;
47using OpenSim.Tests.Common;
48using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
49using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
50
51namespace OpenSim.Region.ScriptEngine.Shared.Tests
52{
53 /// <summary>
54 /// Tests relating directly to avatars
55 /// </summary>
56 [TestFixture]
57 public class LSL_ApiAvatarTests : OpenSimTestCase
58 {
59 protected Scene m_scene;
60 protected XEngine.XEngine m_engine;
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
79 /// <summary>
80 /// Test llSetLinkPrimtiveParams for agents.
81 /// </summary>
82 /// <remarks>
83 /// Also testing entity updates here as well. Possibly that's putting 2 different concerns into one test and
84 /// this should be separated.
85 /// </remarks>
86 [Test]
87 public void TestllSetLinkPrimitiveParamsForAgent()
88 {
89 TestHelpers.InMethod();
90// TestHelpers.EnableLogging();
91
92 UUID userId = TestHelpers.ParseTail(0x1);
93
94 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
95 part.RotationOffset = new Quaternion(0.7071068f, 0, 0, 0.7071068f);
96
97 LSL_Api apiGrp1 = new LSL_Api();
98 apiGrp1.Initialize(m_engine, part, null);
99
100 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
101
102 // sp has to be less than 10 meters away from 0, 0, 0 (default part position)
103 Vector3 startPos = new Vector3(3, 2, 1);
104 sp.AbsolutePosition = startPos;
105
106 sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero);
107
108 int entityUpdates = 0;
109 ((TestClient)sp.ControllingClient).OnReceivedEntityUpdate += (entity, flags) => { if (entity is ScenePresence) { entityUpdates++; }};
110
111 // Test position
112 {
113 Vector3 newPos = new Vector3(1, 2, 3);
114 apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
115
116 Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
117
118 m_scene.Update(1);
119 Assert.That(entityUpdates, Is.EqualTo(1));
120 }
121
122 // Test small reposition
123 {
124 Vector3 newPos = new Vector3(1.001f, 2, 3);
125 apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));
126
127 Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));
128
129 m_scene.Update(1);
130 Assert.That(entityUpdates, Is.EqualTo(2));
131 }
132
133 // Test world rotation
134 {
135 Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
136 apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROTATION, newRot));
137
138 Assert.That(
139 sp.Rotation, new QuaternionToleranceConstraint(part.GetWorldRotation() * newRot, 0.000001));
140
141 m_scene.Update(1);
142 Assert.That(entityUpdates, Is.EqualTo(3));
143 }
144
145 // Test local rotation
146 {
147 Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
148 apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROT_LOCAL, newRot));
149
150 Assert.That(
151 sp.Rotation, new QuaternionToleranceConstraint(newRot, 0.000001));
152
153 m_scene.Update(1);
154 Assert.That(entityUpdates, Is.EqualTo(4));
155 }
156 }
157 }
158}