30 using System.CodeDom.Compiler;
31 using System.Collections.Generic;
32 using Microsoft.CSharp;
33 using NUnit.Framework;
34 using OpenSim.Region.ScriptEngine.Shared.CodeTools;
35 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
36 using OpenSim.Tests.Common;
38 namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
48 private string m_testDir;
49 private CSharpCodeProvider m_CSCodeProvider;
50 private CompilerParameters m_compilerParameters;
52 private ResolveEventHandler m_resolveEventHandler;
60 m_testDir = Path.Combine(Path.GetTempPath(),
"opensim_compilerTest_" + Path.GetRandomFileName());
62 if (!Directory.Exists(m_testDir))
65 Directory.CreateDirectory(m_testDir);
75 m_CSCodeProvider =
new CSharpCodeProvider();
76 m_compilerParameters =
new CompilerParameters();
78 string rootPath = System.AppDomain.CurrentDomain.BaseDirectory;
82 System.AppDomain.CurrentDomain.AssemblyResolve += m_resolveEventHandler;
84 m_compilerParameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
"OpenSim.Region.ScriptEngine.Shared.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"));
87 m_compilerParameters.GenerateExecutable =
false;
97 System.AppDomain.CurrentDomain.AssemblyResolve -= m_resolveEventHandler;
99 if (Directory.Exists(m_testDir))
102 Directory.Delete(m_testDir,
true);
106 private CompilerResults CompileScript(
107 string input, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap)
109 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() +
".dll");
112 string output = cg.Convert(input);
114 output = Compiler.CreateCSCompilerScript(output,
"script1", typeof(
ScriptBaseClass).FullName, null);
117 positionMap = cg.PositionMap;
119 CompilerResults compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
133 return compilerResults;
142 TestHelpers.InMethod();
144 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
146 CompilerResults compilerResults = CompileScript(
155 }", out positionMap);
158 new KeyValuePair<int, int>(7, 9),
159 positionMap[
new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
169 TestHelpers.InMethod();
171 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
173 CompilerResults compilerResults = CompileScript(
180 }", out positionMap);
183 new KeyValuePair<int, int>(5, 21),
184 positionMap[
new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
194 TestHelpers.InMethod();
196 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap;
198 CompilerResults compilerResults = CompileScript(
199 @"string s = "" a string"";
205 key gAvatarKey = llDetectedKey(0);
206 string tmp = (string) gAvatarKey + s;
209 }", out positionMap);
211 Assert.AreEqual(0, compilerResults.Errors.Count);
static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
Interactive OpenSim region server