Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / pptp-client / vector_test.c
blob70b6223f7ffb235a50086d5ef77b005328ef8149
1 /* vector_test.c .... Test the vector package.
2 * C. Scott Ananian <cananian@alumni.princeton.edu>
4 * $Id: vector_test.c,v 1.2 2003/06/17 17:25:47 reink Exp $
5 */
7 #include <stdlib.h>
8 #include <assert.h>
9 #include "vector.h"
11 #define MAX 25
13 void main(void) {
14 int i, j, retval;
16 VECTOR *v = vector_create();
17 assert(v != NULL);
18 assert(vector_size(v)==0);
19 for (i=0; i<=MAX; i++) {
20 assert(!vector_contains(v, i));
21 assert(!vector_remove(v, i));
22 assert(!vector_search(v, i, (PPTP_CALL **)&j));
23 retval = vector_scan(v, i, MAX*2, &j);
24 assert(retval);
25 assert(j==i);
28 for (i=1; i<=MAX; i++) {
29 retval = vector_insert(v, i, (PPTP_CALL *)i);
30 assert(retval);
31 assert(vector_size(v)==i);
33 for (i=1; i<MAX; i++) {
34 retval = vector_search(v, i, (PPTP_CALL **)&j);
35 assert(retval);
36 assert(j==i);
37 retval = vector_contains(v, i);
38 assert(retval);
40 assert(vector_size(v)==MAX);
41 retval = vector_contains(v, MAX+1);
42 assert(!retval);
43 retval = vector_search(v, MAX+1, (PPTP_CALL **)&j);
44 assert(!retval);
46 retval = vector_scan(v, 0, MAX, &j);
47 assert(retval);
48 assert(j==0);
49 retval = vector_scan(v, 1, MAX, &j);
50 assert(!retval);
51 retval = vector_scan(v, 1, MAX+1, &j);
52 assert(retval);
53 assert(j==MAX+1);
54 retval = vector_scan(v, 1, MAX+MAX, &j);
55 assert(retval);
56 assert(j==MAX+1);
58 for (i=0; i<(MAX*10); i++) {
59 int k = (random() % MAX) + 1;
60 assert(vector_contains(v, k));
61 assert(!vector_scan(v, 1, k, &j));
62 assert(!vector_scan(v, k, MAX, &j));
63 retval = vector_remove(v, k);
64 assert(retval);
65 assert(vector_size(v)==MAX-1);
66 assert(!vector_contains(v, k));
67 assert(!vector_search(v, k, (PPTP_CALL **) &j));
68 retval = vector_scan(v, 1, MAX, &j);
69 assert(retval);
70 assert(j==k);
71 retval = vector_insert(v, k, (PPTP_CALL *) k);
72 assert(retval);
73 assert(vector_size(v)==MAX);
74 assert(vector_contains(v, k));
75 assert(!vector_scan(v, 1, MAX, &j));
76 retval = vector_search(v, k, (PPTP_CALL **) &j);
77 assert(retval);
78 assert(j==k);
81 for (i=1; i<=MAX; i++) {
82 assert(vector_size(v)==MAX-(i-1));
83 vector_remove(v, i);
84 assert(vector_size(v)==MAX-i);
85 assert(!vector_contains(v, i));
86 retval = vector_search(v, i, (PPTP_CALL **) &j);
87 assert(!retval);
88 retval = vector_scan(v, 1, MAX, &j);
89 assert(retval);
90 assert(j==1);
92 assert(vector_size(v)==0);
93 vector_destroy(v);