WIN32 updates: ZOOM runs, nmem_init/nmem_exit called in DllMain.
[yaz-moved-to-github.git] / zoom / zoomtst7.c
1 /*
2  * $Id: zoomtst7.c,v 1.2 2001-10-24 12:24:43 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_search s = Z3950_search_create ();
55                 
56                 sprintf (query, "i%dr%d", i, j);
57                 
58                 if (Z3950_search_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_options_set (o, "count", "2");
69                 Z3950_resultset_records (r[j], 0, 0);  /* first two */
70                 
71                 Z3950_options_set (o, "start", "1");
72                 Z3950_options_set (o, "count", "2");
73                 Z3950_resultset_records (r[j], recs, &recs_count);  /* third */
74                 Z3950_resultset_records (r[j], 0, 0);  /* ignored */
75
76                 if (Z3950_resultset_size (r[j]) > 2)
77                 {
78                     if (!recs[0])
79                     {
80                         fprintf (stderr, "\nrecord missing\n");
81                         exit (1);
82                     }
83                 }
84                 Z3950_record_destroy (recs[0]);
85                 Z3950_record_destroy (recs[1]);
86                 
87                 Z3950_search_destroy (s);
88
89                 putchar ('.');
90                 if (block > 0)
91                     while (Z3950_event (1, &z))
92                         ;
93             }
94             for (j = 0; j<i; j++)
95                 Z3950_resultset_destroy (r[j]);
96             Z3950_connection_destroy (z);
97             for (; j < 10; j++)
98                 Z3950_resultset_destroy (r[j]);
99             printf ("10 searches, 20 presents done\n");
100         }
101         
102         for (i = 0; i<1; i++)
103         {
104             Z3950_search s = Z3950_search_create ();
105             char host[40];
106
107             printf ("session %2d", i+10);
108             sprintf (host, "localhost:9999/%d", i);
109             z = Z3950_connection_create (o);
110             Z3950_connection_connect (z, host, 0);
111             
112             for (j = 0; j < 10; j++)
113             {
114                 char query[40];
115                 
116                 sprintf (query, "i%dr%d", i, j);
117                 
118                 Z3950_options_set (o, "count", "0");
119                 
120                 r[j] = Z3950_connection_search_pqf (z, query);
121
122                 putchar ('.');
123                 if (block > 0)
124                     while (Z3950_event (1, &z))
125                         ;
126             }
127             Z3950_connection_destroy (z);
128             
129             Z3950_options_set (o, "count", "1");
130             for (j = 0; j < 10; j++)
131             {
132                 Z3950_resultset_records (r[j], 0, 0);
133                 if (block > 0)
134                     while (Z3950_event (1, &z))
135                         ;
136             }
137             for (j = 0; j < 10; j++)
138                 Z3950_resultset_destroy (r[j]);
139             Z3950_search_destroy (s);
140             printf ("10 searches, 10 ignored presents done\n");
141         }
142     }
143     Z3950_options_destroy (o);
144     exit (0);
145 }
146
147
148