From df4a6ff72eb51de034c8e70af94c1a709d1e8dc7 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 23 Jan 2012 08:53:44 +0100 Subject: Add regress test methods for callbacks taking GError and GHashTable This covers both "transfer none" and "transfer full" cases. This is a requisite for writing a pygobject test case for https://bugzilla.gnome.org/show_bug.cgi?id=666270 --- tests/scanner/Regress-1.0-expected.gir | 79 ++++++++++++++++++++++++++++++++++ tests/scanner/regress.c | 42 ++++++++++++++++++ tests/scanner/regress.h | 14 ++++++ 3 files changed, 135 insertions(+) diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 7d01ef4e..ebdacf56 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -169,6 +169,43 @@ use it should be. + + + + + + + + + + + + + + + + + a hash table; will be modified + + + + + + + + + + + + + + GError instance; must be freed by the callback + + + + @@ -2036,6 +2073,17 @@ call and can be released on return. + + + + + + + + + + @@ -2385,6 +2433,25 @@ element-type annotation. + + + + + + + GHashTable that gets passed to callback + + + + + + + + + + @@ -2563,6 +2630,18 @@ What we're testing here is that the scanner ignores the @a nested inside XML. + + + + + + + + + + diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c index 4b35604f..0f00ec8d 100644 --- a/tests/scanner/regress.c +++ b/tests/scanner/regress.c @@ -3026,6 +3026,48 @@ regress_test_obj_new_callback (RegressTestCallbackUserData callback, gpointer us return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL); } +/** + * regress_test_hash_table_callback: + * @data: (element-type utf8 gint): GHashTable that gets passed to callback + * @callback: (scope call): + **/ +void +regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback) +{ + callback (data); +} + +/** + * regress_test_gerror_callback: + * @callback: (scope call): + **/ +void +regress_test_gerror_callback (RegressTestCallbackGError callback) +{ + GError *error; + + error = g_error_new_literal (G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + "regression test error"); + callback (error); + g_error_free (error); +} + +/** + * regress_test_owned_gerror_callback: + * @callback: (scope call): + **/ +void +regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback) +{ + GError *error; + + error = g_error_new_literal (G_IO_ERROR, + G_IO_ERROR_PERMISSION_DENIED, + "regression test owned error"); + callback (error); +} + /* interface */ static void diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index 91d14713..8fe44e2b 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -520,6 +520,17 @@ regress_test_fundamental_sub_object_new (const char *data); typedef void (*RegressTestSimpleCallback) (void); typedef int (*RegressTestCallback) (void); typedef int (*RegressTestCallbackUserData) (gpointer user_data); +/** + * RegressTestCallbackHashtable: + * @data: (element-type utf8 gint): a hash table; will be modified + */ +typedef void (*RegressTestCallbackHashtable) (GHashTable *data); +typedef void (*RegressTestCallbackGError) (const GError *error); +/** + * RegressTestCallbackOwnedGError: + * @error: (transfer full): GError instance; must be freed by the callback + */ +typedef void (*RegressTestCallbackOwnedGError) (GError *error); /** * RegressTestCallbackFull: * @foo: the investment rate @@ -548,6 +559,9 @@ void regress_test_obj_static_method_callback (RegressTestCallback callback); RegressTestObj *regress_test_obj_new_callback (RegressTestCallbackUserData callback, gpointer user_data, GDestroyNotify notify); +void regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback); +void regress_test_gerror_callback (RegressTestCallbackGError callback); +void regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback); typedef struct _RegressTestInterface RegressTestInterface; -- cgit v1.2.1