示例#1
0
static void
sr_print_val_test(void **state)
{
    sr_val_t *value = NULL;

    /* empty tree */
    sr_test_all_printers(value, NULL);

    assert_int_equal(SR_ERR_OK, sr_new_val(XPATH1, &value));
    value->type = SR_UINT32_T;
    value->data.uint32_val = 123;
    sr_test_all_printers(value, XPATH1" = 123\n");
    sr_free_val(value);

    assert_int_equal(SR_ERR_OK, sr_new_val(XPATH1, &value));
    value->type = SR_BOOL_T;
    value->data.bool_val = true;
    sr_test_all_printers(value, XPATH1" = true\n");
    sr_free_val(value);

    assert_int_equal(SR_ERR_OK, sr_new_val(XPATH3, &value));
    value->type = SR_LIST_T;
    sr_test_all_printers(value, XPATH3" (list instance)\n");
    sr_free_val(value);

    assert_int_equal(SR_ERR_OK, sr_new_val(XPATH4, &value));
    value->type = SR_CONTAINER_T;
    sr_test_all_printers(value, XPATH4" (container)\n");
    sr_free_val(value);

    assert_int_equal(SR_ERR_OK, sr_new_val(XPATH2, &value));
    sr_val_set_str_data(value, SR_STRING_T, "192.168.1.1");
    sr_test_all_printers(value, XPATH2" = 192.168.1.1\n");
    sr_free_val(value);
}
示例#2
0
static void
sr_print_tree_test(void **state)
{
    sr_node_t *tree = NULL, *node = NULL;

    /* empty tree */
    sr_test_all_printers(tree, INT_MAX, NULL);

    /* one leaf tree */
    assert_int_equal(SR_ERR_OK, sr_new_tree("root", "test-module", &tree));
    tree->type = SR_UINT32_T;
    tree->data.uint32_val = 123;
    sr_test_all_printers(tree, INT_MAX, "test-module:root = 123\n");

    /* 2 levels */
    tree->type = SR_CONTAINER_T;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(tree, "root-child1", NULL, &node));
    node->type = SR_CONTAINER_T;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(tree, "root-child2", NULL, &node));
    node->type = SR_CONTAINER_T;
    node->dflt = true;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(tree, "root-child3", NULL, &node));
    node->type = SR_LIST_T;

#define TREE_WITH_TWO_LEVELS \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"

    sr_test_all_printers(tree, INT_MAX, TREE_WITH_TWO_LEVELS);

    /* 3 levels */
    node = tree->first_child;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "a", "another-module", &node));
    node->type = SR_CONTAINER_T;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "b", "another-module", &node));
    node->type = SR_UINT16_T;
    node->data.uint16_val = 1234;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "c", "another-module", &node));
    node->type = SR_CONTAINER_T;
    node = node->parent->next;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "leaf", NULL, &node));
    node->type = SR_LEAF_EMPTY_T;
    node->dflt = true;
    node = node->parent->next;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "list1", NULL, &node));
    node->type = SR_LIST_T;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "list2", NULL, &node));
    node->type = SR_LIST_T;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "list3", NULL, &node));
    node->type = SR_LIST_T;

#define TREE_WITH_THREE_LEVELS \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |   |\n"\
    " |   -- another-module:a (container)\n"\
    " |   |\n"\
    " |   -- another-module:b = 1234\n"\
    " |   |\n"\
    " |   -- another-module:c (container)\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |   |\n"\
    " |   -- leaf (empty leaf)\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"\
    "     |\n"\
    "     -- list1 (list instance)\n"\
    "     |\n"\
    "     -- list2 (list instance)\n"\
    "     |\n"\
    "     -- list3 (list instance)\n"

    sr_test_all_printers(tree, INT_MAX, TREE_WITH_THREE_LEVELS);

    /* 4 levels */
    node = tree->first_child->first_child;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "a1", NULL, &node));
    assert_int_equal(SR_ERR_OK, sr_node_set_str_data(node, SR_STRING_T, "abc"));
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "a2", NULL, &node));
    assert_int_equal(SR_ERR_OK, sr_node_set_str_data(node, SR_STRING_T, "def"));
    node->dflt = true;
    node = node->parent->next->next;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "c1", NULL, &node));
    node->type = SR_BOOL_T;
    node->data.bool_val = true;
    node->dflt = true;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "c2", NULL, &node));
    node->type = SR_BOOL_T;
    node->data.bool_val = true;
    node = node->parent;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "c3", NULL, &node));
    node->type = SR_BOOL_T;
    node->data.bool_val = false;
    node = tree->last_child->first_child;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "key", NULL, &node));
    node->type = SR_UINT16_T;
    node->data.uint16_val = 11;
    node = node->parent->next;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "key", NULL, &node));
    node->type = SR_UINT16_T;
    node->data.uint16_val = 12;
    node = node->parent->next;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "key", NULL, &node));
    node->type = SR_UINT16_T;
    node->data.uint16_val = 13;

