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.cs247
1 files changed, 247 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..53ce405
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs
@@ -0,0 +1,247 @@
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 TestMovingEndEvent()
52 {
53 TestHelpers.InMethod();
54// TestHelpers.EnableLogging();
55
56 TestVoidArgEvent("moving_end");
57 }
58
59 [Test]
60 public void TestMovingStartEvent()
61 {
62 TestHelpers.InMethod();
63// TestHelpers.EnableLogging();
64
65 TestVoidArgEvent("moving_start");
66 }
67
68 [Test]
69 public void TestNoSensorEvent()
70 {
71 TestHelpers.InMethod();
72// TestHelpers.EnableLogging();
73
74 TestVoidArgEvent("no_sensor");
75 }
76
77 [Test]
78 public void TestNotAtRotTargetEvent()
79 {
80 TestHelpers.InMethod();
81// TestHelpers.EnableLogging();
82
83 TestVoidArgEvent("not_at_rot_target");
84 }
85
86 [Test]
87 public void TestNotAtTargetEvent()
88 {
89 TestHelpers.InMethod();
90// TestHelpers.EnableLogging();
91
92 TestVoidArgEvent("not_at_target");
93 }
94
95 [Test]
96 public void TestStateEntryEvent()
97 {
98 TestHelpers.InMethod();
99// TestHelpers.EnableLogging();
100
101 TestVoidArgEvent("state_entry");
102 }
103
104 [Test]
105 public void TestStateExitEvent()
106 {
107 TestHelpers.InMethod();
108// TestHelpers.EnableLogging();
109
110 TestVoidArgEvent("state_exit");
111 }
112
113 [Test]
114 public void TestTimerEvent()
115 {
116 TestHelpers.InMethod();
117// TestHelpers.EnableLogging();
118
119 TestVoidArgEvent("timer");
120 }
121
122 private void TestVoidArgEvent(string eventName)
123 {
124 TestCompile("default { " + eventName + "() {} }", false);
125 TestCompile("default { " + eventName + "(integer n) {} }", true);
126 }
127
128 [Test]
129 public void TestChangedEvent()
130 {
131 TestHelpers.InMethod();
132// TestHelpers.EnableLogging();
133
134 TestIntArgEvent("changed");
135 }
136
137 [Test]
138 public void TestCollisionEvent()
139 {
140 TestHelpers.InMethod();
141// TestHelpers.EnableLogging();
142
143 TestIntArgEvent("collision");
144 }
145
146 [Test]
147 public void TestCollisionStartEvent()
148 {
149 TestHelpers.InMethod();
150// TestHelpers.EnableLogging();
151
152 TestIntArgEvent("collision_start");
153 }
154
155 [Test]
156 public void TestCollisionEndEvent()
157 {
158 TestHelpers.InMethod();
159// TestHelpers.EnableLogging();
160
161 TestIntArgEvent("collision_end");
162 }
163
164 [Test]
165 public void TestOnRezEvent()
166 {
167 TestHelpers.InMethod();
168// TestHelpers.EnableLogging();
169
170 TestIntArgEvent("on_rez");
171 }
172
173 [Test]
174 public void TestRunTimePermissionsEvent()
175 {
176 TestHelpers.InMethod();
177// TestHelpers.EnableLogging();
178
179 TestIntArgEvent("run_time_permissions");
180 }
181
182 [Test]
183 public void TestSensorEvent()
184 {
185 TestHelpers.InMethod();
186// TestHelpers.EnableLogging();
187
188 TestIntArgEvent("sensor");
189 }
190
191 [Test]
192 public void TestTouchEvent()
193 {
194 TestHelpers.InMethod();
195// TestHelpers.EnableLogging();
196
197 TestIntArgEvent("touch");
198 }
199
200 [Test]
201 public void TestTouchStartEvent()
202 {
203 TestHelpers.InMethod();
204// TestHelpers.EnableLogging();
205
206 TestIntArgEvent("touch_start");
207 }
208
209 [Test]
210 public void TestTouchEndEvent()
211 {
212 TestHelpers.InMethod();
213// TestHelpers.EnableLogging();
214
215 TestIntArgEvent("touch_end");
216 }
217
218 private void TestIntArgEvent(string eventName)
219 {
220 TestCompile("default { " + eventName + "(integer n) {} }", false);
221 TestCompile("default { " + eventName + "{{}} }", true);
222 TestCompile("default { " + eventName + "(string s) {{}} }", true);
223 TestCompile("default { " + eventName + "(integer n, integer o) {{}} }", true);
224 }
225
226 private void TestCompile(string script, bool expectException)
227 {
228 bool gotException = false;
229 Exception ge = null;
230
231 try
232 {
233 m_cg.Convert(script);
234 }
235 catch (Exception e)
236 {
237 gotException = true;
238 ge = e;
239 }
240
241 Assert.That(
242 gotException,
243 Is.EqualTo(expectException),
244 "Failed on {0}, exception {1}", script, ge != null ? ge.ToString() : "n/a");
245 }
246 }
247} \ No newline at end of file