Skip to content

Commit 6cab7ff

Browse files
committed
Cleaned up all tests, including their memory, finding a bug in the process.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent f960653 commit 6cab7ff

13 files changed

+1139
-841
lines changed

QtSharp.Tests/Manual/QtCore/Animation/QAbstractAnimationTests.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public void Dispose()
1717
{
1818
// TODO: Add tear down code.
1919
}
20+
21+
// BUG: disposing of any of the animations crashes - the function pointer is null; there's something wrong when constructing custom classes
2022

2123
[Test]
2224
public void TestEmptyConstructor()
@@ -65,7 +67,7 @@ public void TestDirection()
6567
}
6668

6769
[Test]
68-
public unsafe void TestGroup()
70+
public void TestGroup()
6971
{
7072
var anim = new TestableQAbstractAnimation();
7173
var group = new DummyQAnimationGroup();
@@ -76,7 +78,7 @@ public unsafe void TestGroup()
7678
}
7779

7880
[Test]
79-
public unsafe void TestLoopCount()
81+
public void TestLoopCount()
8082
{
8183
var anim = new TestableQAbstractAnimation();
8284
Assert.AreEqual(1, anim.LoopCount);
@@ -86,7 +88,7 @@ public unsafe void TestLoopCount()
8688
}
8789

8890
[Test]
89-
public unsafe void TestState()
91+
public void TestState()
9092
{
9193
var anim = new TestableQAbstractAnimation();
9294
Assert.AreEqual(QAbstractAnimation.State.Stopped, anim.state);
@@ -169,11 +171,11 @@ public void TestAvoidJumpAtStartWithRunning()
169171

170172
private class TestableQAbstractAnimation : QAbstractAnimation
171173
{
172-
private int _duration = 10;
174+
private int duration = 10;
173175

174176
public override int Duration
175177
{
176-
get { return _duration; }
178+
get { return this.duration; }
177179
}
178180

179181
protected override void UpdateCurrentTime(int value)
@@ -183,28 +185,23 @@ protected override void UpdateCurrentTime(int value)
183185

184186
public void SetDuration(int val)
185187
{
186-
_duration = val;
188+
this.duration = val;
187189
}
188190
}
189191

190192
private class DummyQAnimationGroup : QAnimationGroup
191193
{
192-
private int _duration = 10;
194+
private int duration = 10;
193195

194196
public override int Duration
195197
{
196-
get { return _duration; }
198+
get { return this.duration; }
197199
}
198200

199201
protected override void UpdateCurrentTime(int value)
200202
{
201203

202204
}
203-
204-
public void SetDuration(int val)
205-
{
206-
_duration = val;
207-
}
208205
}
209206
}
210207
}

QtSharp.Tests/Manual/QtCore/Animation/QParallelAnimationGroupTests.cs

+15-55
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using NUnit.Framework;
1+
using NUnit.Framework;
62
using QtCore;
73

84
namespace QtSharp.Tests.Manual.QtCore.Animation
@@ -55,13 +51,13 @@ public void TestSetCurrentTime()
5551

5652
// Current time = 1
5753
group.CurrentTime = 1;
58-
Assert.AreEqual(QAnimationGroup.State.Stopped, group.state);
59-
Assert.AreEqual(QAnimationGroup.State.Stopped, parallel.state);
60-
Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o1.state);
61-
Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o2.state);
62-
Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o3.state);
63-
Assert.AreEqual(QAnimationGroup.State.Stopped, notTimeDriven.state);
64-
Assert.AreEqual(QAnimationGroup.State.Stopped, loopsForever.state);
54+
Assert.AreEqual(QAbstractAnimation.State.Stopped, group.state);
55+
Assert.AreEqual(QAbstractAnimation.State.Stopped, parallel.state);
56+
Assert.AreEqual(QAbstractAnimation.State.Stopped, a1_p_o1.state);
57+
Assert.AreEqual(QAbstractAnimation.State.Stopped, a1_p_o2.state);
58+
Assert.AreEqual(QAbstractAnimation.State.Stopped, a1_p_o3.state);
59+
Assert.AreEqual(QAbstractAnimation.State.Stopped, notTimeDriven.state);
60+
Assert.AreEqual(QAbstractAnimation.State.Stopped, loopsForever.state);
6561

6662
Assert.AreEqual(1, group.CurrentLoopTime);
6763
Assert.AreEqual(1, a1_p_o1.CurrentLoopTime);
@@ -232,7 +228,7 @@ public unsafe void TestClearGroup()
232228
}
233229

234230
[Test]
235-
public unsafe void TestPropagateGroupUpdateToChildren()
231+
public void TestPropagateGroupUpdateToChildren()
236232
{
237233
// this test verifies if group state changes are updating its children correctly
238234
var group = new QParallelAnimationGroup();
@@ -324,7 +320,7 @@ public void TestUpdateChildrenWithRunningGroup()
324320
}
325321

