Remove unused variables
[yazpp-moved-to-github.git] / zlint / test-init-07.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-07.cpp,v 1.5 2005-08-11 18:53:01 adam Exp $
6  */
7
8 #include <yaz/log.h>
9 #include <yaz/charneg.h>
10 #include <yaz/otherinfo.h>
11
12 #include <zlint.h>
13
14 Zlint_test_init_07::Zlint_test_init_07()
15 {
16 }
17
18 Zlint_test_init_07::~Zlint_test_init_07()
19 {
20 }
21
22 Zlint_code Zlint_test_init_07::init(Zlint *z)
23 {
24     int len;
25     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
26     Z_InitRequest *init = apdu->u.initRequest;
27     Z_OtherInformation **oi;
28
29     z->msg_check_for("for character set negotiation");
30     
31     /* set all options.. see what target really supports .. */
32     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
33     yaz_oi_APDU(apdu, &oi);
34     if (!oi)
35     {
36         z->msg_check_fail("encoding failure");
37         return TEST_FINISHED;
38     }
39     else
40     {
41         Z_OtherInformationUnit *p0;
42         const char *negotiationCharset[] = {
43             "UTF-8",
44             "UTF-16",
45             "UCS-2",
46             "UCS-4",
47             "ISO-8859-1"
48         };
49         char *yazLang = 0;
50         
51         if ((p0=yaz_oi_update(oi, z->odr_encode(), NULL, 0, 0))) {
52             ODR_MASK_SET(init->options, Z_Options_negotiationModel);
53             
54             p0->which = Z_OtherInfo_externallyDefinedInfo;
55             p0->information.externallyDefinedInfo =
56                 
57                 yaz_set_proposal_charneg(
58                     z->odr_encode(),
59                     negotiationCharset, 5,
60                     (const char**)&yazLang, yazLang ? 1 : 0, 1);
61         }
62     }
63     int r = z->send_Z_PDU(apdu, &len);
64     if (r < 0)
65     {
66         z->msg_check_fail("unable to send init request");
67         return TEST_FINISHED;
68     }
69     return TEST_CONTINUE;
70 }
71
72 Zlint_code Zlint_test_init_07::recv_gdu(Zlint *z, Z_GDU *gdu)
73 {
74     if (gdu->which == Z_GDU_Z3950 &&
75         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
76     {
77         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
78
79         if (ODR_MASK_GET(init->options, Z_Options_negotiationModel))
80         {
81             Z_CharSetandLanguageNegotiation *p =
82                 yaz_get_charneg_record(init->otherInfo);
83             
84             if (p) {
85                 
86                 char *charset=NULL, *lang=NULL;
87                 int selected;
88                 NMEM m = nmem_create();
89                 
90                 yaz_get_response_charneg(m, p, &charset, &lang,
91                                          &selected);
92                 z->msg_check_ok();
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 );
96                 nmem_destroy(m);
97                 return TEST_FINISHED;
98             }
99         }
100         z->msg_check_notapp();
101     }
102     else
103         z->msg_check_fail("did not receive init response as expected");
104     return TEST_FINISHED;
105 }
106
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * indent-tabs-mode: nil
112  * End:
113  * vim: shiftwidth=4 tabstop=8 expandtab
114  */
115