Ejemplo n.º 1
0
TEST_C(DequeTests, DequeCapacity)
{
    DequeConf conf;
    deque_conf_init(&conf);

    conf.capacity = 2;

    Deque *deque;
    deque_new_conf(&conf, &deque);

    CHECK_EQUAL_C_INT(2, deque_capacity(deque));

    int a = 1;
    int b = 2;
    int c = 3;

    deque_add(deque, &a);
    deque_add(deque, &b);
    deque_add(deque, &c);

    CHECK_EQUAL_C_INT(4, deque_capacity(deque));
}
Ejemplo n.º 2
0
/**
 * Creates a new empty Queue based on the specified QueueConf object and
 * returns a status code.
 *
 * The Queue is allocated using the allocators specified in the QueueConf struct.
 * The allocation may fail if the underlying allocator fails.
 *
 * @param[in] conf Queue configuration structure. All fields must be initialized
 *                 with appropriate values.
 * @param[out] out Pointer to where the newly created Queue is to be stored
 *
 * @return CC_OK if the creation was successful, CC_ERR_INVALID_CAPACITY if
 * the above mentioned condition is not met, or CC_ERR_ALLOC if the memory
 * allocation for the new Queue structure failed.
 */
enum cc_stat queue_new_conf(QueueConf const * const conf, Queue **q)
{
    Queue *queue = conf->mem_calloc(1, sizeof(Queue));

    if (!queue)
        return CC_ERR_ALLOC;

    Deque *deque;
    deque_new_conf(conf, &deque);

    if (!deque) {
        conf->mem_free(queue);
        return CC_ERR_ALLOC;
    }

    queue->d          = deque;
    queue->mem_alloc  = conf->mem_alloc;
    queue->mem_calloc = conf->mem_calloc;
    queue->mem_free   = conf->mem_free;

    *q = queue;

    return CC_OK;
}
Ejemplo n.º 3
0
/**
 * Creates a new empty deque and returns a status code.
 *
 * @param[out] out Pointer to where the newly created Deque is to be stored
 *
 * @return CC_OK if the creation was successful, or CC_ERR_ALLOC if the
 * memory allocation for the new Deque structure failed.
 */
enum cc_stat deque_new(Deque **deque)
{
    DequeConf conf;
    deque_conf_init(&conf);
    return deque_new_conf(&conf, deque);
}
Ejemplo n.º 4
0
/**
 * Returns a new empty deque, or NULL if the allocation fails.
 *
 * @return a new deque if the allocation was successful, or NULL if it was not.
 */
Deque *deque_new()
{
    DequeConf conf;
    deque_conf_init(&conf);
    return deque_new_conf(&conf);
}