summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett Regier <garrett.regier@riftio.com>2015-06-03 05:24:21 -0700
committerGarrett Regier <garrett.regier@riftio.com>2015-06-21 13:01:25 -0700
commit0aef39a20bd229170871edda862ade7d24ff7edd (patch)
tree417e9faa0edc487d577b5c3e04d6feaa369c8766 /tests
parent5d47bb3a72e12150d7862d602d5032cf920c3543 (diff)
downloadgobject-introspection-0aef39a20bd229170871edda862ade7d24ff7edd.tar.gz
girepository: Support GError exceptions on callbacks
Generalize "throws" attribute to SignatureBlob which can be used by all callable blob types. Keep FunctionBlob and VFuncBlob throw attributes around and functional for compatibility. Refactor girwriter.c to write out throws attribute for all callable types. Based on a patch by Simon Feltman. https://bugzilla.gnome.org/show_bug.cgi?id=729543
Diffstat (limited to 'tests')
-rw-r--r--tests/repository/gitestthrows.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/repository/gitestthrows.c b/tests/repository/gitestthrows.c
index 17694bfb..826ed414 100644
--- a/tests/repository/gitestthrows.c
+++ b/tests/repository/gitestthrows.c
@@ -42,12 +42,93 @@ test_invoke_gerror (void)
g_assert (error->code == G_FILE_ERROR_NOENT);
}
+static void
+test_vfunc_can_throw_gerror (void)
+{
+ GIRepository *repo;
+ GITypelib *ret;
+ GIBaseInfo *object_info;
+ GIFunctionInfo *invoker_info;
+ GIVFuncInfo *vfunc_info;
+ GError *error = NULL;
+
+ repo = g_irepository_get_default ();
+
+ ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
+ g_assert_nonnull (ret);
+ g_assert_no_error (error);
+
+ object_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "Object");
+ g_assert_nonnull (object_info);
+ g_assert (g_base_info_get_type (object_info) == GI_INFO_TYPE_OBJECT);
+
+ invoker_info = g_object_info_find_method ((GIObjectInfo *)object_info,
+ "vfunc_meth_with_error");
+ g_assert_nonnull (invoker_info);
+ g_assert (g_function_info_get_flags (invoker_info) & GI_FUNCTION_THROWS);
+ g_assert (g_callable_info_can_throw_gerror ((GICallableInfo *)invoker_info));
+
+ vfunc_info = g_object_info_find_vfunc ((GIObjectInfo *)object_info,
+ "vfunc_meth_with_err");
+ g_assert_nonnull (vfunc_info);
+ g_assert (g_vfunc_info_get_flags (vfunc_info) & GI_VFUNC_THROWS);
+ g_assert (g_callable_info_can_throw_gerror ((GICallableInfo *)vfunc_info));
+
+ g_base_info_unref (vfunc_info);
+ g_base_info_unref (invoker_info);
+ g_base_info_unref (object_info);
+}
+
+static void
+test_callback_can_throw_gerror (void)
+{
+ GIRepository *repo;
+ GITypelib *ret;
+ GIStructInfo *class_info;
+ GIFieldInfo *field_info;
+ GITypeInfo *field_type;
+ GICallbackInfo *callback_info;
+ GError *error = NULL;
+
+ repo = g_irepository_get_default ();
+
+ ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
+ g_assert_nonnull (ret);
+ g_assert_no_error (error);
+
+ class_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "ObjectClass");
+ g_assert_nonnull (class_info);
+ g_assert (g_base_info_get_type (class_info) == GI_INFO_TYPE_STRUCT);
+
+ field_info = g_struct_info_find_field (class_info, "vfunc_meth_with_err");
+ g_assert_nonnull (field_info);
+ g_assert (g_base_info_get_type (field_info) == GI_INFO_TYPE_FIELD);
+
+ field_type = g_field_info_get_type (field_info);
+ g_assert_nonnull (field_type);
+ g_assert (g_base_info_get_type (field_type) == GI_INFO_TYPE_TYPE);
+ g_assert (g_type_info_get_tag (field_type) == GI_TYPE_TAG_INTERFACE);
+
+ callback_info = g_type_info_get_interface (field_type);
+ g_assert_nonnull (callback_info);
+ g_assert (g_callable_info_can_throw_gerror ((GICallableInfo *)callback_info));
+
+ g_base_info_unref (callback_info);
+ g_base_info_unref (field_type);
+ g_base_info_unref (field_info);
+ g_base_info_unref (class_info);
+}
+
int
main(int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/girepository/throws/invoke-gerror", test_invoke_gerror);
+ g_test_add_func ("/girepository/throws/vfunc-can-throw-gerror",
+ test_vfunc_can_throw_gerror);
+ g_test_add_func ("/girepository/throws/callback-can-throw-gerror",
+ test_callback_can_throw_gerror);
return g_test_run ();
}