summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/repository/gitypelibtest.c57
-rw-r--r--tests/scanner/Foo-1.0-expected.gir37
-rw-r--r--tests/scanner/Regress-1.0-expected.gir14
3 files changed, 102 insertions, 6 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);
}
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index f18ed56d..ffcf2167 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -186,6 +186,26 @@ and/or use gtk-doc annotations. -->
value="2"
c:identifier="FOO_ENUM_DELTA"
glib:nick="delta"/>
+ <function name="method" c:identifier="foo_enum_type_method">
+ <return-value transfer-ownership="none">
+ <type name="gint" c:type="int"/>
+ </return-value>
+ <parameters>
+ <parameter name="foo_enum" transfer-ownership="none">
+ <type name="EnumType" c:type="FooEnumType"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="returnv" c:identifier="foo_enum_type_returnv">
+ <return-value transfer-ownership="none">
+ <type name="EnumType" c:type="FooEnumType"/>
+ </return-value>
+ <parameters>
+ <parameter name="x" transfer-ownership="none">
+ <type name="gint" c:type="int"/>
+ </parameter>
+ </parameters>
+ </function>
</enumeration>
<enumeration name="Error"
glib:type-name="FooError"
@@ -204,6 +224,11 @@ and/or use gtk-doc annotations. -->
value="2"
c:identifier="FOO_ERROR_UGLY"
glib:nick="ugly"/>
+ <function name="quark" c:identifier="foo_error_quark">
+ <return-value transfer-ownership="none">
+ <type name="GLib.Quark" c:type="GQuark"/>
+ </return-value>
+ </function>
</enumeration>
<union name="Event" c:type="FooEvent">
<field name="type" writable="1">
@@ -954,7 +979,9 @@ exposed to language bindings.</doc>
</parameter>
</parameters>
</function>
- <function name="enum_type_method" c:identifier="foo_enum_type_method">
+ <function name="enum_type_method"
+ c:identifier="foo_enum_type_method"
+ moved-to="EnumType.method">
<return-value transfer-ownership="none">
<type name="gint" c:type="int"/>
</return-value>
@@ -964,7 +991,9 @@ exposed to language bindings.</doc>
</parameter>
</parameters>
</function>
- <function name="enum_type_returnv" c:identifier="foo_enum_type_returnv">
+ <function name="enum_type_returnv"
+ c:identifier="foo_enum_type_returnv"
+ moved-to="EnumType.returnv">
<return-value transfer-ownership="none">
<type name="EnumType" c:type="FooEnumType"/>
</return-value>
@@ -974,7 +1003,9 @@ exposed to language bindings.</doc>
</parameter>
</parameters>
</function>
- <function name="error_quark" c:identifier="foo_error_quark">
+ <function name="error_quark"
+ c:identifier="foo_error_quark"
+ moved-to="Error.quark">
<return-value transfer-ownership="none">
<type name="GLib.Quark" c:type="GQuark"/>
</return-value>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 80b0c68e..ce5af5c0 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -188,6 +188,16 @@ use it should be.</doc>
value="48"
c:identifier="REGRESS_TEST_VALUE4"
glib:nick="value4"/>
+ <function name="param" c:identifier="regress_test_enum_param">
+ <return-value transfer-ownership="none">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ <parameters>
+ <parameter name="e" transfer-ownership="none">
+ <type name="TestEnum" c:type="RegressTestEnum"/>
+ </parameter>
+ </parameters>
+ </function>
</enumeration>
<enumeration name="TestEnumNoGEnum" c:type="RegressTestEnumNoGEnum">
<member name="evalue1" value="0" c:identifier="REGRESS_TEST_EVALUE1"/>
@@ -1887,7 +1897,9 @@ call and can be released on return.</doc>
</parameter>
</parameters>
</function>
- <function name="test_enum_param" c:identifier="regress_test_enum_param">
+ <function name="test_enum_param"
+ c:identifier="regress_test_enum_param"
+ moved-to="TestEnum.param">
<return-value transfer-ownership="none">
<type name="utf8" c:type="gchar*"/>
</return-value>