summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2010-09-14 11:59:03 -0400
committerOwen W. Taylor <otaylor@fishsoup.net>2010-11-01 17:25:45 -0400
commit8916db0a3831cb5e6c3b714125f7596f43d6aa6a (patch)
treec4d523a925a666be85bfdaea804407ca782778f7 /tests
parent29ec4294d9232dcfd7cfec4e20c0e302a5ff3e80 (diff)
downloadgobject-introspection-8916db0a3831cb5e6c3b714125f7596f43d6aa6a.tar.gz
Handle enumerations with the full range of signed and unsigned values
The C compiler will pick an enumeration type that accomodates the specified values for the enumeration, so ignoring 64-bit enumerations, we can have enumeration values from MININT32 to MAXUINT32. To handle this properly: - Use gint64 for holding eumeration values when scanning - Add a 'unsigned_value' bit to ValueBlob so we can distinguish the int32 vs. uint32 cases in the typelib - Change the return value of g_value_info_get_value() to gint64. https://bugzilla.gnome.org/show_bug.cgi?id=629704
Diffstat (limited to 'tests')
-rw-r--r--tests/scanner/Regress-1.0-expected.gir26
-rw-r--r--tests/scanner/regress.c29
-rw-r--r--tests/scanner/regress.h11
3 files changed, 64 insertions, 2 deletions
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index ba3ce29b..36a7b0d9 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -168,10 +168,23 @@ use it should be.</doc>
c:identifier="REGRESS_TEST_VALUE2"
glib:nick="value2"/>
<member name="value3"
- value="42"
+ value="-1"
c:identifier="REGRESS_TEST_VALUE3"
glib:nick="value3"/>
</enumeration>
+ <enumeration name="TestEnumUnsigned"
+ glib:type-name="RegressTestEnumUnsigned"
+ glib:get-type="regress_test_enum_unsigned_get_type"
+ c:type="RegressTestEnumUnsigned">
+ <member name="value1"
+ value="1"
+ c:identifier="REGRESS_TEST_UNSIGNED_VALUE1"
+ glib:nick="value1"/>
+ <member name="value2"
+ value="2147483648"
+ c:identifier="REGRESS_TEST_UNSIGNED_VALUE2"
+ glib:nick="value2"/>
+ </enumeration>
<bitfield name="TestFlags"
glib:type-name="RegressTestFlags"
glib:get-type="regress_test_flags_get_type"
@@ -2250,6 +2263,17 @@ call and can be released on return.</doc>
</parameter>
</parameters>
</function>
+ <function name="test_unsigned_enum_param"
+ c:identifier="regress_test_unsigned_enum_param">
+ <return-value transfer-ownership="none">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ <parameters>
+ <parameter name="e" transfer-ownership="none">
+ <type name="TestEnumUnsigned" c:type="RegressTestEnumUnsigned"/>
+ </parameter>
+ </parameters>
+ </function>
<function name="test_ushort" c:identifier="regress_test_ushort">
<return-value transfer-ownership="none">
<type name="gushort" c:type="gushort"/>
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index b83ed981..40562f55 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1238,6 +1238,22 @@ regress_test_enum_get_type (void)
}
GType
+regress_test_enum_unsigned_get_type (void)
+{
+ static GType etype = 0;
+ if (G_UNLIKELY(etype == 0)) {
+ static const GEnumValue values[] = {
+ { REGRESS_TEST_UNSIGNED_VALUE1, "REGRESS_TEST_UNSIGNED_VALUE1", "value1" },
+ { REGRESS_TEST_UNSIGNED_VALUE2, "REGRESS_TEST_UNSIGNED_VALUE2", "value2" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static (g_intern_static_string ("RegressTestEnumUnsigned"), values);
+ }
+
+ return etype;
+}
+
+GType
regress_test_flags_get_type (void)
{
static GType etype = 0;
@@ -1267,6 +1283,19 @@ regress_test_enum_param(RegressTestEnum e)
return ev->value_nick;
}
+const gchar *
+regress_test_unsigned_enum_param(RegressTestEnumUnsigned e)
+{
+ GEnumValue *ev;
+ GEnumClass *ec;
+
+ ec = g_type_class_ref (regress_test_enum_unsigned_get_type ());
+ ev = g_enum_get_value (ec, e);
+ g_type_class_unref (ec);
+
+ return ev->value_nick;
+}
+
/* structures */
/**
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 8426a95e..6d729f1e 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -136,11 +136,17 @@ typedef enum
{
REGRESS_TEST_VALUE1,
REGRESS_TEST_VALUE2,
- REGRESS_TEST_VALUE3 = 42
+ REGRESS_TEST_VALUE3 = -1
} RegressTestEnum;
typedef enum
{
+ REGRESS_TEST_UNSIGNED_VALUE1 = 1,
+ REGRESS_TEST_UNSIGNED_VALUE2 = 0x80000000
+} RegressTestEnumUnsigned;
+
+typedef enum
+{
REGRESS_TEST_FLAG1 = 1 << 0,
REGRESS_TEST_FLAG2 = 1 << 1,
REGRESS_TEST_FLAG3 = 1 << 2,
@@ -148,10 +154,13 @@ typedef enum
GType regress_test_enum_get_type (void) G_GNUC_CONST;
#define REGRESS_TEST_TYPE_ENUM (regress_test_enum_get_type ())
+GType regress_test_enum_unsigned_get_type (void) G_GNUC_CONST;
+#define REGRESS_TEST_TYPE_ENUM_UNSIGNED (regress_test_enum_unsigned_get_type ())
GType regress_test_flags_get_type (void) G_GNUC_CONST;
#define REGRESS_TEST_TYPE_FLAGS (regress_test_flags_get_type ())
const gchar * regress_test_enum_param(RegressTestEnum e);
+const gchar * regress_test_unsigned_enum_param(RegressTestEnumUnsigned e);
/* constants */