1 |
dpavlin |
237 |
/* |
2 |
|
|
openisis - an open implementation of the CDS/ISIS database |
3 |
|
|
Version 0.8.x (patchlevel see file Version) |
4 |
|
|
Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org |
5 |
|
|
|
6 |
|
|
This library is free software; you can redistribute it and/or |
7 |
|
|
modify it under the terms of the GNU Lesser General Public |
8 |
|
|
License as published by the Free Software Foundation; either |
9 |
|
|
version 2.1 of the License, or (at your option) any later version. |
10 |
|
|
|
11 |
|
|
This library is distributed in the hope that it will be useful, |
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
Lesser General Public License for more details. |
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU Lesser General Public |
17 |
|
|
License along with this library; if not, write to the Free Software |
18 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
|
20 |
|
|
see README for more information |
21 |
|
|
EOH */ |
22 |
|
|
|
23 |
|
|
/* |
24 |
|
|
$Id: lrectest.c,v 1.12 2003/05/01 10:05:41 mawag Exp $ |
25 |
|
|
tests for lrec methods. |
26 |
|
|
*/ |
27 |
|
|
|
28 |
|
|
#include <errno.h> |
29 |
|
|
#include <stdarg.h> |
30 |
|
|
#include <stdio.h> |
31 |
|
|
#include <stdlib.h> |
32 |
|
|
#include <string.h> |
33 |
|
|
|
34 |
|
|
#include "openisis.h" |
35 |
|
|
#include "loi.h" |
36 |
|
|
#include "lfdt.h" |
37 |
|
|
#include "luti.h" |
38 |
|
|
|
39 |
|
|
#ifdef WIN32 |
40 |
|
|
#define snprintf _snprintf |
41 |
|
|
#define vsnprintf _vsnprintf |
42 |
|
|
#endif |
43 |
|
|
|
44 |
|
|
static const char* _TheSummary = "Meeting on the Implementation of the Recommendations of the Third Regional Conference of Ministers of Education and Ministers Responsible for Economic Planning in the Arab States"; |
45 |
|
|
#define SUMLEN (strlen (_TheSummary)) |
46 |
|
|
|
47 |
|
|
static Fd _TheFds[] = { |
48 |
|
|
{ 20, 0, FTX, 0, 0, 32, "author", "", 0, 0, 0, 0 }, |
49 |
|
|
{ 21, 0, FTX, 1, 0, 32, "names", "", 0, 0, 0, 0 }, |
50 |
|
|
{ 22, 0, FTX, 1, 0, 32, "year", "", 0, 0, 0, 0 }, |
51 |
|
|
{ 42, 0, FTX, 1, 0, 32, "title", "", 0, 0, 0, 0 }, |
52 |
|
|
{ 49, 0, FTX, 1, 0, 32, "summary", "", 0, 0, 0, 0 }, |
53 |
|
|
{ 70, 0, FTX, 1, 0, 32, "country", "", 0, 0, 0, 0 }, |
54 |
|
|
{ 80, 0, FTX, 1, 0, 32, "conference", "", 0, 0, 0, 0 }, |
55 |
|
|
{ 81, 0, FTE, 0, 0, 32, "format", "", 0, 0, 0, 0 }, |
56 |
|
|
{ 81, 0, FTV, 0, 0, 1, "autoformat", "", 0, 0, 0, 0 }, |
57 |
|
|
{ 81, 0, FTV, 0, 0, 2, "naligned", "", 0, 0, 0, 0 }, |
58 |
|
|
{ 81, 0, FTV, 0, 0, 73, "aligned", "", 0, 0, 0, 0 }, |
59 |
|
|
{ 82, 0, FTB, 0, 0, 10, "soldout", "", 0, 0, 0, 0 } |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
static Fdt _TheFdt = { |
63 |
|
|
sizeof(_TheFds) / sizeof(_TheFds[0]), |
64 |
|
|
_TheFds, |
65 |
|
|
0 |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
static void check ( |
69 |
|
|
char *msg, Rec *rec, int *tag, const char **val, int len, int used |
70 |
|
|
) { |
71 |
|
|
Field *F; |
72 |
|
|
int idx, vlen, ok; |
73 |
|
|
if (0 == rec) { |
74 |
|
|
fprintf (stderr, "ERR %s: 0 == rec\n", msg); |
75 |
|
|
exit (1); |
76 |
|
|
} |
77 |
|
|
if (! OPENISIS_RECOK (rec)) { |
78 |
|
|
fprintf (stderr, "ERR %s: ! RECOK: b %d u %d/%d f %d/%d\n", |
79 |
|
|
msg, rec->base, rec->used, rec->bytes, rec->len, rec->fields); |
80 |
|
|
exit (1); |
81 |
|
|
} |
82 |
|
|
if (len != rec->len) { |
83 |
|
|
fprintf (stderr, "ERR %s: len %d != %d\n", msg, rec->len, len); |
84 |
|
|
log_rec (LOG_ERROR, rec, 0, 0); |
85 |
|
|
exit (1); |
86 |
|
|
} |
87 |
|
|
if (0 <= used && used != rec->used - rec->base) { |
88 |
|
|
fprintf (stderr, "ERR %s: used %d (%d-%d) != %d\n", |
89 |
|
|
msg, (rec->used - rec->base), rec->used, rec->base, used); |
90 |
|
|
log_rec (LOG_ERROR, rec, 0, 0); |
91 |
|
|
exit (1); |
92 |
|
|
} |
93 |
|
|
ok = !0; |
94 |
|
|
for (idx = 0; len > idx; ++idx) { |
95 |
|
|
vlen = strlen (val[idx]); |
96 |
|
|
F = rec->field + idx; |
97 |
|
|
if (F->tag != tag[idx]) { |
98 |
|
|
fprintf (stderr, "ERR %s: fld[%d] tag %d != %d\n", |
99 |
|
|
msg, idx, F->tag, tag[idx]); |
100 |
|
|
ok = 0; |
101 |
|
|
} |
102 |
|
|
if (F->len != vlen || |
103 |
|
|
strncmp (F->val, val[idx], vlen)) { |
104 |
|
|
fprintf (stderr, "ERR %s: fld[%d] val <%.*s> != <%s>\n", |
105 |
|
|
msg, idx, (int)F->len, F->val, val[idx]); |
106 |
|
|
ok = 0; |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
if (! ok) { |
110 |
|
|
exit (1); |
111 |
|
|
} |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
int main (int argc, char **argv) { |
115 |
|
|
const char *args[32]; |
116 |
|
|
const char *vals[32]; |
117 |
|
|
int tags[32]; |
118 |
|
|
Rec *rec = 0; |
119 |
|
|
|
120 |
|
|
/* call lio_init to prepare stderr on windows */ |
121 |
|
|
openIsisCOpen (0); |
122 |
|
|
|
123 |
|
|
if (1 < argc) { |
124 |
|
|
#define EXPFLD (1332 + (1000 - 888)) |
125 |
|
|
int bytes = 0, used = 0, num = atoi (argv[1]); |
126 |
|
|
printf ("entering loops (%d) ...\n", num); |
127 |
|
|
while (num) { |
128 |
|
|
int j; |
129 |
|
|
rec = 0; |
130 |
|
|
for (j = 1000; 1 <= --j; ) { |
131 |
|
|
RADD (rec, j, _TheSummary, SUMLEN, !0); |
132 |
|
|
} |
133 |
|
|
for (j = 888; 666 <= --j; ) { |
134 |
|
|
rec = rSet (rec, RDEL | RNOC, j, 0); |
135 |
|
|
} |
136 |
|
|
for (j = 666; 444 <= --j; ) { |
137 |
|
|
rec = rSet (rec, RDEL, j, 0); |
138 |
|
|
} |
139 |
|
|
for (j = 444; 222 <= --j; ) { |
140 |
|
|
rec = rSet (rec, RDEL | RNOC, j, 0); |
141 |
|
|
} |
142 |
|
|
for (j = 1333; 222 <= --j; ) { |
143 |
|
|
RADD (rec, j, _TheSummary, SUMLEN, !0); |
144 |
|
|
} |
145 |
|
|
if (EXPFLD != rec->len) { |
146 |
|
|
printf ("%d: ERR: #len = %d, expected %d\n", |
147 |
|
|
num, rec->len, EXPFLD); |
148 |
|
|
exit (1); |
149 |
|
|
} |
150 |
|
|
if (0 == bytes) { |
151 |
|
|
bytes = rec->bytes; |
152 |
|
|
used = rec->used; |
153 |
|
|
printf ("mem %d use %d ...\n", |
154 |
|
|
rec->bytes, rec->used); |
155 |
|
|
} |
156 |
|
|
else { |
157 |
|
|
if (bytes != rec->bytes || used != rec->used) { |
158 |
|
|
printf ("%d: ERR: mem = %d use = %d\n", |
159 |
|
|
num, rec->bytes, rec->used); |
160 |
|
|
exit (1); |
161 |
|
|
} |
162 |
|
|
if (0 == (num % 100)) { |
163 |
|
|
printf ("%d ...\n", num); |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
mFree (rec); |
167 |
|
|
--num; |
168 |
|
|
} |
169 |
|
|
printf ("ok.\n"); |
170 |
|
|
exit (0); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
args[0] = "20"; |
174 |
|
|
args[1] = "Mary"; |
175 |
|
|
rec = rSet (rec, RARGV | 2, args); |
176 |
|
|
tags[0] = 20; |
177 |
|
|
vals[0] = args[1]; |
178 |
|
|
check ("A", rec, tags, vals, 1, 4); |
179 |
|
|
|
180 |
|
|
args[0] = "22"; |
181 |
|
|
args[1] = "1953"; |
182 |
|
|
args[2] = "70"; |
183 |
|
|
args[3] = "Italy"; |
184 |
|
|
args[4] = "98"; |
185 |
|
|
args[5] = "illegal"; |
186 |
|
|
args[6] = "20"; |
187 |
|
|
args[7] = "John"; |
188 |
|
|
rec = rSet (rec, RARGV | RFDT | 8, &_TheFdt, args); |
189 |
|
|
tags[0] = 20; |
190 |
|
|
vals[0] = "Mary"; |
191 |
|
|
tags[1] = 22; |
192 |
|
|
vals[1] = "1953"; |
193 |
|
|
tags[2] = 70; |
194 |
|
|
vals[2] = "Italy"; |
195 |
|
|
tags[3] = 20; |
196 |
|
|
vals[3] = "John"; |
197 |
|
|
check ("B", rec, tags, vals, 3, 13); |
198 |
|
|
|
199 |
|
|
args[0] = "98"; |
200 |
|
|
args[1] = "illegal"; |
201 |
|
|
args[2] = "20"; |
202 |
|
|
args[3] = "John"; |
203 |
|
|
rec = rSet (rec, RARGV | RFDT | RIGN | 4, &_TheFdt, args); |
204 |
|
|
check ("C", rec, tags, vals, 4, 17); |
205 |
|
|
|
206 |
|
|
rec = rSet (rec, RDEL, 20, 0); |
207 |
|
|
tags[0] = 22; |
208 |
|
|
vals[0] = "1953"; |
209 |
|
|
tags[1] = 70; |
210 |
|
|
vals[1] = "Italy"; |
211 |
|
|
check ("D", rec, tags, vals, 2, 9); |
212 |
|
|
|
213 |
|
|
rec = rSet (rec, RDFLT | RFDT, &_TheFdt, |
214 |
|
|
81, "naligned", 22, "already there", 0); |
215 |
|
|
tags[2] = 81; |
216 |
|
|
vals[2] = "2"; |
217 |
|
|
check ("D1", rec, tags, vals, 3, 10); |
218 |
|
|
|
219 |
|
|
tags[3] = 234; |
220 |
|
|
vals[3] = "foo"; |
221 |
|
|
rec = rSet (rec, RDFLT, 234, "foo", 0); |
222 |
|
|
check ("D2", rec, tags, vals, 4, 13); |
223 |
|
|
|
224 |
|
|
rec = rSet (rec, RDEL, 234, 81, 0); |
225 |
|
|
check ("D3", rec, tags, vals, 2, 13); |
226 |
|
|
|
227 |
|
|
rec = rSet (rec, 0, 20, "Mary", 20, "James", 90, "Alabama", 0); |
228 |
|
|
tags[2] = 20; |
229 |
|
|
vals[2] = "Mary"; |
230 |
|
|
tags[3] = 20; |
231 |
|
|
vals[3] = "James"; |
232 |
|
|
tags[4] = 90; |
233 |
|
|
vals[4] = "Alabama"; |
234 |
|
|
check ("E", rec, tags, vals, 5, 29); |
235 |
|
|
|
236 |
|
|
rec = rSet (rec, RFDT | RCHG, &_TheFdt, |
237 |
|
|
20, "Lary", 70, "Greece", 70, "Cuba", 42, "Folklore from Africa", |
238 |
|
|
81, "invalid", 0); |
239 |
|
|
tags[0] = 22; |
240 |
|
|
vals[0] = "1953"; |
241 |
|
|
tags[1] = 70; |
242 |
|
|
vals[1] = "Greece"; |
243 |
|
|
tags[2] = 20; |
244 |
|
|
vals[2] = "Lary"; |
245 |
|
|
tags[3] = 90; |
246 |
|
|
vals[3] = "Alabama"; |
247 |
|
|
tags[4] = 70; |
248 |
|
|
vals[4] = "Cuba"; |
249 |
|
|
tags[5] = 42; |
250 |
|
|
vals[5] = "Folklore from Africa"; |
251 |
|
|
check ("F", rec, tags, vals, 6, 45); |
252 |
|
|
|
253 |
|
|
rec = rSet (rec, 0, 20, "Peter", 20, "Gary", 70, "Egypt", 0); |
254 |
|
|
tags[6] = 20; |
255 |
|
|
vals[6] = "Peter"; |
256 |
|
|
tags[7] = 20; |
257 |
|
|
vals[7] = "Gary"; |
258 |
|
|
tags[8] = 70; |
259 |
|
|
vals[8] = "Egypt"; |
260 |
|
|
check ("G", rec, tags, vals, 9, 59); |
261 |
|
|
|
262 |
|
|
args[0] = "author[1]"; |
263 |
|
|
args[1] = "81"; |
264 |
|
|
args[2] = "70"; |
265 |
|
|
rec = rSet (rec, RFDT | RARGV | RDEL | 3, &_TheFdt, args); |
266 |
|
|
tags[0] = 22; |
267 |
|
|
vals[0] = "1953"; |
268 |
|
|
tags[1] = 20; |
269 |
|
|
vals[1] = "Lary"; |
270 |
|
|
tags[2] = 90; |
271 |
|
|
vals[2] = "Alabama"; |
272 |
|
|
tags[3] = 42; |
273 |
|
|
vals[3] = "Folklore from Africa"; |
274 |
|
|
tags[4] = 20; |
275 |
|
|
vals[4] = "Gary"; |
276 |
|
|
check ("H", rec, tags, vals, 5, 39); |
277 |
|
|
|
278 |
|
|
args[0] = "author[0]"; |
279 |
|
|
args[1] = "May"; |
280 |
|
|
args[2] = "summary"; |
281 |
|
|
args[3] = _TheSummary; |
282 |
|
|
args[4] = "soldout"; |
283 |
|
|
args[5] = "format"; |
284 |
|
|
args[6] = "aligned"; |
285 |
|
|
rec = rSet (rec, RFDT | RARGV | RCHG | RNOC | 7, &_TheFdt, args); |
286 |
|
|
vals[1] = "May"; |
287 |
|
|
tags[5] = 49; |
288 |
|
|
vals[5] = _TheSummary; |
289 |
|
|
tags[6] = 82; |
290 |
|
|
vals[6] = "1"; |
291 |
|
|
tags[7] = 81; |
292 |
|
|
vals[7] = "73"; |
293 |
|
|
check ("I", rec, tags, vals, 8, 42 + SUMLEN); |
294 |
|
|
|
295 |
|
|
args[0] = "20[0]"; |
296 |
|
|
args[1] = "Marilyn"; |
297 |
|
|
args[2] = "49[1]"; |
298 |
|
|
args[3] = _TheSummary; |
299 |
|
|
rec = rSet (rec, RARGV | RCHG | 4, args); |
300 |
|
|
vals[1] = "Marilyn"; |
301 |
|
|
tags[8] = 49; |
302 |
|
|
vals[8] = _TheSummary; |
303 |
|
|
check ("J", rec, tags, vals, 9, 45 + 2 * SUMLEN); |
304 |
|
|
|
305 |
|
|
rec = rSet (rec, RDEL | 2, 82, 22, 0); |
306 |
|
|
tags[0] = 20; |
307 |
|
|
vals[0] = "Marilyn"; |
308 |
|
|
tags[1] = 90; |
309 |
|
|
vals[1] = "Alabama"; |
310 |
|
|
tags[2] = 42; |
311 |
|
|
vals[2] = "Folklore from Africa"; |
312 |
|
|
tags[3] = 20; |
313 |
|
|
vals[3] = "Gary"; |
314 |
|
|
tags[4] = 49; |
315 |
|
|
vals[4] = _TheSummary; |
316 |
|
|
tags[5] = 81; |
317 |
|
|
vals[5] = "73"; |
318 |
|
|
tags[6] = 49; |
319 |
|
|
vals[6] = _TheSummary; |
320 |
|
|
check ("K", rec, tags, vals, 7, 40 + 2 * SUMLEN); |
321 |
|
|
|
322 |
|
|
rec = rSet (rec, RFDT | RCHG, &_TheFdt, |
323 |
|
|
82, "false", 81, "2", 49, "overview", 0); |
324 |
|
|
vals[4] = "overview"; |
325 |
|
|
vals[5] = "2"; |
326 |
|
|
tags[6] = 82; |
327 |
|
|
vals[6] = "0"; |
328 |
|
|
check ("L", rec, tags, vals, 7, 48); |
329 |
|
|
|
330 |
|
|
mFree (rec); |
331 |
|
|
|
332 |
|
|
printf ("ok.\n"); |
333 |
|
|
return 0; |
334 |
|
|
} |
335 |
|
|
|