mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
Merge branch 'refcount_tests' into 'main'
Moving tests/refcount/ directory to gobject/tests/ See merge request GNOME/glib!2553
This commit is contained in:
commit
d1cb96b5e3
@ -57,6 +57,28 @@ gobject_tests = {
|
||||
'signalgroup' : {},
|
||||
'testing' : {},
|
||||
'type-flags' : {},
|
||||
'objects-refcount1' : {},
|
||||
'objects-refcount2' : {'suite' : ['slow']},
|
||||
'properties-refcount1' : {},
|
||||
'properties-refcount2' : {'suite' : ['slow']},
|
||||
'properties-refcount3' : {'suite' : ['slow']},
|
||||
'properties-refcount4' : {},
|
||||
'signals-refcount1' : {
|
||||
'source' : 'signals-refcount.c',
|
||||
'c_args' : ['-DTESTNUM=1'],
|
||||
},
|
||||
'signals-refcount2' : {
|
||||
'source' : 'signals-refcount.c',
|
||||
'c_args' : ['-DTESTNUM=2'],
|
||||
},
|
||||
'signals-refcount3' : {
|
||||
'source' : 'signals-refcount.c',
|
||||
'c_args' : ['-DTESTNUM=3'],
|
||||
},
|
||||
'signals-refcount4' : {
|
||||
'source' : 'signals-refcount.c',
|
||||
'c_args' : ['-DTESTNUM=4'],
|
||||
},
|
||||
}
|
||||
|
||||
if cc.get_id() != 'msvc'
|
||||
|
@ -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);
|
||||
|
||||
@ -133,18 +129,16 @@ main (int argc, char **argv)
|
||||
for (i = 0; i < n_threads; i++) {
|
||||
GThread *thread;
|
||||
|
||||
thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL);
|
||||
thread = g_thread_new (NULL, (GThreadFunc) run_thread, test1);
|
||||
g_array_append_val (test_threads, thread);
|
||||
|
||||
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
|
||||
thread = g_thread_new (NULL, (GThreadFunc) run_thread, test2);
|
||||
g_array_append_val (test_threads, thread);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g_print ("stopped\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/object-basics", test_refcount_object_basics);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -73,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
|
||||
@ -83,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,30 +92,40 @@ static void
|
||||
my_test_do_refcount (GTest * test)
|
||||
{
|
||||
static guint i = 1;
|
||||
|
||||
if (i++ % 100000 == 0)
|
||||
g_print (".");
|
||||
g_object_ref (test);
|
||||
g_object_unref (test);
|
||||
g_test_message (".");
|
||||
|
||||
g_object_ref (test);
|
||||
g_object_unref (test);
|
||||
}
|
||||
|
||||
static void
|
||||
test_refcount_object_advanced (void)
|
||||
{
|
||||
gint i;
|
||||
GTest *test;
|
||||
|
||||
test = g_object_new (G_TYPE_TEST, NULL);
|
||||
|
||||
for (i = 0; i < 100000000; i++)
|
||||
{
|
||||
my_test_do_refcount (test);
|
||||
}
|
||||
|
||||
g_object_unref (test);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
gint i;
|
||||
GTest *test;
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
|
||||
G_LOG_LEVEL_CRITICAL |
|
||||
g_log_set_always_fatal (G_LOG_FATAL_MASK));
|
||||
|
||||
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));
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
test = g_object_new (G_TYPE_TEST, NULL);
|
||||
g_test_add_func ("/gobject/refcount/object-advanced", test_refcount_object_advanced);
|
||||
|
||||
for (i=0; i<100000000; i++) {
|
||||
my_test_do_refcount (test);
|
||||
}
|
||||
|
||||
g_object_unref (test);
|
||||
|
||||
g_print ("\n");
|
||||
|
||||
return 0;
|
||||
return g_test_run ();
|
||||
}
|
@ -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))
|
||||
@ -89,12 +89,12 @@ my_test_class_init (GTestClass * klass)
|
||||
gobject_class->set_property = my_test_set_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DUMMY,
|
||||
g_param_spec_int ("dummy",
|
||||
NULL,
|
||||
NULL,
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
PROP_DUMMY,
|
||||
g_param_spec_int ("dummy",
|
||||
NULL,
|
||||
NULL,
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -110,7 +110,7 @@ my_test_dispose (GObject * object)
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
my_test_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
@ -131,7 +131,7 @@ my_test_get_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
my_test_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
@ -160,7 +160,7 @@ dummy_notify (GObject *object,
|
||||
|
||||
test = MY_TEST (object);
|
||||
|
||||
test->count++;
|
||||
test->count++;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -176,12 +176,12 @@ static gpointer
|
||||
run_thread (GTest * test)
|
||||
{
|
||||
gint i = 1;
|
||||
|
||||
|
||||
while (!g_atomic_int_get (&stopping)) {
|
||||
my_test_do_property (test);
|
||||
if ((i++ % 10000) == 0)
|
||||
{
|
||||
g_print (".%c", 'a' + test->id);
|
||||
g_test_message (".%c", 'a' + test->id);
|
||||
g_thread_yield(); /* force context switch */
|
||||
}
|
||||
}
|
||||
@ -189,49 +189,55 @@ run_thread (GTest * test)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
test_refcount_properties_1 (void)
|
||||
{
|
||||
#define N_THREADS 5
|
||||
GThread *test_threads[N_THREADS];
|
||||
GTest *test_objects[N_THREADS];
|
||||
gint 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));
|
||||
|
||||
for (i = 0; i < N_THREADS; i++) {
|
||||
GTest *test;
|
||||
|
||||
test = g_object_new (G_TYPE_TEST, NULL);
|
||||
test_objects[i] = test;
|
||||
|
||||
g_assert (test->count == test->dummy);
|
||||
g_assert_cmpint (test->count, ==, test->dummy);
|
||||
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
|
||||
}
|
||||
|
||||
g_atomic_int_set (&stopping, FALSE);
|
||||
|
||||
for (i = 0; i < N_THREADS; i++)
|
||||
test_threads[i] = g_thread_create ((GThreadFunc) run_thread, test_objects[i], TRUE, NULL);
|
||||
test_threads[i] = g_thread_new (NULL, (GThreadFunc) run_thread, test_objects[i]);
|
||||
|
||||
g_usleep (3000000);
|
||||
|
||||
g_atomic_int_set (&stopping, TRUE);
|
||||
g_print ("\nstopping\n");
|
||||
|
||||
/* join all threads */
|
||||
for (i = 0; i < N_THREADS; i++)
|
||||
g_thread_join (test_threads[i]);
|
||||
|
||||
g_print ("stopped\n");
|
||||
|
||||
for (i = 0; i < N_THREADS; i++) {
|
||||
GTest *test = test_objects[i];
|
||||
|
||||
g_assert (test->count == test->dummy);
|
||||
g_assert_cmpint (test->count, ==, test->dummy);
|
||||
g_object_unref (test);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/properties-1", test_refcount_properties_1);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -87,18 +87,18 @@ my_test_class_init (GTestClass * klass)
|
||||
gobject_class->set_property = my_test_set_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DUMMY,
|
||||
g_param_spec_int ("dummy",
|
||||
NULL,
|
||||
NULL,
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
PROP_DUMMY,
|
||||
g_param_spec_int ("dummy",
|
||||
NULL,
|
||||
NULL,
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
my_test_init (GTest * test)
|
||||
{
|
||||
g_print ("init %p\n", test);
|
||||
g_test_message ("init %p\n", test);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -108,15 +108,15 @@ 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);
|
||||
}
|
||||
|
||||
static void
|
||||
my_test_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
static void
|
||||
my_test_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GTest *test;
|
||||
@ -134,11 +134,11 @@ my_test_get_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
my_test_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
static void
|
||||
my_test_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GTest *test;
|
||||
|
||||
@ -163,7 +163,7 @@ dummy_notify (GObject *object,
|
||||
{
|
||||
count++;
|
||||
if (count % 10000 == 0)
|
||||
g_print (".");
|
||||
g_test_message (".");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -175,28 +175,36 @@ my_test_do_property (GTest * test)
|
||||
g_object_set (test, "dummy", dummy + 1, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
test_refcount_properties_2 (void)
|
||||
{
|
||||
gint i;
|
||||
GTest *test;
|
||||
|
||||
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));
|
||||
|
||||
test = g_object_new (G_TYPE_TEST, NULL);
|
||||
|
||||
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
|
||||
g_assert_cmpint (count, ==, test->dummy);
|
||||
|
||||
g_assert (count == test->dummy);
|
||||
|
||||
for (i=0; i<1000000; i++) {
|
||||
my_test_do_property (test);
|
||||
}
|
||||
|
||||
g_assert (count == test->dummy);
|
||||
for (i = 0; i < 1000000; i++)
|
||||
{
|
||||
my_test_do_property (test);
|
||||
}
|
||||
g_assert_cmpint (count, ==, test->dummy);
|
||||
|
||||
g_object_unref (test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/properties-2", test_refcount_properties_2);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -144,28 +144,25 @@ run_thread (GTest * test)
|
||||
my_test_do_property (test);
|
||||
if ((i++ % 10000) == 0)
|
||||
{
|
||||
g_print (".%c", 'a' + test->id);
|
||||
g_thread_yield(); /* force context switch */
|
||||
g_test_message (".%c", 'a' + test->id);
|
||||
g_thread_yield(); /* force context switch */
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
test_refcount_properties_3 (void)
|
||||
{
|
||||
gint i;
|
||||
GTest *test;
|
||||
GArray *test_threads;
|
||||
const gint 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));
|
||||
|
||||
test = g_object_new (G_TYPE_TEST, NULL);
|
||||
|
||||
g_assert (test->count == test->dummy);
|
||||
g_assert_cmpint (test->count, ==, test->dummy);
|
||||
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
|
||||
|
||||
test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
|
||||
@ -175,13 +172,13 @@ main (int argc, char **argv)
|
||||
for (i = 0; i < n_threads; i++) {
|
||||
GThread *thread;
|
||||
|
||||
thread = g_thread_create ((GThreadFunc) run_thread, test, TRUE, NULL);
|
||||
thread = g_thread_new (NULL, (GThreadFunc) run_thread, test);
|
||||
g_array_append_val (test_threads, thread);
|
||||
}
|
||||
g_usleep (30000000);
|
||||
|
||||
g_atomic_int_set (&stopping, 1);
|
||||
g_print ("\nstopping\n");
|
||||
g_test_message ("\nstopping\n");
|
||||
|
||||
/* join all threads */
|
||||
for (i = 0; i < n_threads; i++) {
|
||||
@ -191,12 +188,23 @@ main (int argc, char **argv)
|
||||
g_thread_join (thread);
|
||||
}
|
||||
|
||||
g_print ("stopped\n");
|
||||
|
||||
g_print ("%d %d\n", test->setcount, test->count);
|
||||
g_test_message ("stopped\n");
|
||||
g_test_message ("%d %d\n", test->setcount, test->count);
|
||||
|
||||
g_array_free (test_threads, TRUE);
|
||||
g_object_unref (test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/properties-3", test_refcount_properties_3);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -143,19 +143,15 @@ my_badger_mama_notify (GObject *object,
|
||||
MyBadger *self;
|
||||
|
||||
self = MY_BADGER (object);
|
||||
|
||||
self->mama_notify_count++;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
test_refcount_properties_4 (void)
|
||||
{
|
||||
MyBadger * badger1, * badger2;
|
||||
gpointer test;
|
||||
|
||||
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));
|
||||
|
||||
badger1 = g_object_new (MY_TYPE_BADGER, NULL);
|
||||
badger2 = g_object_new (MY_TYPE_BADGER, NULL);
|
||||
|
||||
@ -163,11 +159,23 @@ main (int argc, char **argv)
|
||||
g_assert_cmpuint (badger1->mama_notify_count, ==, 1);
|
||||
g_assert_cmpuint (badger2->mama_notify_count, ==, 1);
|
||||
g_object_get (badger1, "mama", &test, NULL);
|
||||
g_assert (test == badger2);
|
||||
g_assert_cmpmem (test, sizeof (MyBadger), badger2, sizeof (MyBadger));
|
||||
g_object_unref (test);
|
||||
|
||||
g_object_unref (badger1);
|
||||
g_object_unref (badger2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/properties-4", test_refcount_properties_4);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -128,7 +128,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);
|
||||
|
||||
test->value = 0;
|
||||
}
|
||||
@ -140,7 +140,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);
|
||||
}
|
||||
@ -236,8 +236,8 @@ run_thread (GTest * test)
|
||||
if (TESTNUM == 4)
|
||||
my_test_do_signal3 (test);
|
||||
if ((i++ % 10000) == 0) {
|
||||
g_print (".");
|
||||
g_thread_yield(); /* force context switch */
|
||||
g_test_message (".");
|
||||
g_thread_yield (); /* force context switch */
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,20 +250,17 @@ notify (GObject *object, GParamSpec *spec, gpointer user_data)
|
||||
gint value;
|
||||
|
||||
g_object_get (object, "test-prop", &value, NULL);
|
||||
/*g_print ("+ %d", value);*/
|
||||
g_test_message ("+ %d", value);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
test_refcount_signals (void)
|
||||
{
|
||||
gint i;
|
||||
GTest *test1, *test2;
|
||||
GArray *test_threads;
|
||||
const gint n_threads = 1;
|
||||
|
||||
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);
|
||||
|
||||
@ -278,19 +275,17 @@ main (int argc, char **argv)
|
||||
for (i = 0; i < n_threads; i++) {
|
||||
GThread *thread;
|
||||
|
||||
thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL);
|
||||
thread = g_thread_new (NULL, (GThreadFunc) run_thread, test1);
|
||||
g_array_append_val (test_threads, thread);
|
||||
|
||||
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
|
||||
thread = g_thread_new (NULL, (GThreadFunc) run_thread, test2);
|
||||
g_array_append_val (test_threads, thread);
|
||||
}
|
||||
g_usleep (5000000);
|
||||
|
||||
g_atomic_int_set (&stopping, TRUE);
|
||||
|
||||
g_print ("\nstopping\n");
|
||||
|
||||
/* join all threads */
|
||||
/* Join all threads */
|
||||
for (i = 0; i < 2 * n_threads; i++) {
|
||||
GThread *thread;
|
||||
|
||||
@ -298,11 +293,21 @@ main (int argc, char **argv)
|
||||
g_thread_join (thread);
|
||||
}
|
||||
|
||||
g_print ("stopped\n");
|
||||
|
||||
g_array_free (test_threads, TRUE);
|
||||
g_object_unref (test1);
|
||||
g_object_unref (test2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_test_add_func ("/gobject/refcount/signals", test_refcount_signals);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -13,7 +13,6 @@ test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
|
||||
test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
|
||||
|
||||
subdir('gobject')
|
||||
subdir('refcount')
|
||||
|
||||
test_extra_programs = {
|
||||
'assert-msg-test' : {},
|
||||
|
@ -1,60 +0,0 @@
|
||||
refcount_tests = {
|
||||
'objects' : {},
|
||||
'objects2' : {'suite' : ['slow']},
|
||||
'properties' : {},
|
||||
'properties2' : {'suite' : ['slow']},
|
||||
'properties3' : {'suite' : ['slow']},
|
||||
'properties4' : {},
|
||||
'signal1' : {
|
||||
'source' : 'signals.c',
|
||||
'c_args' : ['-DTESTNUM=1'],
|
||||
},
|
||||
'signal2' : {
|
||||
'source' : 'signals.c',
|
||||
'c_args' : ['-DTESTNUM=2'],
|
||||
},
|
||||
'signal3' : {
|
||||
'source' : 'signals.c',
|
||||
'c_args' : ['-DTESTNUM=3'],
|
||||
},
|
||||
'signal4' : {
|
||||
'source' : 'signals.c',
|
||||
'c_args' : ['-DTESTNUM=4'],
|
||||
},
|
||||
}
|
||||
|
||||
common_c_args = test_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS']
|
||||
common_deps = [libm, thread_dep, libglib_dep, libgobject_dep]
|
||||
|
||||
foreach test_name, extra_args : refcount_tests
|
||||
source = extra_args.get('source', test_name + '.c')
|
||||
extra_sources = extra_args.get('extra_sources', [])
|
||||
install = installed_tests_enabled and extra_args.get('install', true)
|
||||
|
||||
if install
|
||||
test_conf = configuration_data()
|
||||
test_conf.set('installed_tests_dir', installed_tests_execdir)
|
||||
test_conf.set('program', test_name)
|
||||
test_conf.set('env', '')
|
||||
configure_file(
|
||||
input: installed_tests_template,
|
||||
output: test_name + '.test',
|
||||
install_dir: installed_tests_metadir,
|
||||
configuration: test_conf
|
||||
)
|
||||
endif
|
||||
|
||||
# FIXME? $(GLIB_DEBUG_FLAGS)
|
||||
exe = executable(test_name, [source, extra_sources],
|
||||
c_args : common_c_args + extra_args.get('c_args', []),
|
||||
dependencies : common_deps + extra_args.get('dependencies', []),
|
||||
install_dir: installed_tests_execdir,
|
||||
install: install,
|
||||
)
|
||||
|
||||
suite = ['refcount'] + extra_args.get('suite', [])
|
||||
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
|
||||
|
||||
# FIXME? TESTS_ENVIRONMENT = LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset
|
||||
test(test_name, exe, env : test_env, timeout : timeout, suite : suite)
|
||||
endforeach
|
Loading…
x
Reference in New Issue
Block a user