Skip to content

Commit

Permalink
Updated C++# to fix a crash when disposing of user impls of abstract …
Browse files Browse the repository at this point in the history
…types.

Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Nov 4, 2015
1 parent 6cab7ff commit dc43593
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 97 deletions.
222 changes: 133 additions & 89 deletions QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
13 changes: 7 additions & 6 deletions QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion QtSharp.Tests/Manual/QtCore/IO/QUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ public void TestSetUserName()
Assert.AreEqual("tray2", baseUrl.UserName());
}

//[Ignore("Bug!")]
[Test]
public void TestSwap()
{
Expand Down
1 change: 0 additions & 1 deletion QtSharp.Tests/Manual/QtCore/Plugin/QUuidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public void TestGuid()
throw new AssertionException("GUID not implemented!");
}

[Ignore("Bug!")]
[Test]
public void TestNotEqualOperator()
{
Expand Down

0 comments on commit dc43593

Please sign in to comment.