ZOOM changes.
[yaz-moved-to-github.git] / zoom / zoomtst7.c
1 /*
2  * $Id: zoomtst7.c,v 1.3 2001-11-06 17:05:19 adam Exp $
3  *
4  * API test..
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
14 #include <yaz/zoom.h>
15
16 int main(int argc, char **argv)
17 {
18     int i, j, block;
19     Z3950_connection z;
20     Z3950_resultset r[10];  /* and result sets .. */
21     Z3950_options o;
22
23     o = Z3950_options_create ();
24
25     for (block = 0; block < 3; block++)
26     {
27         switch (block)
28         {
29         case 0:
30             printf ("blocking - not calling Z3950_events\n");
31             break;
32         case 1:
33             printf ("blocking - calling Z3950_events\n");
34             break;
35         case 2:
36             printf ("non-blocking - calling Z3950_events\n");
37             break;
38         }
39         if (block > 1)
40             Z3950_options_set (o, "async", "1");
41         for (i = 0; i<10; i++)
42         {
43             char host[40];
44             printf ("session %2d", i);
45             sprintf (host, "localhost:9999/%d", i);
46             z = Z3950_connection_create (o);
47             Z3950_connection_connect (z, host, 0);
48             
49             for (j = 0; j < 10; j++)
50             {
51                 Z3950_record recs[2];
52                 size_t recs_count = 2;
53                 char query[40];
54                 Z3950_query s = Z3950_query_create ();
55                 
56                 sprintf (query, "i%dr%d", i, j);
57                 
58                 if (Z3950_query_prefix (s, query))
59                 {
60                     printf ("bad PQF: %s\n", query);
61                     exit (2);
62                 }
63                 Z3950_options_set (o, "start", "0");
64                 Z3950_options_set (o, "count", "0");
65                 
66                 r[j] = Z3950_connection_search (z, s); /* non-piggy */
67                 
68                 Z3950_resultset_records (r[j], recs, 0, 2);  /* first two */
69                 
70                 Z3950_resultset_records (r[j], recs, 1, 2);  /* third */
71                 Z3950_resultset_records (r[j], recs, 0, 0);  /* ignored */
72
73                 if (Z3950_resultset_size (r[j]) > 2)
74                 {
75                     if (!recs[0])
76                     {
77                         fprintf (stderr, "\nrecord missing\n");
78                         exit (1);
79                     }
80                 }
81                 Z3950_record_destroy (recs[0]);
82                 Z3950_record_destroy (recs[1]);
83                 
84                 Z3950_query_destroy (s);
85
86                 putchar ('.');
87                 if (block > 0)
88                     while (Z3950_event (1, &z))
89                         ;
90             }
91             for (j = 0; j<i; j++)
92                 Z3950_resultset_destroy (r[j]);
93             Z3950_connection_destroy (z);
94             for (; j < 10; j++)
95                 Z3950_resultset_destroy (r[j]);
96             printf ("10 searches, 20 presents done\n");
97         }
98         
99         for (i = 0; i<1; i++)
100         {
101             Z3950_query q = Z3950_query_create ();
102             char host[40];
103
104             printf ("session %2d", i+10);
105             sprintf (host, "localhost:9999/%d", i);
106             z = Z3950_connection_create (o);
107             Z3950_connection_connect (z, host, 0);
108             
109             for (j = 0; j < 10; j++)
110             {
111                 char query[40];
112                 
113                 sprintf (query, "i%dr%d", i, j);
114                 
115                 Z3950_options_set (o, "count", "0");
116                 
117                 r[j] = Z3950_connection_search_pqf (z, query);
118
119                 putchar ('.');
120                 if (block > 0)
121                     while (Z3950_event (1, &z))
122                         ;
123             }
124             Z3950_connection_destroy (z);
125             
126             for (j = 0; j < 10; j++)
127             {
128                 Z3950_resultset_records (r[j], 0, 0, 1);
129                 if (block > 0)
130                     while (Z3950_event (1, &z))
131                         ;
132             }
133             for (j = 0; j < 10; j++)
134                 Z3950_resultset_destroy (r[j]);
135             Z3950_query_destroy (q);
136             printf ("10 searches, 10 ignored presents done\n");
137         }
138     }
139     Z3950_options_destroy (o);
140     exit (0);
141 }
142
143
144