| | varnish-cache/include/vbm_test.c |
0 |
|
/*- |
1 |
|
* Copyright 2016 UPLEX - Nils Goroll Systemoptimierung |
2 |
|
* All rights reserved. |
3 |
|
* |
4 |
|
* Author: Nils Goroll <nils.goroll@uplex.de> |
5 |
|
* |
6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
7 |
|
* |
8 |
|
* Redistribution and use in source and binary forms, with or without |
9 |
|
* modification, are permitted provided that the following conditions |
10 |
|
* are met: |
11 |
|
* 1. Redistributions of source code must retain the above copyright |
12 |
|
* notice, this list of conditions and the following disclaimer. |
13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
14 |
|
* notice, this list of conditions and the following disclaimer in the |
15 |
|
* documentation and/or other materials provided with the distribution. |
16 |
|
* |
17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
27 |
|
* SUCH DAMAGE. |
28 |
|
* |
29 |
|
* Test Self-sizing bitmap operations static initialization with dynamic growth |
30 |
|
*/ |
31 |
|
|
32 |
|
#include <assert.h> |
33 |
|
#include <stdio.h> |
34 |
|
|
35 |
|
#include "vbm.h" |
36 |
|
|
37 |
|
int |
38 |
40 |
main(void) |
39 |
|
{ |
40 |
|
|
41 |
40 |
const unsigned sz = VBITMAP_SZ(1); |
42 |
40 |
char spc[sz]; |
43 |
40 |
struct vbitmap *vb = vbit_init(spc, sz); |
44 |
|
|
45 |
|
VBITMAP_TYPE *obits; |
46 |
|
unsigned nbits; |
47 |
|
|
48 |
40 |
assert(vb); |
49 |
40 |
obits = vb->bits; |
50 |
40 |
nbits = vb->nbits; |
51 |
40 |
assert(nbits == VBITMAP_WORD); |
52 |
|
|
53 |
40 |
vbit_set(vb, nbits - 1); |
54 |
40 |
assert(vbit_test(vb, nbits - 1)); |
55 |
|
|
56 |
40 |
assert(vb->bits); |
57 |
|
/* nothing malloc'ed - null ops */ |
58 |
40 |
vbit_destroy(vb); |
59 |
40 |
assert(vb->bits); |
60 |
40 |
assert(vb->bits == obits); |
61 |
|
|
62 |
|
/* re-alloc */ |
63 |
40 |
vbit_set(vb, nbits); |
64 |
40 |
assert(vbit_test(vb, nbits - 1)); |
65 |
40 |
assert(vbit_test(vb, nbits)); |
66 |
40 |
assert(vb->nbits == VBITMAP_LUMP); |
67 |
40 |
assert(vb->bits != obits); |
68 |
40 |
assert(vb->flags & VBITMAP_FL_MALLOC_BITS); |
69 |
|
|
70 |
40 |
assert(vb->bits); |
71 |
|
/* free the bits */ |
72 |
40 |
vbit_destroy(vb); |
73 |
40 |
assert(vb->bits == NULL); |
74 |
40 |
assert(vb->nbits == 0); |
75 |
|
|
76 |
|
/* use again */ |
77 |
|
assert(20 < VBITMAP_LUMP); |
78 |
40 |
vbit_set(vb, 20); |
79 |
40 |
assert(vbit_test(vb, 20)); |
80 |
40 |
assert(vb->nbits == VBITMAP_LUMP); |
81 |
40 |
assert(vb->flags & VBITMAP_FL_MALLOC_BITS); |
82 |
|
|
83 |
|
/* grow */ |
84 |
40 |
vbit_set(vb, VBITMAP_LUMP); |
85 |
40 |
assert(vbit_test(vb, 20)); |
86 |
40 |
assert(vbit_test(vb, VBITMAP_LUMP)); |
87 |
40 |
assert(vb->nbits == 2 * VBITMAP_LUMP); |
88 |
40 |
assert(vb->flags & VBITMAP_FL_MALLOC_BITS); |
89 |
|
|
90 |
40 |
vbit_destroy(vb); |
91 |
|
|
92 |
40 |
return (0); |
93 |
40 |
} |