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