(root)/
glib-2.79.0/
gobject/
tests/
testcommon.h
       1  /* GObject - GLib Type, Object, Parameter and Signal Library
       2   * Copyright (C) 2003 Red Hat, Inc.
       3   *
       4   * SPDX-License-Identifier: LGPL-2.1-or-later
       5   *
       6   * This library is free software; you can redistribute it and/or
       7   * modify it under the terms of the GNU Lesser General Public
       8   * License as published by the Free Software Foundation; either
       9   * version 2.1 of the License, or (at your option) any later version.
      10   *
      11   * This library is distributed in the hope that it will be useful,
      12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14   * Lesser General Public License for more details.
      15   *
      16   * You should have received a copy of the GNU Lesser General
      17   * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18   */
      19  
      20  #ifndef __TEST_COMMON_H__
      21  #define __TEST_COMMON_H__
      22  
      23  G_BEGIN_DECLS
      24  
      25  #define DEFINE_TYPE_FULL(name, prefix,				\
      26  		         class_init, base_init, instance_init,	\
      27  		         parent_type, interface_decl)		\
      28  GType								\
      29  prefix ## _get_type (void)					\
      30  {								\
      31    static GType object_type = 0;					\
      32  								\
      33    if (!object_type)						\
      34      {								\
      35        static const GTypeInfo object_info =			\
      36  	{							\
      37  	  sizeof (name ## Class),				\
      38  	  (GBaseInitFunc) base_init,				\
      39  	  (GBaseFinalizeFunc) NULL,				\
      40  	  (GClassInitFunc) class_init,				\
      41  	  (GClassFinalizeFunc) NULL,				\
      42  	  NULL,           /* class_data */			\
      43  	  sizeof (name),					\
      44  	  0,             /* n_prelocs */			\
      45  	  (GInstanceInitFunc) instance_init,			\
      46  	  (const GTypeValueTable *) NULL,			\
      47  	};							\
      48  								\
      49        object_type = g_type_register_static (parent_type,	\
      50  					    # name,		\
      51  					    &object_info, 0);	\
      52        interface_decl						\
      53      }								\
      54  								\
      55    return object_type;						\
      56  }
      57  
      58  #define DEFINE_TYPE(name, prefix,				\
      59  		    class_init, base_init, instance_init,	\
      60  		    parent_type)				\
      61    DEFINE_TYPE_FULL(name, prefix, class_init, base_init,		\
      62  		   instance_init, parent_type, {})
      63  
      64  #define DEFINE_IFACE(name, prefix, base_init, dflt_init)	\
      65  GType								\
      66  prefix ## _get_type (void)					\
      67  {								\
      68    static GType iface_type = 0;					\
      69  								\
      70    if (!iface_type)						\
      71      {								\
      72        static const GTypeInfo iface_info =			\
      73        {								\
      74  	sizeof (name ## Class),					\
      75  	(GBaseInitFunc)	base_init,				\
      76  	(GBaseFinalizeFunc) NULL,				\
      77  	(GClassInitFunc) dflt_init,				\
      78  	(GClassFinalizeFunc) NULL,				\
      79  	(gconstpointer) NULL,					\
      80  	(guint16) 0,						\
      81  	(guint16) 0,						\
      82  	(GInstanceInitFunc) NULL,				\
      83  	(const GTypeValueTable*) NULL,				\
      84        };							\
      85  								\
      86        iface_type = g_type_register_static (G_TYPE_INTERFACE,	\
      87  					    # name,		\
      88  					    &iface_info, 0);	\
      89      }								\
      90    return iface_type;						\
      91  }
      92  
      93  #define INTERFACE_FULL(type, init_func, iface_type)		\
      94  {								\
      95    static GInterfaceInfo const iface =				\
      96      {								\
      97        (GInterfaceInitFunc) init_func, NULL, NULL		\
      98      };								\
      99  								\
     100    g_type_add_interface_static (type, iface_type, &iface);	\
     101  }
     102  #define INTERFACE(init_func, iface_type)	\
     103    INTERFACE_FULL(object_type, init_func, iface_type)
     104  
     105  G_END_DECLS
     106  
     107  #endif /* __TEST_COMMON_H__ */