diff options
Diffstat (limited to 'tests/repository')
-rw-r--r-- | tests/repository/Makefile.am | 8 | ||||
-rw-r--r-- | tests/repository/giteststructinfo.c | 58 |
2 files changed, 64 insertions, 2 deletions
diff --git a/tests/repository/Makefile.am b/tests/repository/Makefile.am index c79ba81f..da0337b3 100644 --- a/tests/repository/Makefile.am +++ b/tests/repository/Makefile.am @@ -2,13 +2,17 @@ AM_CFLAGS = $(GOBJECT_CFLAGS) AM_LDFLAGS = -module -avoid-version LIBS = $(GOBJECT_LIBS) -EXTRA_PROGRAMS = gitestrepo gitestthrows gitypelibtest +EXTRA_PROGRAMS = gitestrepo giteststructinfo gitestthrows gitypelibtest CLEANFILES = $(EXTRA_PROGRAMS) gitestrepo_SOURCES = $(srcdir)/gitestrepo.c gitestrepo_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository gitestrepo_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS) +giteststructinfo_SOURCES = $(srcdir)/giteststructinfo.c +giteststructinfo_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository +giteststructinfo_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS) + gitestthrows_SOURCES = $(srcdir)/gitestthrows.c gitestthrows_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository gitestthrows_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS) @@ -17,7 +21,7 @@ gitypelibtest_SOURCES = $(srcdir)/gitypelibtest.c gitypelibtest_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository gitypelibtest_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS) -TESTS = gitestrepo gitestthrows gitypelibtest +TESTS = gitestrepo giteststructinfo gitestthrows gitypelibtest TESTS_ENVIRONMENT=env GI_TYPELIB_PATH="$(top_builddir):$(top_builddir)/gir:$(top_builddir)/tests:$(top_builddir)/tests/scanner" \ XDG_DATA_DIRS="$(top_srcdir)/gir:$(XDG_DATA_DIRS)" \ PATH="$(top_builddir)/tests/scanner/.libs:$(PATH)" \ diff --git a/tests/repository/giteststructinfo.c b/tests/repository/giteststructinfo.c new file mode 100644 index 00000000..ed1563b2 --- /dev/null +++ b/tests/repository/giteststructinfo.c @@ -0,0 +1,58 @@ + +#include "girepository.h" + + +static void +test_field_iterators (void) +{ + GIRepository *repo; + GITypelib *ret; + GIStructInfo *class_info; + GIFieldInfo *field_info; + GError *error = NULL; + gint i; + + 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); + + for (i = 0; i < g_struct_info_get_n_fields (class_info); i++) + { + const char *field_name; + GIFieldInfo *found; + + field_info = g_struct_info_get_field (class_info, i); + g_assert_nonnull (field_info); + + field_name = g_base_info_get_name (field_info); + g_assert_nonnull (field_name); + + found = g_struct_info_find_field (class_info, field_name); + g_assert_nonnull (found); + g_assert_cmpstr (g_base_info_get_name (found), ==, field_name); + + g_base_info_unref (found); + g_base_info_unref (field_info); + } + + field_info = g_struct_info_find_field (class_info, "not_a_real_field_name"); + g_assert_null (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/structinfo/field-iterators", test_field_iterators); + + return g_test_run (); +} |