1 /* This file is part of the yazpp toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
10 #include <yaz/pquery.h>
14 static const char *try_scan [] = {
21 Zlint_test_scan_01::Zlint_test_scan_01()
26 Zlint_test_scan_01::~Zlint_test_scan_01()
30 Zlint_code Zlint_test_scan_01::init(Zlint *z)
33 Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
34 Z_InitRequest *init = apdu->u.initRequest;
37 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
38 ODR_MASK_SET(init->options, Z_Options_namedResultSets);
39 ODR_MASK_SET(init->options, Z_Options_scan);
41 int r = z->send_Z_PDU(apdu, &len);
44 z->msg_check_fail("unable to send init request");
50 Zlint_code Zlint_test_scan_01::sendTest(Zlint *z)
52 if (try_scan[m_scan_no])
55 z->msg_check_for("scan support %s", try_scan[m_scan_no]);
57 Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_scanRequest);
58 YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
59 Z_ScanRequest *sr = apdu->u.scanRequest;
60 sr->termListAndStartPoint = yaz_pqf_scan(pqf_parser,
65 z->getDatabase(&sr->databaseNames, &sr->num_databaseNames);
67 yaz_pqf_destroy (pqf_parser);
68 z->send_Z_PDU(apdu, &len);
75 Zlint_code Zlint_test_scan_01::recv_gdu(Zlint *z, Z_GDU *gdu)
77 if (gdu->which == Z_GDU_Z3950 &&
78 gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
80 Z_InitResponse *init = gdu->u.z3950->u.initResponse;
81 int ver = z->initResponseGetVersion(init);
82 int result = init->result ? *init->result : 0;
83 if (ver > 3 || ver < 2)
84 z->msg_check_fail("got version %d, expected 2 or 3", ver);
87 z->msg_check_fail("init rejected (result false)");
90 else if (!ODR_MASK_GET(init->options, Z_Options_scan))
92 z->msg_check_notapp();
93 z->msg_check_info("scan unsupported");
102 else if (gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_scanResponse)
104 Z_ScanResponse *sr = gdu->u.z3950->u.scanResponse;
105 if (sr->entries->nonsurrogateDiagnostics)
108 z->msg_check_info("scan NSD for %s", try_scan[m_scan_no]);
110 else if (sr->entries->entries && sr->entries->num_entries > 0)
116 z->msg_check_fail("scan no entries/diagnostics for %s",
117 try_scan[m_scan_no]);
123 z->msg_check_fail("did not receive init response as expected");
124 return TEST_FINISHED;
127 Zlint_code Zlint_test_scan_01::recv_fail(Zlint *z, int reason)
130 z->msg_check_fail("target closed connection");
131 return TEST_FINISHED;
136 * c-file-style: "Stroustrup"
137 * indent-tabs-mode: nil
139 * vim: shiftwidth=4 tabstop=8 expandtab