326322
[Test]
327-
public unsafe void TestDeleteChildrenWithRunningGroup()
323+
public void TestDeleteChildrenWithRunningGroup()
328324
{
329325
// test if children can be activated when their group is stopped
330326
var group = new QParallelAnimationGroup();
@@ -345,7 +341,6 @@ public unsafe void TestDeleteChildrenWithRunningGroup()
345341
Assert.Greater(group.CurrentLoopTime, 0);
346342

347343
group.RemoveAnimation(anim1);
348-
anim1 = null;
349344
Assert.AreEqual(0, group.AnimationCount);
350345
Assert.AreEqual(0, group.Duration);
351346
Assert.AreEqual(QAbstractAnimation.State.Stopped, group.state);
@@ -671,81 +666,46 @@ public void TestCrashWhenRemovingUncontrolledAnimation()
671666

672667
private class AnimationObject : QObject
673668
{
674-
public int Value { get; set; }
675-
676-
public AnimationObject(int startValue = 0)
677-
{
678-
Value = startValue;
679-
}
680669
}
681670

682671
private class TestAnimation : QVariantAnimation
683672
{
684673
public virtual void UpdateCurrentValue(ref QVariant value)
685674
{ }
686675

687-
public virtual void UpdateState(QAbstractAnimation.State oldState,
688-
QAbstractAnimation.State newState)
676+
protected override void UpdateState(State oldState, State newState)
689677
{ }
690-
691678
}
692679

693680
private class TestAnimation2 : QVariantAnimation
694681
{
695-
int _duration;
682+
private readonly int duration;
696683
public override int Duration
697684
{
698-
get { return _duration; }
685+
get { return this.duration; }
699686
}
700687

701688
public virtual void UpdateCurrentValue(ref QVariant value)
702689
{ }
703690

704-
public virtual void UpdateState(QAbstractAnimation.State oldState,
705-
QAbstractAnimation.State newState)
706-
{ }
707-
708-
public TestAnimation2(QAbstractAnimation animation)
709-
: base(animation)
691+
protected override void UpdateState(State oldState, State newState)
710692
{ }
711693

712694
public TestAnimation2(int duration, QAbstractAnimation animation)
713695
: base(animation)
714696
{
715-
_duration = duration;
697+
this.duration = duration;
716698
}
717699

718700
}
719701

720702
private class UncontrolledAnimation : QPropertyAnimation
721703
{
722-
private int _id;
723-
724704
public override int Duration { get { return -1; } }
725705

726-
public new void TimerEvent(QTimerEvent e)
727-
{
728-
if (e.TimerId == _id)
729-
Stop();
730-
}
731-
732-
protected void UpdateRunning(bool running)
733-
{
734-
if (running)
735-
{
736-
_id = StartTimer(500);
737-
}
738-
else
739-
{
740-
KillTimer(_id);
741-
_id = 0;
742-
}
743-
}
744-
745706
public UncontrolledAnimation(QObject target, QByteArray propertyName, QObject parent = null)
746707
: base(target, propertyName, parent)
747708
{
748-
_id = 0;
749709
SetDuration(250);
750710
EndValue = new QVariant(0);
751711
}

QtSharp.Tests/Manual/QtCore/IO/QFileInfoTests.cs

+23-10
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,63 @@ public class QFileInfoTests
1919
[SetUp]
2020
public void Init()
2121
{
22-
// TODO: Add Init code.
2322
_fileInfo = new QFileInfo(_testFilePath1.FullName);
2423
}
2524

2625
[TearDown]
2726
public void Dispose()
2827
{
29-
// TODO: Add tear down code.
28+
_fileInfo.Dispose();
3029
}
3130

3231
#region Ctor
3332
[Test]
3433
public void TestEmptyConstructorNotThrowingAnException()
3534
{
36-
var q = new QFileInfo();
35+
using (new QFileInfo())
36+
{
37+
}
3738
}
3839

3940
[Test]
4041
public void TestStringConstructorNotThrowingAnException()
4142
{
42-
var q = new QFileInfo(_testFilePath2.FullName);
43+
using (new QFileInfo(this._testFilePath2.FullName))
44+
{
45+
}
4346
}
4447

4548
[Test]
4649
public void TestFileConstructorNotThrowingAnException()
4750
{
48-
var f = new QFile(_testFilePath2.FullName);
49-
var q = new QFileInfo(f);
51+
using (var f = new QFile(_testFilePath2.FullName))
52+
{
53+
using (new QFileInfo(f))
54+
{
55+
}
56+
}
5057
}
5158

5259
[Test]
5360
public void TestDirConstructorNotThrowingAnException()
5461
{
5562
var f = new FileInfo(_testFilePath2.FullName);
56-
var dir = new QDir(f.Directory.FullName);
57-
58-
var q = new QFileInfo(dir, f.Name);
63+
using (var dir = new QDir(f.Directory.FullName))
64+
{
65+
using (new QFileInfo(dir, f.Name))
66+
{
67+
}
68+
}
5969
}
6070

6171
[Test]
6272
public void TestQFileInfoConstructorNotThrowingAnException()
6373
{
64-
var q = new QFileInfo(_fileInfo);
74+
using (new QFileInfo(this._fileInfo))
75+
{
76+
}
6577
}
78+
6679
#endregion
6780

6881
[Test]

QtSharp.Tests/Manual/QtCore/IO/QIODeviceTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ public class QIODeviceTests
99
[SetUp]
1010
public void Init()
1111
{
12-
// TODO: Add Init code.
1312
}
1413

1514
[TearDown]
1615
public void Dispose()
1716
{
18-
// TODO: Add tear down code.
1917
}
2018

2119
[Test]
@@ -27,8 +25,9 @@ public void TestOpenMode()
2725

2826
obj.SetOpenMode(QIODevice.OpenModeFlag.ReadWrite);
2927
Assert.AreEqual(QIODevice.OpenModeFlag.ReadWrite, obj.OpenMode);
28+
// BUG: calling Dispose here causes a crash - the original function pointer is null
3029
}
31-
30+
3231
public class MyIODevice : QIODevice
3332
{
3433
public void SetOpenMode(OpenModeFlag openMode)

0 commit comments

Comments
 (0)