summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaszlo Pandy <lpandy@src.gnome.org>2011-02-22 16:02:12 +0100
committerLaszlo Pandy <lpandy@src.gnome.org>2011-02-23 13:55:04 +0100
commited94a687d874c655386bcef662eb659aaca83ac5 (patch)
tree3fb3e3ba5ac424cb81ccf9ea49c1dc92fca8eea5 /tests
parent3fe4ad82003a5472c44585627f86e5883772acca (diff)
downloadgobject-introspection-ed94a687d874c655386bcef662eb659aaca83ac5.tar.gz
Add "c:identifier" attribute to GIrNodeValue (for flags and enum values).GOBJECT_INTROSPECTION_0_10_3
Flags and enums with a GType have a value_nick and value_name strings available in the class struct. But for flags and enums without GType, we need to get this information from introspection. g_base_info_get_name() gives the string for value_nick. In the GIR, the attribute "c:identifier" is the string neede for value_name. This patch adds the "c:identifier" from GIR to the typelib for all flags and enum values. It can be retireved using g_base_info_get_attribute(info, "c:identifier"). https://bugzilla.gnome.org/show_bug.cgi?id=642757
Diffstat (limited to 'tests')
-rw-r--r--tests/repository/Makefile.am10
-rw-r--r--tests/repository/gitypelibtest.c70
2 files changed, 77 insertions, 3 deletions
diff --git a/tests/repository/Makefile.am b/tests/repository/Makefile.am
index a4557a9c..268d9f9c 100644
--- a/tests/repository/Makefile.am
+++ b/tests/repository/Makefile.am
@@ -2,7 +2,7 @@ AM_CFLAGS = $(GOBJECT_CFLAGS)
AM_LDFLAGS = -module -avoid-version
LIBS = $(GOBJECT_LIBS)
-noinst_PROGRAMS = gitestrepo gitestthrows
+noinst_PROGRAMS = gitestrepo gitestthrows gitypelibtest
gitestrepo_SOURCES = $(srcdir)/gitestrepo.c
gitestrepo_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
@@ -12,6 +12,10 @@ gitestthrows_SOURCES = $(srcdir)/gitestthrows.c
gitestthrows_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
gitestthrows_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS)
-TESTS = gitestrepo gitestthrows
-TESTS_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir) \
+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_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir):$(top_builddir)/tests \
XDG_DATA_DIRS="$(top_srcdir)/gir:$(XDG_DATA_DIRS)" $(DEBUG)
diff --git a/tests/repository/gitypelibtest.c b/tests/repository/gitypelibtest.c
new file mode 100644
index 00000000..9e9b8d22
--- /dev/null
+++ b/tests/repository/gitypelibtest.c
@@ -0,0 +1,70 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ */
+
+#include "girepository.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void
+test_enum_and_flags_cidentifier(GIRepository *repo)
+{
+ GITypelib *ret;
+ GError *error = NULL;
+ gint n_infos, i;
+
+ ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
+ if (!ret)
+ g_error ("%s", error->message);
+
+ n_infos = g_irepository_get_n_infos (repo, "GIMarshallingTests");
+
+ for (i = 0; i < n_infos; i++) {
+ GIBaseInfo *info;
+ GIInfoType type;
+
+ info = g_irepository_get_info (repo, "GIMarshallingTests", i);
+ type = g_base_info_get_type (info);
+
+ /* both GI_INFO_TYPE_ENUM and GI_INFO_TYPE_FLAGS use GIEnumInfo */
+ if (GI_IS_ENUM_INFO (info)) {
+ gint n_values, j;
+
+ n_values = g_enum_info_get_n_values ((GIEnumInfo *) info);
+ for (j = 0; j < n_values; j++) {
+ GIValueInfo *value_info;
+ const gchar *c_identifier = NULL;
+
+ value_info = g_enum_info_get_value ((GIEnumInfo *) info, j);
+ c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info, "c:identifier");
+
+ if (c_identifier == NULL) {
+ g_error ("Error: no 'c:identifier' attribute on GIMarshallingTests.%s.%s\n",
+ g_base_info_get_name (info),
+ g_base_info_get_name ((GIBaseInfo *) value_info));
+ }
+
+ g_base_info_unref ((GIBaseInfo *) value_info);
+ }
+ }
+
+ g_base_info_unref (info);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ GIRepository *repo;
+
+ g_type_init ();
+
+ repo = g_irepository_get_default ();
+
+ /* do tests */
+ test_enum_and_flags_cidentifier (repo);
+
+ exit(0);
+}