aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiUserTests.cs157
1 files changed, 157 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiUserTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiUserTests.cs
new file mode 100644
index 0000000..6424ea1
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiUserTests.cs
@@ -0,0 +1,157 @@
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.Threading;
31using Nini.Config;
32using NUnit.Framework;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.ScriptEngine.Shared.Api;
37using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
38using OpenSim.Services.Interfaces;
39using OpenSim.Tests.Common;
40
41namespace OpenSim.Region.ScriptEngine.Shared.Tests
42{
43 [TestFixture]
44 public class LSL_ApiUserTests : OpenSimTestCase
45 {
46 private Scene m_scene;
47 private MockScriptEngine m_engine;
48
49 [SetUp]
50 public override void SetUp()
51 {
52 base.SetUp();
53
54 m_engine = new MockScriptEngine();
55
56 m_scene = new SceneHelpers().SetupScene();
57 SceneHelpers.SetupSceneModules(m_scene, m_engine);
58 }
59
60 [Test]
61 public void TestLlRequestAgentDataOnline()
62 {
63 TestHelpers.InMethod();
64// TestHelpers.EnableLogging();
65
66 UUID userId = TestHelpers.ParseTail(0x1);
67
68 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
69
70 SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
71 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, part);
72
73 LSL_Api apiGrp1 = new LSL_Api();
74 apiGrp1.Initialize(m_engine, part, scriptItem, null);
75
76 // Initially long timeout to test cache
77 apiGrp1.LlRequestAgentDataCacheTimeoutMs = 20000;
78
79 // Offline test
80 {
81 apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);
82
83 Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));
84
85 List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
86 Assert.That(events.Count, Is.EqualTo(1));
87 EventParams eventParams = events[0];
88 Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));
89
90 string data = eventParams.Params[1].ToString();
91 Assert.AreEqual(0, int.Parse(data));
92
93 m_engine.PostedEvents.Clear();
94 }
95
96 // Online test. Should get the 'wrong' result because of caching.
97 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);
98
99 {
100 apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);
101
102 Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));
103
104 List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
105 Assert.That(events.Count, Is.EqualTo(1));
106 EventParams eventParams = events[0];
107 Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));
108
109 string data = eventParams.Params[1].ToString();
110 Assert.AreEqual(0, int.Parse(data));
111
112 m_engine.PostedEvents.Clear();
113 }
114
115 apiGrp1.LlRequestAgentDataCacheTimeoutMs = 1;
116
117 // Make absolutely sure that we should trigger cache timeout.
118 Thread.Sleep(apiGrp1.LlRequestAgentDataCacheTimeoutMs + 1);
119
120 {
121 apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);
122
123 Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));
124
125 List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
126 Assert.That(events.Count, Is.EqualTo(1));
127 EventParams eventParams = events[0];
128 Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));
129
130 string data = eventParams.Params[1].ToString();
131 Assert.AreEqual(1, int.Parse(data));
132
133 m_engine.PostedEvents.Clear();
134 }
135
136 m_scene.CloseAgent(userId, false);
137
138 Thread.Sleep(apiGrp1.LlRequestAgentDataCacheTimeoutMs + 1 + 1);
139
140 {
141 apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);
142
143 Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));
144
145 List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
146 Assert.That(events.Count, Is.EqualTo(1));
147 EventParams eventParams = events[0];
148 Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));
149
150 string data = eventParams.Params[1].ToString();
151 Assert.AreEqual(0, int.Parse(data));
152
153 m_engine.PostedEvents.Clear();
154 }
155 }
156 }
157} \ No newline at end of file