summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEmmanuel Fleury <emmanuel.fleury@gmail.com>2022-03-13 17:44:45 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-05-26 19:13:16 +0100
commit17ddf79e1d015b6d5fc5cc2331eaee016e4d4e0f (patch)
treed0fbf230522203914617d27872991721861f125e /tests
parentb61d3edc332484107db695010d2227c149f5a3be (diff)
downloadglib-17ddf79e1d015b6d5fc5cc2331eaee016e4d4e0f.tar.gz
Convert tests/gobject/dynamictype.c to glib test framework
Diffstat (limited to 'tests')
-rw-r--r--tests/gobject/dynamictype.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/tests/gobject/dynamictype.c b/tests/gobject/dynamictype.c
index c3db276cf..617433027 100644
--- a/tests/gobject/dynamictype.c
+++ b/tests/gobject/dynamictype.c
@@ -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;
@@ -51,7 +46,7 @@ static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, test_iface_defa
static void
test_iface_default_init (TestIfaceClass *iface,
- gpointer class_data)
+ gpointer class_data)
{
}
@@ -75,10 +70,10 @@ struct _DynamicObjectClass
static void dynamic_object_iface_init (TestIface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED(DynamicObject, dynamic_object, G_TYPE_OBJECT, 0,
- G_IMPLEMENT_INTERFACE_DYNAMIC (TEST_TYPE_IFACE,
- dynamic_object_iface_init));
+ G_IMPLEMENT_INTERFACE_DYNAMIC (TEST_TYPE_IFACE,
+ dynamic_object_iface_init));
-static void
+static void
dynamic_object_class_init (DynamicObjectClass *class)
{
class->val = 42;
@@ -116,26 +111,28 @@ 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,
- TEST_TYPE_IFACE));
+ 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,
- TEST_TYPE_IFACE));
+ g_assert_true (g_type_is_a (DYNAMIC_OBJECT_TYPE,
+ TEST_TYPE_IFACE));
/* Unref causes finalize */
g_type_class_unref (class);
@@ -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
}
@@ -166,10 +168,12 @@ main (int argc,
char *argv[])
{
g_log_set_always_fatal (g_log_set_always_fatal (G_LOG_FATAL_MASK) |
- G_LOG_LEVEL_WARNING |
- G_LOG_LEVEL_CRITICAL);
+ G_LOG_LEVEL_WARNING |
+ G_LOG_LEVEL_CRITICAL);
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gobject/dynamic-type", test_dynamic_type);
- test_dynamic_type ();
-
- return 0;
+ return g_test_run ();
}