diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2009-08-12 12:13:11 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2009-08-12 12:13:11 +0100 |
commit | d87b18675ac02f42be23bf4070134690b8b9934b (patch) | |
tree | 5697a9c79056a7af04fe3996c9dcd26e8ca5241f /json-glib/tests | |
parent | 7411cadc0fdd9ffc2bd7004c9980913ac857a495 (diff) | |
download | json-glib-d87b18675ac02f42be23bf4070134690b8b9934b.tar.gz |
Auto-promote integer types to G_TYPE_INT64
The JSON RFC does not specify the size of the integer type, thus
implicitly falling back to machine-size.
This would all be fine and dandy if some demented Web Developer (and
I use the term "developer" *very much* loosely) did not decide to
use integers to store unique identifiers for objects; obviously, you
can't have more than 2^32-1 status messages in a database with
millions of users who update their status multiple times per day.
Right, Twitter?
Anyway, some languages do a type auto-promotion from Integer to
Long, thus pushing the limit of allowed positive values -- until the
next integer overflow, that is. C, and GLib, do not do that
transparently for us so we need to:
- always use gint64 when parsing a JSON data stream using
JsonScanner
- move all the Node, Object and Array APIs to gint64
- auto-promote G_TYPE_INT to G_TYPE_INT64 when setting
a GValue manually
- auto-promote and auto-demote G_TYPE_INT properties when
(de)serializing GObjects.
The GLib types used internally by JSON-GLib are, thus:
integer -> G_TYPE_INT64
boolean -> G_TYPE_BOOLEAN
float -> G_TYPE_DOUBLE
string -> G_TYPE_STRING
Diffstat (limited to 'json-glib/tests')
-rw-r--r-- | json-glib/tests/array-test.c | 2 | ||||
-rw-r--r-- | json-glib/tests/node-test.c | 14 | ||||
-rw-r--r-- | json-glib/tests/object-test.c | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/json-glib/tests/array-test.c b/json-glib/tests/array-test.c index 3d3bf20..89f0175 100644 --- a/json-glib/tests/array-test.c +++ b/json-glib/tests/array-test.c @@ -56,7 +56,7 @@ static const struct { JsonNodeType element_type; GType element_gtype; } type_verify[] = { - { JSON_NODE_VALUE, G_TYPE_INT }, + { JSON_NODE_VALUE, G_TYPE_INT64 }, { JSON_NODE_VALUE, G_TYPE_BOOLEAN }, { JSON_NODE_VALUE, G_TYPE_STRING }, { JSON_NODE_NULL, G_TYPE_INVALID } diff --git a/json-glib/tests/node-test.c b/json-glib/tests/node-test.c index 8ccc402..3e3d0ff 100644 --- a/json-glib/tests/node-test.c +++ b/json-glib/tests/node-test.c @@ -76,19 +76,19 @@ test_value (void) g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_VALUE); - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, 42); + g_value_init (&value, G_TYPE_INT64); + g_value_set_int64 (&value, 42); - g_assert_cmpint (G_VALUE_TYPE (&value), ==, G_TYPE_INT); - g_assert_cmpint (g_value_get_int (&value), ==, 42); + g_assert_cmpint (G_VALUE_TYPE (&value), ==, G_TYPE_INT64); + g_assert_cmpint (g_value_get_int64 (&value), ==, 42); json_node_set_value (node, &value); json_node_get_value (node, &check); g_assert_cmpint (G_VALUE_TYPE (&value), ==, G_VALUE_TYPE (&check)); - g_assert_cmpint (g_value_get_int (&value), ==, g_value_get_int (&check)); - g_assert_cmpint (G_VALUE_TYPE (&check), ==, G_TYPE_INT); - g_assert_cmpint (g_value_get_int (&check), ==, 42); + g_assert_cmpint (g_value_get_int64 (&value), ==, g_value_get_int64 (&check)); + g_assert_cmpint (G_VALUE_TYPE (&check), ==, G_TYPE_INT64); + g_assert_cmpint (g_value_get_int64 (&check), ==, 42); g_value_unset (&value); g_value_unset (&check); diff --git a/json-glib/tests/object-test.c b/json-glib/tests/object-test.c index 5528342..d9b9edd 100644 --- a/json-glib/tests/object-test.c +++ b/json-glib/tests/object-test.c @@ -57,7 +57,7 @@ static const struct { JsonNodeType member_type; GType member_gtype; } type_verify[] = { - { "integer", JSON_NODE_VALUE, G_TYPE_INT }, + { "integer", JSON_NODE_VALUE, G_TYPE_INT64 }, { "boolean", JSON_NODE_VALUE, G_TYPE_BOOLEAN }, { "string", JSON_NODE_VALUE, G_TYPE_STRING }, { "null", JSON_NODE_NULL, G_TYPE_INVALID } |