From dc435930dc9fa13c9bdbbc3796d94e0549c8c45a Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 4 Nov 2015 03:54:18 +0200 Subject: [PATCH] Updated C++# to fix a crash when disposing of user impls of abstract types. Signed-off-by: Dimitar Dobrev --- .../Animation/QAbstractAnimationTests.cs | 222 +++++++++++------- .../Manual/QtCore/IO/QIODeviceTests.cs | 13 +- QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs | 1 - .../Manual/QtCore/Plugin/QUuidTests.cs | 1 - 4 files changed, 140 insertions(+), 97 deletions(-) diff --git a/QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs b/QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs index 4a36db35..32025b55 100644 --- a/QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs +++ b/QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs @@ -18,156 +18,200 @@ public void Dispose() // TODO: Add tear down code. } - // BUG: disposing of any of the animations crashes - the function pointer is null; there's something wrong when constructing custom classes - + private class TestableQAbstractAnimation1 : QAbstractAnimation + { + private int duration = 10; + + public override int Duration + { + get { return this.duration; } + } + + protected override void UpdateCurrentTime(int value) + { + + } + + public void SetDuration(int val) + { + this.duration = val; + } + } + [Test] public void TestEmptyConstructor() { - var s = new TestableQAbstractAnimation(); + using (new TestableQAbstractAnimation1()) + { + } } - + [Test] public void TestCurrentLoop() { - var anim = new TestableQAbstractAnimation(); - - Assert.AreEqual(0, anim.CurrentLoop); + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(0, anim.CurrentLoop); + } } [Test] public void TestCurrentLoopTime() { - var anim = new TestableQAbstractAnimation(); - - Assert.AreEqual(0, anim.CurrentLoopTime); + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(0, anim.CurrentLoopTime); + } } [Test] public void TestCurrentTime() { - var anim = new TestableQAbstractAnimation(); - Assert.AreEqual(0, anim.CurrentTime); + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(0, anim.CurrentTime); - anim.CurrentTime = 10; - Assert.AreEqual(10, anim.CurrentTime); + anim.CurrentTime = 10; + Assert.AreEqual(10, anim.CurrentTime); + } } [Test] public void TestDirection() { - var anim = new TestableQAbstractAnimation(); - - Assert.AreEqual(QAbstractAnimation.Direction.Forward.ToString(), anim.direction.ToString()); + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(QAbstractAnimation.Direction.Forward.ToString(), anim.direction.ToString()); - anim.direction = QAbstractAnimation.Direction.Backward; - Assert.AreEqual(QAbstractAnimation.Direction.Backward.ToString(), anim.direction.ToString()); + anim.direction = QAbstractAnimation.Direction.Backward; + Assert.AreEqual(QAbstractAnimation.Direction.Backward.ToString(), anim.direction.ToString()); - anim.direction = QAbstractAnimation.Direction.Forward; - Assert.AreEqual(QAbstractAnimation.Direction.Forward.ToString(), anim.direction.ToString()); + anim.direction = QAbstractAnimation.Direction.Forward; + Assert.AreEqual(QAbstractAnimation.Direction.Forward.ToString(), anim.direction.ToString()); + } } [Test] public void TestGroup() - { - var anim = new TestableQAbstractAnimation(); - var group = new DummyQAnimationGroup(); - - group.AddAnimation(anim); - - Assert.AreSame(group, anim.Group); + { + var anim = new TestableQAbstractAnimation(); + using (var group = new DummyQAnimationGroup()) + { + @group.AddAnimation(anim); + + Assert.AreSame(@group, anim.Group); + } } - + [Test] public void TestLoopCount() - { - var anim = new TestableQAbstractAnimation(); - Assert.AreEqual(1, anim.LoopCount); + { + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(1, anim.LoopCount); - anim.LoopCount = 10; - Assert.AreEqual(10, anim.LoopCount); + anim.LoopCount = 10; + Assert.AreEqual(10, anim.LoopCount); + } } [Test] public void TestState() - { - var anim = new TestableQAbstractAnimation(); - Assert.AreEqual(QAbstractAnimation.State.Stopped, anim.state); + { + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(QAbstractAnimation.State.Stopped, anim.state); + } } [Test] public void TestTotalDuration() { - var anim = new TestableQAbstractAnimation(); - Assert.AreEqual(10, anim.TotalDuration); + using (var anim = new TestableQAbstractAnimation()) + { + Assert.AreEqual(10, anim.TotalDuration); - anim.LoopCount = 5; - Assert.AreEqual(50, anim.TotalDuration); + anim.LoopCount = 5; + Assert.AreEqual(50, anim.TotalDuration); + } } [Test] public void TestAvoidJumpAtStart() { - var anim = new TestableQAbstractAnimation(); - anim.SetDuration(1000); + using (var anim = new TestableQAbstractAnimation()) + { + anim.SetDuration(1000); - anim.Start(); + anim.Start(); - System.Threading.Thread.Sleep(300); + System.Threading.Thread.Sleep(300); - QCoreApplication.ProcessEvents(); - Assert.Less(anim.CurrentTime, 50); + QCoreApplication.ProcessEvents(); + Assert.Less(anim.CurrentTime, 50); + } } [Test] public void TestAvoidJumpAtStartWithStop() { - var anim = new TestableQAbstractAnimation(); - anim.SetDuration(1000); - - var anim2 = new TestableQAbstractAnimation(); - anim2.SetDuration(1000); - - var anim3 = new TestableQAbstractAnimation(); - anim3.SetDuration(1000); - - anim.Start(); - System.Threading.Thread.Sleep(300); - anim.Stop(); - - anim2.Start(); - System.Threading.Thread.Sleep(300); - anim3.Start(); - - - QCoreApplication.ProcessEvents(); - Assert.Less(anim2.CurrentTime, 50); - Assert.Less(anim3.CurrentTime, 50); + using (var anim = new TestableQAbstractAnimation()) + { + anim.SetDuration(1000); + + using (var anim2 = new TestableQAbstractAnimation()) + { + anim2.SetDuration(1000); + + using (var anim3 = new TestableQAbstractAnimation()) + { + anim3.SetDuration(1000); + + anim.Start(); + System.Threading.Thread.Sleep(300); + anim.Stop(); + + anim2.Start(); + System.Threading.Thread.Sleep(300); + anim3.Start(); + + QCoreApplication.ProcessEvents(); + Assert.Less(anim2.CurrentTime, 50); + Assert.Less(anim3.CurrentTime, 50); + } + } + } } [Test] public void TestAvoidJumpAtStartWithRunning() { - var anim = new TestableQAbstractAnimation(); - anim.SetDuration(2000); - - var anim2 = new TestableQAbstractAnimation(); - anim2.SetDuration(1000); - - var anim3 = new TestableQAbstractAnimation(); - anim3.SetDuration(1000); - - anim.Start(); - System.Threading.Thread.Sleep(300); - - anim2.Start(); - System.Threading.Thread.Sleep(300); - anim3.Start(); - - - QCoreApplication.ProcessEvents(); - Assert.Less(anim2.CurrentTime, 50); - Assert.Less(anim3.CurrentTime, 50); - } + using (var anim = new TestableQAbstractAnimation()) + { + anim.SetDuration(2000); + + using (var anim2 = new TestableQAbstractAnimation()) + { + anim2.SetDuration(1000); + + using (var anim3 = new TestableQAbstractAnimation()) + { + anim3.SetDuration(1000); + + anim.Start(); + System.Threading.Thread.Sleep(300); + + anim2.Start(); + System.Threading.Thread.Sleep(300); + anim3.Start(); + + QCoreApplication.ProcessEvents(); + Assert.Less(anim2.CurrentTime, 50); + Assert.Less(anim3.CurrentTime, 50); + } + } + } + } private class TestableQAbstractAnimation : QAbstractAnimation { diff --git a/QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs b/QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs index 908a779e..d9d84273 100644 --- a/QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs +++ b/QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs @@ -19,13 +19,14 @@ public void Dispose() [Test] public void TestOpenMode() { - var obj = new MyIODevice(); - obj.SetOpenMode(QIODevice.OpenModeFlag.NotOpen); - Assert.AreEqual(QIODevice.OpenModeFlag.NotOpen, obj.OpenMode); + using (var obj = new MyIODevice()) + { + obj.SetOpenMode(QIODevice.OpenModeFlag.NotOpen); + Assert.AreEqual(QIODevice.OpenModeFlag.NotOpen, obj.OpenMode); - obj.SetOpenMode(QIODevice.OpenModeFlag.ReadWrite); - Assert.AreEqual(QIODevice.OpenModeFlag.ReadWrite, obj.OpenMode); - // BUG: calling Dispose here causes a crash - the original function pointer is null + obj.SetOpenMode(QIODevice.OpenModeFlag.ReadWrite); + Assert.AreEqual(QIODevice.OpenModeFlag.ReadWrite, obj.OpenMode); + } } public class MyIODevice : QIODevice diff --git a/QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs b/QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs index 5c8f78f7..37d8d580 100644 --- a/QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs +++ b/QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs @@ -437,7 +437,6 @@ public void TestSetUserName() Assert.AreEqual("tray2", baseUrl.UserName()); } - //[Ignore("Bug!")] [Test] public void TestSwap() { diff --git a/QtSharp.Tests/Manual/QtCore/Plugin/QUuidTests.cs b/QtSharp.Tests/Manual/QtCore/Plugin/QUuidTests.cs index 5af1bd12..8b9af024 100644 --- a/QtSharp.Tests/Manual/QtCore/Plugin/QUuidTests.cs +++ b/QtSharp.Tests/Manual/QtCore/Plugin/QUuidTests.cs @@ -221,7 +221,6 @@ public void TestGuid() throw new AssertionException("GUID not implemented!"); } - [Ignore("Bug!")] [Test] public void TestNotEqualOperator() {