1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF. The full HDF copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /* $Id$ */
15
16 /*
17 FILE
18 tbv.c
19 Test HDF bit-vector (bv) routines.
20
21 REMARKS
22
23 DESIGN
24
25 BUGS/LIMITATIONS
26
27 EXPORTED ROUTINES
28
29 AUTHOR
30 Quincey Koziol
31
32 MODIFICATION HISTORY
33 12/11/95 - Started coding.
34 */
35
36 #include "tproto.h"
37 #include "bitvect.h"
38
39 static void test_1(void);
40 static void test_2(void);
41 static void test_3(void);
42
43 /* Basic creation & deletion tests */
test_1(void)44 static void test_1(void)
45 {
46 bv_ptr b;
47 int32 size;
48 uint32 flags;
49 intn ret;
50
51 MESSAGE(6, printf("Testing basic bit-vector creation & deletion\n"););
52
53 MESSAGE(7, printf("Create a bit-vector with all defaults\n"););
54 b=bv_new(-1,0); /* test basic default creation */
55 CHECK_VOID(b,NULL,"bv_new");
56 size=bv_size(b);
57 MESSAGE(8, printf("Bit-vector size=%d\n",(int)size););
58 VERIFY_VOID(size,BV_DEFAULT_BITS,"bv_size");
59 flags=bv_flags(b);
60 CHECK_VOID(flags,(uint32)FAIL,"bv_flags");
61 MESSAGE(8, printf("Bit-vector flags=%lx\n",(unsigned long)flags););
62 ret=bv_delete(b);
63 CHECK_VOID(ret,FAIL,"bv_delete");
64
65 MESSAGE(7, printf("Create an extendable bit-vector with large # of bits\n"););
66 b=bv_new(80000,BV_EXTENDABLE); /* test creation */
67 CHECK_VOID(b,NULL,"bv_new");
68 size=bv_size(b);
69 MESSAGE(8, printf("Bit-vector size=%d\n",(int)size););
70 VERIFY_VOID(size,80000,"bv_size");
71 flags=bv_flags(b);
72 CHECK_VOID(flags,(uint32)FAIL,"bv_flags");
73 MESSAGE(8, printf("Bit-vector flags=%lx\n",(unsigned long)flags););
74 ret=bv_delete(b);
75 CHECK_VOID(ret,FAIL,"bv_delete");
76 } /* end test_1 */
77
78 /* Basic set & get tests */
test_2(void)79 static void test_2(void)
80 {
81 bv_ptr b;
82 int32 size;
83 uint32 flags;
84 intn ret;
85
86 MESSAGE(6, printf("Testing basic bit-vector set & get \n"););
87
88 MESSAGE(7, printf("Create a bit-vector with all defaults\n"););
89 b=bv_new(-1,0); /* test basic default creation */
90 CHECK_VOID(b,NULL,"bv_new");
91 size=bv_size(b);
92 MESSAGE(8, printf("Bit-vector size=%d\n",(int)size););
93 VERIFY_VOID(size,BV_DEFAULT_BITS,"bv_size");
94 flags=bv_flags(b);
95 CHECK_VOID(flags,(uint32)FAIL,"bv_flags");
96 MESSAGE(8, printf("Bit-vector flags=%lx\n",(unsigned long)flags););
97 /* Check setting bits */
98 ret=bv_set(b,13,BV_TRUE);
99 CHECK_VOID(ret,FAIL,"bv_set");
100 ret=bv_set(b,3,BV_TRUE);
101 CHECK_VOID(ret,FAIL,"bv_set");
102 ret=bv_set(b,150,BV_TRUE);
103 VERIFY_VOID(ret,FAIL,"bv_set");
104 /* Check getting bits */
105 ret=bv_get(b,2);
106 VERIFY_VOID(ret,BV_FALSE,"bv_get");
107 ret=bv_get(b,3);
108 VERIFY_VOID(ret,BV_TRUE,"bv_get");
109 ret=bv_get(b,0);
110 VERIFY_VOID(ret,BV_FALSE,"bv_get");
111 ret=bv_get(b,13);
112 VERIFY_VOID(ret,BV_TRUE,"bv_get");
113 ret=bv_get(b,-1);
114 VERIFY_VOID(ret,FAIL,"bv_get");
115 ret=bv_delete(b);
116 CHECK_VOID(ret,FAIL,"bv_delete");
117
118 MESSAGE(7, printf("Create an extendable bit-vector with large # of bits\n"););
119 b=bv_new(1000,BV_EXTENDABLE); /* test creation */
120 CHECK_VOID(b,NULL,"bv_new");
121 size=bv_size(b);
122 MESSAGE(8, printf("Bit-vector size=%d\n",(int)size););
123 VERIFY_VOID(size,1000,"bv_size");
124 flags=bv_flags(b);
125 CHECK_VOID(flags,(uint32)FAIL,"bv_flags");
126 MESSAGE(8, printf("Bit-vector flags=%lx\n",(unsigned long)flags););
127 /* Check setting bits */
128 ret=bv_set(b,13,BV_TRUE);
129 CHECK_VOID(ret,FAIL,"bv_set");
130 ret=bv_set(b,3,BV_TRUE);
131 CHECK_VOID(ret,FAIL,"bv_set");
132 ret=bv_set(b,1050,BV_TRUE);
133 CHECK_VOID(ret,FAIL,"bv_set");
134 /* Check getting bits */
135 ret=bv_get(b,2);
136 VERIFY_VOID(ret,BV_FALSE,"bv_get");
137 ret=bv_get(b,3);
138 VERIFY_VOID(ret,BV_TRUE,"bv_get");
139 ret=bv_get(b,0);
140 VERIFY_VOID(ret,BV_FALSE,"bv_get");
141 ret=bv_get(b,13);
142 VERIFY_VOID(ret,BV_TRUE,"bv_get");
143 ret=bv_get(b,1040);
144 VERIFY_VOID(ret,BV_FALSE,"bv_get");
145 ret=bv_get(b,1050);
146 VERIFY_VOID(ret,BV_TRUE,"bv_get");
147 ret=bv_delete(b);
148 CHECK_VOID(ret,FAIL,"bv_delete");
149 } /* end test_2 */
150
151 /* Advanced set & get tests */
test_3(void)152 static void test_3(void)
153 {
154 bv_ptr b;
155 int32 size;
156 uint32 flags;
157 intn ret;
158
159 MESSAGE(6, printf("Testing basic bit-vector set & get \n"););
160
161 MESSAGE(7, printf("Create an extendable bit-vector\n"););
162 b=bv_new(-1,BV_EXTENDABLE); /* test creation */
163 CHECK_VOID(b,NULL,"bv_new");
164 size=bv_size(b);
165 MESSAGE(8, printf("Bit-vector size=%d\n",(int)size););
166 VERIFY_VOID(size,BV_DEFAULT_BITS,"bv_size");
167 flags=bv_flags(b);
168 CHECK_VOID(flags,(uint32)FAIL,"bv_flags");
169 MESSAGE(8, printf("Bit-vector flags=%lx\n",(unsigned long)flags););
170
171 /* Check setting bits */
172 ret=bv_set(b,13,BV_TRUE);
173 CHECK_VOID(ret,FAIL,"bv_set");
174 ret=bv_set(b,3,BV_TRUE);
175 CHECK_VOID(ret,FAIL,"bv_set");
176 ret=bv_set(b,150,BV_TRUE);
177 CHECK_VOID(ret,FAIL,"bv_set");
178
179 /* Check getting bits */
180 ret=bv_get(b,2);
181 VERIFY_VOID(ret,BV_FALSE,"bv_get");
182 ret=bv_get(b,3);
183 VERIFY_VOID(ret,BV_TRUE,"bv_get");
184 ret=bv_get(b,0);
185 VERIFY_VOID(ret,BV_FALSE,"bv_get");
186 ret=bv_get(b,13);
187 VERIFY_VOID(ret,BV_TRUE,"bv_get");
188 ret=bv_get(b,140);
189 VERIFY_VOID(ret,BV_FALSE,"bv_get");
190 ret=bv_get(b,150);
191 VERIFY_VOID(ret,BV_TRUE,"bv_get");
192
193 size=bv_find(b,-1,BV_FALSE);
194 CHECK_VOID(size,FAIL,"bv_find");
195 MESSAGE(8, printf("First 0 found at: %lu\n",(unsigned long)size););
196 ret=bv_set(b,size,BV_TRUE);
197 CHECK_VOID(ret,FAIL,"bv_set");
198
199 size=bv_find(b,-1,BV_FALSE);
200 CHECK_VOID(size,FAIL,"bv_find");
201 MESSAGE(8, printf("Second 0 found at: %lu\n",(unsigned long)size););
202 ret=bv_set(b,size,BV_TRUE);
203 CHECK_VOID(ret,FAIL,"bv_set");
204
205 size=bv_find(b,-1,BV_FALSE);
206 CHECK_VOID(size,FAIL,"bv_find");
207 MESSAGE(8, printf("Third 0 found at: %lu\n",(unsigned long)size););
208 ret=bv_set(b,size,BV_TRUE);
209 CHECK_VOID(ret,FAIL,"bv_set");
210
211 size=bv_find(b,-1,BV_FALSE);
212 CHECK_VOID(size,FAIL,"bv_find");
213 MESSAGE(8, printf("Fourth 0 found at: %lu\n",(unsigned long)size););
214 ret=bv_set(b,size,BV_TRUE);
215 CHECK_VOID(ret,FAIL,"bv_set");
216
217 ret=bv_delete(b);
218 CHECK_VOID(ret,FAIL,"bv_delete");
219 } /* end test_3 */
220
test_bitvect(void)221 void test_bitvect(void)
222 {
223 test_1(); /* basic creation & deletion tests */
224 test_2(); /* basic set & get testing */
225 test_3(); /* advanced set & get testing */
226 } /* end test_bitvect() */
227
228