buildconf.sh --disable-shared --enable-static
[yazpp-moved-to-github.git] / zlint / test-init-05.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-05.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 #define REFID_BUF1 "zlint\000check1"
13 #define REFID_LEN1 12
14 #define REFID_BUF2 "zlint\000check2"
15 #define REFID_LEN2 12
16
17 Zlint_test_init_05::Zlint_test_init_05()
18 {
19     m_init_response_no = 0;
20 }
21
22 Zlint_test_init_05::~Zlint_test_init_05()
23 {
24 }
25
26 Zlint_code Zlint_test_init_05::init(Zlint *z)
27 {
28     int len;
29     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
30     Z_InitRequest *init = apdu->u.initRequest;
31
32     z->msg_check_for("for double init");
33     
34     /* send double init with differnet refID's */
35     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
36     ODR_MASK_SET(init->options, Z_Options_concurrentOperations);
37     init->referenceId = z->mk_refid(REFID_BUF1, REFID_LEN1);
38
39     int r = z->send_Z_PDU(apdu, &len);
40     if (r < 0)
41     {
42         z->msg_check_fail("unable to send init request");
43         return TEST_FINISHED;
44     }
45         
46     apdu = z->create_Z_PDU(Z_APDU_initRequest);
47     init = apdu->u.initRequest;
48     
49     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
50     ODR_MASK_SET(init->options, Z_Options_concurrentOperations);
51     
52     init->referenceId = z->mk_refid(REFID_BUF2, REFID_LEN2);
53
54     r = z->send_Z_PDU(apdu, &len);
55     if (r < 0)
56     {
57         z->msg_check_fail("unable to send init request");
58         return TEST_FINISHED;
59     }
60     return TEST_CONTINUE;
61 }
62
63 Zlint_code Zlint_test_init_05::recv_gdu(Zlint *z, Z_GDU *gdu)
64 {
65     if (gdu->which == Z_GDU_Z3950 &&
66         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
67     {
68         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
69         int result = init->result ? *init->result : 0;
70         
71         if (m_init_response_no == 0)
72         {
73             if (!init->referenceId)
74             {
75                 z->msg_check_fail("missing referenceID from "
76                                   "first init response");
77                 return TEST_FINISHED;
78             }
79             else if (init->referenceId->len != REFID_LEN1
80                      || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1))
81             {
82                 z->msg_check_fail("reference ID does not match from "
83                                   "first init response");
84                 return TEST_FINISHED;
85             }
86         }
87         else
88         {
89             if (!init->referenceId)
90                 z->msg_check_fail("missing referenceID from "
91                                   "second init response");
92             else if (init->referenceId->len != REFID_LEN2
93                      || memcmp(init->referenceId->buf, REFID_BUF2, REFID_LEN2))
94                 z->msg_check_fail("reference ID does not match from "
95                                   "second init response");
96         }
97         
98         if (!result)
99         {
100             z->msg_check_fail("init rejected (result false)");
101             return TEST_FINISHED;
102         }
103         else
104         {
105             if (m_init_response_no == 0)
106             {
107                 m_init_response_no++;
108                 return TEST_CONTINUE;
109             }
110             else
111                 z->msg_check_ok();
112         }
113     }
114     else
115         z->msg_check_fail("did not receive init response as expected");
116     return TEST_FINISHED;
117 }
118
119
120 /*
121  * Local variables:
122  * c-basic-offset: 4
123  * indent-tabs-mode: nil
124  * End:
125  * vim: shiftwidth=4 tabstop=8 expandtab
126  */
127