Browse Source

Added unit test for dynamic code

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6112 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
David Srbecký 15 years ago
parent
commit
9f4495a21e
  1. 12
      src/AddIns/Debugger/Debugger.Core/Module.cs
  2. 1
      src/AddIns/Debugger/Debugger.Tests/Debugger.Tests.csproj
  3. 3
      src/AddIns/Debugger/Debugger.Tests/Tests/ControlFlow_Stepping.cs
  4. 90
      src/AddIns/Debugger/Debugger.Tests/Tests/DynamicCode.cs

12
src/AddIns/Debugger/Debugger.Core/Module.cs

@ -50,6 +50,7 @@ namespace Debugger
get { return this.AppDomain.Process.Debugger; } get { return this.AppDomain.Process.Debugger; }
} }
[Debugger.Tests.Ignore]
public MetaDataImport MetaData { public MetaDataImport MetaData {
get { get {
return metaData; return metaData;
@ -62,12 +63,14 @@ namespace Debugger
} }
} }
[Debugger.Tests.Ignore]
public ISymUnmanagedReader SymReader { public ISymUnmanagedReader SymReader {
get { get {
return symReader; return symReader;
} }
} }
[Debugger.Tests.Ignore]
public ISymUnmanagedDocument[] SymDocuments { public ISymUnmanagedDocument[] SymDocuments {
get { get {
ISymUnmanagedDocument[] docs; ISymUnmanagedDocument[] docs;
@ -93,6 +96,7 @@ namespace Debugger
get { return (ICorDebugModule2)corModule; } get { return (ICorDebugModule2)corModule; }
} }
[Debugger.Tests.Ignore]
public ulong BaseAdress { public ulong BaseAdress {
get { get {
return this.CorModule.GetBaseAddress(); return this.CorModule.GetBaseAddress();
@ -130,14 +134,6 @@ namespace Debugger
} }
} }
[Debugger.Tests.Ignore]
public string DirectoryName {
get {
if (IsDynamic || IsInMemory) return String.Empty;
return System.IO.Path.GetDirectoryName(FullPath);
}
}
public bool HasSymbols { public bool HasSymbols {
get { get {
return symReader != null; return symReader != null;

1
src/AddIns/Debugger/Debugger.Tests/Debugger.Tests.csproj

@ -48,6 +48,7 @@
<Compile Include="DebuggerTestsBase.cs" /> <Compile Include="DebuggerTestsBase.cs" />
<Compile Include="Tests\AppDomain_Tests.cs" /> <Compile Include="Tests\AppDomain_Tests.cs" />
<Compile Include="Tests\ControlFlow_NoBreak.cs" /> <Compile Include="Tests\ControlFlow_NoBreak.cs" />
<Compile Include="Tests\DynamicCode.cs" />
<Compile Include="Tests\ExpressionEvaluator_Tests.cs" /> <Compile Include="Tests\ExpressionEvaluator_Tests.cs" />
<Compile Include="Tests\Breakpoint_Tests.cs" /> <Compile Include="Tests\Breakpoint_Tests.cs" />
<Compile Include="Tests\StackFrame_Callstack.cs" /> <Compile Include="Tests\StackFrame_Callstack.cs" />

3
src/AddIns/Debugger/Debugger.Tests/Tests/ControlFlow_Stepping.cs

@ -188,6 +188,9 @@ namespace Debugger.Tests {
Assert.AreEqual("Main", process.SelectedStackFrame.MethodInfo.Name); Assert.AreEqual("Main", process.SelectedStackFrame.MethodInfo.Name);
} }
// Restore default state
process.Options.EnableJustMyCode = true;
EndTest(); EndTest();
} }
} }

90
src/AddIns/Debugger/Debugger.Tests/Tests/DynamicCode.cs

@ -0,0 +1,90 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using System.Diagnostics.SymbolStore;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
namespace Debugger.Tests
{
public class DynamicCode
{
public static void Main()
{
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "DynamicllyGeneratedAssembly";
AssemblyBuilder assemblyBuilder = System.Threading.Thread.GetDomain().DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave);
ConstructorInfo daCtor = typeof(DebuggableAttribute).GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) });
CustomAttributeBuilder daBuilder = new CustomAttributeBuilder(daCtor, new object[] { DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.Default });
assemblyBuilder.SetCustomAttribute(daBuilder);
ModuleBuilder module = assemblyBuilder.DefineDynamicModule("DynamicllyGeneratedModule.exe", true);
ISymbolDocumentWriter doc = module.DefineDocument(@"Source.txt", Guid.Empty, Guid.Empty, Guid.Empty);
TypeBuilder typeBuilder = module.DefineType("DynamicllyGeneratedType", TypeAttributes.Public | TypeAttributes.Class);
MethodBuilder methodbuilder = typeBuilder.DefineMethod("Main", MethodAttributes.HideBySig | MethodAttributes.Static | MethodAttributes.Public, typeof(void), new Type[] { typeof(string[]) });
ILGenerator ilGenerator = methodbuilder.GetILGenerator();
ilGenerator.MarkSequencePoint(doc, 1, 1, 1, 100);
ilGenerator.Emit(OpCodes.Ldstr, "Hello world!");
MethodInfo infoWriteLine = typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) });
ilGenerator.EmitCall(OpCodes.Call, infoWriteLine, null);
ilGenerator.MarkSequencePoint(doc, 2, 1, 2, 100);
ilGenerator.Emit(OpCodes.Ret);
Type helloWorldType = typeBuilder.CreateType();
System.Diagnostics.Debugger.Break();
helloWorldType.GetMethod("Main").Invoke(null, new string[] { null });
}
}
}
#if TEST_CODE
namespace Debugger.Tests {
using NUnit.Framework;
public partial class DebuggerTests
{
[NUnit.Framework.Test]
public void DynamicCode()
{
StartTest();
process.SelectedStackFrame.StepOver();
process.SelectedStackFrame.StepInto();
Assert.AreEqual("Source.txt", process.SelectedStackFrame.NextStatement.Filename);
EndTest();
}
}
}
#endif
#if EXPECTED_OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<DebuggerTests>
<Test
name="DynamicCode.cs">
<ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>DynamicCode.exe (Has symbols)</ModuleLoaded>
<ModuleLoaded>DynamicllyGeneratedAssembly (No symbols)</ModuleLoaded>
<ModuleLoaded>ISymWrapper.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>System.dll (No symbols)</ModuleLoaded>
<DebuggingPaused>Break DynamicCode.cs:46,4-46,40</DebuggingPaused>
<DebuggingPaused>StepComplete DynamicCode.cs:47,4-47,73</DebuggingPaused>
<DebuggingPaused>StepComplete Source.txt:1,1-1,100</DebuggingPaused>
<ProcessExited />
</Test>
</DebuggerTests>
#endif // EXPECTED_OUTPUT
Loading…
Cancel
Save