2
This file is part of GNUnet
4
GNUnet is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published
6
by the Free Software Foundation; either version 2, or (at your
7
option) any later version.
9
GNUnet is distributed in the hope that it will be useful, but
10
WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with GNUnet; see the file COPYING. If not, write to the
16
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
21
* This is a testcase for the vector, waiting to be extended.
25
#include "gnunet_util.h"
27
#define DUMP(v) fprintf(stderr, "At %d: \n", __LINE__); vectorDump(v);
29
static int test(int size) {
33
if (0 != vectorSize(v))
34
{ DUMP(v); return 1; }
35
if (OK != vectorInsertAt(v, "first", 0))
36
{ DUMP(v); return 1; }
37
if (OK == vectorInsertAt(v, "not", 2))
38
{ DUMP(v); return 1; }
39
if (OK != vectorInsertAt(v, "zero", 0))
40
{ DUMP(v); return 1; }
41
if (OK != vectorInsertAt(v, "second", 2))
42
{ DUMP(v); return 1; }
43
vectorInsertLast(v, "third");
44
if (4 != vectorSize(v))
45
{ DUMP(v); return 1; }
46
if (0 != strcmp(vectorGetAt(v, 1), "first"))
47
{ DUMP(v); return 1; }
48
if (0 != strcmp(vectorGetAt(v, 3), "third"))
49
{ DUMP(v); return 1; }
50
if (0 != strcmp(vectorGetAt(v, 0), "zero"))
51
{ DUMP(v); return 1; }
52
if (0 != strcmp(vectorGetFirst(v), "zero"))
53
{ DUMP(v); return 1; }
54
if (0 != strcmp(vectorGetLast(v), "third"))
55
{ DUMP(v); return 1; }
56
if (0 != strcmp(vectorRemoveAt(v, 1), "first"))
57
{ DUMP(v); return 1; }
58
if (0 != strcmp(vectorGetAt(v, 1), "second"))
59
{ DUMP(v); return 1; }
60
if (NULL != vectorRemoveAt(v, 3))
61
{ DUMP(v); return 1; }
62
if (3 != vectorSize(v))
63
{ DUMP(v); return 1; }
64
if (0 != strcmp(vectorRemoveAt(v, 1), "second"))
65
{ DUMP(v); return 1; }
66
if (0 != strcmp(vectorRemoveObject(v, "third"), "third"))
67
{ DUMP(v); return 1; }
68
if (NULL != vectorRemoveObject(v, "third"))
69
{ DUMP(v); return 1; }
70
if (0 != strcmp(vectorRemoveLast(v), "zero"))
71
{ DUMP(v); return 1; }
72
if (0 != vectorSize(v))
73
{ DUMP(v); return 1; }
74
if (NULL != vectorRemoveLast(v))
75
{ DUMP(v); return 1; }
76
if (0 != vectorSize(v))
77
{ DUMP(v); return 1; }
82
static int test2(int size) {
89
if (OK != vectorInsertAt(v, (void*)i, 0))
90
{ DUMP(v); return 1; }
91
if (500 != vectorSize(v))
92
{ DUMP(v); return 1; }
94
if (499 - i != (long) vectorGetAt(v, i))
95
{ DUMP(v); return 1; }
96
if (499 != (long) vectorGetFirst(v))
97
{ DUMP(v); return 1; }
99
if (i != (long) vectorGetNext(v))
100
{ DUMP(v); return 1; }
102
if (499 != (long) vectorGetFirst(v))
103
{ DUMP(v); return 1; }
104
for (i=498;i>=250;i--)
105
if (i != (long) vectorGetNext(v))
106
{ DUMP(v); return 1; }
107
for (i=251;i<499;i++)
108
if (i != (long) vectorGetPrevious(v))
109
{ DUMP(v); return 1; }
118
if (NULL != vectorNew(0))
119
{ printf("At %d\n", __LINE__); return 1; }
120
if (NULL != vectorNew(1))
121
{ printf("At %d\n", __LINE__); return 1; }
123
{ printf("At %d\n", __LINE__); return 1; }
125
{ printf("At %d\n", __LINE__); return 1; }
127
{ printf("At %d\n", __LINE__); return 1; }
129
{ printf("At %d\n", __LINE__); return 1; }
130
if (test(65536) != 0)
131
{ printf("At %d\n", __LINE__); return 1; }
132
if (test(2*65536) != 0)
133
{ printf("At %d\n", __LINE__); return 1; }
136
{ printf("At %d\n", __LINE__); return 1; }
138
{ printf("At %d\n", __LINE__); return 1; }
140
{ printf("At %d\n", __LINE__); return 1; }
142
{ printf("At %d\n", __LINE__); return 1; }