From 1cee151cf5e7f5efb7a606bfb3ec1cb52b6609e3 Mon Sep 17 00:00:00 2001
From: badcel <1218031+badcel@users.noreply.github.com>
Date: Mon, 4 Nov 2024 21:42:27 +0100
Subject: [PATCH] Refactor GdkPixbuf-2.0.Tests The tests in
MemoryManagementTest.cs and PropertyTest.cs failed in the CI pipeline because
the given test.bmp could not be loaded anymore. This propbably happened due
to changes inside the installed software inside the CI runner.
To make the tests more robust the tests were transferred into the GirTest project thus not being dependent on GdkPixbuf anymore.
---
src/GirCore.Libs.slnf | 1 -
src/GirCore.sln | 15 ------
.../GirTestLib/girtest-property-tester.c | 33 ++++++++++++
.../Libs/GdkPixbuf-2.0.Tests/Assembly.cs | 18 -------
.../GdkPixbuf-2.0.Tests.csproj | 15 ------
.../MemoryManagementTest.cs | 48 ------------------
.../Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs | 24 ---------
src/Tests/Libs/GdkPixbuf-2.0.Tests/Test.cs | 21 --------
src/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp | Bin 750054 -> 0 bytes
src/Tests/Libs/GirTest-0.1.Tests/ClassTest.cs | 42 ++++++++++++++-
.../Libs/GirTest-0.1.Tests/PropertyTest.cs | 23 +++++++++
11 files changed, 97 insertions(+), 143 deletions(-)
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/Assembly.cs
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/Test.cs
delete mode 100644 src/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp
diff --git a/src/GirCore.Libs.slnf b/src/GirCore.Libs.slnf
index de1e5a743..f91215e6d 100644
--- a/src/GirCore.Libs.slnf
+++ b/src/GirCore.Libs.slnf
@@ -48,7 +48,6 @@
"Samples\\WebKit-6.0\\JavascriptCallback\\JavascriptCallback.csproj",
"Tests\\Generation\\GirLoader.Tests\\GirLoader.Tests.csproj",
"Tests\\Libs\\Cairo-1.0.Tests\\Cairo-1.0.Tests.csproj",
- "Tests\\Libs\\GdkPixbuf-2.0.Tests\\GdkPixbuf-2.0.Tests.csproj",
"Tests\\Libs\\Gio-2.0.Tests\\Gio-2.0.Tests.csproj",
"Tests\\Libs\\GLib-2.0.Tests\\GLib-2.0.Tests.csproj",
"Tests\\Libs\\GObject-2.0.Tests\\GObject-2.0.Tests.csproj",
diff --git a/src/GirCore.sln b/src/GirCore.sln
index 8401fb51b..725c152ea 100644
--- a/src/GirCore.sln
+++ b/src/GirCore.sln
@@ -59,8 +59,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestLoading", "Samples\GdkP
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gtk-4.0.Tests", "Tests\Libs\Gtk-4.0.Tests\Gtk-4.0.Tests.csproj", "{F86D983A-9881-4BE7-AF92-FA0CE41FB319}"
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
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generation", "Generation", "{7A05C10C-8797-4D29-A97A-F399316BE893}"
ProjectSection(SolutionItems) = preProject
Generation\Directory.Build.props = Generation\Directory.Build.props
@@ -471,18 +469,6 @@ Global
{F86D983A-9881-4BE7-AF92-FA0CE41FB319}.Release|x64.Build.0 = Release|Any CPU
{F86D983A-9881-4BE7-AF92-FA0CE41FB319}.Release|x86.ActiveCfg = Release|Any CPU
{F86D983A-9881-4BE7-AF92-FA0CE41FB319}.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
{1EA4392E-960D-4327-9426-4C6220A7B60D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EA4392E-960D-4327-9426-4C6220A7B60D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EA4392E-960D-4327-9426-4C6220A7B60D}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -900,7 +886,6 @@ Global
{46E769E2-FEC7-43EA-99B8-E7A7294D68B2} = {7A71B07F-B28B-4DDA-B1EA-565194056951}
{2BB1527F-D7A1-44BA-A297-4E69A3A4411C} = {7A71B07F-B28B-4DDA-B1EA-565194056951}
{F86D983A-9881-4BE7-AF92-FA0CE41FB319} = {46D66262-FC61-43B9-8E76-A361FA3D6C81}
- {61016ABA-608B-47FA-9FBD-CA17D24BAB89} = {46D66262-FC61-43B9-8E76-A361FA3D6C81}
{1EA4392E-960D-4327-9426-4C6220A7B60D} = {7A05C10C-8797-4D29-A97A-F399316BE893}
{0D9C5C7E-F81B-4E0E-B203-22D558E6D7F1} = {B670D679-3B2C-43E8-9F87-5E4E17628011}
{C48DB577-12BB-4AA8-8734-802A39C093BE} = {B670D679-3B2C-43E8-9F87-5E4E17628011}
diff --git a/src/Native/GirTestLib/girtest-property-tester.c b/src/Native/GirTestLib/girtest-property-tester.c
index 678cc734d..d7a60e322 100644
--- a/src/Native/GirTestLib/girtest-property-tester.c
+++ b/src/Native/GirTestLib/girtest-property-tester.c
@@ -12,6 +12,8 @@ typedef enum
PROP_STRING_VALUE = 1,
PROP_PROPERTY_TESTER = 2,
PROP_TYPED_RECORD_VALUE = 3,
+ PROP_INT_VALUE = 4,
+ PROP_BOOLEAN_VALUE = 5,
N_PROPERTIES
} PropertyTesterProperty;
@@ -22,6 +24,8 @@ struct _GirTestPropertyTester
gchar *string_value;
gchar *property_tester;
GirTestTypedRecordTester* record;
+ gint int_value;
+ gboolean boolean_value;
};
G_DEFINE_TYPE(GirTestPropertyTester, girtest_property_tester, G_TYPE_OBJECT)
@@ -48,6 +52,12 @@ girtest_property_tester_get_property (GObject *object,
case PROP_TYPED_RECORD_VALUE:
g_value_set_boxed (value, self->record);
break;
+ case PROP_INT_VALUE:
+ g_value_set_int (value, self->int_value);
+ break;
+ case PROP_BOOLEAN_VALUE:
+ g_value_set_boolean (value, self->boolean_value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -72,6 +82,12 @@ girtest_property_tester_set_property (GObject *object,
case PROP_TYPED_RECORD_VALUE:
self->record = g_value_get_boxed (value);
break;
+ case PROP_INT_VALUE:
+ self->int_value = g_value_get_int (value);
+ break;
+ case PROP_BOOLEAN_VALUE:
+ self->boolean_value = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -111,6 +127,23 @@ girtest_property_tester_class_init(GirTestPropertyTesterClass *class)
properties[PROP_TYPED_RECORD_VALUE] =
g_param_spec_boxed ("record-value", NULL, NULL, GIRTEST_TYPE_TYPED_RECORD_TESTER, G_PARAM_READWRITE);
+
+ properties[PROP_INT_VALUE] =
+ g_param_spec_int ("int-value",
+ "Integer Value",
+ "An int value",
+ G_MININT,
+ G_MAXINT,
+ 0 /* default value */,
+ G_PARAM_READWRITE);
+
+ properties[PROP_BOOLEAN_VALUE] =
+ g_param_spec_boolean ("boolean-value",
+ "Boolean Value",
+ "A boolean value",
+ FALSE /* default value */,
+ G_PARAM_READWRITE);
+
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/Assembly.cs b/src/Tests/Libs/GdkPixbuf-2.0.Tests/Assembly.cs
deleted file mode 100644
index 8c1b0b299..000000000
--- a/src/Tests/Libs/GdkPixbuf-2.0.Tests/Assembly.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace GdkPixbuf.Tests;
-
-[TestClass]
-public static class Assembly
-{
- [AssemblyInitialize]
- public static void Initialize(TestContext context)
- {
- Module.Initialize();
- GLib.Functions.LogSetAlwaysFatal(
- GLib.LogLevelFlags.LevelCritical
- | GLib.LogLevelFlags.LevelError
- | GLib.LogLevelFlags.LevelWarning
- );
- }
-}
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj b/src/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj
deleted file mode 100644
index ba457085c..000000000
--- a/src/Tests/Libs/GdkPixbuf-2.0.Tests/GdkPixbuf-2.0.Tests.csproj
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
- GdkPixbuf.Tests
-
-
-
-
-
-
-
-
- PreserveNewest
-
-
-
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs b/src/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs
deleted file mode 100644
index 7415ba22b..000000000
--- a/src/Tests/Libs/GdkPixbuf-2.0.Tests/MemoryManagementTest.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using System;
-using FluentAssertions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace GdkPixbuf.Tests;
-
-[TestClass, TestCategory("UnitTest")]
-public class MemoryManagementTest : Test
-{
- [TestMethod]
- public void TestAutomaticGObjectDisposal()
- {
- WeakReference weakReference = new(null);
- IDisposable? strongReference = null;
-
- CollectAfter(() =>
- {
- var obj = Pixbuf.NewFromFile("test.bmp");
- GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
- weakReference.Target = obj;
- });
-
- GObject.Internal.ObjectMapper.ObjectCount.Should().Be(0);
- weakReference.IsAlive.Should().BeFalse();
-
- CollectAfter(() =>
- {
- var obj = Pixbuf.NewFromFile("test.bmp");
-
- GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
-
- strongReference = obj;
- weakReference.Target = obj;
- });
-
- weakReference.IsAlive.Should().BeTrue();
- strongReference.Should().NotBeNull();
- }
-
- [TestMethod]
- public void TestManualGObjectDisposal()
- {
- var obj = Pixbuf.NewFromFile("test.bmp");
- GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
- obj.Dispose();
- GObject.Internal.ObjectMapper.ObjectCount.Should().Be(0);
- }
-}
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs b/src/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs
deleted file mode 100644
index 4d3c6a031..000000000
--- a/src/Tests/Libs/GdkPixbuf-2.0.Tests/PropertyTest.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using FluentAssertions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace GdkPixbuf.Tests;
-
-[TestClass, TestCategory("UnitTest")]
-public class PropertyTest : Test
-{
- [TestMethod]
- public void TestIntegerProperty()
- {
- var pixbuf = Pixbuf.NewFromFile("test.bmp");
- pixbuf.Width.Should().Be(500);
- pixbuf.Height.Should().Be(500);
- pixbuf.NChannels.Should().Be(3);
- }
-
- [TestMethod]
- public void TestBoolProperty()
- {
- var pixbuf = Pixbuf.NewFromFile("test.bmp");
- pixbuf.HasAlpha.Should().Be(false);
- }
-}
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/Test.cs b/src/Tests/Libs/GdkPixbuf-2.0.Tests/Test.cs
deleted file mode 100644
index 72e547e8c..000000000
--- a/src/Tests/Libs/GdkPixbuf-2.0.Tests/Test.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace GdkPixbuf.Tests;
-
-public abstract class Test
-{
- [TestCleanup]
- public void Cleanup()
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
-
- protected static void CollectAfter(Action action)
- {
- action();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
-}
diff --git a/src/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp b/src/Tests/Libs/GdkPixbuf-2.0.Tests/test.bmp
deleted file mode 100644
index c599257f5d3e227071e798896fcdd4e0c7d79172..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 750054
zcmeIup%H*U3(executor.Handle);
instanceData.RefCount.Should().Be(1);
}
+
+ [TestMethod]
+ public void TestManualGObjectDisposal()
+ {
+ var obj = ClassTester.New();
+ GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
+ obj.Dispose();
+ GObject.Internal.ObjectMapper.ObjectCount.Should().Be(0);
+ }
+
+ [TestMethod]
+ public void TestAutomaticGObjectDisposal()
+ {
+ WeakReference weakReference = new(null);
+ IDisposable? strongReference = null;
+
+ CollectAfter(() =>
+ {
+ var obj = ClassTester.New();
+ GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
+ weakReference.Target = obj;
+ });
+
+ GObject.Internal.ObjectMapper.ObjectCount.Should().Be(0);
+ weakReference.IsAlive.Should().BeFalse();
+
+ CollectAfter(() =>
+ {
+ var obj = ClassTester.New();
+
+ GObject.Internal.ObjectMapper.ObjectCount.Should().Be(1);
+
+ strongReference = obj;
+ weakReference.Target = obj;
+ });
+
+ weakReference.IsAlive.Should().BeTrue();
+ strongReference.Should().NotBeNull();
+ }
}
diff --git a/src/Tests/Libs/GirTest-0.1.Tests/PropertyTest.cs b/src/Tests/Libs/GirTest-0.1.Tests/PropertyTest.cs
index a9b4d1864..bf249d610 100644
--- a/src/Tests/Libs/GirTest-0.1.Tests/PropertyTest.cs
+++ b/src/Tests/Libs/GirTest-0.1.Tests/PropertyTest.cs
@@ -75,4 +75,27 @@ public void SupportsTypedRecordProperty()
PropertyTester.RecordValuePropertyDefinition.UnmanagedName.Should().Be("record-value");
PropertyTester.RecordValuePropertyDefinition.ManagedName.Should().Be(nameof(PropertyTester.RecordValue));
}
+
+ [DataTestMethod]
+ [DataRow(10)]
+ [DataRow(-10)]
+ [DataRow(0)]
+ public void TestIntProperty(int i)
+ {
+ var obj = PropertyTester.New();
+ obj.IntValue = i;
+
+ obj.IntValue.Should().Be(i);
+ }
+
+ [DataTestMethod]
+ [DataRow(true)]
+ [DataRow(false)]
+ public void TestBooleanProperty(bool b)
+ {
+ var obj = PropertyTester.New();
+ obj.BooleanValue = b;
+
+ obj.BooleanValue.Should().Be(b);
+ }
}