2 This file is part of GNUnet
3 (C) 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * This is a testcase for the vector, waiting to be extended.
26 #include "gnunet_container_lib.h"
28 #define DUMP(v) fprintf(stderr, "At %d: \n", __LINE__); GNUNET_CONTAINER_vector_dump(v);
30 static int test(int size) {
31 struct GNUNET_CONTAINER_Vector * v;
33 v = GNUNET_CONTAINER_vector_create(size);
34 if (0 != GNUNET_CONTAINER_vector_size(v))
35 { DUMP(v); return 1; }
36 if (GNUNET_OK != GNUNET_CONTAINER_vector_insert_at(v, "first", 0))
37 { DUMP(v); return 1; }
38 if (GNUNET_OK == GNUNET_CONTAINER_vector_insert_at(v, "not", 2))
39 { DUMP(v); return 1; }
40 if (GNUNET_OK != GNUNET_CONTAINER_vector_insert_at(v, "zero", 0))
41 { DUMP(v); return 1; }
42 if (GNUNET_OK != GNUNET_CONTAINER_vector_insert_at(v, "second", 2))
43 { DUMP(v); return 1; }
44 GNUNET_CONTAINER_vector_insert_last(v, "third");
45 if (4 != GNUNET_CONTAINER_vector_size(v))
46 { DUMP(v); return 1; }
47 if (0 != strcmp(GNUNET_CONTAINER_vector_get_at(v, 1), "first"))
48 { DUMP(v); return 1; }
49 if (0 != strcmp(GNUNET_CONTAINER_vector_get_at(v, 3), "third"))
50 { DUMP(v); return 1; }
51 if (0 != strcmp(GNUNET_CONTAINER_vector_get_at(v, 0), "zero"))
52 { DUMP(v); return 1; }
53 if (0 != strcmp(GNUNET_CONTAINER_vector_get_first(v), "zero"))
54 { DUMP(v); return 1; }
55 if (0 != strcmp(GNUNET_CONTAINER_vector_get_last(v), "third"))
56 { DUMP(v); return 1; }
57 if (0 != strcmp(GNUNET_CONTAINER_vector_remove_at(v, 1), "first"))
58 { DUMP(v); return 1; }
59 if (0 != strcmp(GNUNET_CONTAINER_vector_get_at(v, 1), "second"))
60 { DUMP(v); return 1; }
61 if (NULL != GNUNET_CONTAINER_vector_remove_at(v, 3))
62 { DUMP(v); return 1; }
63 if (3 != GNUNET_CONTAINER_vector_size(v))
64 { DUMP(v); return 1; }
65 if (0 != strcmp(GNUNET_CONTAINER_vector_remove_at(v, 1), "second"))
66 { DUMP(v); return 1; }
67 if (0 != strcmp(GNUNET_CONTAINER_vector_remove_object(v, "third"), "third"))
68 { DUMP(v); return 1; }
69 if (NULL != GNUNET_CONTAINER_vector_remove_object(v, "third"))
70 { DUMP(v); return 1; }
71 if (0 != strcmp(GNUNET_CONTAINER_vector_remove_last(v), "zero"))
72 { DUMP(v); return 1; }
73 if (0 != GNUNET_CONTAINER_vector_size(v))
74 { DUMP(v); return 1; }
75 if (NULL != GNUNET_CONTAINER_vector_remove_last(v))
76 { DUMP(v); return 1; }
77 if (0 != GNUNET_CONTAINER_vector_size(v))
78 { DUMP(v); return 1; }
79 GNUNET_CONTAINER_vector_destroy(v);
83 static int test2(int size) {
85 struct GNUNET_CONTAINER_Vector * v;
87 v = GNUNET_CONTAINER_vector_create(size);
90 if (GNUNET_OK != GNUNET_CONTAINER_vector_insert_at(v, (void*)i, 0))
91 { DUMP(v); return 1; }
92 if (500 != GNUNET_CONTAINER_vector_size(v))
93 { DUMP(v); return 1; }
95 if (499 - i != (long) GNUNET_CONTAINER_vector_get_at(v, i))
96 { DUMP(v); return 1; }
97 if (499 != (long) GNUNET_CONTAINER_vector_get_first(v))
98 { DUMP(v); return 1; }
100 if (i != (long) GNUNET_CONTAINER_vector_get_next(v))
101 { DUMP(v); return 1; }
103 if (499 != (long) GNUNET_CONTAINER_vector_get_first(v))
104 { DUMP(v); return 1; }
105 for (i=498;i>=250;i--)
106 if (i != (long) GNUNET_CONTAINER_vector_get_next(v))
107 { DUMP(v); return 1; }
108 for (i=251;i<499;i++)
109 if (i != (long) GNUNET_CONTAINER_vector_get_previous(v))
110 { DUMP(v); return 1; }
112 GNUNET_CONTAINER_vector_destroy(v);
119 if (NULL != GNUNET_CONTAINER_vector_create(0))
120 { printf("At %d\n", __LINE__); return 1; }
121 if (NULL != GNUNET_CONTAINER_vector_create(1))
122 { printf("At %d\n", __LINE__); return 1; }
124 { printf("At %d\n", __LINE__); return 1; }
126 { printf("At %d\n", __LINE__); return 1; }
128 { printf("At %d\n", __LINE__); return 1; }
130 { printf("At %d\n", __LINE__); return 1; }
131 if (test(65536) != 0)
132 { printf("At %d\n", __LINE__); return 1; }
133 if (test(2*65536) != 0)
134 { printf("At %d\n", __LINE__); return 1; }
137 { printf("At %d\n", __LINE__); return 1; }
139 { printf("At %d\n", __LINE__); return 1; }
141 { printf("At %d\n", __LINE__); return 1; }
143 { printf("At %d\n", __LINE__); return 1; }