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