1
/* GObject - GLib Type, Object, Parameter and Signal Library
2
* Copyright (C) 2013 Red Hat, Inc.
3
* Copy and pasted from accumulator.c and modified.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General
16
* Public License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
* Boston, MA 02111-1307, USA.
22
#define G_LOG_DOMAIN "TestSignals"
24
#undef G_DISABLE_ASSERT
25
#undef G_DISABLE_CHECKS
26
#undef G_DISABLE_CAST_CHECKS
28
#include <glib-object.h>
30
#include "testcommon.h"
32
/* What this test tests is the behavior of signal disconnection
33
* from within a signal handler for the signal being disconnected.
35
* The test demonstrates that signal handlers disconnected from a signal
36
* from an earlier handler in the same emission will not be run.
38
* It also demonstrates that signal handlers connected from a signal
39
* from an earlier handler in the same emission will not be run.
43
* TestObject, a parent class for TestObject
45
#define TEST_TYPE_OBJECT (test_object_get_type ())
46
typedef struct _TestObject TestObject;
47
typedef struct _TestObjectClass TestObjectClass;
48
static gboolean callback1_ran = FALSE, callback2_ran = FALSE, callback3_ran = FALSE, default_handler_ran = FALSE;
52
GObject parent_instance;
54
struct _TestObjectClass
56
GObjectClass parent_class;
58
void (*test_signal) (TestObject *object);
61
static GType test_object_get_type (void);
64
test_object_real_signal (TestObject *object)
66
default_handler_ran = TRUE;
70
test_object_signal_callback3 (TestObject *object,
77
test_object_signal_callback2 (TestObject *object,
84
test_object_signal_callback1 (TestObject *object,
88
g_signal_handlers_disconnect_by_func (G_OBJECT (object),
89
test_object_signal_callback2,
91
g_signal_connect (object, "test-signal",
92
G_CALLBACK (test_object_signal_callback3), NULL);
96
test_object_class_init (TestObjectClass *class)
98
class->test_signal = test_object_real_signal;
100
g_signal_new ("test-signal",
101
G_OBJECT_CLASS_TYPE (class),
103
G_STRUCT_OFFSET (TestObjectClass, test_signal),
104
NULL, NULL, NULL, G_TYPE_NONE, 0);
107
static DEFINE_TYPE(TestObject, test_object,
108
test_object_class_init, NULL, NULL,
117
g_log_set_always_fatal (g_log_set_always_fatal (G_LOG_FATAL_MASK) |
118
G_LOG_LEVEL_WARNING |
119
G_LOG_LEVEL_CRITICAL);
121
object = g_object_new (TEST_TYPE_OBJECT, NULL);
123
g_signal_connect (object, "test-signal",
124
G_CALLBACK (test_object_signal_callback1), NULL);
125
g_signal_connect (object, "test-signal",
126
G_CALLBACK (test_object_signal_callback2), NULL);
127
g_signal_emit_by_name (object, "test-signal");
129
g_assert (callback1_ran);
130
g_assert (!callback2_ran);
131
g_assert (!callback3_ran);
132
g_assert (default_handler_ran);