aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs359
1 files changed, 359 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs
new file mode 100644
index 0000000..67ce10a
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs
@@ -0,0 +1,359 @@
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.Text.RegularExpressions;
31using NUnit.Framework;
32using OpenSim.Region.ScriptEngine.Shared.CodeTools;
33using OpenSim.Tests.Common;
34
35namespace OpenSim.Region.ScriptEngine.Shared.Tests
36{
37 public class LSL_EventTests : OpenSimTestCase
38 {
39 CSCodeGenerator m_cg = new CSCodeGenerator();
40
41 [Test]
42 public void TestBadEvent()
43 {
44 TestHelpers.InMethod();
45// TestHelpers.EnableLogging();
46
47 TestCompile("default { bad() {} }", true);
48 }
49
50 [Test]
51 public void TestAttachEvent()
52 {
53 TestHelpers.InMethod();
54// TestHelpers.EnableLogging();
55
56 TestKeyArgEvent("attach");
57 }
58
59 [Test]
60 public void TestObjectRezEvent()
61 {
62 TestHelpers.InMethod();
63// TestHelpers.EnableLogging();
64
65 TestKeyArgEvent("object_rez");
66 }
67
68 [Test]
69 public void TestMovingEndEvent()
70 {
71 TestHelpers.InMethod();
72// TestHelpers.EnableLogging();
73
74 TestVoidArgEvent("moving_end");
75 }
76
77 [Test]
78 public void TestMovingStartEvent()
79 {
80 TestHelpers.InMethod();
81// TestHelpers.EnableLogging();
82
83 TestVoidArgEvent("moving_start");
84 }
85
86 [Test]
87 public void TestNoSensorEvent()
88 {
89 TestHelpers.InMethod();
90// TestHelpers.EnableLogging();
91
92 TestVoidArgEvent("no_sensor");
93 }
94
95 [Test]
96 public void TestNotAtRotTargetEvent()
97 {
98 TestHelpers.InMethod();
99// TestHelpers.EnableLogging();
100
101 TestVoidArgEvent("not_at_rot_target");
102 }
103
104 [Test]
105 public void TestNotAtTargetEvent()
106 {
107 TestHelpers.InMethod();
108// TestHelpers.EnableLogging();
109
110 TestVoidArgEvent("not_at_target");
111 }
112
113 [Test]
114 public void TestStateEntryEvent()
115 {
116 TestHelpers.InMethod();
117// TestHelpers.EnableLogging();
118
119 TestVoidArgEvent("state_entry");
120 }
121
122 [Test]
123 public void TestStateExitEvent()
124 {
125 TestHelpers.InMethod();
126// TestHelpers.EnableLogging();
127
128 TestVoidArgEvent("state_exit");
129 }
130
131 [Test]
132 public void TestTimerEvent()
133 {
134 TestHelpers.InMethod();
135// TestHelpers.EnableLogging();
136
137 TestVoidArgEvent("timer");
138 }
139
140 private void TestVoidArgEvent(string eventName)
141 {
142 TestCompile("default { " + eventName + "() {} }", false);
143 TestCompile("default { " + eventName + "(integer n) {} }", true);
144 }
145
146 [Test]
147 public void TestChangedEvent()
148 {
149 TestHelpers.InMethod();
150// TestHelpers.EnableLogging();
151
152 TestIntArgEvent("changed");
153 }
154
155 [Test]
156 public void TestCollisionEvent()
157 {
158 TestHelpers.InMethod();
159// TestHelpers.EnableLogging();
160
161 TestIntArgEvent("collision");
162 }
163
164 [Test]
165 public void TestCollisionStartEvent()
166 {
167 TestHelpers.InMethod();
168// TestHelpers.EnableLogging();
169
170 TestIntArgEvent("collision_start");
171 }
172
173 [Test]
174 public void TestCollisionEndEvent()
175 {
176 TestHelpers.InMethod();
177// TestHelpers.EnableLogging();
178
179 TestIntArgEvent("collision_end");
180 }
181
182 [Test]
183 public void TestOnRezEvent()
184 {
185 TestHelpers.InMethod();
186// TestHelpers.EnableLogging();
187
188 TestIntArgEvent("on_rez");
189 }
190
191 [Test]
192 public void TestRunTimePermissionsEvent()
193 {
194 TestHelpers.InMethod();
195// TestHelpers.EnableLogging();
196
197 TestIntArgEvent("run_time_permissions");
198 }
199
200 [Test]
201 public void TestSensorEvent()
202 {
203 TestHelpers.InMethod();
204// TestHelpers.EnableLogging();
205
206 TestIntArgEvent("sensor");
207 }
208
209 [Test]
210 public void TestTouchEvent()
211 {
212 TestHelpers.InMethod();
213// TestHelpers.EnableLogging();
214
215 TestIntArgEvent("touch");
216 }
217
218 [Test]
219 public void TestTouchStartEvent()
220 {
221 TestHelpers.InMethod();
222// TestHelpers.EnableLogging();
223
224 TestIntArgEvent("touch_start");
225 }
226
227 [Test]
228 public void TestTouchEndEvent()
229 {
230 TestHelpers.InMethod();
231// TestHelpers.EnableLogging();
232
233 TestIntArgEvent("touch_end");
234 }
235
236 [Test]
237 public void TestLandCollisionEvent()
238 {
239 TestHelpers.InMethod();
240// TestHelpers.EnableLogging();
241
242 TestVectorArgEvent("land_collision");
243 }
244
245 [Test]
246 public void TestLandCollisionStartEvent()
247 {
248 TestHelpers.InMethod();
249// TestHelpers.EnableLogging();
250
251 TestVectorArgEvent("land_collision_start");
252 }
253
254 [Test]
255 public void TestLandCollisionEndEvent()
256 {
257 TestHelpers.InMethod();
258// TestHelpers.EnableLogging();
259
260 TestVectorArgEvent("land_collision_end");
261 }
262
263 [Test]
264 public void TestAtRotTargetEvent()
265 {
266 TestHelpers.InMethod();
267// TestHelpers.EnableLogging();
268
269 TestIntRotRotArgEvent("at_rot_target");
270 }
271
272 [Test]
273 public void TestAtTargetEvent()
274 {
275 TestHelpers.InMethod();
276// TestHelpers.EnableLogging();
277
278 TestIntVecVecArgEvent("at_target");
279 }
280
281 [Test]
282 public void TestControlEvent()
283 {
284 TestHelpers.InMethod();
285// TestHelpers.EnableLogging();
286
287 TestKeyIntIntArgEvent("control");
288 }
289
290 private void TestIntArgEvent(string eventName)
291 {
292 TestCompile("default { " + eventName + "(integer n) {} }", false);
293 TestCompile("default { " + eventName + "{{}} }", true);
294 TestCompile("default { " + eventName + "(string s) {{}} }", true);
295 TestCompile("default { " + eventName + "(integer n, integer o) {{}} }", true);
296 }
297
298 private void TestKeyArgEvent(string eventName)
299 {
300 TestCompile("default { " + eventName + "(key k) {} }", false);
301 TestCompile("default { " + eventName + "{{}} }", true);
302 TestCompile("default { " + eventName + "(string s) {{}} }", true);
303 TestCompile("default { " + eventName + "(key k, key l) {{}} }", true);
304 }
305
306 private void TestVectorArgEvent(string eventName)
307 {
308 TestCompile("default { " + eventName + "(vector v) {} }", false);
309 TestCompile("default { " + eventName + "{{}} }", true);
310 TestCompile("default { " + eventName + "(string s) {{}} }", true);
311 TestCompile("default { " + eventName + "(vector v, vector w) {{}} }", true);
312 }
313
314 private void TestIntRotRotArgEvent(string eventName)
315 {
316 TestCompile("default { " + eventName + "(integer n, rotation r, rotation s) {} }", false);
317 TestCompile("default { " + eventName + "{{}} }", true);
318 TestCompile("default { " + eventName + "(string s) {{}} }", true);
319 TestCompile("default { " + eventName + "(integer n, rotation r, rotation s, rotation t) {{}} }", true);
320 }
321
322 private void TestIntVecVecArgEvent(string eventName)
323 {
324 TestCompile("default { " + eventName + "(integer n, vector v, vector w) {} }", false);
325 TestCompile("default { " + eventName + "{{}} }", true);
326 TestCompile("default { " + eventName + "(string s) {{}} }", true);
327 TestCompile("default { " + eventName + "(integer n, vector v, vector w, vector x) {{}} }", true);
328 }
329
330 private void TestKeyIntIntArgEvent(string eventName)
331 {
332 TestCompile("default { " + eventName + "(key k, integer n, integer o) {} }", false);
333 TestCompile("default { " + eventName + "{{}} }", true);
334 TestCompile("default { " + eventName + "(string s) {{}} }", true);
335 TestCompile("default { " + eventName + "(key k, integer n, integer o, integer p) {{}} }", true);
336 }
337
338 private void TestCompile(string script, bool expectException)
339 {
340 bool gotException = false;
341 Exception ge = null;
342
343 try
344 {
345 m_cg.Convert(script);
346 }
347 catch (Exception e)
348 {
349 gotException = true;
350 ge = e;
351 }
352
353 Assert.That(
354 gotException,
355 Is.EqualTo(expectException),
356 "Failed on {0}, exception {1}", script, ge != null ? ge.ToString() : "n/a");
357 }
358 }
359} \ No newline at end of file