From 6ae9b6acff7b96dda296313b8c0e24c1626afdd8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 21 Feb 2007 09:10:19 +0000 Subject: [PATCH] Added test for checking ZOOM task/event handling. --- zoom/.cvsignore | 12 +----- zoom/Makefile.am | 7 ++-- zoom/zoomtst11.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 zoom/zoomtst11.c diff --git a/zoom/.cvsignore b/zoom/.cvsignore index 4ea6585..6c4ae35 100644 --- a/zoom/.cvsignore +++ b/zoom/.cvsignore @@ -4,16 +4,8 @@ Makefile Makefile.in libzoom.la zoomsh -zoomtst1 -zoomtst2 -zoomtst3 -zoomtst4 -zoomtst5 -zoomtst6 -zoomtst7 -zoomtst8 -zoomtst9 -zoomtst10 +zoomtst[0-9] +zoomtst1[0-1] zoom-benchmark zoom-ka zoom-bug-641 diff --git a/zoom/Makefile.am b/zoom/Makefile.am index f576da1..aff2c27 100644 --- a/zoom/Makefile.am +++ b/zoom/Makefile.am @@ -1,10 +1,10 @@ -## $Id: Makefile.am,v 1.22 2006-09-19 21:15:01 adam Exp $ -## Copyright (C) 2001, Index Data +## $Id: Makefile.am,v 1.23 2007-02-21 09:10:19 adam Exp $ +## Copyright (C) 2001-2007, Index Data AM_CPPFLAGS = -I$(top_srcdir)/include $(XML2_CFLAGS) bin_PROGRAMS = zoomsh -noinst_PROGRAMS = zoomtst1 zoomtst2 zoomtst3 zoomtst4 zoomtst5 zoomtst6 zoomtst7 zoomtst8 zoomtst9 zoomtst10 zoom-benchmark zoom-ka zoom-bug-641 +noinst_PROGRAMS = zoomtst1 zoomtst2 zoomtst3 zoomtst4 zoomtst5 zoomtst6 zoomtst7 zoomtst8 zoomtst9 zoomtst10 zoomtst11 zoom-benchmark zoom-ka zoom-bug-641 LDADD = ../src/libyaz.la $(READLINE_LIBS) @@ -18,6 +18,7 @@ zoomtst7_SOURCES = zoomtst7.c zoomtst8_SOURCES = zoomtst8.c zoomtst9_SOURCES = zoomtst9.c zoomtst10_SOURCES = zoomtst10.c +zoomtst11_SOURCES = zoomtst11.c zoomsh_SOURCES = zoomsh.c zoom_benchmark_SOURCES = zoom-benchmark.c zoom_ka_SOURCES = zoom-ka.c diff --git a/zoom/zoomtst11.c b/zoom/zoomtst11.c new file mode 100644 index 0000000..a3ce111 --- /dev/null +++ b/zoom/zoomtst11.c @@ -0,0 +1,112 @@ +/* $Id: zoomtst11.c,v 1.1 2007-02-21 09:10:19 adam Exp $ */ + +/** \file zoomtst11.c + \brief Asynchronous single-target which tests event/error handling +*/ + +#include +#include + +#include + +void probe_package(ZOOM_connection z) +{ + int i; + for (i = 1; i<10; i++) + { + ZOOM_package pkg = ZOOM_connection_package(z, 0); + ZOOM_package_option_set(pkg, "action", "recordInsert"); + ZOOM_package_option_set(pkg, "record", "1234"); + ZOOM_package_send(pkg, "update"); + } +} + +void probe_search(ZOOM_connection z, int start, int error) +{ + char pqf_str[100]; + ZOOM_resultset set; + + /* provoke error with yaz-ztest */ + if (error) + ZOOM_connection_option_set(z, "databaseName", "x"); + + sprintf(pqf_str, "@attr 1=%d water", start); + printf("sending search %s\n", pqf_str); + set = ZOOM_connection_search_pqf (z, pqf_str); + ZOOM_resultset_destroy(set); + + /* restore database */ + if (error) + ZOOM_connection_option_set(z, "databaseName", "Default"); +} + +int main(int argc, char **argv) +{ + ZOOM_connection z; + int error; + int use = 0; + const char *errmsg, *addinfo, *diagset; + + if (argc < 2) + { + fprintf (stderr, "usage:\n%s target\n", *argv); + fprintf (stderr, + "Verify: asynchronous single-target client\n"); + exit (1); + } + + /* create connection (don't connect yet) */ + z = ZOOM_connection_create(0); + + /* option: set sru/get operation (only applicable if http: is used) */ + ZOOM_connection_option_set (z, "sru", "post"); + + /* option: set async operation */ + ZOOM_connection_option_set (z, "async", "1"); + + /* connect to target and initialize */ + ZOOM_connection_connect (z, argv[1], 0); + + probe_search(z, use, 1); + + /* block here: only one connection */ + while (ZOOM_event (1, &z)) + { + int ev = ZOOM_connection_last_event(z); + if (ev == ZOOM_EVENT_RECV_SEARCH) + { + int idle = ZOOM_connection_is_idle(z); + /* see if any error occurred */ + if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset))) + { + fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error, + addinfo); + + } + else /* OK print hit count */ + printf ("Search OK\n"); + printf("idle=%d\n", idle); + if (idle) + { + ZOOM_connection_connect(z, 0, 0); /* allow reconnect */ + + if (++use <= 10) + { + probe_search(z, use, use&1); + } + printf("Press enter\n"); + getchar(); + } + } + } + ZOOM_connection_destroy (z); + exit (0); +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4