1 /* This file is part of the yazpp toolkit.
2 * Copyright (C) 1998-2009 Index Data and Mike Taylor
3 * See the file LICENSE for details.
7 #include <yaz/pquery.h>
11 static const char *try_scan [] = {
18 Zlint_test_scan_01::Zlint_test_scan_01()
23 Zlint_test_scan_01::~Zlint_test_scan_01()
27 Zlint_code Zlint_test_scan_01::init(Zlint *z)
30 Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
31 Z_InitRequest *init = apdu->u.initRequest;
34 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
35 ODR_MASK_SET(init->options, Z_Options_namedResultSets);
36 ODR_MASK_SET(init->options, Z_Options_scan);
38 int r = z->send_Z_PDU(apdu, &len);
41 z->msg_check_fail("unable to send init request");
47 Zlint_code Zlint_test_scan_01::sendTest(Zlint *z)
49 if (try_scan[m_scan_no])
52 z->msg_check_for("scan support %s", try_scan[m_scan_no]);
54 Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_scanRequest);
55 YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
56 Z_ScanRequest *sr = apdu->u.scanRequest;
57 sr->termListAndStartPoint = yaz_pqf_scan(pqf_parser,
62 z->getDatabase(&sr->databaseNames, &sr->num_databaseNames);
64 yaz_pqf_destroy (pqf_parser);
65 z->send_Z_PDU(apdu, &len);
72 Zlint_code Zlint_test_scan_01::recv_gdu(Zlint *z, Z_GDU *gdu)
74 if (gdu->which == Z_GDU_Z3950 &&
75 gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
77 Z_InitResponse *init = gdu->u.z3950->u.initResponse;
78 int ver = z->initResponseGetVersion(init);
79 int result = init->result ? *init->result : 0;
80 if (ver > 3 || ver < 2)
81 z->msg_check_fail("got version %d, expected 2 or 3", ver);
84 z->msg_check_fail("init rejected (result false)");
87 else if (!ODR_MASK_GET(init->options, Z_Options_scan))
89 z->msg_check_notapp();
90 z->msg_check_info("scan unsupported");
99 else if (gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_scanResponse)
101 Z_ScanResponse *sr = gdu->u.z3950->u.scanResponse;
102 if (sr->entries->nonsurrogateDiagnostics)
105 z->msg_check_info("scan NSD for %s", try_scan[m_scan_no]);
107 else if (sr->entries->entries && sr->entries->num_entries > 0)
113 z->msg_check_fail("scan no entries/diagnostics for %s",
114 try_scan[m_scan_no]);
120 z->msg_check_fail("did not receive init response as expected");
121 return TEST_FINISHED;
124 Zlint_code Zlint_test_scan_01::recv_fail(Zlint *z, int reason)
127 z->msg_check_fail("target closed connection");
128 return TEST_FINISHED;
133 * indent-tabs-mode: nil
135 * vim: shiftwidth=4 tabstop=8 expandtab