m2.alobe/src/testfifo.c
glenux 5ca782e8b1 alobe: inital import (test).
git-svn-id: https://websvn.glenux.net/svn/Upoc/alobe/trunk@1348 eaee96b3-f302-0410-b096-c6cfd47f7835
2009-05-02 07:36:25 +00:00

72 lines
2.1 KiB
C

/* vim: set sw=4 ts=4 si et: */
#include "fifo.h"
int main(){
Fifo_t * fifo = fifo_create(20);
Fifo_t * fifo2;
nodeindex_t i;
nodeindex_t before, after;
printf("\n************************************************************************\n");
printf(" PHASE 1 (fill with 0..19)\n");
printf("************************************************************************\n");
for (i=0; i<20; i++){
before = fifo_get_size(fifo);
fifo_push (fifo, i);
after = fifo_get_size(fifo);
printf("Pushed %ld\n", i);
printf("Fifo size %ld -> %ld\n", before, after);
}
fifo_display (fifo);
printf("\n************************************************************************\n");
printf(" PHASE 2 (move 5 to back)\n");
printf("************************************************************************\n");
for (i=0; i<5; i++){
nodeindex_t tmp;
tmp = fifo_pop(fifo);
fifo_push(fifo, tmp);
}
fifo_display (fifo);
printf("\n************************************************************************\n");
printf(" PHASE 3 (reverse)\n");
printf("************************************************************************\n");
fifo_reverse (fifo);
fifo_display (fifo);
printf("\n************************************************************************\n");
printf(" PHASE 4 (copy)\n");
printf("************************************************************************\n");
fifo2 = fifo_copy (fifo);
fifo_destroy (fifo);
fifo = fifo2;
fifo2 = NULL;
fifo_display (fifo);
printf("\n************************************************************************\n");
printf(" PHASE 5 (pop everything)\n");
printf("************************************************************************\n");
while (!fifo_is_empty(fifo)){
before = fifo_get_size(fifo);
nodeindex_t val = fifo_pop (fifo);
after = fifo_get_size(fifo);
printf("Popped %ld\n", val);
printf("Fifo size %ld -> %ld\n", before, after);
}
fifo_display (fifo);
fifo_destroy (fifo);
return EXIT_SUCCESS;
}