c8a5c5026e954f57cc55efecfe4521847449244d
[yazpp-moved-to-github.git] / zlint / test-init-02.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-02.cpp,v 1.5 2005-08-11 18:53:01 adam Exp $
6  */
7
8 #include <yaz/log.h>
9
10 #include <zlint.h>
11
12 Zlint_test_init_02::Zlint_test_init_02()
13 {
14 }
15
16 Zlint_test_init_02::~Zlint_test_init_02()
17 {
18 }
19
20 Zlint_code Zlint_test_init_02::init(Zlint *z)
21 {
22     int len;
23     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
24     Z_InitRequest *init = apdu->u.initRequest;
25
26     z->msg_check_for("for V2 init");
27
28     ODR_MASK_ZERO(init->protocolVersion);
29     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_1);
30     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_2);
31     
32     int r = z->send_Z_PDU(apdu, &len);
33     if (r < 0)
34     {
35         z->msg_check_fail("unable to send init request");
36         return TEST_FINISHED;
37     }
38     return TEST_CONTINUE;
39 }
40
41 Zlint_code Zlint_test_init_02::recv_gdu(Zlint *z, Z_GDU *gdu)
42 {
43     if (gdu->which == Z_GDU_Z3950 &&
44         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
45     {
46         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
47         int ver = z->initResponseGetVersion(init);
48         if (ver != 2)
49             z->msg_check_fail("got version %d, expected 2", ver);
50         z->msg_check_ok();
51     }
52     else
53         z->msg_check_fail("did not receive init response as expected");
54     return TEST_FINISHED;
55 }
56
57
58
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66