Add a couple of callback tests.
authorJohan Dahlin <jdahlin@async.com.br>
Tue, 27 Jan 2009 00:34:02 +0000 (00:34 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Tue, 27 Jan 2009 00:34:02 +0000 (00:34 +0000)
2009-01-26  Johan Dahlin  <jdahlin@async.com.br>

        * tests/everything/everything.c (test_callback):
        * tests/everything/everything.h:
        Add a couple of callback tests.

svn path=/trunk/; revision=1070

ChangeLog
tests/everything/everything.c
tests/everything/everything.h

index 76447b8..8a3f0a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,8 @@
 2009-01-26  Johan Dahlin  <jdahlin@async.com.br>
 
 2009-01-26  Johan Dahlin  <jdahlin@async.com.br>
 
-       reviewed by: <delete if not using a buddy>
-
        * tests/everything/everything.c (test_callback):
        * tests/everything/everything.h:
        * tests/everything/everything.c (test_callback):
        * tests/everything/everything.h:
+       Add a couple of callback tests.
 
 2009-01-26  Johan Dahlin  <jdahlin@async.com.br>
 
 
 2009-01-26  Johan Dahlin  <jdahlin@async.com.br>
 
        * giscanner/transformer.py:
 
        Catch SkipError for all nodes, not just functions.
        * giscanner/transformer.py:
 
        Catch SkipError for all nodes, not just functions.
-       Makes it possible to skip unsupported parameter types in
+       Makes it possible to skip unsupported parameter types in 
        callbacks.
 
 2009-01-12  Johan Dahlin  <jdahlin@async.com.br>
 
        Bug 563794 - Redo annotation parsing & applying
        callbacks.
 
 2009-01-12  Johan Dahlin  <jdahlin@async.com.br>
 
        Bug 563794 - Redo annotation parsing & applying
-
+       
        Thanks to Colin for helping out considerably in landing this.
 
        * giscanner/Makefile.am:
        Thanks to Colin for helping out considerably in landing this.
 
        * giscanner/Makefile.am:
 
        This commit merges the annotation parser rewrite branch.
        It'll change the annotation parsing to be done completely in python
 
        This commit merges the annotation parser rewrite branch.
        It'll change the annotation parsing to be done completely in python
-       code which will make it easier to do further annotation parsing
+       code which will make it easier to do further annotation parsing 
        easier.
 
 2009-01-03  Andreas Rottmann  <a.rottmann@gmx.at>
        easier.
 
 2009-01-03  Andreas Rottmann  <a.rottmann@gmx.at>
-
        Bug 563469 – Arrays not treated correctly in struct offset calculation
        Bug 563469 – Arrays not treated correctly in struct offset calculation
-
+       
        * tests/scanner/foo.h (FooObject): Added field `some_int'.
        * tests/scanner/foo-1.0-expected.gir,
        * tests/scanner/foo-1.0-expected.tgir: Adapted.
        * tests/scanner/foo.h (FooObject): Added field `some_int'.
        * tests/scanner/foo-1.0-expected.gir,
        * tests/scanner/foo-1.0-expected.tgir: Adapted.
-
        * giscanner/glibtransformer.py (GLibTransformer._create_gobject):
        carry over object fields from original (struct) node.
        (GLibTransformer._pair_class_struct): Don't add fields of the
        * giscanner/glibtransformer.py (GLibTransformer._create_gobject):
        carry over object fields from original (struct) node.
        (GLibTransformer._pair_class_struct): Don't add fields of the
        otherwise offset calculation would not work, as the instance
        fields are mingled with the class fields without a way to
        distinguish them.
        otherwise offset calculation would not work, as the instance
        fields are mingled with the class fields without a way to
        distinguish them.
-
+  
 2009-01-03  Johan Dahlin  <jdahlin@async.com.br>
 
        * misc/pep8.py:
 2009-01-03  Johan Dahlin  <jdahlin@async.com.br>
 
        * misc/pep8.py:
 2008-01-03  Andreas Rottmann  <a.rottmann@gmx.at>
 
        Bug 556489 – callback annotations
 2008-01-03  Andreas Rottmann  <a.rottmann@gmx.at>
 
        Bug 556489 – callback annotations
-
-       * giscanner/transformer.py
+       
+       * giscanner/transformer.py 
 
        * tools/generate.c (write_callable_info): Write out the new scope,
        closure and destroy attributes.
 
        * tools/generate.c (write_callable_info): Write out the new scope,
        closure and destroy attributes.
        method, checking if a given type is a callback.
        (Transformer._augment_callback_params): New method; adds
        information (closure, destroy) to callback parameters.
        method, checking if a given type is a callback.
        (Transformer._augment_callback_params): New method; adds
        information (closure, destroy) to callback parameters.
-       (Transformer._handle_closure, Transformer._handle_destroy): New methods,
+       (Transformer._handle_closure, Transformer._handle_destroy): New methods, 
        auxiliary to _augment_callback_params.
        (Transformer._create_function): Call _augment_callback_params().
        (Transformer._create_parameter): Handle scope option.
        auxiliary to _augment_callback_params.
        (Transformer._create_function): Call _augment_callback_params().
        (Transformer._create_parameter): Handle scope option.
        * giscanner/ast.py (Parameter): Added callback-related fields.
        * giscanner/girwriter.py: Write out new Parameter fields.
 
        * giscanner/ast.py (Parameter): Added callback-related fields.
        * giscanner/girwriter.py: Write out new Parameter fields.
 
-       * girepository/girnode.h (GIrNodeParam): Added fields scope,
+       * girepository/girnode.h (GIrNodeParam): Added fields scope, 
        closure and destroy.
        * girepository/gtypelib.h (ArgBlob): Ditto.
        * girepository/girparser.c (start_parameter): Handle new fields.
        closure and destroy.
        * girepository/gtypelib.h (ArgBlob): Ditto.
        * girepository/girparser.c (start_parameter): Handle new fields.
        (g_ir_node_build_typelib)
        * girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
        adjustments.
        (g_ir_node_build_typelib)
        * girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
        adjustments.
-       (g_ir_node_build_typelib): Fill in new ArgBlob flags from param.
+       (g_ir_node_build_typelib): Fill in new ArgBlob flags from param. 
 
        * girepository/girepository.h (GIScope): New enumeration, listing
        the different possible scopes for callbacks.
 
        * girepository/girepository.h (GIScope): New enumeration, listing
        the different possible scopes for callbacks.
        callback, destroy notification for a callback).
 
        * tests/scanner/: Added testcases for new features.
        callback, destroy notification for a callback).
 
        * tests/scanner/: Added testcases for new features.
