diff --git a/GirCore.sln b/GirCore.sln index 16de37ecc..0aab041ac 100644 --- a/GirCore.sln +++ b/GirCore.sln @@ -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 @@ -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} @@ -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 diff --git a/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj b/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj new file mode 100644 index 000000000..ba457085c --- /dev/null +++ b/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj @@ -0,0 +1,15 @@ + + + GdkPixbuf.Tests + + + + + + + + + PreserveNewest + + + diff --git a/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs b/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs new file mode 100644 index 000000000..0fdbdb466 --- /dev/null +++ b/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs @@ -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); + } + } +} diff --git a/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs b/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs new file mode 100644 index 000000000..9e815842f --- /dev/null +++ b/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs @@ -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); + } + } +} diff --git a/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp b/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp new file mode 100644 index 000000000..c599257f5 Binary files /dev/null and b/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp differ