~ubuntu-branches/ubuntu/intrepid/gnunet/intrepid

« back to all changes in this revision

Viewing changes to src/util/vectortest.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-07-03 14:17:00 UTC
  • mfrom: (1.2.11 upstream) (16 hardy)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20080703141700-355g0g164kaw2kwk
Tags: 0.8.0-2
* Creating /var/run/gnunetd in initscript in case /var/run is on a tmpfs.
* Adding versioned conflicts/replaces against gnunet in order to allow etch to
  lenny upgrades.
* Updating contact address in po files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
      This file is part of GNUnet
3
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
/**
21
 
 * This is a testcase for the vector, waiting to be extended.
22
 
 */
23
 
 
24
 
#include "platform.h"
25
 
#include "gnunet_util.h"
26
 
 
27
 
#define DUMP(v) fprintf(stderr, "At %d: \n", __LINE__); vectorDump(v);
28
 
 
29
 
static int test(int size) {
30
 
  struct Vector * v;
31
 
 
32
 
  v = vectorNew(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; }
78
 
  vectorFree(v);
79
 
  return 0;
80
 
}
81
 
 
82
 
static int test2(int size) {
83
 
  long i;
84
 
  struct Vector * v;
85
 
 
86
 
  v = vectorNew(size);
87
 
 
88
 
  for (i=0;i<500;i++)
89
 
    if (OK != vectorInsertAt(v, (void*)i, 0))
90
 
      { DUMP(v); return 1; }
91
 
  if (500 != vectorSize(v))
92
 
    { DUMP(v); return 1; }
93
 
  for (i=0;i<500;i++)
94
 
    if (499 - i != (long) vectorGetAt(v, i))
95
 
      { DUMP(v); return 1; }
96
 
  if (499 != (long) vectorGetFirst(v))
97
 
    { DUMP(v); return 1; }
98
 
  for (i=498;i>=0;i--)
99
 
    if (i != (long) vectorGetNext(v))
100
 
      { DUMP(v); return 1; }
101
 
 
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; }
110
 
 
111
 
  vectorFree(v);
112
 
  return 0;
113
 
}
114
 
 
115
 
 
116
 
int main(int argc,
117
 
         char * argv[]) {
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; }
122
 
  if (test(2) != 0)
123
 
    { printf("At %d\n", __LINE__); return 1; }
124
 
  if (test(3) != 0)
125
 
    { printf("At %d\n", __LINE__); return 1; }
126
 
  if (test(4) != 0)
127
 
    { printf("At %d\n", __LINE__); return 1; }
128
 
  if (test(128) != 0)
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; }
134
 
 
135
 
  if (test2(2) != 0)
136
 
    { printf("At %d\n", __LINE__); return 1; }
137
 
  if (test2(3) != 0)
138
 
    { printf("At %d\n", __LINE__); return 1; }
139
 
  if (test2(4) != 0)
140
 
    { printf("At %d\n", __LINE__); return 1; }
141
 
  if (test2(128) != 0)
142
 
    { printf("At %d\n", __LINE__); return 1; }
143
 
  return 0;
144
 
}