1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-08-14 04:57:46 +02:00
Files
build
docs
gio
glib
gmodule
gobject
gthread
m4macros
po
subprojects
tests
collate
gobject
.gitignore
Makefile.am
accumulator.c
defaultiface.c
deftype.c
dynamictype.c
gvalue-test.c
ifacecheck.c
ifaceinherit.c
ifaceinit.c
meson.build
override.c
paramspec-test.c
performance-threaded.c
performance.c
references.c
run-performance.sh
signals.c
singleton.c
testcommon.h
testgobject.c
testmarshal.list
testmodule.c
testmodule.h
timeloop-closure.c
refcount
.gitignore
Makefile.am
assert-msg-test.c
assert-msg-test.gdb
asyncqueue-test.c
atomic-test.c
bit-test.c
casefold.txt
casemap.txt
child-test.c
completion-test.c
cxx-test.C
datetime.c
dirname-test.c
env-test.c
file-test.c
gen-casefold-txt.pl
gen-casemap-txt.pl
gio-ls.c
gio-test.c
iochannel-test-infile
iochannel-test.c
libmoduletestplugin_a.c
libmoduletestplugin_b.c
mainloop-test.c
mapping-test.c
memchunks.c
meson.build
module-test.c
onceinit.c
qsort-test.c
relation-test.c
run-assert-msg-test.sh
run-collate-tests.sh
slice-color.c
slice-concurrent.c
slice-test.c
slice-threadinit.c
sources.c
spawn-test-win32-gui.c
spawn-test.c
testgdate.c
testgdateparser.c
testglib.c
thread-test.c
threadpool-test.c
timeloop-basic.c
timeloop.c
type-test.c
unicode-caseconv.c
unicode-collate.c
unicode-encoding.c
unicode-normalize.c
utf8.txt
win32
.dir-locals.el
.gitattributes
.gitignore
AUTHORS
COPYING
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-14
ChangeLog.pre-2-16
ChangeLog.pre-2-18
ChangeLog.pre-2-2
ChangeLog.pre-2-20
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL.in
Makefile.am
NEWS
NEWS.pre-1-3
README.commits
README.in
README.rationale
README.win32
acglib.m4
acinclude.m4
autogen.sh
check-abis.sh
config.h.meson
config.h.win32.in
configure.ac
gio-2.0.pc.in
gio-unix-2.0.pc.in
gio-windows-2.0.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-tap.mk
glib-zip.in
glib.doap
glib.mk
glib.supp
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0.pc.in
gthread-2.0.pc.in
meson.build
meson_options.txt
msvc_recommended_pragmas.h
sanity_check
tap-driver.sh
tap-test
glib/tests/gobject/signals.c
Sébastien Wilmet f6c44ec3e4 tests/: LGPLv2+ -> LGPLv2.1+
gen-casefold-txt.pl and gen-casemap-txt.pl are licensed under GPLv2+, so
they are not touched by this commit.

A lot of *.c files in tests/ don't have a license header.

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:35 +02:00

135 lines
3.9 KiB
C

/* GObject - GLib Type, Object, Parameter and Signal Library
* Copyright (C) 2013 Red Hat, Inc.
* Copy and pasted from accumulator.c and modified.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestSignals"
#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS
#include <glib-object.h>
#include "testcommon.h"
/* What this test tests is the behavior of signal disconnection
* from within a signal handler for the signal being disconnected.
*
* The test demonstrates that signal handlers disconnected from a signal
* from an earlier handler in the same emission will not be run.
*
* It also demonstrates that signal handlers connected from a signal
* from an earlier handler in the same emission will not be run.
*/
/*
* TestObject, a parent class for TestObject
*/
#define TEST_TYPE_OBJECT (test_object_get_type ())
typedef struct _TestObject TestObject;
typedef struct _TestObjectClass TestObjectClass;
static gboolean callback1_ran = FALSE, callback2_ran = FALSE, callback3_ran = FALSE, default_handler_ran = FALSE;
struct _TestObject
{
GObject parent_instance;
};
struct _TestObjectClass
{
GObjectClass parent_class;
void (*test_signal) (TestObject *object);
};
static GType test_object_get_type (void);
static void
test_object_real_signal (TestObject *object)
{
default_handler_ran = TRUE;
}
static void
test_object_signal_callback3 (TestObject *object,
gpointer data)
{
callback3_ran = TRUE;
}
static void
test_object_signal_callback2 (TestObject *object,
gpointer data)
{
callback2_ran = TRUE;
}
static void
test_object_signal_callback1 (TestObject *object,
gpointer data)
{
callback1_ran = TRUE;
g_signal_handlers_disconnect_by_func (G_OBJECT (object),
test_object_signal_callback2,
data);
g_signal_connect (object, "test-signal",
G_CALLBACK (test_object_signal_callback3), NULL);
}
static void
test_object_class_init (TestObjectClass *class)
{
class->test_signal = test_object_real_signal;
g_signal_new ("test-signal",
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TestObjectClass, test_signal),
NULL, NULL, NULL, G_TYPE_NONE, 0);
}
static DEFINE_TYPE(TestObject, test_object,
test_object_class_init, NULL, NULL,
G_TYPE_OBJECT)
int
main (int argc,
char *argv[])
{
TestObject *object;
g_log_set_always_fatal (g_log_set_always_fatal (G_LOG_FATAL_MASK) |
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL);
object = g_object_new (TEST_TYPE_OBJECT, NULL);
g_signal_connect (object, "test-signal",
G_CALLBACK (test_object_signal_callback1), NULL);
g_signal_connect (object, "test-signal",
G_CALLBACK (test_object_signal_callback2), NULL);
g_signal_emit_by_name (object, "test-signal");
g_assert (callback1_ran);
g_assert (!callback2_ran);
g_assert (!callback3_ran);
g_assert (default_handler_ran);
g_object_unref (object);
return 0;
}