From edd7e1946372bc57bb49d0b6b65c546795ea896a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 16 Nov 2013 02:50:14 +0000 Subject: If anything other than a single integer is specified for events that only take a single integer, generate a syntax error on LSL script compile rather than an exception later on. This applies to events changed, collision, collision_start, collision_end, on_rez, run_time_permissions, sensor, touch, touch_start, touch_end --- .../Shared/CodeTools/Tests/LSL_EventTests.cs | 107 ++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs index 6c51060..42d2d7b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/LSL_EventTests.cs @@ -108,20 +108,123 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests TestCompile("default { timer(integer n) {} }", true); } + [Test] + public void TestChangedEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("changed"); + } + + [Test] + public void TestCollisionEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("collision"); + } + + [Test] + public void TestCollisionStartEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("collision_start"); + } + + [Test] + public void TestCollisionEndEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("collision_end"); + } + + [Test] + public void TestOnRezEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("on_rez"); + } + + [Test] + public void TestRunTimePermissionsEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("run_time_permissions"); + } + + [Test] + public void TestSensorEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("sensor"); + } + + [Test] + public void TestTouchEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("touch"); + } + + [Test] + public void TestTouchStartEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("touch_start"); + } + + [Test] + public void TestTouchEndEvent() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestIntArgEvent("touch_end"); + } + + private void TestIntArgEvent(string eventName) + { + TestCompile("default { " + eventName + "(integer n) {} }", false); + TestCompile("default { " + eventName + "{{}} }", true); + TestCompile("default { " + eventName + "(string s) {{}} }", true); + TestCompile("default { " + eventName + "(integer n, integer o) {{}} }", true); + } + private void TestCompile(string script, bool expectException) { bool gotException = false; + Exception ge = null; try { m_cg.Convert(script); } - catch (Exception) + catch (Exception e) { gotException = true; + ge = e; } - Assert.That(gotException, Is.EqualTo(expectException)); + Assert.That( + gotException, + Is.EqualTo(expectException), + "Failed on {0}, exception {1}", script, ge != null ? ge.ToString() : "n/a"); } } } \ No newline at end of file -- cgit v1.1