Tests as separate object implementations
[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.1 2004-03-25 23:14:07 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         int ver = z->initResponseGetVersion(init);
53         int result = init->result ? *init->result : 0;
54         
55         if (m_no * m_no * 100000 + 2000 < *init->maximumRecordSize)
56             z->msg_check_fail("maximumRecordSize bigger than proposed size");
57         if (m_no * m_no * 100000 + 2000 < *init->preferredMessageSize)
58             z->msg_check_fail("preferredMessage bigger than proposed size");
59         z->msg_check_ok();
60         if (m_no < 2)
61         {
62             m_no++;
63             return TEST_REOPEN;
64         }
65     }
66     else
67         z->msg_check_fail("did not receive init response as expected");
68     return TEST_FINISHED;
69 }
70
71 Zlint_code Zlint_test_init_08::recv_fail(Zlint *z, int reason)
72 {
73     z->msg_check_fail("target closed connection");
74     if (m_no < 2)
75     {
76         m_no++;
77         return TEST_REOPEN;
78     }
79     return TEST_FINISHED;
80 }
81