/* vector_t */
void _type_init_vector(const void* cpv_input, void* pv_output)
{
    bool_t b_result = false;

    assert(cpv_input != NULL && pv_output != NULL);

    b_result = _create_vector_auxiliary((vector_t*)cpv_input, (char*)pv_output);
    assert(b_result);
    /* initialize vector_t */
    vector_init((vector_t*)cpv_input);
}
Exemple #2
0
/**
 * Create stack container auxiliary function.
 */
bool_t _create_stack_auxiliary(stack_t* psk_stack, const char* s_typename)
{
    assert(psk_stack != NULL);
    assert(s_typename != NULL);

#if defined (CSTL_STACK_VECTOR_SEQUENCE)
    return _create_vector_auxiliary(&psk_stack->_t_sequence, s_typename);
#elif defined (CSTL_STACK_LIST_SEQUENCE)
    return _create_list_auxiliary(&psk_stack->_t_sequence, s_typename);
#else
    return _create_deque_auxiliary(&psk_stack->_t_sequence, s_typename);
#endif
}
void test__create_vector_auxiliary__libcstl_builtin_type(void** state)
{
    vector_t* pvec = (vector_t*)malloc(sizeof(vector_t));
    assert_true(pvec != NULL);
    assert_true(_create_vector_auxiliary(pvec, "list_t< int>    "));
    assert_true(pvec->_pby_endofstorage == NULL);
    assert_true(pvec->_pby_finish == NULL);
    assert_true(pvec->_pby_start == NULL);
    assert_true(pvec->_t_typeinfo._pt_type != NULL);
    assert_true(pvec->_t_typeinfo._t_style == _TYPE_CSTL_BUILTIN);
    assert_true(strcmp(pvec->_t_typeinfo._s_typename, "list_t<int>") == 0);

    vector_destroy(pvec);
}
/**
 * Create vector container.
 */
vector_t* _create_vector(const char* s_typename)
{
    vector_t*   pvec_vector = NULL;

    /* allocate for vector_t and initialize it */
    if ((pvec_vector = (vector_t*)malloc(sizeof(vector_t))) == NULL) {
        return NULL;
    }

    if (!_create_vector_auxiliary(pvec_vector, s_typename)) {
        free(pvec_vector);
        return NULL;
    }

    return pvec_vector;
}
void test__create_vector_auxiliary__registed_type(void** state)
{
    typedef struct _tag_create_vector_auxiliary__registed_type{int n_elem;}_create_vector_auxiliary__registed_type_t;
    vector_t* pvec = (vector_t*)malloc(sizeof(vector_t));
    assert_true(pvec != NULL);
    type_register(_create_vector_auxiliary__registed_type_t, NULL, NULL, NULL, NULL);
    assert_true(_create_vector_auxiliary(pvec, "_create_vector_auxiliary__registed_type_t"));
    assert_true(pvec->_pby_endofstorage == NULL);
    assert_true(pvec->_pby_finish == NULL);
    assert_true(pvec->_pby_start == NULL);
    assert_true(pvec->_t_typeinfo._pt_type != NULL);
    assert_true(pvec->_t_typeinfo._t_style == _TYPE_USER_DEFINE);
    assert_true(strcmp(pvec->_t_typeinfo._s_typename, "_create_vector_auxiliary__registed_type_t") == 0);

    vector_destroy(pvec);
}
void test__create_vector_auxiliary__unregisted_type(void** state)
{
    vector_t vec;
    assert_false(_create_vector_auxiliary(&vec, "unregisted_type_t"));
}
void test__create_vector_auxiliary__null_typename(void** state)
{
    vector_t vec;
    expect_assert_failure(_create_vector_auxiliary(&vec, NULL));
}
void test__create_vector_auxiliary__null_vector_container(void** state)
{
    expect_assert_failure(_create_vector_auxiliary(NULL, "int"));
}