-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds some basic tests using GdkPixbuf which allows to run them as integration tests. Integration tests can be automatically run during continous integration on the server. - Add test for basic property reading - Add test for object disposal by garbage collector - Add test for object disposal by "Dispose" method.
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>GdkPixbuf.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Libs\GdkPixbuf-2.0\GdkPixbuf-2.0.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="test.bmp"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GdkPixbuf.Tests | ||
{ | ||
[TestClass, TestCategory("IntegrationTest")] | ||
public class MemoryManagementTest | ||
{ | ||
[TestMethod] | ||
public void TestAutomaticGObjectDisposal() | ||
{ | ||
WeakReference weakReference = new(null); | ||
object? strongReference = null; | ||
|
||
void CreateInstance(bool keepInstance) | ||
{ | ||
var obj = Pixbuf.NewFromFile("test.bmp"); | ||
|
||
GObject.Native.ObjectMapper.ObjectCount.Should().Be(1); | ||
|
||
if(keepInstance) | ||
strongReference = obj; | ||
|
||
weakReference.Target = obj; | ||
} | ||
|
||
CreateInstance(keepInstance: false); | ||
|
||
GC.Collect(); | ||
GC.WaitForPendingFinalizers(); | ||
GObject.Native.ObjectMapper.ObjectCount.Should().Be(0); | ||
weakReference.IsAlive.Should().BeFalse(); | ||
strongReference.Should().BeNull(); | ||
|
||
CreateInstance(keepInstance: true); | ||
GC.Collect(); | ||
GC.WaitForPendingFinalizers(); | ||
GObject.Native.ObjectMapper.ObjectCount.Should().Be(1); | ||
weakReference.IsAlive.Should().BeTrue(); | ||
strongReference.Should().NotBeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestManualGObjectDisposal() | ||
{ | ||
var obj = Pixbuf.NewFromFile("test.bmp"); | ||
GObject.Native.ObjectMapper.ObjectCount.Should().Be(1); | ||
obj.Dispose(); | ||
GObject.Native.ObjectMapper.ObjectCount.Should().Be(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GdkPixbuf.Tests | ||
{ | ||
[TestClass, TestCategory("IntegrationTest")] | ||
public class PropertyTests | ||
{ | ||
[TestMethod] | ||
public void ReadPropertyTest() | ||
{ | ||
var pixbuf = Pixbuf.NewFromFile("test.bmp"); | ||
pixbuf.GetWidth().Should().Be(500); | ||
pixbuf.GetHeight().Should().Be(500); | ||
pixbuf.GetHasAlpha().Should().Be(false); | ||
pixbuf.GetNChannels().Should().Be(3); | ||
} | ||
} | ||
} |
Binary file not shown.