aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs (renamed from OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs)6
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs120
2 files changed, 123 insertions, 3 deletions
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs
index 70472cb..0b07b30 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSLCompilerTest.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs
@@ -38,7 +38,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
38 /// The generated C# code is compared against the expected C# code. 38 /// The generated C# code is compared against the expected C# code.
39 /// </summary> 39 /// </summary>
40 [TestFixture] 40 [TestFixture]
41 public class LSLCompilerTest 41 public class CSCodeGeneratorTest
42 { 42 {
43 [Test] 43 [Test]
44 public void TestDefaultState() 44 public void TestDefaultState()
@@ -685,7 +685,7 @@ default
685 integer x = 1; 685 integer x = 1;
686 686
687 if(x) llSay(0, ""Hello""); 687 if(x) llSay(0, ""Hello"");
688 if(1) 688 if(1)
689 { 689 {
690 llSay(0, ""Hi""); 690 llSay(0, ""Hi"");
691 integer r = 3; 691 integer r = 3;
@@ -791,7 +791,7 @@ default
791 integer y = 0; 791 integer y = 0;
792 792
793 if(x && y) llSay(0, ""Hello""); 793 if(x && y) llSay(0, ""Hello"");
794 if(x || y) 794 if(x || y)
795 { 795 {
796 llSay(0, ""Hi""); 796 llSay(0, ""Hi"");
797 integer r = 3; 797 integer r = 3;
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs
new file mode 100644
index 0000000..7a11d33
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CompilerTest.cs
@@ -0,0 +1,120 @@
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 OpenSim 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.IO;
29using System.CodeDom.Compiler;
30using System.Collections.Generic;
31using Microsoft.CSharp;
32using NUnit.Framework;
33using OpenSim.Region.ScriptEngine.Shared.CodeTools;
34
35namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
36{
37 /// <summary>
38 /// Tests the LSL compiler. Among other things, test that error messages
39 /// generated by the C# compiler can be mapped to prper lines/columns in
40 /// the LSL source.
41 /// </summary>
42 [TestFixture]
43 public class CompilerTest
44 {
45 private string m_testDir;
46 private CSharpCodeProvider m_CSCodeProvider;
47 private CompilerParameters m_compilerParameters;
48 private CompilerResults m_compilerResults;
49
50 /// <summary>
51 /// Creates a temporary directory where build artifacts are stored.
52 /// </summary>
53 [TestFixtureSetUp]
54 public void Init()
55 {
56 m_testDir = Path.Combine(Path.GetTempPath(), "opensim_compilerTest_" + Path.GetRandomFileName());
57
58 if (!Directory.Exists(m_testDir))
59 {
60 // Create the temporary directory for housing build artifacts.
61 Directory.CreateDirectory(m_testDir);
62 }
63
64 // Create a CSCodeProvider and CompilerParameters.
65 m_CSCodeProvider = new CSharpCodeProvider();
66 m_compilerParameters = new CompilerParameters();
67
68 string rootPath = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "bin");
69 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
70 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
71 m_compilerParameters.GenerateExecutable = false;
72 }
73
74 /// <summary>
75 /// Removes the temporary build directory and any build artifacts
76 /// inside it.
77 /// </summary>
78 [TestFixtureTearDown]
79 public void CleanUp()
80 {
81 if (Directory.Exists(m_testDir))
82 {
83 // Blow away the temporary directory with artifacts.
84 Directory.Delete(m_testDir, true);
85 }
86 }
87
88 [Test]
89 /// <summary>
90 /// 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.
92 /// </summary>
93 public void TestUseUndeclaredVariable()
94 {
95 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");
96
97 string input = @"default
98{
99 state_entry()
100 {
101 integer y = x + 3;
102 }
103}";
104
105 CSCodeGenerator cg = new CSCodeGenerator();
106 string output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" +
107 "namespace SecondLife { " +
108 "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" +
109 "public Script() { } " +
110 cg.Convert(input) +
111 "} }\n";
112 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
113
114 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
115
116 Assert.AreEqual(new KeyValuePair<int, int>(5, 21),
117 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
118 }
119 }
120}