Updated copyright headers.
[yazpp-moved-to-github.git] / zlint / test-init-01.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2008 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_01::Zlint_test_init_01()
11 {
12 }
13
14 Zlint_test_init_01::~Zlint_test_init_01()
15 {
16 }
17
18 Zlint_code Zlint_test_init_01::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 V3 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     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
30     
31     int r = z->send_Z_PDU(apdu, &len);
32     if (r < 0)
33     {
34         z->msg_check_fail("unable to send init request");
35         return TEST_FINISHED;
36     }
37     return TEST_CONTINUE;
38 }
39
40 Zlint_code Zlint_test_init_01::recv_gdu(Zlint *z, Z_GDU *gdu)
41 {
42     if (gdu->which == Z_GDU_Z3950 &&
43         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
44     {
45         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
46         int ver = z->initResponseGetVersion(init);
47         int result = init->result ? *init->result : 0;
48         if (ver > 3 || ver < 2)
49             z->msg_check_fail("got version %d, expected 2 or 3", ver);
50         if (!result)
51         {
52             z->msg_check_fail("init rejected (result false)");
53             return TEST_FINISHED;
54         }
55         else
56             z->msg_check_ok();
57     }
58     else
59         z->msg_check_fail("did not receive init response as expected");
60     return TEST_FINISHED;
61 }
62
63
64 /*
65  * Local variables:
66  * c-basic-offset: 4
67  * indent-tabs-mode: nil
68  * End:
69  * vim: shiftwidth=4 tabstop=8 expandtab
70  */
71