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