internal static void VerifyPdb(
            this Compilation compilation,
            string qualifiedMethodName,
            string expectedPdb,
            [CallerLineNumber] int expectedValueSourceLine  = 0,
            [CallerFilePath] string expectedValueSourcePath = null)
        {
            string actualPdb = GetPdbXml(compilation, qualifiedMethodName);

            AssertXml.Equal(ParseExpectedPdbXml(expectedPdb), XElement.Parse(actualPdb), expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral: false);
        }
Exemple #2
0
        public void Bug693206()
        {
            #region "Source"
            var text =
                @"
namespace X
{ 
	class DynamicMembers
	{
        enum HRESULT : int
        {
            S_OK = 0x0000,
            S_FALSE = 0x0001,
            S_PT_NO_CONFLICT = 0x40001,
            E_INVALID_DATA = unchecked((int)0x8007000D),
            E_INVALIDARG = unchecked((int)0x80070057),
            E_OUTOFMEMORY = unchecked((int)0x8007000E),
            ERROR_NOT_FOUND = unchecked((int)0x80070490)
        }
    }
}";
            #endregion

            string expected =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""8"" end-line=""4"" end-column=""22"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""8"" end-line=""4"" end-column=""22"" />
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""14"" end-line=""6"" end-column=""21"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""8"" start-column=""13"" end-line=""8"" end-column=""17"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""13"" end-line=""9"" end-column=""20"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""10"" start-column=""13"" end-line=""10"" end-column=""29"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""11"" start-column=""13"" end-line=""11"" end-column=""27"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""12"" start-column=""13"" end-line=""12"" end-column=""25"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""13"" start-column=""13"" end-line=""13"" end-column=""26"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""14"" start-column=""13"" end-line=""14"" end-column=""28"" />
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs"
                )
                              .VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }
        private void VerifyPdb(
            IEnumerable <int> methodTokens,
            string expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(default(DebugInformationFormat), format);
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(new ImmutableMemoryStream(PdbDelta), methodTokens);

            var(actualXml, expectedXml) = PdbValidation.AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: NextGeneration.InitialBaseline.HasPortablePdb);

            AssertXml.Equal(expectedXml, actualXml, $"Format: {format}{Environment.NewLine}", expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
        }
Exemple #4
0
        private static void VerifyPdbImpl(
            this Compilation compilation,
            IMethodSymbol debugEntryPoint,
            string qualifiedMethodName,
            XElement expectedPdb,
            DebugInformationFormat format,
            PdbToXmlOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            if (format == 0 || format == DebugInformationFormat.Pdb)
            {
                XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: false));
                AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }

            if (format == 0 || format == DebugInformationFormat.PortablePdb)
            {
                XElement actualPortablePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: true));

                // SymWriter doesn't create empty scopes. When the C# compiler uses forwarding CDI instead of a NamespaceScope
                // the scope is actually not empty - it logically contains the imports. Portable PDB does not used forwarding and thus
                // creates the scope. When generating PDB XML for testing the Portable DiaSymReader returns empty namespaces.
                RemoveEmptyScopes(actualPortablePdb);

                // sharing the same expected output with native PDB
                if (format == 0)
                {
                    RemoveNonPortablePdb(expectedPdb);

                    // TODO: remove
                    RemoveEmptySequencePoints(expectedPdb);

                    // remove scopes that only contained non-portable elements (namespace scopes)
                    RemoveEmptyScopes(expectedPdb);
                    RemoveMethodsWithNoSequencePoints(expectedPdb);
                    RemoveEmptyMethods(expectedPdb);
                }

                AssertXml.Equal(expectedPdb, actualPortablePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }
        }
Exemple #5
0
        public void TestWinMdExpData_Empty()
        {
            #region "Source"
            var text = @"";
            #endregion

            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs").VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }
Exemple #6
0
        private void VerifyPdb(
            IEnumerable <int> methodTokens,
            XElement expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            var actualXml = XElement.Parse(PdbToXmlConverter.DeltaPdbToXml(new ImmutableMemoryStream(PdbDelta), methodTokens));

            PdbValidation.AdjustToPdbFormat(
                actualPdb: actualXml,
                actualIsPortable: NextGeneration.InitialBaseline.HasPortablePdb,
                expectedPdb: expectedPdb,
                expectedIsPortable: format != DebugInformationFormat.Pdb);

            AssertXml.Equal(expectedPdb, actualXml, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
        }
 private static void VerifyPdbImpl(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format,
     int expectedValueSourceLine,
     string expectedValueSourcePath,
     bool expectedIsXmlLiteral)
 {
     if (format == 0 || format == DebugInformationFormat.Pdb)
     {
         XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, qualifiedMethodName));
         AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
     }
     else
     {
         // Portable PDBs not supported yet
         throw ExceptionUtilities.Unreachable;
     }
 }
Exemple #8
0
        public void TestWinMdExpData_AnonymousTypes()
        {
            #region "Source"
            var text =
                @"
namespace X
{ 
	public sealed class TestCase
	{
		public void M() 
		{ 
			var a = new { x = 1, y = new { a = 1 } };
			var b = new { t = new { t = new { t = new { t = new { a = 1 } } } } };
		}
	}
}";
            #endregion

            string expected =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""22"" end-line=""4"" end-column=""30"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""22"" end-line=""4"" end-column=""30"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""15"" end-line=""6"" end-column=""16"" />
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs"
                )
                              .VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }
Exemple #9
0
        public void TestWinMdExpData_Basic()
        {
            var    text     = @"using System;
using System.Threading;
using System.Threading.Tasks;

namespace X
{ 
	class DynamicMembers
	{
		public Func<Task<int>> Prop { get; set; }
	}
	public sealed partial class TestCase
	{
		private static int Count = 0;
		public async void Run()
		{
			DynamicMembers dc2 = new DynamicMembers();
			dc2.Prop = async () => { await Task.Delay(10000); return 3; };
			var rez2 = await dc2.Prop();
			if (rez2 == 3) Count++;
	 
			Driver.Result = TestCase.Count - 1;
			//When test complete, set the flag.
			Driver.CompletedSignal.Set();
		}

        static  partial void Goo();
        static  partial void Bar();
	}

	public sealed partial class TestCase
    {
        static partial void Bar(){}
    }

	class Driver
	{
		public static int Result = -1;
		public static AutoResetEvent CompletedSignal = new AutoResetEvent(false);
		static int Main()
		{
			var t = new TestCase();
			t.Run();
	 
			CompletedSignal.WaitOne();
			return Driver.Result;
		}
	}
}";
            string expected = @"
<token-map>
    <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""7"" start-column=""8"" end-line=""7"" end-column=""22""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""7"" start-column=""8"" end-line=""7"" end-column=""22""/>
    <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""26"" end-line=""9"" end-column=""30""/>
    <token-location token=""0x17xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""26"" end-line=""9"" end-column=""30""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""33"" end-line=""9"" end-column=""36""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""38"" end-line=""9"" end-column=""41""/>
    <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""11"" start-column=""30"" end-line=""11"" end-column=""38""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""11"" start-column=""30"" end-line=""11"" end-column=""38""/>
    <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""13"" start-column=""22"" end-line=""13"" end-column=""27""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""14"" start-column=""21"" end-line=""14"" end-column=""24""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""27"" start-column=""30"" end-line=""27"" end-column=""33""/>
    <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""35"" start-column=""8"" end-line=""35"" end-column=""14""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""35"" start-column=""8"" end-line=""35"" end-column=""14""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""35"" start-column=""8"" end-line=""35"" end-column=""14""/>
    <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""37"" start-column=""21"" end-line=""37"" end-column=""27""/>
    <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""38"" start-column=""32"" end-line=""38"" end-column=""47""/>
    <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""39"" start-column=""14"" end-line=""39"" end-column=""18""/>
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs").VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);

            AssertXml.Equal(expected, actual);
        }
Exemple #10
0
        public void TestWinMdExpData_Property_Event()
        {
            #region "Source"
            var text = @"
using System;

namespace X
{ 
	public delegate void D(int k);

	public sealed class TestCase
	{
		static TestCase()
		{
		}

		public TestCase(int rr)
		{
		}
		
		public event D E;
		
		public event Action E2;
		
		public int P { get; set; }
		
		public int P2 
		{ 
			get{ return 1; }
			set{}
		}
		
		public int this[int a]
		{
			get{ return 1; }
			set{}
		}
	}
}";
            #endregion

            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""23"" end-line=""6"" end-column=""24"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""23"" end-line=""6"" end-column=""24"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""23"" end-line=""6"" end-column=""24"" />
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""8"" start-column=""22"" end-line=""8"" end-column=""30"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""10"" start-column=""10"" end-line=""10"" end-column=""18"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""14"" start-column=""10"" end-line=""14"" end-column=""18"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""18"" start-column=""18"" end-line=""18"" end-column=""19"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""18"" start-column=""18"" end-line=""18"" end-column=""19"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""18"" start-column=""18"" end-line=""18"" end-column=""19"" />
  <token-location token=""0x14xxxxxx"" file=""source.cs"" start-line=""18"" start-column=""18"" end-line=""18"" end-column=""19"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""20"" start-column=""23"" end-line=""20"" end-column=""25"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""20"" start-column=""23"" end-line=""20"" end-column=""25"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""20"" start-column=""23"" end-line=""20"" end-column=""25"" />
  <token-location token=""0x14xxxxxx"" file=""source.cs"" start-line=""20"" start-column=""23"" end-line=""20"" end-column=""25"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""22"" start-column=""14"" end-line=""22"" end-column=""15"" />
  <token-location token=""0x17xxxxxx"" file=""source.cs"" start-line=""22"" start-column=""14"" end-line=""22"" end-column=""15"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""22"" start-column=""18"" end-line=""22"" end-column=""21"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""22"" start-column=""23"" end-line=""22"" end-column=""26"" />
  <token-location token=""0x17xxxxxx"" file=""source.cs"" start-line=""24"" start-column=""14"" end-line=""24"" end-column=""16"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""26"" start-column=""4"" end-line=""26"" end-column=""7"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""27"" start-column=""4"" end-line=""27"" end-column=""7"" />
  <token-location token=""0x17xxxxxx"" file=""source.cs"" start-line=""30"" start-column=""14"" end-line=""30"" end-column=""18"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""32"" start-column=""4"" end-line=""32"" end-column=""7"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""33"" start-column=""4"" end-line=""33"" end-column=""7"" />
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs").VerifyDiagnostics(
                Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("X.TestCase.E"),
                Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E2").WithArguments("X.TestCase.E2"));

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }