2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: test-scan-01.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $
9 #include <yaz/pquery.h>
13 static const char *try_scan [] = {
20 Zlint_test_scan_01::Zlint_test_scan_01()
25 Zlint_test_scan_01::~Zlint_test_scan_01()
29 Zlint_code Zlint_test_scan_01::init(Zlint *z)
32 Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
33 Z_InitRequest *init = apdu->u.initRequest;
36 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
37 ODR_MASK_SET(init->options, Z_Options_namedResultSets);
38 ODR_MASK_SET(init->options, Z_Options_scan);
40 int r = z->send_Z_PDU(apdu, &len);
43 z->msg_check_fail("unable to send init request");
49 Zlint_code Zlint_test_scan_01::sendTest(Zlint *z)
51 if (try_scan[m_scan_no])
54 z->msg_check_for("scan support %s", try_scan[m_scan_no]);
56 Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_scanRequest);
57 YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
58 Z_ScanRequest *sr = apdu->u.scanRequest;
59 sr->termListAndStartPoint = yaz_pqf_scan(pqf_parser,
64 z->getDatabase(&sr->databaseNames, &sr->num_databaseNames);
66 yaz_pqf_destroy (pqf_parser);
67 z->send_Z_PDU(apdu, &len);
74 Zlint_code Zlint_test_scan_01::recv_gdu(Zlint *z, Z_GDU *gdu)
76 if (gdu->which == Z_GDU_Z3950 &&
77 gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
79 Z_InitResponse *init = gdu->u.z3950->u.initResponse;
80 int ver = z->initResponseGetVersion(init);
81 int result = init->result ? *init->result : 0;
82 if (ver > 3 || ver < 2)
83 z->msg_check_fail("got version %d, expected 2 or 3", ver);
86 z->msg_check_fail("init rejected (result false)");
89 else if (!ODR_MASK_GET(init->options, Z_Options_scan))
91 z->msg_check_notapp();
92 z->msg_check_info("scan unsupported");
101 else if (gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_scanResponse)
103 Z_ScanResponse *sr = gdu->u.z3950->u.scanResponse;
104 if (sr->entries->nonsurrogateDiagnostics)
107 z->msg_check_info("scan NSD for %s", try_scan[m_scan_no]);
109 else if (sr->entries->entries && sr->entries->num_entries > 0)
115 z->msg_check_fail("scan no entries/diagnostics for %s",
116 try_scan[m_scan_no]);
122 z->msg_check_fail("did not receive init response as expected");
123 return TEST_FINISHED;
126 Zlint_code Zlint_test_scan_01::recv_fail(Zlint *z, int reason)
129 z->msg_check_fail("target closed connection");
130 return TEST_FINISHED;