예제 #1
0
 public void TestNotDestroyingForeignObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
         Assert.Catch <InvalidOperationException>(hasVirtualDtor2.Dispose);
         var hasVirtualDtor1 = hasVirtualDtor2.HasVirtualDtor1;
         Assert.AreEqual(5, hasVirtualDtor1.TestField);
         Assert.Catch <InvalidOperationException>(hasVirtualDtor1.Dispose);
     }
 }
예제 #2
0
 public void TestNativeToManagedMapWithOwnObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var bar = new Bar();
         testNativeToManagedMap.PropertyWithNoVirtualDtor = bar;
         Assert.AreSame(bar, testNativeToManagedMap.PropertyWithNoVirtualDtor);
         Assert.IsTrue(Qux.NativeToManagedMap.ContainsKey(bar.__Instance));
         bar.Dispose();
         Assert.IsFalse(Qux.NativeToManagedMap.ContainsKey(bar.__Instance));
     }
 }
예제 #3
0
 public void TestNotDestroyingForeignObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
         hasVirtualDtor2.Dispose();
         using (var hasVirtualDtor1 = hasVirtualDtor2.HasVirtualDtor1)
         {
             Assert.AreEqual(5, hasVirtualDtor1.TestField);
         }
     }
 }
예제 #4
0
 public void TestNativeToManagedMapWithOwnObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var quxMap = (IDictionary <IntPtr, IQux>) typeof(
             Qux).GetField("NativeToManagedMap",
                           BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
         var bar = new Bar();
         testNativeToManagedMap.PropertyWithNoVirtualDtor = bar;
         Assert.AreSame(bar, testNativeToManagedMap.PropertyWithNoVirtualDtor);
         Assert.IsTrue(quxMap.ContainsKey(bar.__Instance));
         bar.Dispose();
         Assert.IsFalse(quxMap.ContainsKey(bar.__Instance));
     }
 }
예제 #5
0
    public void TestNativeToManagedMapWithForeignObjects()
    {
        IntPtr native1;
        IntPtr native2;

        using (var testNativeToManagedMap = new TestNativeToManagedMap())
        {
            var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
            native2 = hasVirtualDtor2.__Instance;
            native1 = hasVirtualDtor2.HasVirtualDtor1.__Instance;
            Assert.IsTrue(HasVirtualDtor2.NativeToManagedMap.ContainsKey(native2));
            Assert.IsTrue(HasVirtualDtor1.NativeToManagedMap.ContainsKey(native1));
            Assert.AreSame(hasVirtualDtor2, testNativeToManagedMap.HasVirtualDtor2);
        }
        Assert.IsFalse(HasVirtualDtor2.NativeToManagedMap.ContainsKey(native2));
        Assert.IsFalse(HasVirtualDtor1.NativeToManagedMap.ContainsKey(native1));
    }
예제 #6
0
    public void TestNativeToManagedMapWithForeignObjects()
    {
        IntPtr native1;
        IntPtr native2;
        var    hasVirtualDtor1Map = (IDictionary <IntPtr, HasVirtualDtor1>) typeof(
            HasVirtualDtor1).GetField("NativeToManagedMap",
                                      BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
        var hasVirtualDtor2Map = (IDictionary <IntPtr, HasVirtualDtor2>) typeof(
            HasVirtualDtor2).GetField("NativeToManagedMap",
                                      BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

        using (var testNativeToManagedMap = new TestNativeToManagedMap())
        {
            var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
            native2 = hasVirtualDtor2.__Instance;
            native1 = hasVirtualDtor2.HasVirtualDtor1.__Instance;
            Assert.IsTrue(hasVirtualDtor1Map.ContainsKey(native1));
            Assert.IsTrue(hasVirtualDtor2Map.ContainsKey(native2));
            Assert.AreSame(hasVirtualDtor2, testNativeToManagedMap.HasVirtualDtor2);
        }
        Assert.IsFalse(hasVirtualDtor1Map.ContainsKey(native1));
        Assert.IsFalse(hasVirtualDtor2Map.ContainsKey(native2));
    }
예제 #7
0
 public void TestNativeToManagedMapWithOwnObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var bar = new Bar();
         testNativeToManagedMap.PropertyWithNoVirtualDtor = bar;
         Assert.AreSame(bar, testNativeToManagedMap.PropertyWithNoVirtualDtor);
         Assert.IsTrue(Qux.NativeToManagedMap.ContainsKey(bar.__Instance));
         bar.Dispose();
         Assert.IsFalse(Qux.NativeToManagedMap.ContainsKey(bar.__Instance));
     }
 }
예제 #8
0
 public void TestNativeToManagedMapWithForeignObjects()
 {
     IntPtr native1;
     IntPtr native2;
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
         native2 = hasVirtualDtor2.__Instance;
         native1 = hasVirtualDtor2.HasVirtualDtor1.__Instance;
         Assert.IsTrue(HasVirtualDtor2.NativeToManagedMap.ContainsKey(native2));
         Assert.IsTrue(HasVirtualDtor1.NativeToManagedMap.ContainsKey(native1));
         Assert.AreSame(hasVirtualDtor2, testNativeToManagedMap.HasVirtualDtor2);
     }
     Assert.IsFalse(HasVirtualDtor2.NativeToManagedMap.ContainsKey(native2));
     Assert.IsFalse(HasVirtualDtor1.NativeToManagedMap.ContainsKey(native1));
 }
예제 #9
0
 public void TestNotDestroyingForeignObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
         Assert.Catch<InvalidOperationException>(hasVirtualDtor2.Dispose);
         var hasVirtualDtor1 = hasVirtualDtor2.HasVirtualDtor1;
         Assert.AreEqual(5, hasVirtualDtor1.TestField);
         Assert.Catch<InvalidOperationException>(hasVirtualDtor1.Dispose);
     }
 }
예제 #10
0
 public void TestNotDestroyingForeignObjects()
 {
     using (var testNativeToManagedMap = new TestNativeToManagedMap())
     {
         var hasVirtualDtor2 = testNativeToManagedMap.HasVirtualDtor2;
         hasVirtualDtor2.Dispose();
         using (var hasVirtualDtor1 = hasVirtualDtor2.HasVirtualDtor1)
         {
             Assert.AreEqual(5, hasVirtualDtor1.TestField);
         }
     }
 }