Exemplo n.º 1
0
void test__slist_iterator_next__invalid_iter(void** state)
{
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(int);

    slist_init_elem(pslist, 10, 100);
    it_iter = slist_begin(pslist);
    it_iter._t_pos._pby_corepos = (_byte_t*)0x83;
    expect_assert_failure(_slist_iterator_next(it_iter));

    slist_destroy(pslist);
}
Exemplo n.º 2
0
void test__slist_iterator_get_pointer__invalid_iter_container_type(void** state)
{
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(int);

    slist_init_elem(pslist, 10, 100);
    it_iter = slist_begin(pslist);
    it_iter._t_containertype = 224;
    expect_assert_failure(_slist_iterator_get_pointer(it_iter));

    slist_destroy(pslist);
}
Exemplo n.º 3
0
void test__slist_iterator_get_value__invalid_iterator_iterator_type(void** state)
{
    int n_value = 0;
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(int);

    slist_init_elem(pslist, 10, 100);
    it_iter = slist_begin(pslist);
    it_iter._t_iteratortype = 24455;
    expect_assert_failure(_slist_iterator_get_value(it_iter, &n_value));

    slist_destroy(pslist);
}
Exemplo n.º 4
0
void test__slist_iterator_get_value__invalid_iterator(void** state)
{
    int n_value = 0;
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(int);

    slist_init_elem(pslist, 10, 100);
    it_iter = slist_begin(pslist);
    it_iter._t_pos._pby_corepos = (_byte_t*)0x998;
    expect_assert_failure(_slist_iterator_get_value(it_iter, &n_value));

    slist_destroy(pslist);
}
Exemplo n.º 5
0
void test__slist_iterator_set_value__successfully_cstr(void** state)
{
    const char* s_str = "mmmmm";
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(char*);

    slist_init_elem(pslist, 10, "abcdefg");
    it_iter = slist_begin(pslist);
    _slist_iterator_set_value(it_iter, s_str);
    assert_true(strcmp((char*)slist_front(pslist), "mmmmm") == 0);

    slist_destroy(pslist);
}
Exemplo n.º 6
0
void test__slist_iterator_set_value__successfully(void** state)
{
    int n_value = 0;
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(int);

    slist_init_elem(pslist, 10, 100);
    it_iter = slist_begin(pslist);
    _slist_iterator_set_value(it_iter, &n_value);
    assert_true(*(int*)slist_front(pslist) == 0);

    slist_destroy(pslist);
}
Exemplo n.º 7
0
void test__slist_iterator_get_value__successfully_cstr(void** state)
{
    char* s_str = NULL;
    slist_iterator_t it_iter;
    slist_t* pslist = create_slist(char*);

    slist_init_elem(pslist, 10, "abcdefg");
    it_iter = slist_begin(pslist);
    _slist_iterator_get_value(it_iter, &s_str);
    assert_true(strcmp(s_str, "abcdefg") == 0);

    slist_destroy(pslist);
}
Exemplo n.º 8
0
/**
 * Reset the size of slist elements, and filled element is from variable argument slist.
 */
void _slist_resize_elem_varg(slist_t* pslist_slist, size_t t_resize, va_list val_elemlist)
{
    assert(pslist_slist != NULL);
    assert(_slist_is_inited(pslist_slist));

    if (t_resize <= slist_size(pslist_slist)) {
        slist_iterator_t it_pos = iterator_advance(slist_begin(pslist_slist), t_resize);
        slist_erase_range(pslist_slist, it_pos, slist_end(pslist_slist));
    } else {
        slist_iterator_t it_pos;
        _slistnode_t*    pt_node = NULL;
        _slistnode_t*    pt_varg = NULL;
        size_t           t_size = slist_size(pslist_slist);
        size_t           i = 0;
        bool_t           b_result = false;

        if (!slist_empty(pslist_slist)) {
            it_pos = slist_previous(pslist_slist, slist_end(pslist_slist));
        } else {
            _SLIST_ITERATOR_COREPOS(it_pos) = (_byte_t*)&pslist_slist->_t_head;
        }

        /* get varg value only once */
        pt_varg = _alloc_allocate(&pslist_slist->_t_allocator, _SLIST_NODE_SIZE(_GET_SLIST_TYPE_SIZE(pslist_slist)), 1);
        assert(pt_varg != NULL);
        _slist_get_varg_value_auxiliary(pslist_slist, val_elemlist, pt_varg);

        for (i = 0; i < t_resize - t_size; ++i) {
            pt_node = _alloc_allocate(&pslist_slist->_t_allocator, _SLIST_NODE_SIZE(_GET_SLIST_TYPE_SIZE(pslist_slist)), 1);
            assert(pt_node != NULL);
            _slist_init_node_auxiliary(pslist_slist, pt_node);

            /* copy value from varg */
            b_result = _GET_SLIST_TYPE_SIZE(pslist_slist);
            _GET_SLIST_TYPE_COPY_FUNCTION(pslist_slist)(pt_node->_pby_data, pt_varg->_pby_data, &b_result);
            assert(b_result);

            pt_node->_pt_next = ((_slistnode_t*)_SLIST_ITERATOR_COREPOS(it_pos))->_pt_next;
            ((_slistnode_t*)_SLIST_ITERATOR_COREPOS(it_pos))->_pt_next = pt_node;
            pt_node = NULL;
        }

        _slist_destroy_varg_value_auxiliary(pslist_slist, pt_varg);
        _alloc_deallocate(&pslist_slist->_t_allocator, pt_varg, _SLIST_NODE_SIZE(_GET_SLIST_TYPE_SIZE(pslist_slist)), 1);
    }
}
Exemplo n.º 9
0
/**
 * Insert one copy of element befor specificed position.
 */
slist_iterator_t _slist_insert(slist_t* pslist_slist, slist_iterator_t it_pos, ...)
{
    va_list val_elemlist;

    assert(pslist_slist != NULL);
    assert(_slist_is_inited(pslist_slist));
    assert(_slist_iterator_belong_to_slist(pslist_slist, it_pos));

    /* if the pos is slist begin iterator */
    va_start(val_elemlist, it_pos);
    if (iterator_equal(it_pos, slist_begin(pslist_slist))) {
        /* call push front */
        _slist_push_front_varg(pslist_slist, val_elemlist);
    } else {
        /* call insert_after */
        _slist_insert_after_n_varg(pslist_slist, slist_previous(pslist_slist, it_pos), 1, val_elemlist);
    }
    va_end(val_elemlist);

    /* return the new element iterator */
    return slist_previous(pslist_slist, it_pos);
}
Exemplo n.º 10
0
/*
 * test _slist_iterator_equal
 */
UT_CASE_DEFINATION(_slist_iterator_equal)
void test__slist_iterator_equal__first_invalid_container_type(void** state)
{
    slist_t* pslist_first = create_slist(int);
    slist_t* pslist_second = create_slist(double);
    slist_iterator_t it_first;
    slist_iterator_t it_second;

    slist_init(pslist_first);
    slist_init(pslist_second);

    it_first = slist_begin(pslist_first);
    it_second = slist_begin(pslist_second);
    it_first._t_containertype = 284923;

    expect_assert_failure(_slist_iterator_equal(it_first, it_second));

    slist_destroy(pslist_first);
    slist_destroy(pslist_second);
}

void test__slist_iterator_equal__first_invalid_iterator_type(void** state)
{
    slist_t* pslist_first = create_slist(int);
    slist_t* pslist_second = create_slist(double);
    slist_iterator_t it_first;
    slist_iterator_t it_second;