3 /* dynar_int: A test case for the dynar using integers as content */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
16 int main(int argc,char *argv[]) {
21 // TRYFAIL(gras_log_control_set("root.thresh=debug dynar.thresh=info"));
22 TRYFAIL(gras_log_control_set("root.thresh=info"));
23 fprintf(stderr,"==== Push %d int, set them again 3 times, traverse them, shift them\n",NB_ELEM);
24 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
25 for (cpt=0; cpt< NB_ELEM; cpt++) {
26 TRYFAIL(gras_dynar_push(d,&cpt));
27 // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
29 for (cpt=0; cpt< NB_ELEM; cpt++) {
30 TRYFAIL(gras_dynar_set(d,cpt,&cpt));
32 for (cpt=0; cpt< NB_ELEM; cpt++) {
33 TRYFAIL(gras_dynar_set(d,cpt,&cpt));
35 for (cpt=0; cpt< NB_ELEM; cpt++) {
36 TRYFAIL(gras_dynar_set(d,cpt,&cpt));
39 gras_dynar_foreach(d,cursor,i){
42 "The retrieved value is not the same than the injected one (%d!=%d)\n",
50 "Cannot retrieve my %d values. Last got one is %d\n",NB_ELEM,
55 for (cpt=0; cpt< NB_ELEM; cpt++) {
56 gras_dynar_shift(d,&i);
59 "The retrieved value is not the same than the injected one (%d!=%d)\n",
63 // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
68 fprintf(stderr,"==== Unshift/pop %d int\n",NB_ELEM);
69 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
70 for (cpt=0; cpt< NB_ELEM; cpt++) {
71 TRYFAIL(gras_dynar_unshift(d,&cpt));
72 // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
74 for (cpt=0; cpt< NB_ELEM; cpt++) {
78 "The retrieved value is not the same than the injected one (%d!=%d)\n",
82 // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
88 fprintf(stderr,"==== Push %d int, insert 1000 int in the middle, shift everything\n",NB_ELEM);
89 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
90 for (cpt=0; cpt< NB_ELEM; cpt++) {
91 TRYFAIL(gras_dynar_push(d,&cpt));
92 // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
94 for (cpt=0; cpt< 1000; cpt++) {
95 TRYFAIL(gras_dynar_insert_at(d,2500,&cpt));
96 // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d));
99 for (cpt=0; cpt< 2500; cpt++) {
100 gras_dynar_shift(d,&i);
103 "The retrieved value is not the same than the injected one at the begining (%d!=%d)\n",
107 // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
109 for (cpt=999; cpt>=0; cpt--) {
110 gras_dynar_shift(d,&i);
113 "The retrieved value is not the same than the injected one in the middle (%d!=%d)\n",
118 for (cpt=2500; cpt< NB_ELEM; cpt++) {
119 gras_dynar_shift(d,&i);
122 "The retrieved value is not the same than the injected one at the end (%d!=%d)\n",
130 fprintf(stderr,"==== Push %d int, remove 2000-4000. free the rest\n",NB_ELEM);
131 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
132 for (cpt=0; cpt< NB_ELEM; cpt++) {
133 TRYFAIL(gras_dynar_push(d,&cpt));
135 for (cpt=2000; cpt< 4000; cpt++) {
136 gras_dynar_remove_at(d,2000,&i);
139 "Remove a bad value. Got %d, expected %d\n",
143 // fprintf (stderr,"remove %d, length=%d \n",cpt, gras_dynar_length(d));