mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
Convert tests/gobject/dynamictype.c to glib test framework
This commit is contained in:
parent
b61d3edc33
commit
17ddf79e1d
@ -15,20 +15,12 @@
|
||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "TestDynamicType"
|
||||
|
||||
#undef G_DISABLE_ASSERT
|
||||
#undef G_DISABLE_CHECKS
|
||||
#undef G_DISABLE_CAST_CHECKS
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "testcommon.h"
|
||||
#include "testmodule.h"
|
||||
|
||||
/* This test tests the macros for defining dynamic types.
|
||||
*/
|
||||
/* This test tests the macros for defining dynamic types */
|
||||
|
||||
static gboolean loaded = FALSE;
|
||||
|
||||
@ -39,8 +31,11 @@ struct _TestIfaceClass
|
||||
};
|
||||
|
||||
static GType test_iface_get_type (void);
|
||||
|
||||
#define TEST_TYPE_IFACE (test_iface_get_type ())
|
||||
#define TEST_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass))
|
||||
#define TEST_IFACE_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass))
|
||||
|
||||
typedef struct _TestIface TestIface;
|
||||
typedef struct _TestIfaceClass TestIfaceClass;
|
||||
|
||||
@ -116,25 +111,27 @@ test_dynamic_type (void)
|
||||
|
||||
/* Not loaded until we call ref for the first time */
|
||||
class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
|
||||
g_assert (class == NULL);
|
||||
g_assert (!loaded);
|
||||
g_assert_null (class);
|
||||
g_assert_false (loaded);
|
||||
|
||||
/* Make sure interfaces work */
|
||||
g_assert (g_type_is_a (DYNAMIC_OBJECT_TYPE,
|
||||
g_assert_true (g_type_is_a (DYNAMIC_OBJECT_TYPE,
|
||||
TEST_TYPE_IFACE));
|
||||
|
||||
/* Ref loads */
|
||||
class = g_type_class_ref (DYNAMIC_OBJECT_TYPE);
|
||||
g_assert (class && class->val == 42);
|
||||
g_assert (loaded);
|
||||
g_assert_nonnull (class);
|
||||
g_assert_cmpint (class->val, ==, 42);
|
||||
g_assert_true (loaded);
|
||||
|
||||
/* Peek then works */
|
||||
class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
|
||||
g_assert (class && class->val == 42);
|
||||
g_assert (loaded);
|
||||
g_assert_nonnull (class);
|
||||
g_assert_cmpint (class->val, ==, 42);
|
||||
g_assert_true (loaded);
|
||||
|
||||
/* Make sure interfaces still work */
|
||||
g_assert (g_type_is_a (DYNAMIC_OBJECT_TYPE,
|
||||
g_assert_true (g_type_is_a (DYNAMIC_OBJECT_TYPE,
|
||||
TEST_TYPE_IFACE));
|
||||
|
||||
/* Unref causes finalize */
|
||||
@ -143,21 +140,26 @@ test_dynamic_type (void)
|
||||
/* Peek returns NULL */
|
||||
class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
|
||||
#if 0
|
||||
g_assert (!class);
|
||||
g_assert (!loaded);
|
||||
/* Disabled as unloading dynamic types is disabled.
|
||||
* See https://gitlab.gnome.org/GNOME/glib/-/issues/667 */
|
||||
g_assert_false (class);
|
||||
g_assert_false (loaded);
|
||||
#endif
|
||||
|
||||
/* Ref reloads */
|
||||
class = g_type_class_ref (DYNAMIC_OBJECT_TYPE);
|
||||
g_assert (class && class->val == 42);
|
||||
g_assert (loaded);
|
||||
g_assert_nonnull (class);
|
||||
g_assert_cmpint (class->val, ==, 42);
|
||||
g_assert_true (loaded);
|
||||
|
||||
/* And Unref causes finalize once more*/
|
||||
g_type_class_unref (class);
|
||||
class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
|
||||
#if 0
|
||||
g_assert (!class);
|
||||
g_assert (!loaded);
|
||||
/* Disabled as unloading dynamic types is disabled.
|
||||
* See https://gitlab.gnome.org/GNOME/glib/-/issues/667 */
|
||||
g_assert_null (class);
|
||||
g_assert_false (loaded);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -169,7 +171,9 @@ main (int argc,
|
||||
G_LOG_LEVEL_WARNING |
|
||||
G_LOG_LEVEL_CRITICAL);
|
||||
|
||||
test_dynamic_type ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
return 0;
|
||||
g_test_add_func ("/gobject/dynamic-type", test_dynamic_type);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user