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