Expanded tabs in all source files. Added vim/emacs local variables
[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.4 2005-06-25 15:53:21 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         int ver = z->initResponseGetVersion(init);
51         int result = init->result ? *init->result : 0;
52         
53         if (init->options)
54         {
55             int i;
56             int no_set = 0;
57             int no_reset = 0;
58             for (i = 0; i <= 24; i++)
59                 if (ODR_MASK_GET(init->options, i))
60                     no_set++;
61                 else
62                     no_reset++;
63             if (no_set < 2)
64             {
65                 z->msg_check_fail("suspicuously few option bits set");
66                 return TEST_FINISHED;
67             }
68             if (no_reset == 0)
69             {
70                 z->msg_check_fail("suspicuously many option bits set");
71                 return TEST_FINISHED;
72             }
73         }
74         z->msg_check_ok();
75     }
76     else
77         z->msg_check_fail("did not receive init response as expected");
78     return TEST_FINISHED;
79 }
80
81
82 /*
83  * Local variables:
84  * c-basic-offset: 4
85  * indent-tabs-mode: nil
86  * End:
87  * vim: shiftwidth=4 tabstop=8 expandtab
88  */
89