diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-11-27 14:35:09 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-11-27 14:35:09 +0000 |
commit | bd13543736d2042f8f6c68c145286f396ad632f9 (patch) | |
tree | 5f5d4cda65a17e36d8c3e5b1975f65ce7695848f | |
parent | 1069de984331165d72e5cbfa4576325a624ad9c7 (diff) |
Add a script to generate GObject type macros etc., and a test case
-rw-r--r-- | tests/tools/Makefile.am | 16 | ||||
-rw-r--r-- | tests/tools/expected-ginterface-foo.h | 16 | ||||
-rw-r--r-- | tests/tools/expected-gobject-foo.h | 21 | ||||
-rw-r--r-- | tests/tools/test-gobject-foo.sh | 18 | ||||
-rw-r--r-- | tools/Makefile.am | 1 | ||||
-rw-r--r-- | tools/gobject-foo.py | 81 |
6 files changed, 153 insertions, 0 deletions
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index e69de29b..df9ad480 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -0,0 +1,16 @@ +dist_noinst_SCRIPTS = \ + test-gobject-foo.sh + +EXTRA_DIST = \ + expected-gobject-foo.h \ + expected-ginterface-foo.h + +all-local: + chmod +x $(dist_noinst_SCRIPTS) + +TESTS = $(dist_noinst_SCRIPTS) + +TESTS_ENVIRONMENT = \ + PYTHON=$(PYTHON) \ + srcdir=$(srcdir) \ + top_srcdir=$(top_srcdir) diff --git a/tests/tools/expected-ginterface-foo.h b/tests/tools/expected-ginterface-foo.h new file mode 100644 index 00000000..03761b22 --- /dev/null +++ b/tests/tools/expected-ginterface-foo.h @@ -0,0 +1,16 @@ +typedef struct _XyzBadgerMushroomSnake XyzBadgerMushroomSnake; +typedef struct _XyzBadgerMushroomSnakeClass XyzBadgerMushroomSnakeClass; +typedef struct _XyzBadgerMushroomSnakePrivate XyzBadgerMushroomSnakePrivate; + +GType xyz_badger_mushroom_snake_get_type (void); + +#define XYZ_BADGER_TYPE_MUSHROOM_SNAKE \ + (xyz_badger_mushroom_snake_get_type ()) +#define XYZ_BADGER_MUSHROOM_SNAKE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE, \ + XyzBadgerMushroomSnake)) +#define XYZ_BADGER_IS_MUSHROOM_SNAKE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE)) +#define XYZ_BADGER_MUSHROOM_SNAKE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE, \ + XyzBadgerMushroomSnakeClass)) diff --git a/tests/tools/expected-gobject-foo.h b/tests/tools/expected-gobject-foo.h new file mode 100644 index 00000000..528ff5a5 --- /dev/null +++ b/tests/tools/expected-gobject-foo.h @@ -0,0 +1,21 @@ +typedef struct _XyzBadgerMushroomSnake XyzBadgerMushroomSnake; +typedef struct _XyzBadgerMushroomSnakeClass XyzBadgerMushroomSnakeClass; +typedef struct _XyzBadgerMushroomSnakePrivate XyzBadgerMushroomSnakePrivate; + +GType xyz_badger_mushroom_snake_get_type (void); + +#define XYZ_BADGER_TYPE_MUSHROOM_SNAKE \ + (xyz_badger_mushroom_snake_get_type ()) +#define XYZ_BADGER_MUSHROOM_SNAKE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE, \ + XyzBadgerMushroomSnake)) +#define XYZ_BADGER_MUSHROOM_SNAKE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), XYZ_BADGER_TYPE_MUSHROOM_SNAKE, \ + XyzBadgerMushroomSnakeClass)) +#define XYZ_BADGER_IS_MUSHROOM_SNAKE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE)) +#define XYZ_BADGER_IS_MUSHROOM_SNAKE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), XYZ_BADGER_TYPE_MUSHROOM_SNAKE)) +#define XYZ_BADGER_MUSHROOM_SNAKE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), XYZ_BADGER_TYPE_MUSHROOM_SNAKE, \ + XyzBadgerMushroomSnakeClass)) diff --git a/tests/tools/test-gobject-foo.sh b/tests/tools/test-gobject-foo.sh new file mode 100644 index 00000000..46567810 --- /dev/null +++ b/tests/tools/test-gobject-foo.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +${PYTHON} ${top_srcdir}/tools/gobject-foo.py Xyz_Badger Mushroom_Snake \ + > gobject-foo.h +${PYTHON} ${top_srcdir}/tools/gobject-foo.py --interface \ + Xyz_Badger Mushroom_Snake > ginterface-foo.h + +e=0 +# We assume POSIX diff, until someone complains +diff -b -c ${srcdir}/expected-gobject-foo.h gobject-foo.h || e=$? +diff -b -c ${srcdir}/expected-ginterface-foo.h ginterface-foo.h || e=$? + +rm -f gobject-foo.h +rm -f ginterface-foo.h + +exit $e diff --git a/tools/Makefile.am b/tools/Makefile.am index a3f9712a..eb1e2e0d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -14,6 +14,7 @@ EXTRA_DIST = \ glib-ginterface-gen.py \ glib-gtypes-generator.py \ glib-signals-marshal-gen.py \ + gobject-foo.py \ identity.xsl \ libglibcodegen.py \ ls-interfaces.xsl \ diff --git a/tools/gobject-foo.py b/tools/gobject-foo.py new file mode 100644 index 00000000..a59c56c0 --- /dev/null +++ b/tools/gobject-foo.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +# gobject-foo.py: generate standard GObject type macros etc. +# +# The master copy of this program is in the telepathy-glib repository - +# please make any changes there. +# +# Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> +# +# 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 +# Library 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 + +def gobject_header(head, tail, as_interface=False): + out = [] + o = out.append + + name = head + '_' + tail + MixedCase = name.replace('_', '') + lower_case = name.lower() + UPPER_CASE = name.upper() + + gtype = head.upper() + '_TYPE_' + tail.upper() + + o("typedef struct _%s %s;" % (MixedCase, MixedCase)) + o("typedef struct _%sClass %sClass;" % (MixedCase, MixedCase)) + o("typedef struct _%sPrivate %sPrivate;" % (MixedCase, MixedCase)) + o("") + o("GType %s_get_type (void);" % lower_case) + o("") + + o("#define %s \\" % gtype) + o(" (%s_get_type ())" % lower_case) + + o("#define %s(obj) \\" % UPPER_CASE) + o(" (G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, \\" % gtype) + o(" %s))" % MixedCase) + + if not as_interface: + o("#define %s_CLASS(klass) \\" % UPPER_CASE) + o(" (G_TYPE_CHECK_CLASS_CAST ((klass), %s, \\" % gtype) + o(" %sClass))" % MixedCase) + + o("#define %s_IS_%s(obj) \\" % (head.upper(), tail.upper())) + o(" (G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))" % gtype) + + if not as_interface: + o("#define %s_IS_%s_CLASS(klass) \\" % (head.upper(), tail.upper())) + o(" (G_TYPE_CHECK_CLASS_TYPE ((klass), %s))" % gtype) + + o("#define %s_GET_CLASS(obj) \\" % UPPER_CASE) + o(" (G_TYPE_INSTANCE_GET_CLASS ((obj), %s, \\" % gtype) + o(" %sClass))" % MixedCase) + + return out + +if __name__ == '__main__': + import sys + from getopt import gnu_getopt + + options, argv = gnu_getopt(sys.argv[1:], '', ['interface']) + + as_interface = False + + for opt, val in options: + if opt == '--interface': + as_interface = True + + head, tail = argv + + print '\n'.join(gobject_header(head, tail, as_interface=as_interface)) |