Merge branch 'move_testgobject' into 'main'

Move tests/gobject/testgobject.c to gobject/tests/basics-gobject.c

See merge request GNOME/glib!2696
This commit is contained in:
Philip Withnall 2022-06-08 09:52:55 +00:00
commit 5d498f4d1c
3 changed files with 91 additions and 91 deletions

View File

@ -15,11 +15,12 @@
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <glib-object.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestObject"
#include <glib-object.h>
/* --- TestIface --- */
#define TEST_TYPE_IFACE (test_iface_get_type ())
@ -99,11 +100,10 @@ test_object_test_iface_init (gpointer giface,
TestIfaceClass *iface = giface;
g_assert (iface_data == GUINT_TO_POINTER (42));
g_assert (G_TYPE_FROM_INTERFACE (iface) == TEST_TYPE_IFACE);
g_assert_cmpint (G_TYPE_FROM_INTERFACE (iface), ==, TEST_TYPE_IFACE);
/* assert iface_base_init() was already called */
g_assert (iface_base_init_count > 0);
g_assert_cmpuint (iface_base_init_count, >, 0);
/* initialize stuff */
iface->print_string = print_foo;
@ -219,8 +219,7 @@ static void
test_object_init (TestObject *tobject)
{
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
g_assert (priv);
g_assert_nonnull (priv);
priv->dummy1 = 54321;
}
@ -232,8 +231,8 @@ test_object_check_private_init (TestObject *tobject)
{
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
g_print ("private data during initialization: %u == %u\n", priv->dummy1, 54321);
g_assert (priv->dummy1 == 54321);
g_test_message ("private data during initialization: %u == %u", priv->dummy1, 54321);
g_assert_cmpint (priv->dummy1, ==, 54321);
}
static gboolean
test_signal_accumulator (GSignalInvocationHint *ihint,
@ -261,7 +260,7 @@ test_object_test_signal (TestObject *tobject,
TestIface *iface_object,
gpointer tdata)
{
g_message ("::test_signal default_handler called");
g_test_message ("::test_signal default_handler called");
g_return_val_if_fail (TEST_IS_IFACE (iface_object), NULL);
@ -280,13 +279,13 @@ print_bar (TestIface *tiobj,
if (!string)
string = "<NULL>";
g_print ("Iface-BAR: \"%s\" from %p\n", string, tiobj);
g_test_message ("Iface-BAR: \"%s\" from %p", string, tiobj);
g_print ("chaining: ");
g_test_message ("chaining: ");
parent_iface = g_type_interface_peek_parent (TEST_IFACE_GET_CLASS (tiobj));
parent_iface->print_string (tiobj, string);
g_assert (g_type_interface_peek_parent (parent_iface) == NULL);
g_assert_null (g_type_interface_peek_parent (parent_iface));
}
static void
@ -296,7 +295,6 @@ derived_object_test_iface_init (gpointer giface,
TestIfaceClass *iface = giface;
g_assert (iface_data == GUINT_TO_POINTER (87));
g_assert (G_TYPE_FROM_INTERFACE (iface) == TEST_TYPE_IFACE);
/* assert test_object_test_iface_init() was already called */
@ -378,18 +376,14 @@ derived_object_init (DerivedObject *dobject)
DerivedObjectPrivate *derived_priv;
derived_priv = derived_object_get_instance_private (dobject);
g_assert (derived_priv);
g_assert_nonnull (derived_priv);
test_priv = test_object_get_instance_private (TEST_OBJECT (dobject));
g_assert (test_priv);
g_assert_nonnull (test_priv);
}
/* --- main --- */
int
main (int argc,
char *argv[])
static void
test_gobject_basics (void)
{
GTypeInfo info = { 0, };
GTypeFundamentalInfo finfo = { 0, };
@ -422,24 +416,30 @@ main (int argc,
sigarg = g_object_new (TEST_TYPE_OBJECT, NULL);
g_print ("MAIN: emit test-signal:\n");
g_test_message ("MAIN: emit test-signal:");
g_signal_emit_by_name (dobject, "test-signal", sigarg, NULL, &string);
g_message ("signal return: \"%s\"", string);
g_test_message ("signal return: \"%s\"", string);
g_assert_cmpstr (string, ==, "<default_handler><default_handler><default_handler>");
g_free (string);
g_print ("MAIN: call iface print-string on test and derived object:\n");
g_test_message ("MAIN: call iface print-string on test and derived object:");
iface_print_string (TEST_IFACE (sigarg), "iface-string-from-test-type");
iface_print_string (TEST_IFACE (dobject), "iface-string-from-derived-type");
priv = test_object_get_instance_private (TEST_OBJECT (dobject));
g_print ("private data after initialization: %u == %u\n", priv->dummy1, 54321);
g_assert (priv->dummy1 == 54321);
g_test_message ("private data after initialization: %u == %u", priv->dummy1, 54321);
g_assert_cmpint (priv->dummy1, ==, 54321);
g_object_unref (sigarg);
g_object_unref (dobject);
g_message ("%s done", argv[0]);
return 0;
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gobject/basics", test_gobject_basics);
return g_test_run ();
}

View File

@ -31,6 +31,7 @@ gobject_tests = {
'accumulator' : {
'source' : ['accumulator.c', marshalers_h, marshalers_c],
},
'basics-gobject' : {},
'boxed' : {},
'cxx' : {
'source' : ['cxx.cpp'],

View File

@ -1,5 +1,4 @@
gobject_tests = {
'testgobject' : {},
}
if host_system != 'windows'