summaryrefslogtreecommitdiff
path: root/tests/repository
diff options
context:
space:
mode:
authorTorsten Schönfeld <kaffeetisch@gmx.de>2011-08-13 17:28:30 +0200
committerTorsten Schönfeld <kaffeetisch@gmx.de>2011-08-16 18:43:23 +0200
commit169b206cbb4b347e4b17854e8f0c62a40404f803 (patch)
tree929ddaefcedf7c9d4778ea355e58f0b1cc2f2f96 /tests/repository
parent64848acb817369436d629d153c5750789c0addc3 (diff)
downloadgobject-introspection-169b206cbb4b347e4b17854e8f0c62a40404f803.tar.gz
Allow enums and bitfields to have static methods
This uses the same backcompat machinery that was introduced for static methods for non-class types, so this change does not break users of the existing presentations. New libgirepository API: g_enum_info_get_n_methods g_enum_info_get_method https://bugzilla.gnome.org/show_bug.cgi?id=656499
Diffstat (limited to 'tests/repository')
-rw-r--r--tests/repository/gitypelibtest.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/tests/repository/gitypelibtest.c b/tests/repository/gitypelibtest.c
index 9e9b8d22..2896846a 100644
--- a/tests/repository/gitypelibtest.c
+++ b/tests/repository/gitypelibtest.c
@@ -23,10 +23,8 @@ test_enum_and_flags_cidentifier(GIRepository *repo)
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)) {
@@ -54,6 +52,60 @@ test_enum_and_flags_cidentifier(GIRepository *repo)
}
}
+static void
+_check_enum_methods (GIBaseInfo *info, const gchar *name, const gchar *prefix)
+{
+ gint n_methods, i;
+
+ n_methods = g_enum_info_get_n_methods ((GIEnumInfo *) info);
+ if (n_methods <= 0)
+ g_error ("%s should have methods", name);
+
+ for (i = 0; i < n_methods; i += n_methods-1) {
+ GIBaseInfo *function_info;
+ GIFunctionInfoFlags flags;
+ const gchar *symbol;
+ function_info = g_enum_info_get_method ((GIEnumInfo *) info, i);
+ if (!function_info)
+ g_error ("Could not find %s method nr. %d", name, i+1);
+ flags = g_function_info_get_flags ((GIFunctionInfo *) function_info);
+ if (flags != 0)
+ g_error ("%s methods should be static", name);
+ symbol = g_function_info_get_symbol ((GIFunctionInfo *) function_info);
+ if (!symbol || !g_str_has_prefix (symbol, prefix))
+ g_error ("Could not find valid function symbol");
+ g_base_info_unref (function_info);
+ }
+}
+
+static void
+test_enum_and_flags_static_methods(GIRepository *repo)
+{
+ GITypelib *ret;
+ GError *error = NULL;
+ GIBaseInfo *enum_info;
+
+ ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
+ if (!ret)
+ g_error ("%s", error->message);
+
+ enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "GEnum");
+ if (!enum_info)
+ g_error ("Could not find GIMarshallingTests.GEnum");
+ _check_enum_methods (enum_info,
+ "GIMarshallingTests.GEnum",
+ "gi_marshalling_tests_genum_");
+ g_base_info_unref (enum_info);
+
+ enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "Flags");
+ if (!enum_info)
+ g_error ("Could not find GIMarshallingTests.Flags");
+ _check_enum_methods (enum_info,
+ "GIMarshallingTests.Flags",
+ "gi_marshalling_tests_flags_");
+ g_base_info_unref (enum_info);
+}
+
int
main(int argc, char **argv)
{
@@ -65,6 +117,7 @@ main(int argc, char **argv)
/* do tests */
test_enum_and_flags_cidentifier (repo);
+ test_enum_and_flags_static_methods (repo);
exit(0);
}