예제 #1
0
        public unsafe void ShouldTryAgain_Mixed()
        {
            var comp1 = CreateCompilation("public class C { }", assemblyName: GetUniqueName());
            var comp2 = CreateCompilation("public class D { }", assemblyName: GetUniqueName());

            using (
                PinnedMetadata pinned1 = new PinnedMetadata(GetMetadataBytes(comp1)),
                pinned2 = new PinnedMetadata(GetMetadataBytes(comp2))
                )
            {
                var assemblyIdentity1 = comp1.Assembly.Identity;
                var assemblyIdentity2 = comp2.Assembly.Identity;
                Assert.NotEqual(assemblyIdentity1, assemblyIdentity2);

                IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize)
                {
                    if (assemblyIdentity == assemblyIdentity1)
                    {
                        uSize = (uint)pinned1.Size;
                        return(pinned1.Pointer);
                    }
                    else if (assemblyIdentity == assemblyIdentity2)
                    {
                        uSize = (uint)pinned2.Size;
                        return(pinned2.Pointer);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(
                            DkmExceptionUtilities.CORDBG_E_MISSING_METADATA
                            );
                        throw ExceptionUtilities.Unreachable;
                    }
                }

                var references = ImmutableArray.Create(default(MetadataBlock));
                var unknownAssemblyIdentity   = new AssemblyIdentity(GetUniqueName());
                var missingAssemblyIdentities = ImmutableArray.Create(
                    assemblyIdentity1,
                    unknownAssemblyIdentity,
                    assemblyIdentity2
                    );
                Assert.True(
                    ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(
                        gmdbpf,
                        missingAssemblyIdentities,
                        ref references
                        )
                    );
                Assert.Equal(3, references.Length);

                Assert.Equal(default(MetadataBlock), references[0]);

                Assert.Equal(pinned1.Pointer, references[1].Pointer);
                Assert.Equal(pinned1.Size, references[1].Size);

                Assert.Equal(pinned2.Pointer, references[2].Pointer);
                Assert.Equal(pinned2.Size, references[2].Size);
            }
        }
예제 #2
0
        public unsafe void ShouldTryAgain_Success()
        {
            var comp = CreateCompilation("public class C { }");

            using (var pinned = new PinnedMetadata(GetMetadataBytes(comp)))
            {
                IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize)
                {
                    uSize = (uint)pinned.Size;
                    return(pinned.Pointer);
                }

                var references = ImmutableArray <MetadataBlock> .Empty;
                var missingAssemblyIdentity   = new AssemblyIdentity("A");
                var missingAssemblyIdentities = ImmutableArray.Create(missingAssemblyIdentity);
                Assert.True(
                    ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(
                        gmdbpf,
                        missingAssemblyIdentities,
                        ref references
                        )
                    );

                var newReference = references.Single();
                Assert.Equal(pinned.Pointer, newReference.Pointer);
                Assert.Equal(pinned.Size, newReference.Size);
            }
        }
예제 #3
0
        private static void ShouldTryAgain_False(DkmUtilities.GetMetadataBytesPtrFunction gmdbpf)
        {
            var references = ImmutableArray <MetadataBlock> .Empty;
            var missingAssemblyIdentities = ImmutableArray.Create(new AssemblyIdentity("A"));

            Assert.False(ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(gmdbpf, missingAssemblyIdentities, ref references));
            Assert.Empty(references);
        }
예제 #4
0
        public void ShouldTryAgain_Exception()
        {
            IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize)
            {
                throw new Exception();
            }

            var references = ImmutableArray <MetadataBlock> .Empty;
            var missingAssemblyIdentities = ImmutableArray.Create(new AssemblyIdentity("A"));

            Assert.Throws <Exception>(() => ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(gmdbpf, missingAssemblyIdentities, ref references));
        }
예제 #5
0
        public void ShouldTryAgain_OtherException()
        {
            DkmUtilities.GetMetadataBytesPtrFunction gmdbpf = (AssemblyIdentity assemblyIdentity, out uint uSize) =>
            {
                throw new Exception();
            };

            var references = ImmutableArray <MetadataBlock> .Empty;
            var missingAssemblyIdentities = ImmutableArray.Create(new AssemblyIdentity("A"));

            Assert.Throws <Exception>(() => ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(gmdbpf, missingAssemblyIdentities, ref references));
        }
예제 #6
0
        public void ShouldTryAgain_RPC_E_DISCONNECTED()
        {
            IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize)
            {
                Marshal.ThrowExceptionForHR(unchecked ((int)0x80010108));
                throw ExceptionUtilities.Unreachable;
            }

            var references = ImmutableArray <MetadataBlock> .Empty;
            var missingAssemblyIdentities = ImmutableArray.Create(new AssemblyIdentity("A"));

            Assert.Throws <COMException>(() => ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(gmdbpf, missingAssemblyIdentities, ref references));
        }
예제 #7
0
        public void ShouldTryAgain_COR_E_BADIMAGEFORMAT()
        {
            DkmUtilities.GetMetadataBytesPtrFunction gmdbpf = (AssemblyIdentity assemblyIdentity, out uint uSize) =>
            {
                Marshal.ThrowExceptionForHR(unchecked ((int)MetadataUtilities.COR_E_BADIMAGEFORMAT));
                throw ExceptionUtilities.Unreachable;
            };

            var references = ImmutableArray <MetadataBlock> .Empty;
            var missingAssemblyIdentities = ImmutableArray.Create(new AssemblyIdentity("A"));

            Assert.False(ExpressionCompiler.ShouldTryAgainWithMoreMetadataBlocks(gmdbpf, missingAssemblyIdentities, ref references));
            Assert.Empty(references);
        }