Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Test case for g_type_add_interface_check().
Browse files Browse the repository at this point in the history
Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>

        * tests/gobject/ifacecheck.c: Test case for
        g_type_add_interface_check().

        * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.
  • Loading branch information
owtaylor authored and Owen Taylor committed Oct 2, 2003
1 parent 3963846 commit 3e61c90
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 31 deletions.
12 changes: 7 additions & 5 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog.pre-2-10
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog.pre-2-12
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog.pre-2-4
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog.pre-2-6
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog.pre-2-8
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Thu Oct 2 01:15:46 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifacecheck.c: Test case for
g_type_add_interface_check().

* tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

Thu Oct 2 01:11:39 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c: Remove some tests that
were testing things that weren't supposed to work; add
a test for adding an interface first to the child class,
then to the parent class.

Thu Oct 2 01:08:13 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/ifaceinherit.c (main): Remove some tests
that

Thu Oct 2 00:02:55 2003 Owen Taylor <otaylor@redhat.com>

* tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
Expand Down
1 change: 1 addition & 0 deletions tests/gobject/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ LDADD = $(libgobject) libtestgobject.la
test_programs = \
accumulator \
defaultiface \
ifacecheck \
ifaceinit \
ifaceinherit \
override
Expand Down
169 changes: 169 additions & 0 deletions tests/gobject/ifacecheck.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/* 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)
{
if (iface->history)
g_string_free (iface->history, TRUE);
iface->history = g_string_new (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;
}
7 changes: 6 additions & 1 deletion tests/gobject/ifaceinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestIfaceInit"
#include <glib-object.h>

#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS

#include <glib-object.h>

#include "testcommon.h"

Expand Down

0 comments on commit 3e61c90

Please sign in to comment.