Changed IPDU_Observer's interface WRT close.
[yazpp-moved-to-github.git] / zlint / test-init-08.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-08.cpp,v 1.5 2005-08-11 18:53:01 adam Exp $
6  */
7
8 #include <yaz/log.h>
9 #include <yaz/charneg.h>
10 #include <yaz/otherinfo.h>
11
12 #include <zlint.h>
13
14 Zlint_test_init_08::Zlint_test_init_08()
15 {
16     m_no = 0;
17 }
18
19 Zlint_test_init_08::~Zlint_test_init_08()
20 {
21 }
22
23 Zlint_code Zlint_test_init_08::init(Zlint *z)
24 {
25     int len;
26     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
27     Z_InitRequest *init = apdu->u.initRequest;
28
29     z->msg_check_for("for init message sizes %d", m_no);
30     
31     /* set all options.. see what target really supports .. */
32     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
33
34     *init->maximumRecordSize = m_no * m_no * 100000 + 2000;
35     *init->preferredMessageSize = m_no * m_no *100000 + 2000;
36
37     int r = z->send_Z_PDU(apdu, &len);
38     if (r < 0)
39     {
40         z->msg_check_fail("unable to send init request");
41         return TEST_FINISHED;
42     }
43     return TEST_CONTINUE;
44 }
45
46 Zlint_code Zlint_test_init_08::recv_gdu(Zlint *z, Z_GDU *gdu)
47 {
48     if (gdu->which == Z_GDU_Z3950 &&
49         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
50     {
51         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
52         
53         if (m_no * m_no * 100000 + 2000 < *init->maximumRecordSize)
54             z->msg_check_fail("maximumRecordSize bigger than proposed size");
55         if (m_no * m_no * 100000 + 2000 < *init->preferredMessageSize)
56             z->msg_check_fail("preferredMessage bigger than proposed size");
57         z->msg_check_ok();
58         if (m_no < 2)
59         {
60             m_no++;
61             return TEST_REOPEN;
62         }
63     }
64     else
65         z->msg_check_fail("did not receive init response as expected");
66     return TEST_FINISHED;
67 }
68
69 Zlint_code Zlint_test_init_08::recv_fail(Zlint *z, int reason)
70 {
71     z->msg_check_fail("target closed connection");
72     if (m_no < 2)
73     {
74         m_no++;
75         return TEST_REOPEN;
76     }
77     return TEST_FINISHED;
78 }
79
80 /*
81  * Local variables:
82  * c-basic-offset: 4
83  * indent-tabs-mode: nil
84  * End:
85  * vim: shiftwidth=4 tabstop=8 expandtab
86  */
87