[glib: 2/11] tests: Port closure-refcount to use g_test_run()



commit 15958c3ba9d02c0f627e9d6955680a43e0edd62b
Author: Philip Withnall <withnall endlessm com>
Date:   Wed Feb 27 11:53:55 2019 +0000

    tests: Port closure-refcount to use g_test_run()
    
    This allows more structured test running and output.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 gobject/tests/closure-refcount.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gobject/tests/closure-refcount.c b/gobject/tests/closure-refcount.c
index a4c283156..e7d79703a 100644
--- a/gobject/tests/closure-refcount.c
+++ b/gobject/tests/closure-refcount.c
@@ -228,18 +228,18 @@ test_emissions (GTest *test)
   my_test_emit_test_signal2 (test, TEST_INT2);
 }
 
-int
-main (int    argc,
-      char **argv)
+/* Test that closure refcounting works even when high contested between three
+ * threads (the main thread, thread1 and thread2). Both child threads are
+ * contesting refs/unrefs, while the main thread periodically emits signals
+ * which also do refs/unrefs on closures. */
+static void
+test_closure_refcount (void)
 {
   GThread *thread1, *thread2;
   GClosure *closure;
   GTest *object;
   guint i;
 
-  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));
-
   object = g_object_new (G_TYPE_TEST, NULL);
   closure = g_cclosure_new (G_CALLBACK (test_signal_handler), TEST_POINTER2, destroy_data);
 
@@ -292,6 +292,15 @@ main (int    argc,
   g_assert (seen_test_int2 != FALSE);
   g_assert (seen_signal_handler != FALSE);
   g_assert (seen_cleanup != FALSE);
+}
+
+int
+main (int argc,
+      char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/closure/refcount", test_closure_refcount);
 
-  return 0;
+  return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]