1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-08-19 23:28:54 +02:00
Files
build
debian
docs
gio
glib
gmodule
gobject
gthread
m4macros
po
tests
bookmarks
collate
gobject
.gitignore
Makefile.am
accumulator.c
defaultiface.c
deftype.c
dynamictype.c
gvalue-test.c
ifacecheck.c
ifaceinherit.c
ifaceinit.c
ifaceproperties.c
override.c
paramspec-test.c
performance-threaded.c
performance.c
references.c
run-performance.sh
singleton.c
testcommon.h
testmarshal.list
testmodule.c
testmodule.h
markups
refcount
.gitignore
Makefile.am
assert-msg-test.c
asyncqueue-test.c
atomic-test.c
base64-test.c
bit-test.c
bookmarkfile-test.c
casefold.txt
casemap.txt
checksum-test.c
child-test.c
completion-test.c
convert-test.c
cxx-test.C
date-test.c
dirname-test.c
env-test.c
errorcheck-mutex-test.c
file-test.c
gen-casefold-txt.pl
gen-casemap-txt.pl
gio-ls.c
gio-test.c
hash-test.c
iochannel-test-infile
iochannel-test.c
libmoduletestplugin_a.c
libmoduletestplugin_b.c
list-test.c
mainloop-test.c
makefile.msc.in
mapping-test.c
markup-collect.c
markup-escape-test.c
markup-test.c
memchunks.c
module-test.c
node-test.c
onceinit.c
patterntest.c
qsort-test.c
queue-test.c
regex-test.c
relation-test.c
run-assert-msg-test.sh
run-bookmark-test.sh
run-collate-tests.sh
run-markup-tests.sh
scannerapi.c
sequence-test.c
shell-test.c
slice-color.c
slice-concurrent.c
slice-test.c
slice-threadinit.c
slist-test.c
spawn-test-win32-gui.c
spawn-test.c
testgdate.c
testgdateparser.c
testglib.c
testingbase64.c
thread-test.c
threadpool-test.c
timeloop-basic.c
timeloop-closure.c
timeloop.c
tree-test.c
type-test.c
unicode-caseconv.c
unicode-collate.c
unicode-encoding.c
unicode-normalize.c
uri-test.c
utf8-pointer.c
utf8-validate.c
utf8.txt
.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
MAINTAINERS
Makefile.am
Makefile.decl
NEWS
NEWS.pre-1-3
README.commits
README.in
README.win32
acglib.m4
acinclude.m4
autogen.sh
config.h.win32.in
configure.in
gio-2.0-uninstalled.pc.in
gio-2.0.pc.in
gio-unix-2.0-uninstalled.pc.in
gio-unix-2.0.pc.in
glib-2.0-uninstalled.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-zip.in
glibconfig.h.win32.in
gmodule-2.0-uninstalled.pc.in
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0-uninstalled.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0-uninstalled.pc.in
gobject-2.0.pc.in
gthread-2.0-uninstalled.pc.in
gthread-2.0.pc.in
makefile.msc
mkinstalldirs
msvc_recommended_pragmas.h
sanity_check
win32-fixup.pl
glib/tests/gobject/ifacecheck.c

168 lines
4.4 KiB
C
Raw Normal View History

/* GObject - GLib Type, Object, Parameter and Signal Library
* Copyright (C) 2001, 2003 Red Hat, Inc.
*
* 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 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, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestIfaceCheck"
#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS
#include <string.h>
#include <glib-object.h>
#include "testcommon.h"
/* This test tests g_type_add_interface_check_func(), which allows
* installing a post-initialization check function.
*/
#define TEST_TYPE_IFACE (test_iface_get_type ())
#define TEST_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass))
typedef struct _TestIfaceClass TestIfaceClass;
struct _TestIfaceClass
{
GTypeInterface base_iface;
GString *history;
};
static void
test_iface_base_init (TestIfaceClass *iface)
{
2005-12-01 18:06:17 +00:00
iface->history = g_string_new (iface->history ? iface->history->str : NULL);
}
static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, NULL)
/*
* TestObject1
*/
#define TEST_TYPE_OBJECT1 (test_object1_get_type ())
typedef struct _GObject TestObject1;
typedef struct _GObjectClass TestObject1Class;
static DEFINE_TYPE_FULL (TestObject1, test_object1,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject2
*/
#define TEST_TYPE_OBJECT2 (test_object2_get_type ())
typedef struct _GObject TestObject2;
typedef struct _GObjectClass TestObject2Class;
static DEFINE_TYPE_FULL (TestObject2, test_object2,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject3
*/
#define TEST_TYPE_OBJECT3 (test_object3_get_type ())
typedef struct _GObject TestObject3;
typedef struct _GObjectClass TestObject3Class;
static DEFINE_TYPE_FULL (TestObject3, test_object3,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject4
*/
#define TEST_TYPE_OBJECT4 (test_object4_get_type ())
typedef struct _GObject TestObject4;
typedef struct _GObjectClass TestObject4Class;
static DEFINE_TYPE_FULL (TestObject4, test_object4,
NULL, NULL, NULL,
G_TYPE_OBJECT, {})
static void
check_func (gpointer check_data,
gpointer g_iface)
{
TestIfaceClass *iface = g_iface;
g_string_append (iface->history, check_data);
}
int
main (int argc,
char *argv[])
{
TestIfaceClass *iface;
GObject *object;
char *string1 = "A";
char *string2 = "B";
g_type_init ();
/* Basic check of interfaces added before class_init time
*/
g_type_add_interface_check (string1, check_func);
object = g_object_new (TEST_TYPE_OBJECT1, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "A") == 0);
g_object_unref (object);
/* Add a second check function
*/
g_type_add_interface_check (string2, check_func);
object = g_object_new (TEST_TYPE_OBJECT2, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "AB") == 0);
g_object_unref (object);
/* Remove the first check function
*/
g_type_remove_interface_check (string1, check_func);
object = g_object_new (TEST_TYPE_OBJECT3, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "B") == 0);
g_object_unref (object);
/* Test interfaces added after class_init time
*/
g_type_class_ref (TEST_TYPE_OBJECT4);
{
static GInterfaceInfo const iface = {
NULL, NULL, NULL
};
g_type_add_interface_static (TEST_TYPE_OBJECT4, TEST_TYPE_IFACE, &iface);
}
object = g_object_new (TEST_TYPE_OBJECT4, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "B") == 0);
g_object_unref (object);
return 0;
}