mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.3 KiB
54 lines
2.3 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Reflection.PortableExecutable; |
|
using System.Runtime.CompilerServices; |
|
using System.Xml.Linq; |
|
using ICSharpCode.Decompiler.CSharp; |
|
using ICSharpCode.Decompiler.CSharp.OutputVisitor; |
|
using ICSharpCode.Decompiler.DebugInfo; |
|
using ICSharpCode.Decompiler.Metadata; |
|
using ICSharpCode.Decompiler.Tests.Helpers; |
|
using ICSharpCode.Decompiler.TypeSystem; |
|
using Microsoft.CodeAnalysis.CSharp; |
|
using Microsoft.DiaSymReader.Tools; |
|
using NUnit.Framework; |
|
|
|
namespace ICSharpCode.Decompiler.Tests |
|
{ |
|
[TestFixture] |
|
public class PdbGenerationTestRunner |
|
{ |
|
static readonly string TestCasePath = Tester.TestCasePath + "/PdbGen"; |
|
|
|
[Test, Ignore("Needs adjustments in generator")] |
|
public void HelloWorld() |
|
{ |
|
TestGeneratePdb(); |
|
} |
|
|
|
private void TestGeneratePdb([CallerMemberName] string testName = null) |
|
{ |
|
const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans; |
|
|
|
string xmlFile = Path.Combine(TestCasePath, testName + ".xml"); |
|
string xmlContent = File.ReadAllText(xmlFile); |
|
XDocument document = XDocument.Parse(xmlContent); |
|
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value); |
|
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files, options); |
|
|
|
string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll"); |
|
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb"); |
|
var moduleDefinition = new PEFile(peFileName); |
|
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchEntireImage); |
|
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings()); |
|
using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, testName + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { |
|
PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream); |
|
pdbStream.Position = 0; |
|
string resultFile = PdbToXmlConverter.ToXml(pdbStream, moduleDefinition.Reader.GetEntireImage().GetContent().ToArray(), options); |
|
Assert.AreEqual(xmlContent, resultFile); |
|
} |
|
} |
|
} |
|
}
|
|
|