summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEmmanuel Fleury <emmanuel.fleury@gmail.com>2022-03-16 09:51:51 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-05-26 18:37:35 +0100
commit70401ae8c395461bcd6b205d019d339e5686788e (patch)
tree983f3f3da573baa0c730a416165f5433ae51bca9 /tests
parentb65260abe482ff1e0647228446ab7ed8dbf7f40a (diff)
downloadglib-70401ae8c395461bcd6b205d019d339e5686788e.tar.gz
Moving tests/refcount/ directory to gobject/tests/
Modified by Philip Withnall to omit the subdirectory and drop the `refcount` suite as both seem like unnecessary over-categorisation. Related to issue #1434
Diffstat (limited to 'tests')
-rw-r--r--tests/meson.build1
-rw-r--r--tests/refcount/meson.build60
-rw-r--r--tests/refcount/objects.c167
-rw-r--r--tests/refcount/objects2.c131
-rw-r--r--tests/refcount/properties.c243
-rw-r--r--tests/refcount/properties2.c210
-rw-r--r--tests/refcount/properties3.c210
-rw-r--r--tests/refcount/properties4.c181
-rw-r--r--tests/refcount/signals.c313
9 files changed, 0 insertions, 1516 deletions
diff --git a/tests/meson.build b/tests/meson.build
index ea5b86013..7ebdc24a0 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -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' : {},
diff --git a/tests/refcount/meson.build b/tests/refcount/meson.build
deleted file mode 100644
index 02571fe98..000000000
--- a/tests/refcount/meson.build
+++ /dev/null
@@ -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
diff --git a/tests/refcount/objects.c b/tests/refcount/objects.c
deleted file mode 100644
index 0d8e20b03..000000000
--- a/tests/refcount/objects.c
+++ /dev/null
@@ -1,167 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#ifdef G_OS_UNIX
-#include <unistd.h>
-#endif
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_test_get_type (void);
-static gint stopping; /* (atomic) */
-
-static void my_test_class_init (GTestClass * klass);
-static void my_test_init (GTest * test);
-static void my_test_dispose (GObject * object);
-
-static GObjectClass *parent_class = NULL;
-
-static GType
-my_test_get_type (void)
-{
- static GType test_type = 0;
-
- if (!test_type) {
- const GTypeInfo test_info = {
- sizeof (GTestClass),
- NULL,
- NULL,
- (GClassInitFunc) my_test_class_init,
- NULL,
- NULL,
- sizeof (GTest),
- 0,
- (GInstanceInitFunc) my_test_init,
- NULL
- };
-
- test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
- &test_info, 0);
- }
- return test_type;
-}
-
-static void
-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;
-}
-
-static void
-my_test_init (GTest * test)
-{
- g_test_message ("init %p\n", test);
-}
-
-static void
-my_test_dispose (GObject * object)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- g_test_message ("dispose %p!\n", test);
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-my_test_do_refcount (GTest * test)
-{
- g_object_ref (test);
- g_object_unref (test);
-}
-
-static gpointer
-run_thread (GTest * test)
-{
- gint i = 1;
-
- while (!g_atomic_int_get (&stopping)) {
- my_test_do_refcount (test);
- if ((i++ % 10000) == 0) {
- g_test_message (".");
- g_thread_yield (); /* force context switch */
- }
- }
-
- return NULL;
-}
-
-static void
-test_refcount_object_basics (void)
-{
- guint i;
- GTest *test1, *test2;
- GArray *test_threads;
- const guint n_threads = 5;
-
- test1 = g_object_new (G_TYPE_TEST, NULL);
- test2 = g_object_new (G_TYPE_TEST, NULL);
-
- test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
-
- g_atomic_int_set (&stopping, 0);
-
- for (i = 0; i < n_threads; i++) {
- GThread *thread;
-
- thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL);
- g_array_append_val (test_threads, thread);
-
- thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
- g_array_append_val (test_threads, thread);
- }
-
- g_usleep (5000000);
- g_atomic_int_set (&stopping, 1);
-
- /* join all threads */
- for (i = 0; i < 2 * n_threads; i++) {
- GThread *thread;
-
- thread = g_array_index (test_threads, GThread *, i);
- g_thread_join (thread);
- }
-
- 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_test_add_func ("/gobject/refcount/object-basics", test_refcount_object_basics);
-
- return g_test_run ();
-}
diff --git a/tests/refcount/objects2.c b/tests/refcount/objects2.c
deleted file mode 100644
index 2e7c03836..000000000
--- a/tests/refcount/objects2.c
+++ /dev/null
@@ -1,131 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#ifdef G_OS_UNIX
-#include <unistd.h>
-#endif
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_test_get_type (void);
-
-static void my_test_class_init (GTestClass * klass);
-static void my_test_init (GTest * test);
-static void my_test_dispose (GObject * object);
-
-static GObjectClass *parent_class = NULL;
-
-static GType
-my_test_get_type (void)
-{
- static GType test_type = 0;
-
- if (!test_type) {
- const GTypeInfo test_info = {
- sizeof (GTestClass),
- NULL,
- NULL,
- (GClassInitFunc) my_test_class_init,
- NULL,
- NULL,
- sizeof (GTest),
- 0,
- (GInstanceInitFunc) my_test_init,
- NULL
- };
-
- test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
- &test_info, 0);
- }
- return test_type;
-}
-
-static void
-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;
-}
-
-static void
-my_test_init (GTest * test)
-{
- g_test_message ("init %p\n", test);
-}
-
-static void
-my_test_dispose (GObject * object)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- g_test_message ("dispose %p!\n", test);
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-my_test_do_refcount (GTest * test)
-{
- static guint i = 1;
-
- if (i++ % 100000 == 0)
- 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)
-{
- 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-advanced", test_refcount_object_advanced);
-
- return g_test_run ();
-}
diff --git a/tests/refcount/properties.c b/tests/refcount/properties.c
deleted file mode 100644
index 42176e923..000000000
--- a/tests/refcount/properties.c
+++ /dev/null
@@ -1,243 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#ifdef G_OS_UNIX
-#include <unistd.h>
-#endif
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-enum {
- PROP_0,
- PROP_DUMMY
-};
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
- gint id;
- gint dummy;
-
- gint count;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_test_get_type (void);
-static gboolean stopping;
-
-static void my_test_class_init (GTestClass * klass);
-static void my_test_init (GTest * test);
-static void my_test_dispose (GObject * object);
-static void my_test_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-static GObjectClass *parent_class = NULL;
-
-static GType
-my_test_get_type (void)
-{
- static GType test_type = 0;
-
- if (!test_type) {
- const GTypeInfo test_info = {
- sizeof (GTestClass),
- NULL,
- NULL,
- (GClassInitFunc) my_test_class_init,
- NULL,
- NULL,
- sizeof (GTest),
- 0,
- (GInstanceInitFunc) my_test_init,
- NULL
- };
-
- test_type = g_type_register_static (G_TYPE_OBJECT, "GTest", &test_info, 0);
- }
- return test_type;
-}
-
-static void
-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;
- gobject_class->get_property = my_test_get_property;
- 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));
-}
-
-static void
-my_test_init (GTest * test)
-{
- static guint static_id = 1;
- test->id = static_id++;
-}
-
-static void
-my_test_dispose (GObject * object)
-{
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-my_test_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- g_value_set_int (value, test->dummy);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- test->dummy = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-dummy_notify (GObject *object,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- test->count++;
-}
-
-static void
-my_test_do_property (GTest * test)
-{
- gint dummy;
-
- g_object_get (test, "dummy", &dummy, NULL);
- g_object_set (test, "dummy", dummy + 1, NULL);
-}
-
-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_test_message (".%c", 'a' + test->id);
- g_thread_yield(); /* force context switch */
- }
- }
-
- return NULL;
-}
-
-static void
-test_refcount_properties_1 (void)
-{
-#define N_THREADS 5
- GThread *test_threads[N_THREADS];
- GTest *test_objects[N_THREADS];
- gint i;
-
- for (i = 0; i < N_THREADS; i++) {
- GTest *test;
-
- test = g_object_new (G_TYPE_TEST, NULL);
- test_objects[i] = test;
-
- 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);
-
- g_usleep (3000000);
-
- g_atomic_int_set (&stopping, TRUE);
-
- /* join all threads */
- for (i = 0; i < N_THREADS; i++)
- g_thread_join (test_threads[i]);
-
- for (i = 0; i < N_THREADS; i++) {
- GTest *test = test_objects[i];
-
- g_assert_cmpint (test->count, ==, test->dummy);
- g_object_unref (test);
- }
-}
-
-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 ();
-}
diff --git a/tests/refcount/properties2.c b/tests/refcount/properties2.c
deleted file mode 100644
index 9536b5144..000000000
--- a/tests/refcount/properties2.c
+++ /dev/null
@@ -1,210 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#ifdef G_OS_UNIX
-#include <unistd.h>
-#endif
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-enum {
- PROP_0,
- PROP_DUMMY
-};
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
-
- gint dummy;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_test_get_type (void);
-
-static void my_test_class_init (GTestClass * klass);
-static void my_test_init (GTest * test);
-static void my_test_dispose (GObject * object);
-static void my_test_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-static GObjectClass *parent_class = NULL;
-
-static GType
-my_test_get_type (void)
-{
- static GType test_type = 0;
-
- if (!test_type) {
- const GTypeInfo test_info = {
- sizeof (GTestClass),
- NULL,
- NULL,
- (GClassInitFunc) my_test_class_init,
- NULL,
- NULL,
- sizeof (GTest),
- 0,
- (GInstanceInitFunc) my_test_init,
- NULL
- };
-
- test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
- &test_info, 0);
- }
- return test_type;
-}
-
-static void
-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;
- gobject_class->get_property = my_test_get_property;
- 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));
-}
-
-static void
-my_test_init (GTest * test)
-{
- g_test_message ("init %p\n", test);
-}
-
-static void
-my_test_dispose (GObject * object)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- 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,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- g_value_set_int (value, test->dummy);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- test->dummy = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static gint count = 0;
-
-static void
-dummy_notify (GObject *object,
- GParamSpec *pspec)
-{
- count++;
- if (count % 10000 == 0)
- g_test_message (".");
-}
-
-static void
-my_test_do_property (GTest * test)
-{
- gint dummy;
-
- g_object_get (test, "dummy", &dummy, NULL);
- g_object_set (test, "dummy", dummy + 1, NULL);
-}
-
-static void
-test_refcount_properties_2 (void)
-{
- gint i;
- GTest *test;
-
- 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);
-
- for (i = 0; i < 1000000; i++)
- {
- my_test_do_property (test);
- }
- g_assert_cmpint (count, ==, test->dummy);
-
- g_object_unref (test);
-}
-
-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 ();
-}
diff --git a/tests/refcount/properties3.c b/tests/refcount/properties3.c
deleted file mode 100644
index 8a96fb804..000000000
--- a/tests/refcount/properties3.c
+++ /dev/null
@@ -1,210 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-enum {
- PROP_0,
- PROP_DUMMY
-};
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
- gint id;
- gint dummy;
-
- gint count;
- gint setcount;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_test_get_type (void);
-G_DEFINE_TYPE (GTest, my_test, G_TYPE_OBJECT)
-
-static gint stopping; /* (atomic) */
-
-static void my_test_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-static void
-my_test_class_init (GTestClass * klass)
-{
- GObjectClass *gobject_class;
-
- gobject_class = (GObjectClass *) klass;
-
- gobject_class->get_property = my_test_get_property;
- 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));
-}
-
-static void
-my_test_init (GTest * test)
-{
- static guint static_id = 1;
- test->id = static_id++;
-}
-
-static void
-my_test_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- g_value_set_int (value, g_atomic_int_get (&test->dummy));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_test_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id)
- {
- case PROP_DUMMY:
- g_atomic_int_set (&test->dummy, g_value_get_int (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-dummy_notify (GObject *object,
- GParamSpec *pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- g_atomic_int_inc (&test->count);
-}
-
-static void
-my_test_do_property (GTest * test)
-{
- gint dummy;
-
- g_atomic_int_inc (&test->setcount);
-
- g_object_get (test, "dummy", &dummy, NULL);
- g_object_set (test, "dummy", dummy + 1, NULL);
-}
-
-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_test_message (".%c", 'a' + test->id);
- g_thread_yield(); /* force context switch */
- }
- }
-
- return NULL;
-}
-
-static void
-test_refcount_properties_3 (void)
-{
- gint i;
- GTest *test;
- GArray *test_threads;
- const gint n_threads = 5;
-
- test = g_object_new (G_TYPE_TEST, NULL);
-
- 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 *));
-
- g_atomic_int_set (&stopping, 0);
-
- for (i = 0; i < n_threads; i++) {
- GThread *thread;
-
- thread = g_thread_create ((GThreadFunc) run_thread, test, TRUE, NULL);
- g_array_append_val (test_threads, thread);
- }
- g_usleep (30000000);
-
- g_atomic_int_set (&stopping, 1);
- g_test_message ("\nstopping\n");
-
- /* join all threads */
- for (i = 0; i < n_threads; i++) {
- GThread *thread;
-
- thread = g_array_index (test_threads, GThread *, i);
- g_thread_join (thread);
- }
-
- 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);
-}
-
-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 ();
-}
diff --git a/tests/refcount/properties4.c b/tests/refcount/properties4.c
deleted file mode 100644
index 462f9e3cd..000000000
--- a/tests/refcount/properties4.c
+++ /dev/null
@@ -1,181 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#define MY_TYPE_BADGER (my_badger_get_type ())
-#define MY_BADGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_BADGER, MyBadger))
-#define MY_IS_BADGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_BADGER))
-#define MY_BADGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_BADGER, MyBadgerClass))
-#define MY_IS_BADGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_BADGER))
-#define MY_BADGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_BADGER, MyBadgerClass))
-
-enum {
- PROP_0,
- PROP_MAMA
-};
-
-typedef struct _MyBadger MyBadger;
-typedef struct _MyBadgerClass MyBadgerClass;
-
-struct _MyBadger
-{
- GObject parent_instance;
-
- MyBadger * mama;
- guint mama_notify_count;
-};
-
-struct _MyBadgerClass
-{
- GObjectClass parent_class;
-};
-
-static GType my_badger_get_type (void);
-G_DEFINE_TYPE (MyBadger, my_badger, G_TYPE_OBJECT)
-
-static void my_badger_dispose (GObject * object);
-
-static void my_badger_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void my_badger_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-static void my_badger_mama_notify (GObject *object,
- GParamSpec *pspec);
-
-static void
-my_badger_class_init (MyBadgerClass * klass)
-{
- GObjectClass *gobject_class;
-
- gobject_class = (GObjectClass *) klass;
-
- gobject_class->dispose = my_badger_dispose;
-
- gobject_class->get_property = my_badger_get_property;
- gobject_class->set_property = my_badger_set_property;
-
- g_object_class_install_property (gobject_class,
- PROP_MAMA,
- g_param_spec_object ("mama",
- NULL,
- NULL,
- MY_TYPE_BADGER,
- G_PARAM_READWRITE));
-}
-
-static void
-my_badger_init (MyBadger * self)
-{
- g_signal_connect (self, "notify::mama", G_CALLBACK (my_badger_mama_notify),
- NULL);
-}
-
-static void
-my_badger_dispose (GObject * object)
-{
- MyBadger * self;
-
- self = MY_BADGER (object);
-
- if (self->mama != NULL)
- {
- g_object_unref (self->mama);
- self->mama = NULL;
- }
-
- G_OBJECT_CLASS (my_badger_parent_class)->dispose (object);
-}
-
-static void
-my_badger_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MyBadger *self;
-
- self = MY_BADGER (object);
-
- switch (prop_id)
- {
- case PROP_MAMA:
- g_value_set_object (value, self->mama);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_badger_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MyBadger *self;
-
- self = MY_BADGER (object);
-
- switch (prop_id)
- {
- case PROP_MAMA:
- if (self->mama)
- g_object_unref (self->mama);
- self->mama = g_value_dup_object (value);
- if (self->mama)
- g_object_set (self->mama, "mama", NULL, NULL); /* another notify */
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_badger_mama_notify (GObject *object,
- GParamSpec *pspec)
-{
- MyBadger *self;
-
- self = MY_BADGER (object);
- self->mama_notify_count++;
-}
-
-static void
-test_refcount_properties_4 (void)
-{
- MyBadger * badger1, * badger2;
- gpointer test;
-
- badger1 = g_object_new (MY_TYPE_BADGER, NULL);
- badger2 = g_object_new (MY_TYPE_BADGER, NULL);
-
- g_object_set (badger1, "mama", badger2, NULL);
- 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_cmpmem (test, sizeof (MyBadger), badger2, sizeof (MyBadger));
- g_object_unref (test);
-
- g_object_unref (badger1);
- g_object_unref (badger2);
-}
-
-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 ();
-}
diff --git a/tests/refcount/signals.c b/tests/refcount/signals.c
deleted file mode 100644
index a9c11e32e..000000000
--- a/tests/refcount/signals.c
+++ /dev/null
@@ -1,313 +0,0 @@
-#include <glib.h>
-#include <glib-object.h>
-
-#ifdef G_OS_UNIX
-#include <unistd.h>
-#endif
-
-#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))
-#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
-#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
-
-typedef struct _GTest GTest;
-typedef struct _GTestClass GTestClass;
-
-struct _GTest
-{
- GObject object;
-
- gint value;
-};
-
-struct _GTestClass
-{
- GObjectClass parent_class;
-
- void (*test_signal1) (GTest * test, gint an_int);
- void (*test_signal2) (GTest * test, gint an_int);
- gchar * (*test_signal3) (GTest * test, gint an_int);
-};
-
-static GType my_test_get_type (void);
-static gboolean stopping;
-
-/* Element signals and args */
-enum
-{
- TEST_SIGNAL1,
- TEST_SIGNAL2,
- TEST_SIGNAL3,
- /* add more above */
- LAST_SIGNAL
-};
-
-enum
-{
- ARG_0,
- ARG_TEST_PROP
-};
-
-static void my_test_class_init (GTestClass * klass);
-static void my_test_init (GTest * test);
-static void my_test_dispose (GObject * object);
-
-static void signal2_handler (GTest * test, gint anint);
-static gchar * signal3_handler (GTest * test, gint anint);
-
-static void my_test_set_property (GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec);
-static void my_test_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
-
-static GObjectClass *parent_class = NULL;
-
-static guint my_test_signals[LAST_SIGNAL] = { 0 };
-
-static GType
-my_test_get_type (void)
-{
- static GType test_type = 0;
-
- if (!test_type) {
- const GTypeInfo test_info = {
- sizeof (GTestClass),
- NULL,
- NULL,
- (GClassInitFunc) my_test_class_init,
- NULL,
- NULL,
- sizeof (GTest),
- 0,
- (GInstanceInitFunc) my_test_init,
- NULL
- };
-
- test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
- &test_info, 0);
- }
- return test_type;
-}
-
-static void
-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;
- gobject_class->set_property = my_test_set_property;
- gobject_class->get_property = my_test_get_property;
-
- my_test_signals[TEST_SIGNAL1] =
- g_signal_new ("test-signal1", G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GTestClass, test_signal1), NULL,
- NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
- my_test_signals[TEST_SIGNAL2] =
- g_signal_new ("test-signal2", G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GTestClass, test_signal2), NULL,
- NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
- my_test_signals[TEST_SIGNAL3] =
- g_signal_new ("test-signal3", G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GTestClass, test_signal3), NULL,
- NULL, g_cclosure_marshal_generic, G_TYPE_STRING, 1, G_TYPE_INT);
-
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TEST_PROP,
- g_param_spec_int ("test-prop", "Test Prop", "Test property",
- 0, 1, 0, G_PARAM_READWRITE));
-
- klass->test_signal2 = signal2_handler;
- klass->test_signal3 = signal3_handler;
-}
-
-static void
-my_test_init (GTest * test)
-{
- g_test_message ("init %p\n", test);
-
- test->value = 0;
-}
-
-static void
-my_test_dispose (GObject * object)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- g_test_message ("dispose %p!\n", test);
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-my_test_set_property (GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id) {
- case ARG_TEST_PROP:
- test->value = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_test_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec)
-{
- GTest *test;
-
- test = MY_TEST (object);
-
- switch (prop_id) {
- case ARG_TEST_PROP:
- g_value_set_int (value, test->value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-my_test_do_signal1 (GTest * test)
-{
- g_signal_emit (G_OBJECT (test), my_test_signals[TEST_SIGNAL1], 0, 0);
-}
-
-static void
-signal2_handler (GTest * test, gint anint)
-{
-}
-
-static void
-my_test_do_signal2 (GTest * test)
-{
- g_signal_emit (G_OBJECT (test), my_test_signals[TEST_SIGNAL2], 0, 0);
-}
-
-static gchar *
-signal3_handler (GTest * test, gint anint)
-{
- return g_strdup ("test");
-}
-
-static void
-my_test_do_signal3 (GTest * test)
-{
- gchar *res;
-
- g_signal_emit (G_OBJECT (test), my_test_signals[TEST_SIGNAL3], 0, 0, &res);
- g_assert (res);
- g_free (res);
-}
-
-static void
-my_test_do_prop (GTest * test)
-{
- test->value = g_random_int ();
- g_object_notify (G_OBJECT (test), "test-prop");
-}
-
-static gpointer
-run_thread (GTest * test)
-{
- gint i = 1;
-
- while (!g_atomic_int_get (&stopping)) {
- if (TESTNUM == 1)
- my_test_do_signal1 (test);
- if (TESTNUM == 2)
- my_test_do_signal2 (test);
- if (TESTNUM == 3)
- my_test_do_prop (test);
- if (TESTNUM == 4)
- my_test_do_signal3 (test);
- if ((i++ % 10000) == 0) {
- g_test_message (".");
- g_thread_yield (); /* force context switch */
- }
- }
-
- return NULL;
-}
-
-static void
-notify (GObject *object, GParamSpec *spec, gpointer user_data)
-{
- gint value;
-
- g_object_get (object, "test-prop", &value, NULL);
- g_test_message ("+ %d", value);
-}
-
-static void
-test_refcount_signals (void)
-{
- gint i;
- GTest *test1, *test2;
- GArray *test_threads;
- const gint n_threads = 1;
-
- test1 = g_object_new (G_TYPE_TEST, NULL);
- test2 = g_object_new (G_TYPE_TEST, NULL);
-
- g_signal_connect (test1, "notify::test-prop", G_CALLBACK (notify), NULL);
- g_signal_connect (test1, "test-signal1", G_CALLBACK (notify), NULL);
- g_signal_connect (test1, "test-signal2", G_CALLBACK (notify), NULL);
-
- test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
-
- stopping = FALSE;
-
- for (i = 0; i < n_threads; i++) {
- GThread *thread;
-
- thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL);
- g_array_append_val (test_threads, thread);
-
- thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
- g_array_append_val (test_threads, thread);
- }
- g_usleep (5000000);
-
- g_atomic_int_set (&stopping, TRUE);
-
- /* Join all threads */
- for (i = 0; i < 2 * n_threads; i++) {
- GThread *thread;
-
- thread = g_array_index (test_threads, GThread *, i);
- g_thread_join (thread);
- }
-
- g_array_free (test_threads, TRUE);
- g_object_unref (test1);
- g_object_unref (test2);
-}
-
-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 ();
-}