Ignore more files
[yazpp-moved-to-github.git] / zlint / test-init-06.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-06.cpp,v 1.5 2005-08-11 18:53:01 adam Exp $
6  */
7
8 #include <yaz/log.h>
9
10 #include <zlint.h>
11
12 Zlint_test_init_06::Zlint_test_init_06()
13 {
14 }
15
16 Zlint_test_init_06::~Zlint_test_init_06()
17 {
18 }
19
20 Zlint_code Zlint_test_init_06::init(Zlint *z)
21 {
22     int len;
23     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
24     Z_InitRequest *init = apdu->u.initRequest;
25
26     z->msg_check_for("for init options");
27     
28     /* set all options.. see what target really supports .. */
29     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
30     ODR_MASK_ZERO(init->options);
31     int i;
32     for (i = 0; i <= 24; i++)
33         ODR_MASK_SET(init->options, i);
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_06::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 (init->options)
52         {
53             int i;
54             int no_set = 0;
55             int no_reset = 0;
56             for (i = 0; i <= 24; i++)
57                 if (ODR_MASK_GET(init->options, i))
58                     no_set++;
59                 else
60                     no_reset++;
61             if (no_set < 2)
62             {
63                 z->msg_check_fail("suspicuously few option bits set");
64                 return TEST_FINISHED;
65             }
66             if (no_reset == 0)
67             {
68                 z->msg_check_fail("suspicuously many option bits set");
69                 return TEST_FINISHED;
70             }
71         }
72         z->msg_check_ok();
73     }
74     else
75         z->msg_check_fail("did not receive init response as expected");
76     return TEST_FINISHED;
77 }
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