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