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
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.
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.
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
20 see README for more information
24 $Id: lrectest.c,v 1.12 2003/05/01 10:05:41 mawag Exp $
25 tests for lrec methods.
40 #define snprintf _snprintf
41 #define vsnprintf _vsnprintf
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))
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 }
62 static Fdt _TheFdt = {
63 sizeof(_TheFds) / sizeof(_TheFds[0]),
69 char *msg, Rec *rec, int *tag, const char **val, int len, int used
74 fprintf (stderr, "ERR %s: 0 == rec\n", msg);
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);
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);
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);
94 for (idx = 0; len > idx; ++idx) {
95 vlen = strlen (val[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]);
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]);
114 int main (int argc, char **argv) {
115 const char *args[32];
116 const char *vals[32];
120 /* call lio_init to prepare stderr on windows */
124 #define EXPFLD (1332 + (1000 - 888))
125 int bytes = 0, used = 0, num = atoi (argv[1]);
126 printf ("entering loops (%d) ...\n", num);
130 for (j = 1000; 1 <= --j; ) {
131 RADD (rec, j, _TheSummary, SUMLEN, !0);
133 for (j = 888; 666 <= --j; ) {
134 rec = rSet (rec, RDEL | RNOC, j, 0);
136 for (j = 666; 444 <= --j; ) {
137 rec = rSet (rec, RDEL, j, 0);
139 for (j = 444; 222 <= --j; ) {
140 rec = rSet (rec, RDEL | RNOC, j, 0);
142 for (j = 1333; 222 <= --j; ) {
143 RADD (rec, j, _TheSummary, SUMLEN, !0);
145 if (EXPFLD != rec->len) {
146 printf ("%d: ERR: #len = %d, expected %d\n",
147 num, rec->len, EXPFLD);
153 printf ("mem %d use %d ...\n",
154 rec->bytes, rec->used);
157 if (bytes != rec->bytes || used != rec->used) {
158 printf ("%d: ERR: mem = %d use = %d\n",
159 num, rec->bytes, rec->used);
162 if (0 == (num % 100)) {
163 printf ("%d ...\n", num);
175 rec = rSet (rec, RARGV | 2, args);
178 check ("A", rec, tags, vals, 1, 4);
188 rec = rSet (rec, RARGV | RFDT | 8, &_TheFdt, args);
197 check ("B", rec, tags, vals, 3, 13);
203 rec = rSet (rec, RARGV | RFDT | RIGN | 4, &_TheFdt, args);
204 check ("C", rec, tags, vals, 4, 17);
206 rec = rSet (rec, RDEL, 20, 0);
211 check ("D", rec, tags, vals, 2, 9);
213 rec = rSet (rec, RDFLT | RFDT, &_TheFdt,
214 81, "naligned", 22, "already there", 0);
217 check ("D1", rec, tags, vals, 3, 10);
221 rec = rSet (rec, RDFLT, 234, "foo", 0);
222 check ("D2", rec, tags, vals, 4, 13);
224 rec = rSet (rec, RDEL, 234, 81, 0);
225 check ("D3", rec, tags, vals, 2, 13);
227 rec = rSet (rec, 0, 20, "Mary", 20, "James", 90, "Alabama", 0);
234 check ("E", rec, tags, vals, 5, 29);
236 rec = rSet (rec, RFDT | RCHG, &_TheFdt,
237 20, "Lary", 70, "Greece", 70, "Cuba", 42, "Folklore from Africa",
250 vals[5] = "Folklore from Africa";
251 check ("F", rec, tags, vals, 6, 45);
253 rec = rSet (rec, 0, 20, "Peter", 20, "Gary", 70, "Egypt", 0);
260 check ("G", rec, tags, vals, 9, 59);
262 args[0] = "author[1]";
265 rec = rSet (rec, RFDT | RARGV | RDEL | 3, &_TheFdt, args);
273 vals[3] = "Folklore from Africa";
276 check ("H", rec, tags, vals, 5, 39);
278 args[0] = "author[0]";
281 args[3] = _TheSummary;
285 rec = rSet (rec, RFDT | RARGV | RCHG | RNOC | 7, &_TheFdt, args);
288 vals[5] = _TheSummary;
293 check ("I", rec, tags, vals, 8, 42 + SUMLEN);
298 args[3] = _TheSummary;
299 rec = rSet (rec, RARGV | RCHG | 4, args);
302 vals[8] = _TheSummary;
303 check ("J", rec, tags, vals, 9, 45 + 2 * SUMLEN);
305 rec = rSet (rec, RDEL | 2, 82, 22, 0);
311 vals[2] = "Folklore from Africa";
315 vals[4] = _TheSummary;
319 vals[6] = _TheSummary;
320 check ("K", rec, tags, vals, 7, 40 + 2 * SUMLEN);
322 rec = rSet (rec, RFDT | RCHG, &_TheFdt,
323 82, "false", 81, "2", 49, "overview", 0);
324 vals[4] = "overview";
328 check ("L", rec, tags, vals, 7, 48);