summaryrefslogtreecommitdiff
path: root/tests/repository
diff options
context:
space:
mode:
authorJohan Bilien <jobi@via.ecp.fr>2008-10-21 17:04:11 +0000
committerJohan Bilien <jobi@src.gnome.org>2008-10-21 17:04:11 +0000
commitefcca1bcac888b214b80fe2451edacbb3b224be3 (patch)
tree1f781e2fb232e65cc48731d19de4254d3bdb5f49 /tests/repository
parent05d588fc2d77ad6068ec992915d23afdfed1b7b4 (diff)
downloadgobject-introspection-efcca1bcac888b214b80fe2451edacbb3b224be3.tar.gz
Bug 557241 – "throws" flag for functions
2008-10-21 Johan Bilien <jobi@via.ecp.fr> Bug 557241 – "throws" flag for functions * tests/scanner/drawable-1.0-expected.gir, tests/scanner/drawable-injected-1.0-expected.gir, tests/scanner/drawable.[ch]: add simple test for throwing function (has GError ** as last argument) * giscanner/ast.py: add a 'throws' flag to Function * giscanner/glibtransformer.py: if a function's last paramerter is a GError, set the 'throws' flag and remove that parameter * giscanner/girwriter.py: write out the 'throws' attribute * giscanner/girparser.py: support parsing the 'throws' attribute * tests/repository/gitestthrows.c: add a simple test to check the throws flag in a typelib and invoke the function * girepository/ginfo.c, girepository/girnode.[ch], girepository/girnode.h, girepository/girparser.c, girepository/girepository.h: Add and parse the GI_FUNCTION_THROWS flag * girepository/ginvoke.c: if a function throws, add a GError as last arguments, and propagate the error to the invoker. svn path=/trunk/; revision=773
Diffstat (limited to 'tests/repository')
-rw-r--r--tests/repository/Makefile.am10
-rw-r--r--tests/repository/gitestthrows.c55
2 files changed, 62 insertions, 3 deletions
diff --git a/tests/repository/Makefile.am b/tests/repository/Makefile.am
index 8bafe723..6790c427 100644
--- a/tests/repository/Makefile.am
+++ b/tests/repository/Makefile.am
@@ -2,11 +2,15 @@ AM_CFLAGS = $(GOBJECT_CFLAGS)
AM_LDFLAGS = -module -avoid-version
LIBS = $(GOBJECT_LIBS)
-noinst_PROGRAMS = gitestrepo
+noinst_PROGRAMS = gitestrepo gitestthrows
gitestrepo_SOURCES = $(srcdir)/gitestrepo.c
gitestrepo_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
gitestrepo_LDADD = $(GIREPO_LIBS) $(top_builddir)/girepository/libgirepository.la
-TESTS = gitestrepo
-TESTS_ENVIRONMENT=env top_builddir="$(top_builddir)" $(DEBUG) \ No newline at end of file
+gitestthrows_SOURCES = $(srcdir)/gitestthrows.c
+gitestthrows_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
+gitestthrows_LDADD = $(GIREPO_LIBS) $(top_builddir)/girepository/libgirepository.la
+
+TESTS = gitestrepo gitestthrows
+TESTS_ENVIRONMENT=env top_builddir="$(top_builddir)" $(DEBUG)
diff --git a/tests/repository/gitestthrows.c b/tests/repository/gitestthrows.c
new file mode 100644
index 00000000..3b12cabf
--- /dev/null
+++ b/tests/repository/gitestthrows.c
@@ -0,0 +1,55 @@
+
+#include "girepository.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+main(int argc, char **argv)
+{
+ GIRepository *repo;
+ gboolean ret;
+ GIBaseInfo *info;
+ char *girdir;
+ GArgument in_arg[1];
+ GArgument ret_arg;
+ GError *error;
+ gboolean invoke_return;
+
+ g_type_init ();
+
+ repo = g_irepository_get_default ();
+
+ girdir = g_build_filename (g_getenv ("top_builddir"), "gir", NULL);
+ g_irepository_prepend_search_path (girdir);
+ g_free (girdir);
+
+ error = NULL;
+ ret = g_irepository_require (repo, "GLib", NULL, 0, &error);
+ g_assert (ret);
+ g_assert (error == NULL);
+
+ info = g_irepository_find_by_name (repo, "GLib", "file_read_link");
+ g_assert (info != NULL);
+ g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
+ g_assert (g_function_info_get_flags ((GIFunctionInfo *)info) & GI_FUNCTION_THROWS);
+
+ in_arg[0].v_string = g_strdup ("non-existent-file/hope");
+ error = NULL;
+ invoke_return = g_function_info_invoke ((GIFunctionInfo *)info,
+ in_arg,
+ 1,
+ NULL,
+ 0,
+ &ret_arg,
+ &error);
+ g_free(in_arg[0].v_string);
+
+ g_assert (invoke_return == FALSE);
+ g_assert (error != NULL);
+ g_assert (error->domain == G_FILE_ERROR);
+ g_assert (error->code == G_FILE_ERROR_NOENT);
+
+ exit(0);
+}