1
#include <glib/gtestutils.h>
2
#include <json-glib/json-glib.h>
8
JsonNode *node = json_node_new (JSON_NODE_NULL);
9
JsonNode *copy = json_node_copy (node);
11
g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
12
g_assert_cmpint (json_node_get_value_type (node), ==, json_node_get_value_type (copy));
13
g_assert_cmpstr (json_node_type_name (node), ==, json_node_type_name (copy));
15
json_node_free (copy);
16
json_node_free (node);
20
test_copy_value (void)
22
JsonNode *node = json_node_new (JSON_NODE_VALUE);
25
json_node_set_string (node, "hello");
27
copy = json_node_copy (node);
28
g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
29
g_assert_cmpstr (json_node_type_name (node), ==, json_node_type_name (copy));
30
g_assert_cmpstr (json_node_get_string (node), ==, json_node_get_string (copy));
32
json_node_free (copy);
33
json_node_free (node);
37
test_copy_object (void)
39
JsonObject *obj = json_object_new ();
40
JsonNode *node = json_node_new (JSON_NODE_OBJECT);
41
JsonNode *value = json_node_new (JSON_NODE_VALUE);
44
json_node_set_int (value, 42);
45
json_object_set_member (obj, "answer", value);
47
json_node_take_object (node, obj);
49
copy = json_node_copy (node);
51
g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
52
g_assert (json_node_get_object (node) == json_node_get_object (copy));
54
json_node_free (copy);
55
json_node_free (node);
61
JsonNode *node = json_node_new (JSON_NODE_NULL);
63
g_assert (JSON_NODE_HOLDS_NULL (node));
64
g_assert_cmpint (json_node_get_value_type (node), ==, G_TYPE_INVALID);
65
g_assert_cmpstr (json_node_type_name (node), ==, "NULL");
67
json_node_free (node);
73
JsonNode *node = json_node_new (JSON_NODE_VALUE);
74
GValue value = { 0, };
75
GValue check = { 0, };
77
g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_VALUE);
79
g_value_init (&value, G_TYPE_INT64);
80
g_value_set_int64 (&value, 42);
82
g_assert_cmpint (G_VALUE_TYPE (&value), ==, G_TYPE_INT64);
83
g_assert_cmpint (g_value_get_int64 (&value), ==, 42);
85
json_node_set_value (node, &value);
86
json_node_get_value (node, &check);
88
g_assert_cmpint (G_VALUE_TYPE (&value), ==, G_VALUE_TYPE (&check));
89
g_assert_cmpint (g_value_get_int64 (&value), ==, g_value_get_int64 (&check));
90
g_assert_cmpint (G_VALUE_TYPE (&check), ==, G_TYPE_INT64);
91
g_assert_cmpint (g_value_get_int64 (&check), ==, 42);
93
g_value_unset (&value);
94
g_value_unset (&check);
95
json_node_free (node);
103
g_test_init (&argc, &argv, NULL);
105
g_test_add_func ("/nodes/null-node", test_null);
106
g_test_add_func ("/nodes/copy-null", test_copy_null);
107
g_test_add_func ("/nodes/copy-value", test_copy_value);
108
g_test_add_func ("/nodes/copy-object", test_copy_object);
109
g_test_add_func ("/nodes/value", test_value);
111
return g_test_run ();