mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 01:36:17 +01:00
Convert tests/gobject/testgobject.c to glib test framework
This commit is contained in:
parent
81fd75b4bb
commit
ccfabc0f99
@ -15,11 +15,12 @@
|
|||||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#define G_LOG_DOMAIN "TestObject"
|
#define G_LOG_DOMAIN "TestObject"
|
||||||
#include <glib-object.h>
|
|
||||||
|
|
||||||
/* --- TestIface --- */
|
/* --- TestIface --- */
|
||||||
#define TEST_TYPE_IFACE (test_iface_get_type ())
|
#define TEST_TYPE_IFACE (test_iface_get_type ())
|
||||||
@ -99,11 +100,10 @@ test_object_test_iface_init (gpointer giface,
|
|||||||
TestIfaceClass *iface = giface;
|
TestIfaceClass *iface = giface;
|
||||||
|
|
||||||
g_assert (iface_data == GUINT_TO_POINTER (42));
|
g_assert (iface_data == GUINT_TO_POINTER (42));
|
||||||
|
g_assert_cmpint (G_TYPE_FROM_INTERFACE (iface), ==, TEST_TYPE_IFACE);
|
||||||
g_assert (G_TYPE_FROM_INTERFACE (iface) == TEST_TYPE_IFACE);
|
|
||||||
|
|
||||||
/* assert iface_base_init() was already called */
|
/* assert iface_base_init() was already called */
|
||||||
g_assert (iface_base_init_count > 0);
|
g_assert_cmpuint (iface_base_init_count, >, 0);
|
||||||
|
|
||||||
/* initialize stuff */
|
/* initialize stuff */
|
||||||
iface->print_string = print_foo;
|
iface->print_string = print_foo;
|
||||||
@ -219,8 +219,7 @@ static void
|
|||||||
test_object_init (TestObject *tobject)
|
test_object_init (TestObject *tobject)
|
||||||
{
|
{
|
||||||
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
|
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
|
||||||
|
g_assert_nonnull (priv);
|
||||||
g_assert (priv);
|
|
||||||
|
|
||||||
priv->dummy1 = 54321;
|
priv->dummy1 = 54321;
|
||||||
}
|
}
|
||||||
@ -232,8 +231,8 @@ test_object_check_private_init (TestObject *tobject)
|
|||||||
{
|
{
|
||||||
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
|
TestObjectPrivate *priv = test_object_get_instance_private (tobject);
|
||||||
|
|
||||||
g_print ("private data during initialization: %u == %u\n", priv->dummy1, 54321);
|
g_test_message ("private data during initialization: %u == %u", priv->dummy1, 54321);
|
||||||
g_assert (priv->dummy1 == 54321);
|
g_assert_cmpint (priv->dummy1, ==, 54321);
|
||||||
}
|
}
|
||||||
static gboolean
|
static gboolean
|
||||||
test_signal_accumulator (GSignalInvocationHint *ihint,
|
test_signal_accumulator (GSignalInvocationHint *ihint,
|
||||||
@ -261,7 +260,7 @@ test_object_test_signal (TestObject *tobject,
|
|||||||
TestIface *iface_object,
|
TestIface *iface_object,
|
||||||
gpointer tdata)
|
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);
|
g_return_val_if_fail (TEST_IS_IFACE (iface_object), NULL);
|
||||||
|
|
||||||
@ -280,13 +279,13 @@ print_bar (TestIface *tiobj,
|
|||||||
|
|
||||||
if (!string)
|
if (!string)
|
||||||
string = "<NULL>";
|
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 = g_type_interface_peek_parent (TEST_IFACE_GET_CLASS (tiobj));
|
||||||
parent_iface->print_string (tiobj, string);
|
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
|
static void
|
||||||
@ -296,7 +295,6 @@ derived_object_test_iface_init (gpointer giface,
|
|||||||
TestIfaceClass *iface = giface;
|
TestIfaceClass *iface = giface;
|
||||||
|
|
||||||
g_assert (iface_data == GUINT_TO_POINTER (87));
|
g_assert (iface_data == GUINT_TO_POINTER (87));
|
||||||
|
|
||||||
g_assert (G_TYPE_FROM_INTERFACE (iface) == TEST_TYPE_IFACE);
|
g_assert (G_TYPE_FROM_INTERFACE (iface) == TEST_TYPE_IFACE);
|
||||||
|
|
||||||
/* assert test_object_test_iface_init() was already called */
|
/* assert test_object_test_iface_init() was already called */
|
||||||
@ -378,18 +376,14 @@ derived_object_init (DerivedObject *dobject)
|
|||||||
DerivedObjectPrivate *derived_priv;
|
DerivedObjectPrivate *derived_priv;
|
||||||
|
|
||||||
derived_priv = derived_object_get_instance_private (dobject);
|
derived_priv = derived_object_get_instance_private (dobject);
|
||||||
|
g_assert_nonnull (derived_priv);
|
||||||
g_assert (derived_priv);
|
|
||||||
|
|
||||||
test_priv = test_object_get_instance_private (TEST_OBJECT (dobject));
|
test_priv = test_object_get_instance_private (TEST_OBJECT (dobject));
|
||||||
|
g_assert_nonnull (test_priv);
|
||||||
g_assert (test_priv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- main --- */
|
static void
|
||||||
int
|
test_gobject_basics (void)
|
||||||
main (int argc,
|
|
||||||
char *argv[])
|
|
||||||
{
|
{
|
||||||
GTypeInfo info = { 0, };
|
GTypeInfo info = { 0, };
|
||||||
GTypeFundamentalInfo finfo = { 0, };
|
GTypeFundamentalInfo finfo = { 0, };
|
||||||
@ -422,24 +416,30 @@ main (int argc,
|
|||||||
|
|
||||||
sigarg = g_object_new (TEST_TYPE_OBJECT, NULL);
|
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_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_assert_cmpstr (string, ==, "<default_handler><default_handler><default_handler>");
|
||||||
g_free (string);
|
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 (sigarg), "iface-string-from-test-type");
|
||||||
iface_print_string (TEST_IFACE (dobject), "iface-string-from-derived-type");
|
iface_print_string (TEST_IFACE (dobject), "iface-string-from-derived-type");
|
||||||
|
|
||||||
priv = test_object_get_instance_private (TEST_OBJECT (dobject));
|
priv = test_object_get_instance_private (TEST_OBJECT (dobject));
|
||||||
g_print ("private data after initialization: %u == %u\n", priv->dummy1, 54321);
|
g_test_message ("private data after initialization: %u == %u", priv->dummy1, 54321);
|
||||||
g_assert (priv->dummy1 == 54321);
|
g_assert_cmpint (priv->dummy1, ==, 54321);
|
||||||
|
|
||||||
g_object_unref (sigarg);
|
g_object_unref (sigarg);
|
||||||
g_object_unref (dobject);
|
g_object_unref (dobject);
|
||||||
|
}
|
||||||
g_message ("%s done", argv[0]);
|
|
||||||
|
int
|
||||||
return 0;
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/gobject/basics", test_gobject_basics);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user