-
+       
 2009-01-03  Jürg Billeter  <j@bitron.ch>
 
        * giscanner/ast.py:
 2009-01-03  Jürg Billeter  <j@bitron.ch>
 
        * giscanner/ast.py:
 2008-11-18  Johan Dahlin  <jdahlin@async.com.br>
 
        * giscanner/cachestore.py:
 2008-11-18  Johan Dahlin  <jdahlin@async.com.br>
 
        * giscanner/cachestore.py:
-       Catch BadPickleGet exceptions as well.
+       Catch BadPickleGet exceptions as well.  
 
 2008-11-17  Owen Taylor  <otaylor@redhat.com>
 
 
 2008-11-17  Owen Taylor  <otaylor@redhat.com>
 
 2008-11-11  Owen Taylor  <otaylor@redhat.com>
 
        * girepository/giroffsets.c: Fail gracefully with an informative
 2008-11-11  Owen Taylor  <otaylor@redhat.com>
 
        * girepository/giroffsets.c: Fail gracefully with an informative
-       error message when recursion is encountered when computing a
+       error message when recursion is encountered when computing a 
        structure size.
 
 2008-11-11  Owen Taylor  <otaylor@redhat.com>
        structure size.
 
 2008-11-11  Owen Taylor  <otaylor@redhat.com>
        * configure.ac: Check for Windows, set Automake conditional
        OS_WIN32. Change backslashes to forward slashes in pyexecdir to
        avoid shell quoting issues
        * configure.ac: Check for Windows, set Automake conditional
        OS_WIN32. Change backslashes to forward slashes in pyexecdir to
        avoid shell quoting issues
