Skip to content

Commit

Permalink
Add Tests
Browse files Browse the repository at this point in the history
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
badcel committed Aug 8, 2021
1 parent fe05f41 commit 9aee619
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions GirCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawingArea", "Samples\Gtk3
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextEditor", "Samples\Gtk3\TextEditor\TextEditor.csproj", "{2510B0C1-793D-4EA7-A296-F54F881C94C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GdkPixbuf-2.0.Tests", "Tests\Libs\GdkPixbuf-2.0.Tests\GdkPixbuf-2.0.Tests.csproj", "{61016ABA-608B-47FA-9FBD-CA17D24BAB89}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -504,6 +506,18 @@ Global
{2510B0C1-793D-4EA7-A296-F54F881C94C8}.Release|x64.Build.0 = Release|Any CPU
{2510B0C1-793D-4EA7-A296-F54F881C94C8}.Release|x86.ActiveCfg = Release|Any CPU
{2510B0C1-793D-4EA7-A296-F54F881C94C8}.Release|x86.Build.0 = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|x64.ActiveCfg = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|x64.Build.0 = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|x86.ActiveCfg = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Debug|x86.Build.0 = Debug|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|Any CPU.Build.0 = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|x64.ActiveCfg = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|x64.Build.0 = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|x86.ActiveCfg = Release|Any CPU
{61016ABA-608B-47FA-9FBD-CA17D24BAB89}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BF7F9B0B-CB43-4161-BFAD-C6EE479FC86B} = {386AE10F-B7AC-4C97-AC5C-202D3662A868}
Expand Down Expand Up @@ -539,5 +553,6 @@ Global
{189A1440-3BFE-432E-8F43-931D1B571DCA} = {8BC11A63-D52B-40CB-9DDD-CD7C6DC21059}
{F1A41389-B4AD-4D0F-8C44-918BF3A6A57F} = {79FE88D9-9545-4AE8-80AF-8E2E2E55E8A3}
{2510B0C1-793D-4EA7-A296-F54F881C94C8} = {79FE88D9-9545-4AE8-80AF-8E2E2E55E8A3}
{61016ABA-608B-47FA-9FBD-CA17D24BAB89} = {46D66262-FC61-43B9-8E76-A361FA3D6C81}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj
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>
53 changes: 53 additions & 0 deletions Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs
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);
}
}
}
19 changes: 19 additions & 0 deletions Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs
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 added Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp
Binary file not shown.

0 comments on commit 9aee619

Please sign in to comment.