diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests')
3 files changed, 450 insertions, 34 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index 77e087c..b92f3a3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | |||
@@ -762,6 +762,7 @@ default | |||
762 | public void TestIfStatement() | 762 | public void TestIfStatement() |
763 | { | 763 | { |
764 | TestHelpers.InMethod(); | 764 | TestHelpers.InMethod(); |
765 | // TestHelpers.EnableLogging(); | ||
765 | 766 | ||
766 | string input = @"// let's test if statements | 767 | string input = @"// let's test if statements |
767 | 768 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 05a8756..b476e32 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs | |||
@@ -25,12 +25,14 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.IO; | 29 | using System.IO; |
29 | using System.CodeDom.Compiler; | 30 | using System.CodeDom.Compiler; |
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using Microsoft.CSharp; | 32 | using Microsoft.CSharp; |
32 | using NUnit.Framework; | 33 | using NUnit.Framework; |
33 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | 34 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; |
35 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
34 | using OpenSim.Tests.Common; | 36 | using OpenSim.Tests.Common; |
35 | 37 | ||
36 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | 38 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests |
@@ -46,7 +48,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
46 | private string m_testDir; | 48 | private string m_testDir; |
47 | private CSharpCodeProvider m_CSCodeProvider; | 49 | private CSharpCodeProvider m_CSCodeProvider; |
48 | private CompilerParameters m_compilerParameters; | 50 | private CompilerParameters m_compilerParameters; |
49 | private CompilerResults m_compilerResults; | 51 | // private CompilerResults m_compilerResults; |
52 | private ResolveEventHandler m_resolveEventHandler; | ||
50 | 53 | ||
51 | /// <summary> | 54 | /// <summary> |
52 | /// Creates a temporary directory where build artifacts are stored. | 55 | /// Creates a temporary directory where build artifacts are stored. |
@@ -61,14 +64,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
61 | // Create the temporary directory for housing build artifacts. | 64 | // Create the temporary directory for housing build artifacts. |
62 | Directory.CreateDirectory(m_testDir); | 65 | Directory.CreateDirectory(m_testDir); |
63 | } | 66 | } |
67 | } | ||
68 | |||
69 | [SetUp] | ||
70 | public override void SetUp() | ||
71 | { | ||
72 | base.SetUp(); | ||
64 | 73 | ||
65 | // Create a CSCodeProvider and CompilerParameters. | 74 | // Create a CSCodeProvider and CompilerParameters. |
66 | m_CSCodeProvider = new CSharpCodeProvider(); | 75 | m_CSCodeProvider = new CSharpCodeProvider(); |
67 | m_compilerParameters = new CompilerParameters(); | 76 | m_compilerParameters = new CompilerParameters(); |
68 | 77 | ||
69 | string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin"); | 78 | string rootPath = System.AppDomain.CurrentDomain.BaseDirectory; |
79 | |||
80 | m_resolveEventHandler = new ResolveEventHandler(AssemblyResolver.OnAssemblyResolve); | ||
81 | |||
82 | System.AppDomain.CurrentDomain.AssemblyResolve += m_resolveEventHandler; | ||
83 | |||
70 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); | 84 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll")); |
71 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); | 85 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); |
86 | m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenMetaverseTypes.dll")); | ||
72 | m_compilerParameters.GenerateExecutable = false; | 87 | m_compilerParameters.GenerateExecutable = false; |
73 | } | 88 | } |
74 | 89 | ||
@@ -76,9 +91,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
76 | /// Removes the temporary build directory and any build artifacts | 91 | /// Removes the temporary build directory and any build artifacts |
77 | /// inside it. | 92 | /// inside it. |
78 | /// </summary> | 93 | /// </summary> |
79 | [TestFixtureTearDown] | 94 | [TearDown] |
80 | public void CleanUp() | 95 | public void CleanUp() |
81 | { | 96 | { |
97 | System.AppDomain.CurrentDomain.AssemblyResolve -= m_resolveEventHandler; | ||
98 | |||
82 | if (Directory.Exists(m_testDir)) | 99 | if (Directory.Exists(m_testDir)) |
83 | { | 100 | { |
84 | // Blow away the temporary directory with artifacts. | 101 | // Blow away the temporary directory with artifacts. |
@@ -86,52 +103,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
86 | } | 103 | } |
87 | } | 104 | } |
88 | 105 | ||
106 | private CompilerResults CompileScript( | ||
107 | string input, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap) | ||
108 | { | ||
109 | m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); | ||
110 | |||
111 | CSCodeGenerator cg = new CSCodeGenerator(); | ||
112 | string output = cg.Convert(input); | ||
113 | |||
114 | output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); | ||
115 | // System.Console.WriteLine(output); | ||
116 | |||
117 | positionMap = cg.PositionMap; | ||
118 | |||
119 | CompilerResults compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); | ||
120 | |||
121 | // foreach (KeyValuePair<int, int> key in positionMap.Keys) | ||
122 | // { | ||
123 | // KeyValuePair<int, int> val = positionMap[key]; | ||
124 | // | ||
125 | // System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value); | ||
126 | // } | ||
127 | // | ||
128 | // foreach (CompilerError compErr in m_compilerResults.Errors) | ||
129 | // { | ||
130 | // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); | ||
131 | // } | ||
132 | |||
133 | return compilerResults; | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Test that line number errors are resolved as expected when preceding code contains a jump. | ||
138 | /// </summary> | ||
139 | [Test] | ||
140 | public void TestJumpAndSyntaxError() | ||
141 | { | ||
142 | TestHelpers.InMethod(); | ||
143 | |||
144 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap; | ||
145 | |||
146 | CompilerResults compilerResults = CompileScript( | ||
147 | @"default | ||
148 | { | ||
149 | state_entry() | ||
150 | { | ||
151 | jump l; | ||
152 | @l; | ||
153 | i = 1; | ||
154 | } | ||
155 | }", out positionMap); | ||
156 | |||
157 | Assert.AreEqual( | ||
158 | new KeyValuePair<int, int>(7, 9), | ||
159 | positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); | ||
160 | } | ||
161 | |||
89 | /// <summary> | 162 | /// <summary> |
90 | /// Test the C# compiler error message can be mapped to the correct | 163 | /// Test the C# compiler error message can be mapped to the correct |
91 | /// line/column in the LSL source when an undeclared variable is used. | 164 | /// line/column in the LSL source when an undeclared variable is used. |
92 | /// </summary> | 165 | /// </summary> |
93 | //[Test] | 166 | [Test] |
94 | public void TestUseUndeclaredVariable() | 167 | public void TestUseUndeclaredVariable() |
95 | { | 168 | { |
96 | TestHelpers.InMethod(); | 169 | TestHelpers.InMethod(); |
97 | 170 | ||
98 | m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); | 171 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap; |
99 | 172 | ||
100 | string input = @"default | 173 | CompilerResults compilerResults = CompileScript( |
174 | @"default | ||
101 | { | 175 | { |
102 | state_entry() | 176 | state_entry() |
103 | { | 177 | { |
104 | integer y = x + 3; | 178 | integer y = x + 3; |
105 | } | 179 | } |
106 | }"; | 180 | }", out positionMap); |
107 | 181 | ||
108 | CSCodeGenerator cg = new CSCodeGenerator(); | 182 | Assert.AreEqual( |
109 | string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + | 183 | new KeyValuePair<int, int>(5, 21), |
110 | "namespace SecondLife { " + | 184 | positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); |
111 | "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + | ||
112 | "public Script() { } " + | ||
113 | cg.Convert(input) + | ||
114 | "} }\n"; | ||
115 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap; | ||
116 | |||
117 | m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); | ||
118 | |||
119 | Assert.AreEqual(new KeyValuePair<int, int>(5, 21), | ||
120 | positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); | ||
121 | } | 185 | } |
122 | 186 | ||
123 | /// <summary> | 187 | /// <summary> |
124 | /// Test that a string can be cast to string and another string | 188 | /// Test that a string can be cast to string and another string |
125 | /// concatenated. | 189 | /// concatenated. |
126 | /// </summary> | 190 | /// </summary> |
127 | //[Test] | 191 | [Test] |
128 | public void TestCastAndConcatString() | 192 | public void TestCastAndConcatString() |
129 | { | 193 | { |
130 | TestHelpers.InMethod(); | 194 | TestHelpers.InMethod(); |
131 | 195 | ||
132 | m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); | 196 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap; |
133 | 197 | ||
134 | string input = @"string s = "" a string""; | 198 | CompilerResults compilerResults = CompileScript( |
199 | @"string s = "" a string""; | ||
135 | 200 | ||
136 | default | 201 | default |
137 | { | 202 | { |
@@ -141,18 +206,9 @@ default | |||
141 | string tmp = (string) gAvatarKey + s; | 206 | string tmp = (string) gAvatarKey + s; |
142 | llSay(0, tmp); | 207 | llSay(0, tmp); |
143 | } | 208 | } |
144 | }"; | 209 | }", out positionMap); |
145 | 210 | ||
146 | CSCodeGenerator cg = new CSCodeGenerator(); | 211 | Assert.AreEqual(0, compilerResults.Errors.Count); |
147 | string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" + | ||
148 | "namespace SecondLife { " + | ||
149 | "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" + | ||
150 | "public Script() { } " + | ||
151 | cg.Convert(input) + | ||
152 | "} }\n"; | ||
153 | m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); | ||
154 | |||
155 | Assert.AreEqual(0, m_compilerResults.Errors.Count); | ||
156 | } | 212 | } |
157 | } | 213 | } |
158 | } \ No newline at end of file | 214 | } \ No newline at end of file |
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text.RegularExpressions; | ||
31 | using NUnit.Framework; | ||
32 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
33 | using OpenSim.Tests.Common; | ||
34 | |||
35 | namespace 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 | ||