/[webpac]/openisis/0.9.9e/pw/test.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /openisis/0.9.9e/pw/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 604 - (show annotations)
Mon Dec 27 21:49:01 2004 UTC (19 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 4028 byte(s)
import of new openisis release, 0.9.9e

1 /*
2 The Malete project - the Z39.2/Z39.50 database framework of OpenIsis.
3 Version 0.9.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.
14 See the GNU 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: test.c,v 1.3 2004/03/29 09:35:20 kripke Exp $
25 patchwork test
26 */
27
28
29 #include "../pw/pw.h"
30
31 typedef struct str str;
32
33 struct str {
34 str *nxt;
35 int len;
36 char val[1];
37 };
38
39 static int checkHash ( const char* fn )
40 {
41 char buf[8192];
42 char *p, *q, *s;
43 int k = 8192, n, j = 0, m = 0;
44 str *c = 0, *nc;
45 HTable *ht;
46 file fd;
47 if ( fOpen( &fd, fn, FIL_RD ) ) return 1;
48 ht = (HTable *) mAlloc( sizeof(HTable) );
49 hInit( ht, "unnamed table" );
50 memset( buf, 0, 8192 );
51 p = q = s = buf;
52 HSTAT(ht)
53 while ( 0 < ( n = fRead( &fd, p, k ) ) ) {
54 m += n;
55 for ( ; n > p - s; ++p ) {
56 if ( *p == LF && q < p ) {
57 int l = (p-q);
58 nc = (str *) mAlloc( sizeof(str) + l - sizeof(nc->val));
59 memcpy( nc->val, q, l );
60 nc->len = l;
61 if ( c ) {
62 nc->nxt = c;
63 }
64 c = nc;
65 q = p+1;
66 ++j;
67 }
68 }
69 k = 8192;
70 if ( q != p ) {
71 unsigned i = p-q;
72 memmove( buf, q, i );
73 p = buf + i;
74 k -= i;
75 } else
76 p = buf;
77 s = p;
78 q = buf;
79 }
80 fClose(&fd);
81 eRr( LOG_INFO, "read %u bytes, parsed %u strings", m, j );
82 for ( nc = c, j = 0; nc; nc = nc->nxt )
83 if ( hAdd( ht, nc->val, nc->len ) ) ++j;
84 eRr( LOG_INFO, "added %u strings", j );
85 HSTAT(ht)
86 for ( nc = c, j = 0; nc; nc = nc->nxt )
87 if ( hGet( ht, nc->val, nc->len ) ) ++j;
88 eRr( LOG_INFO, "got %u strings", j );
89 HSTAT(ht)
90 for ( nc = c, j = 0; nc; nc = nc->nxt )
91 if ( hDel( ht, nc->val, nc->len ) ) ++j;
92 eRr( LOG_INFO, "deleted %u strings", j );
93 HSTAT(ht)
94 return 0;
95 } /* checkHash */
96
97
98 static int checkSrv ()
99 {
100 List rec;
101
102 lInit( &rec, 0 );
103 LADD( &rec, -1, "test.W\t0x0", 10 );
104 LADD( &rec, 33, "blabloaab", 9 );
105 if ( dispatch( rec.fld ) )
106 return eRr( LOG_DEBUG, "single write failed" );
107 SEOR(env.out);
108
109 lClr(&rec);
110 LADD( &rec, -1, "test.W", 6 );
111 LADD( &rec, -3, "0", 1 );
112 LADD( &rec, 42, "fourtytwo", 9 );
113 LADD( &rec, 43, "fourtythree", 11 );
114 LADD( &rec, -3, "0", 1 );
115 LADD( &rec, 52, "fiftytwo", 8 );
116 LADD( &rec, 53, "fiftythree", 10 );
117 if ( 0 > dispatch( rec.fld ) )
118 return eRr( LOG_DEBUG, "multi write failed" );
119 SEOR(env.out);
120
121 lClr(&rec);
122 LADDS( &rec, -1, "test.;\tR\t3\t;R\t56\t0" );
123 if ( 0 > dispatch( rec.fld ) )
124 return eRr( LOG_DEBUG, "read failed" );
125 SEOR(env.out);
126 return 0;
127 } /* checkSrv */
128
129
130 /* ************************************************************
131 */
132
133 int main ( int argc, const char **argv )
134 {
135 List arg;
136 Ses s;
137 Fld cmd;
138
139 lVar( lInit( &arg, 0 ), argc-1, argv+1 );
140 cInit( &arg, 0, 0 );
141 sInit(ses = &s);
142 if ( !VPRI( &cmd, arg.fld ) ) {
143 eRr( 0, "tss tss" );
144 return 0;
145 }
146 switch ( cmd.val[0] ) {
147 case 'h':
148 if ( vGet( &cmd, arg.fld, "d" ) && 128 > cmd.len ) {
149 char name[128];
150 memcpy( name, cmd.val, cmd.len );
151 name[cmd.len] = 0;
152 eRr( LOG_INFO, "checking hashtable. file: %s", name );
153 if ( checkHash(name) )
154 eRr( LOG_ERROR, "hashtable test failed" );
155 }
156 break;
157 case 's':
158 if ( checkSrv() )
159 eRr( LOG_ERROR, "server test failed" );
160 break;
161 case 'i': {
162 List in;
163 FIL_DEFBUF(env.in);
164 lInit(&in, 0);
165 while ( fGetr(lClr(&in), &fb) ) {
166 dispatch(in.fld);
167 SEOR(env.out);
168 }
169 }
170 }
171 return 0;
172 } /* main */

  ViewVC Help
Powered by ViewVC 1.1.26