Esempio n. 1
0
void check_back_api(struct sdeque *sdeque)
{
    long i;
    for (i = 0; i < 1024; ++i)
        sdeque_push_back(sdeque, (void *)i);
    assert(sdeque->head->value == (void *)0);
    assert(sdeque->tail->value == (void *)1023);
    assert(sdeque_size(sdeque) == 1024);

    void *value;
    while (sdeque_back(sdeque, &value) != -1) {
        printf("value=%ld\n", (long)value);
        assert(sdeque_pop_back(sdeque) == 0);
    }
    assert(sdeque_size(sdeque) == 0);
    assert(sdeque_pop_back(sdeque) == -1);
    assert(sdeque->head == sdeque->tail && sdeque->head == NULL);
}
Esempio n. 2
0
int main(void) {
	sdeque   lst;
	int	 i;

	sdeque_init(&lst, 5);
	testar;
	for (i=1; i<=10; i++)
		(void) sdeque_push_back(lst, i);
	while (!sdeque_empty(lst)) {
		printf("%d\n", sdeque_pop_front(lst));
		testar;
	}
	testar;
	for (i=1; i<=10; i++)
		(void) sdeque_push_front(lst, i);
	while (!sdeque_empty(lst)) {
		printf("%d\n", sdeque_pop_back(lst));
		testar;
	}
	sdeque_free(&lst);
	return (EXIT_SUCCESS);
}
Esempio n. 3
0
void check_mixed_api(struct sdeque *sdeque)
{
    sdeque_push_front(sdeque, (void *)1);
    assert(sdeque_size(sdeque) == 1);
    assert(sdeque->head == sdeque->tail && sdeque->head->value == (void *)1);
    void *value = NULL;
    assert(sdeque_front(sdeque, &value) == 0 && value == (void *)1);
    value = NULL;
    assert(sdeque_back(sdeque, &value) == 0 && value == (void *)1);
    assert(sdeque_pop_back(sdeque) == 0);
    assert(sdeque->head == sdeque->tail  && sdeque->head == NULL);
    assert(sdeque_size(sdeque) == 0);

    sdeque_push_back(sdeque, (void *)1);
    assert(sdeque_size(sdeque) == 1);
    assert(sdeque->head == sdeque->tail && sdeque->head->value == (void *)1);
    value = NULL;
    assert(sdeque_front(sdeque, &value) == 0 && value == (void *)1);
    value = NULL;
    assert(sdeque_back(sdeque, &value) == 0 && value == (void *)1);
    assert(sdeque_pop_front(sdeque) == 0);
    assert(sdeque->head == sdeque->tail  && sdeque->head == NULL);
    assert(sdeque_size(sdeque) == 0);
}