Split YAZ library into two libs : libyaz.la and libyaz_server.la.
[yaz-moved-to-github.git] / zoom / zoomtst7.c
1 /* $Id: zoomtst7.c,v 1.19 2007-04-17 20:26:19 adam Exp $  */
2
3 /** \file zoomtst7.c
4     \brief Mix of operations
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <assert.h>
10
11 #include <yaz/xmalloc.h>
12 #include <yaz/nmem.h>
13 #include <yaz/log.h>
14 #include <yaz/zoom.h>
15
16 int main(int argc, char **argv)
17 {
18     int block;
19     int i, j;
20     ZOOM_connection z;
21     ZOOM_resultset r[10];  /* and result sets .. */
22     ZOOM_options o;
23
24     o = ZOOM_options_create ();
25
26     z = ZOOM_connection_new ("localhost", 9999);
27     if (ZOOM_connection_error (z, 0, 0))
28     {
29         printf ("error - couldn't connect?\n");
30         exit (1);
31     }
32         
33     ZOOM_connection_destroy (z);
34
35     for (block = 0; block < 3; block++)
36     {
37         switch (block)
38         {
39         case 0:
40             printf ("blocking - not calling ZOOM_events\n");
41             break;
42         case 1:
43             printf ("blocking - calling ZOOM_events\n");
44             break;
45         case 2:
46             printf ("non-blocking - calling ZOOM_events\n");
47             break;
48         }
49         if (block > 1)
50             ZOOM_options_set (o, "async", "1");
51         for (i = 0; i<10; i++)
52         {
53             char host[40];
54
55             printf ("session %2d", i);
56             sprintf (host, "localhost:9999/%d", i);
57             z = ZOOM_connection_create (o);
58             ZOOM_connection_connect (z, host, 0);
59             
60             for (j = 0; j < 10; j++)
61             {
62                 ZOOM_record recs[2];
63                 char query[40];
64                 ZOOM_query s = ZOOM_query_create ();
65                 
66                 sprintf (query, "i%dr%d", i, j);
67                 
68                 if (ZOOM_query_prefix (s, query))
69                 {
70                     printf ("bad PQF: %s\n", query);
71                     exit (2);
72                 }
73                 ZOOM_options_set (o, "start", "0");
74                 ZOOM_options_set (o, "count", "0");
75                 
76                 r[j] = ZOOM_connection_search (z, s); /* non-piggy */
77                 
78                 ZOOM_resultset_records (r[j], recs, 0, 2);  /* first two */
79                 
80                 ZOOM_resultset_records (r[j], recs, 1, 2);  /* third */
81
82                 ZOOM_resultset_records (r[j], recs, 0, 0);  /* ignored */
83
84                 if (ZOOM_resultset_size (r[j]) > 2)
85                 {
86                     if (!recs[0])
87                     {
88                         fprintf (stderr, "\nrecord missing\n");
89                         exit (1);
90                     }
91                 }
92                 
93                 ZOOM_query_destroy (s);
94
95                 printf (".");
96                 if (block > 0)
97                     while (ZOOM_event (1, &z))
98                         ;
99             }
100             for (j = 0; j<i; j++)
101                 ZOOM_resultset_destroy (r[j]);
102             ZOOM_connection_destroy (z);
103             for (; j < 10; j++)
104                 ZOOM_resultset_destroy (r[j]);
105             printf ("10 searches, 20 presents done\n");
106
107         }
108
109         for (i = 0; i<1; i++)
110         {
111             ZOOM_query q = ZOOM_query_create ();
112             char host[40];
113
114             printf ("session %2d", i+10);
115             sprintf (host, "localhost:9999/%d", i);
116             z = ZOOM_connection_create (o);
117             ZOOM_connection_connect (z, host, 0);
118             
119             for (j = 0; j < 10; j++)
120             {
121                 char query[40];
122                 
123                 sprintf (query, "i%dr%d", i, j);
124                 
125                 ZOOM_options_set (o, "count", "0");
126                 
127                 r[j] = ZOOM_connection_search_pqf (z, query);
128
129                 printf (".");
130                 if (block > 0)
131                     while (ZOOM_event (1, &z))
132                         ;
133             }
134
135             ZOOM_connection_destroy (z);
136             
137             for (j = 0; j < 10; j++)
138             {
139                 ZOOM_resultset_records (r[j], 0, 0, 1);
140             }
141             for (j = 0; j < 10; j++)
142                 ZOOM_resultset_destroy (r[j]);
143             ZOOM_query_destroy (q);
144             printf ("10 searches, 10 ignored presents done\n");
145         }
146
147
148         for (i = 0; i<1; i++)
149         {
150             char host[40];
151             ZOOM_scanset scan = 0;
152
153             printf ("session %2d", i);
154             sprintf (host, "localhost:9999/%d", i);
155             z = ZOOM_connection_create (o);
156             ZOOM_connection_connect (z, host, 0);
157
158             scan = ZOOM_connection_scan(z, "@attr 1=4 a");
159             if (block > 0)
160                 while (ZOOM_event (1, &z))
161                     ;
162             printf (" scan size = %ld\n", (long) ZOOM_scanset_size(scan));
163             for (j = 0; j<ZOOM_scanset_size (scan); j++)
164             {
165                 int occur, len;
166                 const char *term;
167                 term = ZOOM_scanset_term (scan, j, &occur, &len);
168                 if (term)
169                     printf ("%d %.*s %d\n", j, len, term, occur);
170                 
171             }
172             ZOOM_scanset_destroy (scan);
173             ZOOM_connection_destroy (z);
174         }
175
176     }
177     ZOOM_options_destroy (o);
178     exit (0);
179 }
180
181 /*
182  * Local variables:
183  * c-basic-offset: 4
184  * indent-tabs-mode: nil
185  * End:
186  * vim: shiftwidth=4 tabstop=8 expandtab
187  */
188