#define TREE_WITH_FOUR_LEVELS \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |   |\n"\
    " |   -- another-module:a (container)\n"\
    " |   |   |\n"\
    " |   |   -- a1 = abc\n"\
    " |   |   |\n"\
    " |   |   -- a2 = def [default]\n"\
    " |   |\n"\
    " |   -- another-module:b = 1234\n"\
    " |   |\n"\
    " |   -- another-module:c (container)\n"\
    " |       |\n"\
    " |       -- c1 = true [default]\n"\
    " |       |\n"\
    " |       -- c2 = true\n"\
    " |       |\n"\
    " |       -- c3 = false\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |   |\n"\
    " |   -- leaf (empty leaf)\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"\
    "     |\n"\
    "     -- list1 (list instance)\n"\
    "     |   |\n"\
    "     |   -- key = 11\n"\
    "     |\n"\
    "     -- list2 (list instance)\n"\
    "     |   |\n"\
    "     |   -- key = 12\n"\
    "     |\n"\
    "     -- list3 (list instance)\n"\
    "         |\n"\
    "         -- key = 13\n"

    sr_test_all_printers(tree, INT_MAX, TREE_WITH_FOUR_LEVELS);

    /* depth limit = 0 */
    sr_test_all_printers(tree, 0, NULL);

    /* depth limit = 1 */
#define DEPTH_LIMIT_ONE \
    "test-module:root (container)\n"\
    " |\n"\
    " ...\n"

    sr_test_all_printers(tree, 1, DEPTH_LIMIT_ONE);

    /* depth limit = 2 */
#define DEPTH_LIMIT_TWO \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |   |\n"\
    " |   ...\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |   |\n"\
    " |   ...\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"\
    "     |\n"\
    "     ...\n"

    sr_test_all_printers(tree, 2, DEPTH_LIMIT_TWO);

    /* depth limit = 3 */
#define DEPTH_LIMIT_THREE \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |   |\n"\
    " |   -- another-module:a (container)\n"\
    " |   |   |\n"\
    " |   |   ...\n"\
    " |   |\n"\
    " |   -- another-module:b = 1234\n"\
    " |   |\n"\
    " |   -- another-module:c (container)\n"\
    " |       |\n"\
    " |       ...\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |   |\n"\
    " |   -- leaf (empty leaf)\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"\
    "     |\n"\
    "     -- list1 (list instance)\n"\
    "     |   |\n"\
    "     |   ...\n"\
    "     |\n"\
    "     -- list2 (list instance)\n"\
    "     |   |\n"\
    "     |   ...\n"\
    "     |\n"\
    "     -- list3 (list instance)\n"\
    "         |\n"\
    "         ...\n"

    sr_test_all_printers(tree, 3, DEPTH_LIMIT_THREE);

    /* subtree */
#define SUBTREE \
    "root-child1 (container)\n"\
    " |\n"\
    " -- another-module:a (container)\n"\
    " |   |\n"\
    " |   -- a1 = abc\n"\
    " |   |\n"\
    " |   -- a2 = def [default]\n"\
    " |\n"\
    " -- another-module:b = 1234\n"\
    " |\n"\
    " -- another-module:c (container)\n"\
    "     |\n"\
    "     -- c1 = true [default]\n"\
    "     |\n"\
    "     -- c2 = true\n"\
    "     |\n"\
    "     -- c3 = false\n"\

    sr_test_all_printers(tree->first_child, INT_MAX, SUBTREE);

    /* with tree iterator */
    node = tree->first_child->first_child;
    assert_int_equal(SR_ERR_OK, sr_node_add_child(node, "iter", NULL, &node));
    node->type = SR_TREE_ITERATOR_T;
    node->data.int32_val = 1;
    node->prev = node->next = node->parent = NULL;

#define TREE_WITH_ITERATOR \
    "test-module:root (container)\n"\
    " |\n"\
    " -- root-child1 (container)\n"\
    " |   |\n"\
    " |   -- another-module:a (container)\n"\
    " |   |   |\n"\
    " |   |   -- a1 = abc\n"\
    " |   |   |\n"\
    " |   |   -- a2 = def [default]\n"\
    " |   |   |\n"\
    " |   |   ...\n"\
    " |   |\n"\
    " |   -- another-module:b = 1234\n"\
    " |   |\n"\
    " |   -- another-module:c (container)\n"\
    " |       |\n"\
    " |       -- c1 = true [default]\n"\
    " |       |\n"\
    " |       -- c2 = true\n"\
    " |       |\n"\
    " |       -- c3 = false\n"\
    " |\n"\
    " -- root-child2 (container)\n"\
    " |   |\n"\
    " |   -- leaf (empty leaf)\n"\
    " |\n"\
    " -- root-child3 (list instance)\n"\
    "     |\n"\
    "     -- list1 (list instance)\n"\
    "     |   |\n"\
    "     |   -- key = 11\n"\
    "     |\n"\
    "     -- list2 (list instance)\n"\
    "     |   |\n"\
    "     |   -- key = 12\n"\
    "     |\n"\
    "     -- list3 (list instance)\n"\
    "         |\n"\
    "         -- key = 13\n"

    sr_test_all_printers(tree, INT_MAX, TREE_WITH_ITERATOR);

    sr_free_tree(tree);
}