diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2012-07-15 13:24:03 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2012-07-15 13:40:24 +0100 |
commit | 7819e630b8fd88d269dd75a2e0fb1aeb294aed96 (patch) | |
tree | 47c1241d6d2aa33002f49d5befcf4ed16864c458 /json-glib/tests/node.c | |
parent | b1b50ec3ad76955651abe92696c4f4717e353840 (diff) | |
download | json-glib-7819e630b8fd88d269dd75a2e0fb1aeb294aed96.tar.gz |
node: Implicitly convert numeric types
When retrieving an int, a double, or a boolean, we can use the C rules
of implicit conversion to move from the actual stored type inside the
JsonValue to the requested C type.
https://bugzilla.gnome.org/show_bug.cgi?id=660795
Diffstat (limited to 'json-glib/tests/node.c')
-rw-r--r-- | json-glib/tests/node.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/json-glib/tests/node.c b/json-glib/tests/node.c index a50d980..51dc3ff 100644 --- a/json-glib/tests/node.c +++ b/json-glib/tests/node.c @@ -113,6 +113,39 @@ test_null (void) } static void +test_get_int (void) +{ + JsonNode *node = json_node_new (JSON_NODE_VALUE); + + json_node_set_int (node, 0); + g_assert_cmpint (json_node_get_int (node), ==, 0); + g_assert_cmpfloat (json_node_get_double (node), ==, 0.0); + g_assert (!json_node_get_boolean (node)); + g_assert (!json_node_is_null (node)); + + json_node_set_int (node, 42); + g_assert_cmpint (json_node_get_int (node), ==, 42); + g_assert_cmpfloat (json_node_get_double (node), ==, 42.0); + g_assert (json_node_get_boolean (node)); + g_assert (!json_node_is_null (node)); + + json_node_free (node); +} + +static void +test_get_double (void) +{ + JsonNode *node = json_node_new (JSON_NODE_VALUE); + + json_node_set_double (node, 3.14); + g_assert_cmpfloat (json_node_get_double (node), ==, 3.14); + g_assert_cmpint (json_node_get_int (node), ==, 3); + g_assert (json_node_get_boolean (node)); + + json_node_free (node); +} + +static void test_gvalue (void) { JsonNode *node = json_node_new (JSON_NODE_VALUE); @@ -224,6 +257,8 @@ main (int argc, g_test_add_func ("/nodes/copy/null", test_copy_null); g_test_add_func ("/nodes/copy/value", test_copy_value); g_test_add_func ("/nodes/copy/object", test_copy_object); + g_test_add_func ("/nodes/get/int", test_get_int); + g_test_add_func ("/nodes/get/double", test_get_double); g_test_add_func ("/nodes/gvalue", test_gvalue); g_test_add_func ("/nodes/gvalue/autopromotion", test_gvalue_autopromotion); |