[nautilus-actions] src/test/test-iface2.c: new interface test program
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] src/test/test-iface2.c: new interface test program
- Date: Wed, 11 Jan 2012 22:09:49 +0000 (UTC)
commit 3e84a0dd979566626c7a9816ea9db4b16c283291
Author: Pierre Wieser <pwieser trychlos org>
Date: Sun Jan 8 13:41:44 2012 +0100
src/test/test-iface2.c: new interface test program
ChangeLog | 7 +
src/test/Makefile.am | 9 ++
src/test/test-iface2.c | 356 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 372 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e70ca88..f3c71ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2012-01-08 Pierre Wieser <pwieser trychlos org>
+ A program to test a class which implements an interface, this same
+ interface itself requiring the class...
+
+ * src/test/test-iface2.c: New interface test program.
+
+ * src/test/Makefile.am: Updated accordingly.
+
Rather call parent_class::instance_constructed() method before executing
the derived class one.
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index ab01344..79efe4d 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -34,6 +34,7 @@ if NA_MAINTAINER_MODE
noinst_PROGRAMS = \
test-reader \
test-iface \
+ test-iface2 \
test-parse-uris \
test-virtuals \
test-virtuals-without-test \
@@ -71,6 +72,14 @@ test_iface_LDADD = \
$(NAUTILUS_ACTIONS_LIBS) \
$(NULL)
+test_iface2_SOURCES = \
+ test-iface2.c \
+ $(NULL)
+
+test_iface2_LDADD = \
+ $(NAUTILUS_ACTIONS_LIBS) \
+ $(NULL)
+
if NA_MAINTAINER_MODE
noinst_PROGRAMS += test-module
pkglib_LTLIBRARIES = libtest_module_plugin.la
diff --git a/src/test/test-iface2.c b/src/test/test-iface2.c
new file mode 100755
index 0000000..05ae8ce
--- /dev/null
+++ b/src/test/test-iface2.c
@@ -0,0 +1,356 @@
+/*
+ * Nautilus-Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010, 2011, 2012 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+/* A class with implements an interface
+ * This interface itself requiring the class...
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+/* ********************************************************************
+ * Declaring the interface
+ * ********************************************************************/
+#define TEST_IFACE_TYPE ( test_iface_get_type())
+#define TEST_IFACE( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, TEST_IFACE_TYPE, TestIFace ))
+#define TEST_IS_IFACE( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, TEST_IFACE_TYPE ))
+#define TEST_IFACE_GET_INTERFACE( instance )( G_TYPE_INSTANCE_GET_INTERFACE(( instance ), TEST_IFACE_TYPE, TestIFaceInterface ))
+
+typedef struct TestIFace TestIFace;
+
+typedef struct TestIFaceInterfacePrivate TestIFaceInterfacePrivate;
+
+typedef struct {
+ GTypeInterface parent;
+ TestIFaceInterfacePrivate *private;
+}
+ TestIFaceInterface;
+
+GType test_iface_get_type( void );
+
+/* ********************************************************************
+ * Declaring the class
+ * ********************************************************************/
+#define TEST_BASE_TYPE ( test_base_get_type())
+#define TEST_BASE( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, TEST_BASE_TYPE, TestBase ))
+#define TEST_BASE_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, TEST_BASE_TYPE, TestBaseClass ))
+#define TEST_IS_BASE( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, TEST_BASE_TYPE ))
+#define TEST_IS_BASE_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), TEST_BASE_TYPE ))
+#define TEST_BASE_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), TEST_BASE_TYPE, TestBaseClass ))
+
+typedef struct TestBasePrivate TestBasePrivate;
+
+typedef struct {
+ GObject parent;
+ TestBasePrivate *private;
+}
+ TestBase;
+
+typedef struct TestBaseClassPrivate TestBaseClassPrivate;
+
+typedef struct {
+ GObjectClass parent;
+ TestBaseClassPrivate *private;
+}
+ TestBaseClass;
+
+GType test_base_get_type( void );
+
+static TestBase *test_base_new( void );
+
+/* ********************************************************************
+ * Implementing the interface
+ * ********************************************************************/
+
+/* private interface data
+ */
+struct TestIFaceInterfacePrivate {
+ void *empty; /* so that gcc -pedantic is happy */
+};
+
+static guint st_initializations = 0;
+
+static GType iface_register_type( void );
+static void interface_base_init( TestIFaceInterface *klass );
+static void interface_base_finalize( TestIFaceInterface *klass );
+
+GType
+test_iface_get_type( void )
+{
+ static GType iface_type = 0;
+
+ if( !iface_type ){
+ iface_type = iface_register_type();
+ }
+
+ return( iface_type );
+}
+
+static GType
+iface_register_type( void )
+{
+ static const gchar *thisfn = "test_iface_iface_register_type";
+ GType type;
+
+ static const GTypeInfo info = {
+ sizeof( TestIFaceInterface ),
+ ( GBaseInitFunc ) interface_base_init,
+ ( GBaseFinalizeFunc ) interface_base_finalize,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ g_debug( "%s", thisfn );
+
+ type = g_type_register_static( G_TYPE_INTERFACE, "TestIFace", &info, 0 );
+
+ g_type_interface_add_prerequisite( type, TEST_BASE_TYPE );
+
+ return( type );
+}
+
+static void
+interface_base_init( TestIFaceInterface *klass )
+{
+ static const gchar *thisfn = "test_iface_iface_interface_base_init";
+
+ if( !st_initializations ){
+
+ g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+ klass->private = g_new0( TestIFaceInterfacePrivate, 1 );
+ }
+
+ st_initializations += 1;
+}
+
+static void
+interface_base_finalize( TestIFaceInterface *klass )
+{
+ static const gchar *thisfn = "test_iface_iface_interface_base_finalize";
+
+ st_initializations -= 1;
+
+ if( !st_initializations ){
+
+ g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+ g_free( klass->private );
+ }
+}
+
+/* ********************************************************************
+ * Implementing the class
+ * ********************************************************************/
+
+/* private class data
+ */
+struct TestBaseClassPrivate {
+ void *empty; /* so that gcc -pedantic is happy */
+};
+
+/* private instance data
+ */
+struct TestBasePrivate {
+ gboolean dispose_has_run;
+};
+
+static GObjectClass *st_parent_class = NULL;
+
+static GType base_register_type( void );
+static void class_init( TestBaseClass *klass );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *object );
+static void instance_finalize( GObject *object );
+
+static void iface_iface_init( TestIFaceInterface *iface, void *user_data );
+
+GType
+test_base_get_type( void )
+{
+ static GType object_type = 0;
+
+ static const GInterfaceInfo iface_iface_info = {
+ ( GInterfaceInitFunc ) iface_iface_init,
+ NULL,
+ NULL
+ };
+
+ if( !object_type ){
+ object_type = base_register_type();
+ g_type_add_interface_static( object_type, TEST_IFACE_TYPE, &iface_iface_info );
+ }
+
+ return( object_type );
+}
+
+static GType
+base_register_type( void )
+{
+ static const gchar *thisfn = "test_iface_base_register_type";
+ GType type;
+
+ static GTypeInfo info = {
+ sizeof( TestBaseClass ),
+ ( GBaseInitFunc ) NULL,
+ ( GBaseFinalizeFunc ) NULL,
+ ( GClassInitFunc ) class_init,
+ NULL,
+ NULL,
+ sizeof( TestBase ),
+ 0,
+ ( GInstanceInitFunc ) instance_init
+ };
+
+ g_debug( "%s", thisfn );
+
+ type = g_type_register_static( G_TYPE_OBJECT, "TestBase", &info, 0 );
+
+ return( type );
+}
+
+static void
+class_init( TestBaseClass *klass )
+{
+ static const gchar *thisfn = "test_iface_base_class_init";
+ GObjectClass *object_class;
+
+ g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+ st_parent_class = g_type_class_peek_parent( klass );
+
+ object_class = G_OBJECT_CLASS( klass );
+ object_class->dispose = instance_dispose;
+ object_class->finalize = instance_finalize;
+
+ klass->private = g_new0( TestBaseClassPrivate, 1 );
+}
+
+static void
+instance_init( GTypeInstance *instance, gpointer klass )
+{
+ static const gchar *thisfn = "test_iface_base_instance_init";
+ TestBase *self;
+
+ g_return_if_fail( TEST_IS_BASE( instance ));
+
+ self = TEST_BASE( instance );
+
+ g_debug( "%s: instance=%p, klass=%p", thisfn, ( void * ) instance, ( void * ) klass );
+
+ self->private = g_new0( TestBasePrivate, 1 );
+
+ self->private->dispose_has_run = FALSE;
+}
+
+static void
+instance_dispose( GObject *object )
+{
+ static const gchar *thisfn = "test_iface_base_instance_dispose";
+ TestBase *self;
+
+ g_return_if_fail( TEST_IS_BASE( object ));
+
+ self = TEST_BASE( object );
+
+ if( !self->private->dispose_has_run ){
+
+ g_debug( "%s: object=%p", thisfn, ( void * ) object );
+
+ self->private->dispose_has_run = TRUE;
+
+ /* chain up to the parent class */
+ if( G_OBJECT_CLASS( st_parent_class )->dispose ){
+ G_OBJECT_CLASS( st_parent_class )->dispose( object );
+ }
+ }
+}
+
+static void
+instance_finalize( GObject *object )
+{
+ static const gchar *thisfn = "test_iface_base_instance_finalize";
+ TestBase *self;
+
+ g_return_if_fail( TEST_IS_BASE( object ));
+
+ self = ( TestBase * ) object;
+
+ g_debug( "%s: object=%p", thisfn, ( void * ) object );
+
+ g_free( self->private );
+
+ /* chain call to parent class */
+ if( G_OBJECT_CLASS( st_parent_class )->finalize ){
+ G_OBJECT_CLASS( st_parent_class )->finalize( object );
+ }
+}
+
+static TestBase *
+test_base_new( void )
+{
+ TestBase *object = g_object_new( TEST_BASE_TYPE, NULL );
+
+ return( object );
+}
+
+static void
+iface_iface_init( TestIFaceInterface *iface, void *user_data )
+{
+ static const gchar *thisfn = "test_iface_base_iface_iface_init";
+
+ g_debug( "%s: iface=%p, user_data=%p", thisfn, ( void * ) iface, ( void * ) user_data );
+}
+
+/* ********************************************************************
+ * main
+ * ********************************************************************/
+
+int
+main( int argc, char **argv )
+{
+ TestBase *base;
+
+ g_type_init();
+
+ g_debug( "allocating TestBase -------------------------------------" );
+ base = test_base_new();
+
+ g_debug( "unreffing TestBase ------------------------------------" );
+ g_object_unref( base );
+
+ g_debug( "end -----------------------------------------------------" );
+
+ return( 0 );
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]