summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Fleury <emmanuel.fleury@gmail.com>2022-03-16 09:26:15 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-05-26 18:37:34 +0100
commit62b5fe5991335d5580585e059de6e58b0450ff64 (patch)
tree0a0d3e3927e296a0321c6cca0a495e727af33b4b
parentce585ba4d2e885b3b0c83b44dd236e3d0a45a3a8 (diff)
downloadglib-62b5fe5991335d5580585e059de6e58b0450ff64.tar.gz
Convert tests/refcount/objects.c to glib test framework
-rw-r--r--tests/refcount/objects.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/tests/refcount/objects.c b/tests/refcount/objects.c
index 06b871936..0d8e20b03 100644
--- a/tests/refcount/objects.c
+++ b/tests/refcount/objects.c
@@ -5,7 +5,7 @@
#include <unistd.h>
#endif
-#define G_TYPE_TEST (my_test_get_type ())
+#define G_TYPE_TEST (my_test_get_type ())
#define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
#define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
#define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
@@ -65,7 +65,6 @@ my_test_class_init (GTestClass * klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
-
parent_class = g_type_class_ref (G_TYPE_OBJECT);
gobject_class->dispose = my_test_dispose;
@@ -74,7 +73,7 @@ my_test_class_init (GTestClass * klass)
static void
my_test_init (GTest * test)
{
- g_print ("init %p\n", test);
+ g_test_message ("init %p\n", test);
}
static void
@@ -84,7 +83,7 @@ my_test_dispose (GObject * object)
test = MY_TEST (object);
- g_print ("dispose %p!\n", test);
+ g_test_message ("dispose %p!\n", test);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -92,8 +91,8 @@ my_test_dispose (GObject * object)
static void
my_test_do_refcount (GTest * test)
{
- g_object_ref (test);
- g_object_unref (test);
+ g_object_ref (test);
+ g_object_unref (test);
}
static gpointer
@@ -104,25 +103,22 @@ run_thread (GTest * test)
while (!g_atomic_int_get (&stopping)) {
my_test_do_refcount (test);
if ((i++ % 10000) == 0) {
- g_print (".");
- g_thread_yield(); /* force context switch */
+ g_test_message (".");
+ g_thread_yield (); /* force context switch */
}
}
return NULL;
}
-int
-main (int argc, char **argv)
+static void
+test_refcount_object_basics (void)
{
guint i;
GTest *test1, *test2;
GArray *test_threads;
const guint n_threads = 5;
- g_print ("START: %s\n", argv[0]);
- g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
-
test1 = g_object_new (G_TYPE_TEST, NULL);
test2 = g_object_new (G_TYPE_TEST, NULL);
@@ -139,12 +135,10 @@ main (int argc, char **argv)
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
g_array_append_val (test_threads, thread);
}
- g_usleep (5000000);
+ g_usleep (5000000);
g_atomic_int_set (&stopping, 1);
- g_print ("\nstopping\n");
-
/* join all threads */
for (i = 0; i < 2 * n_threads; i++) {
GThread *thread;
@@ -156,8 +150,18 @@ main (int argc, char **argv)
g_object_unref (test1);
g_object_unref (test2);
g_array_unref (test_threads);
+}
+
+int
+main (int argc, gchar *argv[])
+{
+ g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
+ G_LOG_LEVEL_CRITICAL |
+ g_log_set_always_fatal (G_LOG_FATAL_MASK));
+
+ g_test_init (&argc, &argv, NULL);
- g_print ("stopped\n");
+ g_test_add_func ("/gobject/refcount/object-basics", test_refcount_object_basics);
- return 0;
+ return g_test_run ();
}