clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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;
48 using OpenSim.Tests.Common.Mock;
49 using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
50 using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
51  
52 namespace OpenSim.Region.ScriptEngine.Shared.Tests
53 {
54 /// <summary>
55 /// Tests relating directly to avatars
56 /// </summary>
57 [TestFixture]
58 public class LSL_ApiAvatarTests : OpenSimTestCase
59 {
60 protected Scene m_scene;
61 protected XEngine.XEngine m_engine;
62  
63 [SetUp]
64 public override void SetUp()
65 {
66 base.SetUp();
67  
68 IConfigSource initConfigSource = new IniConfigSource();
69 IConfig config = initConfigSource.AddConfig("XEngine");
70 config.Set("Enabled", "true");
71  
72 m_scene = new SceneHelpers().SetupScene();
73 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
74  
75 m_engine = new XEngine.XEngine();
76 m_engine.Initialise(initConfigSource);
77 m_engine.AddRegion(m_scene);
78 }
79  
80 /// <summary>
81 /// Test llSetLinkPrimtiveParams for agents.
82 /// </summary>
83 /// <remarks>
84 /// Also testing entity updates here as well. Possibly that's putting 2 different concerns into one test and
85 /// this should be separated.
86 /// </remarks>
87 [Test]
88 public void TestllSetLinkPrimitiveParamsForAgent()
89 {
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, 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 }