-
+       
        * girepository/Makefile.am: Use -no-undefined so that libtool
        agrees to build a shared library on Windows.
 
        * girepository/Makefile.am: Use -no-undefined so that libtool
        agrees to build a shared library on Windows.
 
 
 2008-08-24  Colin Walters  <walters@verbum.org>
 
 
 2008-08-24  Colin Walters  <walters@verbum.org>
 
-       * girepository/girepository.c (g_irepository_require):
+       * girepository/girepository.c (g_irepository_require): 
        Don't open shared library here; we already do it
        in gtypelib.c.
 
        Don't open shared library here; we already do it
        in gtypelib.c.
 
 
 2008-08-21  Colin Walters  <walters@verbum.org>
 
 
 2008-08-21  Colin Walters  <walters@verbum.org>
 
-       * girepository/girmodule.c (g_ir_module_build_typelib):
+       * girepository/girmodule.c (g_ir_module_build_typelib): 
        Revert change to increment header_size; we do that in
        write_string.
 
        Revert change to increment header_size; we do that in
        write_string.
 
 
 2008-08-21  Johan Dahlin  <johan@gnome.org>
 
 
 2008-08-21  Johan Dahlin  <johan@gnome.org>
 
-       * gir/Makefile.am (typelibs_DATA): Build and
+       * gir/Makefile.am (typelibs_DATA): Build and 
        install the Gio.typelib too
 
        * girepository/gtypelib.c (_g_typelib_init):
        install the Gio.typelib too
 
        * girepository/gtypelib.c (_g_typelib_init):
 
 2008-08-20  Johan Dahlin  <johan@gnome.org>
 
 
 2008-08-20  Johan Dahlin  <johan@gnome.org>
 
-       * giscanner/glibtransformer.py (GLibTransformer._resolve_type_name):
+       * giscanner/glibtransformer.py (GLibTransformer._resolve_type_name): 
        Add a workaround for #548689.
        We can now compile gtk!
 
        Add a workaround for #548689.
        We can now compile gtk!
 
        ones which have a paired GObject.
        Fix printing of type warning.
        * giscanner/transformer.py: Make strip_namespace_object
        ones which have a paired GObject.
        Fix printing of type warning.
        * giscanner/transformer.py: Make strip_namespace_object
-       be the identity function if it doesn't match the
+       be the identity function if it doesn't match the 
        namespace.
 
 2008-08-15  Colin Walters  <walters@verbum.org>
        namespace.
 
 2008-08-15  Colin Walters  <walters@verbum.org>
        * girepository/girepository.c (g_irepository_register): Add
        environment variable G_IREPOSITORY_VERBOSE so we can print
        out what we're doing.
        * girepository/girepository.c (g_irepository_register): Add
        environment variable G_IREPOSITORY_VERBOSE so we can print
        out what we're doing.
-       * girepository/girepository.c (g_irepository_register_file):
+       * girepository/girepository.c (g_irepository_register_file): 
        Add GError error message to g_debug call.
 
 2008-07-08  Jürg Billeter  <j@bitron.ch>
        Add GError error message to g_debug call.
 
 2008-07-08  Jürg Billeter  <j@bitron.ch>
 
        * giscanner/gidlwriter.py:
        * giscanner/xmlwriter.py:
 
        * giscanner/gidlwriter.py:
        * giscanner/xmlwriter.py:
-       Add a simple api for writing tags which can be used
+       Add a simple api for writing tags which can be used 
        with the new 'with statement' in python 2.5
 
 2008-04-21  Johan Dahlin  <johan@gnome.org>
        with the new 'with statement' in python 2.5
 
 2008-04-21  Johan Dahlin  <johan@gnome.org>
        * tools/g-ir-scanner (main): Add --pkg option to pass in
        pkg-config modules to get cflags from.
 
        * tools/g-ir-scanner (main): Add --pkg option to pass in
        pkg-config modules to get cflags from.
 
