2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: test-init-07.cpp,v 1.5 2005-08-11 18:53:01 adam Exp $
9 #include <yaz/charneg.h>
10 #include <yaz/otherinfo.h>
14 Zlint_test_init_07::Zlint_test_init_07()
18 Zlint_test_init_07::~Zlint_test_init_07()
22 Zlint_code Zlint_test_init_07::init(Zlint *z)
25 Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
26 Z_InitRequest *init = apdu->u.initRequest;
27 Z_OtherInformation **oi;
29 z->msg_check_for("for character set negotiation");
31 /* set all options.. see what target really supports .. */
32 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
33 yaz_oi_APDU(apdu, &oi);
36 z->msg_check_fail("encoding failure");
41 Z_OtherInformationUnit *p0;
42 const char *negotiationCharset[] = {
51 if ((p0=yaz_oi_update(oi, z->odr_encode(), NULL, 0, 0))) {
52 ODR_MASK_SET(init->options, Z_Options_negotiationModel);
54 p0->which = Z_OtherInfo_externallyDefinedInfo;
55 p0->information.externallyDefinedInfo =
57 yaz_set_proposal_charneg(
59 negotiationCharset, 5,
60 (const char**)&yazLang, yazLang ? 1 : 0, 1);
63 int r = z->send_Z_PDU(apdu, &len);
66 z->msg_check_fail("unable to send init request");
72 Zlint_code Zlint_test_init_07::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;
79 if (ODR_MASK_GET(init->options, Z_Options_negotiationModel))
81 Z_CharSetandLanguageNegotiation *p =
82 yaz_get_charneg_record(init->otherInfo);
86 char *charset=NULL, *lang=NULL;
88 NMEM m = nmem_create();
90 yaz_get_response_charneg(m, p, &charset, &lang,
93 z->msg_check_info("Accepted character set : %s", charset);
94 z->msg_check_info("Accepted code language : %s", lang ? lang : "none");
95 z->msg_check_info("Accepted records in ...: %d", selected );
100 z->msg_check_notapp();
103 z->msg_check_fail("did not receive init response as expected");
104 return TEST_FINISHED;
111 * indent-tabs-mode: nil
113 * vim: shiftwidth=4 tabstop=8 expandtab