bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
fcd3d6214ce1b8169b6481c78e02d9054901fed3Phil Carmody const struct json_tree_node *root, *node, *node1, *node2;
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen unsigned int i;
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen for (i = 0; i < N_ELEMENTS(test_input); i++) {
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert_idx(json_tree_append(tree, test_input[i].type,
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(root->value_type == JSON_TYPE_OBJECT);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen node = json_tree_find_key(root, test_input[i].value);
f946ee9814f653cd8baa8596277861b4582c7887Phil Carmody null_strcmp(json_tree_get_value_str(node), test_input[i+1].value) == 0);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen node = json_tree_find_key(root, "key-arr-empty");
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node != NULL && node->value_type == JSON_TYPE_ARRAY &&
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node != NULL && node->value_type == JSON_TYPE_ARRAY);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node != NULL && node->value_type == JSON_TYPE_STRING &&
f946ee9814f653cd8baa8596277861b4582c7887Phil Carmody strcmp(json_tree_get_value_str(node), "foo") == 0);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node != NULL && node->value_type == JSON_TYPE_ARRAY &&
f946ee9814f653cd8baa8596277861b4582c7887Phil Carmody json_tree_get_child(node)->value_type == JSON_TYPE_TRUE);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node != NULL && node->value_type == JSON_TYPE_OBJECT &&
f946ee9814f653cd8baa8596277861b4582c7887Phil Carmody json_tree_get_child(node)->value_type == JSON_TYPE_ARRAY &&
f946ee9814f653cd8baa8596277861b4582c7887Phil Carmody json_tree_get_child(json_tree_get_child(node)) == NULL);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen node1 = json_tree_find_child_with(node->parent, "aobj-key", "value1");
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen node2 = json_tree_find_child_with(node->parent, "aobj-key", "value2");
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(node1 != NULL && node2 != NULL && node1 != node2);
31e6dbee5fc7d6c33b44c75c7e18ea576f44184bTimo Sirainen test_assert(json_tree_find_child_with(node->parent, "aobj-key", "value3") == NULL);