示例#1
0
        public void SameHandleReturnsSameReferenceAndReleasesObject()
        {
            VerifyImmediateFinalizers();

            var handle = (IntPtr)234;

            TestConstruction(handle);

            CollectGarbage();

            Assert.False(SKObject.GetInstance <LifecycleObject>(handle, out var inst));
            Assert.Null(inst);

            void TestConstruction(IntPtr h)
            {
                LifecycleObject i = null;

                Assert.False(SKObject.GetInstance(h, out i));
                Assert.Null(i);

                var first = SKObject.GetObject <LifecycleObject>(h);

                Assert.True(SKObject.GetInstance(h, out i));
                Assert.NotNull(i);

                Assert.Same(first, i);

                var second = SKObject.GetObject <LifecycleObject>(h);

                Assert.Same(first, second);
            }
        }
示例#2
0
        public void ObjectsWithTheSameHandleAndOwnTheirHandlesThrowInDebugBuildsButNotRelease()
        {
            var handle = (IntPtr)568;

            var inst1 = new LifecycleObject(handle, true)
            {
                Value = 1
            };

#if THROW_OBJECT_EXCEPTIONS
            Assert.Throws <InvalidOperationException>(() => new LifecycleObject(handle, true)
            {
                Value = 2
            });

            GarbageCleanupFixture.ignoredExceptions.Add(handle);
#else
            var inst2 = new LifecycleObject(handle, true)
            {
                Value = 2
            };
            Assert.True(inst1.DestroyedNative);

            inst1.Dispose();
            inst2.Dispose();
#endif
        }
示例#3
0
        public void ObjectsWithTheSameHandleButDoNotOwnTheirHandlesAreCreatedAndDisposedCorrectly()
        {
            var handle = (IntPtr)567;

            var inst = Construct();

            CollectGarbage();

            Assert.True(SKObject.GetInstance <LifecycleObject>(handle, out var obj));
            Assert.Equal(2, obj.Value);
            Assert.Same(inst, obj);

            LifecycleObject Construct()
            {
                var inst1 = new LifecycleObject(handle, false)
                {
                    Value = 1
                };
                var inst2 = new LifecycleObject(handle, false)
                {
                    Value = 2
                };

                Assert.NotSame(inst1, inst2);

                return(inst2);
            }
        }
示例#4
0
        public void ObjectsWithTheSameHandleAndOwnTheirHandlesThrowInDebugBuildsButNotRelease()
        {
            var handle = (IntPtr)568;

            var inst1 = new LifecycleObject(handle, true)
            {
                Value = 1
            };

#if THROW_OBJECT_EXCEPTIONS
            var ex = Assert.Throws <InvalidOperationException>(() => new LifecycleObject(handle, true)
            {
                Value = 2
            });
            Assert.Contains("H: " + handle.ToString("x") + " ", ex.Message);
#else
            var inst2 = new LifecycleObject(handle, true)
            {
                Value = 2
            };
            Assert.True(inst1.DestroyedNative);

            inst1.Dispose();
            inst2.Dispose();
#endif
        }
示例#5
0
        public void ObjectsWithTheSameHandleButDoNotOwnTheirHandlesAreCreatedAndCollectedCorrectly()
        {
            VerifyImmediateFinalizers();

            var handle = (IntPtr)566;

            Construct();

            CollectGarbage();

            Assert.False(SKObject.GetInstance <LifecycleObject>(handle, out _));

            void Construct()
            {
                var inst1 = new LifecycleObject(handle, false);
                var inst2 = new LifecycleObject(handle, false);

                Assert.NotSame(inst1, inst2);
            }
        }
示例#6
0
            static void TestConstruction(IntPtr h)
            {
                // make sure there is nothing
                Assert.False(SKObject.GetInstance(h, out LifecycleObject i));
                Assert.Null(i);

                // get/create the object
                var first = LifecycleObject.GetObject(h);

                // get the same one
                Assert.True(SKObject.GetInstance(h, out i));
                Assert.NotNull(i);

                // compare
                Assert.Same(first, i);

                // get/create the object
                var second = LifecycleObject.GetObject(h);

                // compare
                Assert.Same(first, second);
            }