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