3 /* dynar_string: A test case for the dynar using strings 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. */
14 void free_string(void *d);
16 void free_string(void *d){
20 int main(int argc,char *argv[]) {
27 fprintf(stderr,"==== Push 5000 strings, set them again 3 times, shift them\n");
28 TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
29 for (cpt=0; cpt< 5000; cpt++) {
30 sprintf(buf,"%d",cpt);
32 TRYFAIL(gras_dynar_push(d,&s1));
34 for (cpt=0; cpt< 5000; cpt++) {
35 sprintf(buf,"%d",cpt);
37 TRYFAIL(gras_dynar_remplace(d,cpt,&s1));
39 for (cpt=0; cpt< 5000; cpt++) {
40 sprintf(buf,"%d",cpt);
42 TRYFAIL(gras_dynar_remplace(d,cpt,&s1));
44 for (cpt=0; cpt< 5000; cpt++) {
45 sprintf(buf,"%d",cpt);
47 TRYFAIL(gras_dynar_remplace(d,cpt,&s1));
49 for (cpt=0; cpt< 5000; cpt++) {
50 sprintf(buf,"%d",cpt);
51 gras_dynar_shift(d,&s2);
54 "The retrieved value is not the same than the injected one (%s!=%s)\n",
63 fprintf(stderr,"==== Unshift/pop 5000 strings\n");
64 TRYFAIL(gras_dynar_new(&d,sizeof(char**),&free_string));
65 for (cpt=0; cpt< 5000; cpt++) {
66 sprintf(buf,"%d",cpt);
68 TRYFAIL(gras_dynar_unshift(d,&s1));
70 for (cpt=0; cpt< 5000; cpt++) {
71 sprintf(buf,"%d",cpt);
72 gras_dynar_pop(d,&s2);
75 "The retrieved value is not the same than the injected one (%s!=%s)\n",
85 fprintf(stderr,"==== Push 5000 strings, insert 1000 strings in the middle, shift everything\n");
86 TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
87 for (cpt=0; cpt< 5000; cpt++) {
88 sprintf(buf,"%d",cpt);
90 TRYFAIL(gras_dynar_push(d,&s1));
92 for (cpt=0; cpt< 1000; cpt++) {
93 sprintf(buf,"%d",cpt);
95 TRYFAIL(gras_dynar_insert_at(d,2500,&s1));
98 for (cpt=0; cpt< 2500; cpt++) {
99 sprintf(buf,"%d",cpt);
100 gras_dynar_shift(d,&s2);
101 if (strcmp(buf,s2)) {
103 "The retrieved value is not the same than the injected one at the begining (%s!=%s)\n",
109 for (cpt=999; cpt>=0; cpt--) {
110 sprintf(buf,"%d",cpt);
111 gras_dynar_shift(d,&s2);
112 if (strcmp(buf,s2)) {
114 "The retrieved value is not the same than the injected one in the middle (%s!=%s)\n",
120 for (cpt=2500; cpt< 5000; cpt++) {
121 sprintf(buf,"%d",cpt);
122 gras_dynar_shift(d,&s2);
123 if (strcmp(buf,s2)) {
125 "The retrieved value is not the same than the injected one at the end (%s!=%s)\n",
134 fprintf(stderr,"==== Push 5000 strings, remove 2000-4000. free the rest\n");
135 TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string));
136 for (cpt=0; cpt< 5000; cpt++) {
137 sprintf(buf,"%d",cpt);
139 TRYFAIL(gras_dynar_push(d,&s1));
141 for (cpt=2000; cpt< 4000; cpt++) {
142 sprintf(buf,"%d",cpt);
143 gras_dynar_remove_at(d,2000,&s2);
144 if (strcmp(buf,s2)) {
146 "Remove a bad value. Got %s, expected %s\n",