-       * giscanner/gidlwriter.py (GIDLWriter._write_method):
+       * giscanner/gidlwriter.py (GIDLWriter._write_method): 
        Avoid duplication, reuse function writer for methods.
 
 2008-04-21  Johan Dahlin  <jdahlin@async.com.br>
        Avoid duplication, reuse function writer for methods.
 
 2008-04-21  Johan Dahlin  <jdahlin@async.com.br>
        Fix a typo and add an example python test program.
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
        Fix a typo and add an example python test program.
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
-
+       
        * giscanner/__init__.py:
        * giscanner/giscannermodule.c:
        * giscanner/sourcescanner.c:
        * giscanner/__init__.py:
        * giscanner/giscannermodule.c:
        * giscanner/sourcescanner.c:
        Add constants and wrap a few more SymbolType fields
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
        Add constants and wrap a few more SymbolType fields
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
-
+       
        * configure.ac:
        * giscanner:
        * giscanner/__init__.py:
        * giscanner/giscannermodule.c:
        * giscanner/Makefile.am:
 
        * configure.ac:
        * giscanner:
        * giscanner/__init__.py:
        * giscanner/giscannermodule.c:
        * giscanner/Makefile.am:
 
-       Add initial python bindings for the scanner and
+       Add initial python bindings for the scanner and 
        depend on python 2.5.
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
        depend on python 2.5.
 
 2008-03-25  Johan Dahlin  <johan@gnome.org>
        * tools/sourcescanner.h:
 
        Move the scanner to a separate library.
        * tools/sourcescanner.h:
 
        Move the scanner to a separate library.
-
+       
 2008-03-23  Johan Dahlin  <johan@gnome.org>
 
        * tools/Makefile.am:
 2008-03-23  Johan Dahlin  <johan@gnome.org>
 
        * tools/Makefile.am:
 
 2008-03-23  Johan Dahlin  <johan@gnome.org>
 
 
 2008-03-23  Johan Dahlin  <johan@gnome.org>
 
-       * tests/parser/Makefile.am (utility.gidl):
-       * tests/parser/utility-expected.gidl:
+       * tests/parser/Makefile.am (utility.gidl): 
+       * tests/parser/utility-expected.gidl: 
        Pass in the gobject.gidl since we're defining a GObject.
 
 2008-03-12  Johan Dahlin  <johan@gnome.org>
        Pass in the gobject.gidl since we're defining a GObject.
 
 2008-03-12  Johan Dahlin  <johan@gnome.org>
        * tests/parser/utility.h:
        Add a get_type-function, so the scanner actually
        parses it as an object.
        * tests/parser/utility.h:
        Add a get_type-function, so the scanner actually
        parses it as an object.
-
+       
 2008-03-12  Johan Dahlin  <johan@gnome.org>
 
        * tools/gidlwriter.c (function_generate): Add missing trailing quote.
 2008-03-12  Johan Dahlin  <johan@gnome.org>
 
        * tools/gidlwriter.c (function_generate): Add missing trailing quote.
        Remove most global variables
 
 2008-03-11  Philip Van Hoof  <me@pvanhoof.be>
        Remove most global variables
 
 2008-03-11  Philip Van Hoof  <me@pvanhoof.be>
-
        * tools/scannerlexer.l:
        * tools/scanner.c:
        * tests/parser/Foo-expected.gidl:
        * tests/parser/foo.c:
        * tests/parser/Makefile.am:
        * tests/parser/foo-object.h:
        * tools/scannerlexer.l:
        * tools/scanner.c:
        * tests/parser/Foo-expected.gidl:
        * tests/parser/foo.c:
        * tests/parser/Makefile.am:
        * tests/parser/foo-object.h:
-
        Added a few extra tests. Which resulted in finding a few
        bugs. Which resulted in me fixing those bugs
 
        Added a few extra tests. Which resulted in finding a few
        bugs. Which resulted in me fixing those bugs
 
        Add support for parsing return arguments. Add support for
        caller-owns return types.
        Patch by Philip Van Hoof.
        Add support for parsing return arguments. Add support for
        caller-owns return types.
        Patch by Philip Van Hoof.
-
+       
        * tools/scannerparser.y:
        Remove parsing of the @deprecated syntax used in headers.
        We will support gtk-doc deprecation in the future instead.
        * tools/scannerparser.y:
        Remove parsing of the @deprecated syntax used in headers.
        We will support gtk-doc deprecation in the future instead.
 
 2008-03-10  Johan Dahlin  <johan@gnome.org>
 
 
 2008-03-10  Johan Dahlin  <johan@gnome.org>
 
