2 * $Id: testclient.c,v 1.3 2006-05-10 08:13:35 adam Exp $
4 * Z39.50 client specifically for Zebra testing.
14 #include <yaz/xmalloc.h>
15 #include <yaz/options.h>
18 char *prog = "testclient";
20 int main(int argc, char **argv)
25 const char *errmsg, *addinfo;
31 int retrieve_number = 0;
32 int retrieve_offset = 0;
38 while ((ret = options("d:n:o:f:c:", argv, argc, &arg)) != -2)
44 target = xstrdup(arg);
49 delay_sec = atoi(arg);
52 retrieve_number = atoi(arg);
55 retrieve_offset = atoi(arg);
58 format = xstrdup(arg);
61 check_count = atoi(arg);
64 printf ("%s: unknown option %s\n", prog, arg);
65 printf ("usage:\n%s [options] target query \n", prog);
66 printf (" eg. indexdata.dk/gils computer\n");
71 if (!target || !target)
73 printf ("%s: missing target/query\n", prog);
74 printf ("usage:\n%s [options] target query \n", prog);
75 printf (" eg. bagel.indexdata.dk/gils computer\n");
76 printf ("Options:\n");
77 printf (" -n num number of records to fetch. Default: 0.\n");
78 printf (" -o off offset for records - counting from 0.\n");
79 printf (" -f format set record syntax. Default: none\n");
80 printf (" -d sec delay a number of seconds before exit.\n");
81 printf (" -c count expect count hits, fail if not.\n");
84 z = ZOOM_connection_new (target, 0);
86 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
88 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
92 r = ZOOM_connection_search_pqf (z, query);
93 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
95 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
96 if (check_count != -1)
101 printf ("Result count: %d\n", ZOOM_resultset_size(r));
102 if (check_count != -1 && check_count != ZOOM_resultset_size(r))
104 printf("Wrong number of hits, expected %d, got %d\n",
105 check_count, ZOOM_resultset_size(r) );
110 ZOOM_resultset_option_set(r, "preferredRecordSyntax", format);
111 for (pos = 0; pos < retrieve_number; pos++)
116 ZOOM_resultset_record(r, pos + retrieve_offset),
120 fwrite (rec, 1, len, stdout);
124 ZOOM_resultset_destroy (r);
125 ZOOM_connection_destroy (z);
131 * indent-tabs-mode: nil
133 * vim: shiftwidth=4 tabstop=8 expandtab