Bump year
[yazpp-moved-to-github.git] / zlint / test-init-06.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2013 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
11 #include <zlint.h>
12
13 Zlint_test_init_06::Zlint_test_init_06()
14 {
15 }
16
17 Zlint_test_init_06::~Zlint_test_init_06()
18 {
19 }
20
21 Zlint_code Zlint_test_init_06::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 options");
28
29     /* set all options.. see what target really supports .. */
30     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
31     ODR_MASK_ZERO(init->options);
32     int i;
33     for (i = 0; i <= 24; i++)
34         ODR_MASK_SET(init->options, i);
35
36     int r = z->send_Z_PDU(apdu, &len);
37     if (r < 0)
38     {
39         z->msg_check_fail("unable to send init request");
40         return TEST_FINISHED;
41     }
42     return TEST_CONTINUE;
43 }
44
45 Zlint_code Zlint_test_init_06::recv_gdu(Zlint *z, Z_GDU *gdu)
46 {
47     if (gdu->which == Z_GDU_Z3950 &&
48         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
49     {
50         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
51
52         if (init->options)
53         {
54             int i;
55             int no_set = 0;
56             int no_reset = 0;
57             for (i = 0; i <= 24; i++)
58                 if (ODR_MASK_GET(init->options, i))
59                     no_set++;
60                 else
61                     no_reset++;
62             if (no_set < 2)
63             {
64                 z->msg_check_fail("suspicuously few option bits set");
65                 return TEST_FINISHED;
66             }
67             if (no_reset == 0)
68             {
69                 z->msg_check_fail("suspicuously many option bits set");
70                 return TEST_FINISHED;
71             }
72         }
73         z->msg_check_ok();
74     }
75     else
76         z->msg_check_fail("did not receive init response as expected");
77     return TEST_FINISHED;
78 }
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