-       * tests/invoke/Makefile.am: Make the generated metadata
+       * tests/invoke/Makefile.am: Make the generated metadata 
        depend on the g-idl-compiler
 
 2008-02-21  Mark Doffman  <mark.doffman@codethink.co.uk>
        depend on the g-idl-compiler
 
 2008-02-21  Mark Doffman  <mark.doffman@codethink.co.uk>
index c30fbb7..7d8a020 100644 (file)
@@ -747,3 +747,68 @@ test_obj_static_method (int x)
 {
   return x;
 }
 {
   return x;
 }
+
+/**
+ * test_callback:
+ * @callback: (scope call):
+ *
+ **/
+int
+test_callback (TestCallback callback)
+{
+  return callback();
+}
+
+/**
+ * test_callback_user_data:
+ * @callback: (scope call):
+ *
+ * Call - callback parameter persists for the duration of the method
+ * call and can be released on return.
+ **/
+int
+test_callback_user_data (TestCallbackUserData callback,
+                         gpointer user_data)
+{
+  return callback(user_data);
+}
+
+/**
+ * test_callback_destroy_notify:
+ * @callback: (scope notified): 
+ *
+ * Notified - callback persists until a DestroyNotify delegate
+ * is invoked.
+ **/
+int
+test_callback_destroy_notify (TestCallbackUserData callback,
+                              gpointer user_data,
+                              GDestroyNotify notify)
+{
+  int retval;
+
+  retval = callback(user_data);
+  if (notify)
+    notify(user_data);
+
+  return retval;
+}
+
+/**
+ * test_callback_infinte:
+ * @callback: (scope infinte): 
+ *
+ * Infinite - callback persists forever.
+ **/
+
+static GSList *infinite_callbacks = NULL;
+
+int
+test_callback_infinte (TestCallbackUserData callback,
+                       gpointer user_data)
+{
+  infinite_callbacks = g_slist_prepend(infinite_callbacks, callback);
+  
+  return callback(user_data);
+}
+
index 29ec8d7..6347c63 100644 (file)
@@ -167,6 +167,7 @@ TestBoxed *test_boxed_copy     (TestBoxed *boxed);
 gboolean   test_boxed_equals   (TestBoxed *boxed,
                                TestBoxed *other);
 
 gboolean   test_boxed_equals   (TestBoxed *boxed,
                                TestBoxed *other);
 
+/* gobject */
 #define TEST_TYPE_OBJ              (test_obj_get_type ())
 #define TEST_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_CAST ((object), TEST_TYPE_OBJ, TestObj))
 #define TEST_IS_OBJECT(object)     (G_TYPE_CHECK_INSTANCE_TYPE ((object), TEST_TYPE_OBJ))
 #define TEST_TYPE_OBJ              (test_obj_get_type ())
 #define TEST_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_CAST ((object), TEST_TYPE_OBJ, TestObj))
 #define TEST_IS_OBJECT(object)     (G_TYPE_CHECK_INSTANCE_TYPE ((object), TEST_TYPE_OBJ))
@@ -187,4 +188,18 @@ GType      test_obj_get_type (void);
 TestObj*   test_obj_new_from_file (const char *x, GError **error);
 double     test_obj_static_method (int x);
 
 TestObj*   test_obj_new_from_file (const char *x, GError **error);
 double     test_obj_static_method (int x);
 
+/* callback */
+typedef int (*TestCallback) ();
+typedef int (*TestCallbackUserData) (gpointer user_data);
+
+int test_callback (TestCallback callback);
+int test_callback_user_data (TestCallbackUserData callback,
+                             gpointer user_data);
+int test_callback_destroy_notify (TestCallbackUserData callback,
+                                  gpointer user_data,
+                                  GDestroyNotify notify);
+int test_callback_infinte (TestCallbackUserData callback,
+                           gpointer user_data);
+
+
 #endif /* __GITESTTYPES_H__ */
 #endif /* __GITESTTYPES_H__ */