Ejemplo n.º 1
0
    public static int Main()
    {
        try
        {
            // Test that our SafeHandle-derived object has its underlying handle set after a P/Invoke
            // even if there's an exception during the unmarshal phase.
            IntPtr     value = (IntPtr)123;
            FakeHandle h     = new FakeHandle();

            Assert.Throws <InvalidOperationException>(() => ReliableUnmarshalNative.GetFakeHandle(value, out h, out var cookie));

            Assert.AreEqual(value, h.DangerousGetHandle());
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex);
            return(101);
        }
        return(100);
    }
Ejemplo n.º 2
0
        public void SetUp()
        {
            factory = Substitute.For <RemoteObjectFake.Factory>();

            handle1 = new FakeHandle();
            handle2 = new FakeHandle();
            handle3 = new FakeHandle();
            handles = new List <FakeHandle> {
                handle1, handle2, handle3, null
            };

            obj1 = new RemoteObjectFake();
            factory.Create(handle1).Returns(obj1);

            obj2 = new RemoteObjectFake();
            factory.Create(handle2).Returns(obj2);

            obj3 = new RemoteObjectFake();
            factory.Create(handle3).Returns(obj3);

            factory.Create(null).Returns(_ => { throw new ArgumentNullException(); });
            factory.When(x => x.Delete(null)).Do(_ => { throw new ArgumentNullException(); });
        }
Ejemplo n.º 3
0
 public static extern void GetFakeHandle(IntPtr value, out FakeHandle handle, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ThrowingCustomMarshaler), MarshalCookie = "")] out object cookie);