Updates for yaz/ylog.h
[yazpp-moved-to-github.git] / zlint / test-init-03.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-03.cpp,v 1.2 2004-11-30 21:10:31 adam Exp $
6  */
7
8 #include <yaz/ylog.h>
9
10 #include <zlint.h>
11
12 Zlint_test_init_03::Zlint_test_init_03()
13 {
14 }
15
16 Zlint_test_init_03::~Zlint_test_init_03()
17 {
18 }
19
20 Zlint_code Zlint_test_init_03::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 V9 init");
27
28     ODR_MASK_ZERO(init->protocolVersion);
29     int i;
30     for (i = 0; i< 9; i++)
31         ODR_MASK_SET(init->protocolVersion, i);
32     
33     int r = z->send_Z_PDU(apdu, &len);
34     if (r < 0)
35     {
36         z->msg_check_fail("unable to send init request");
37         return TEST_FINISHED;
38     }
39     return TEST_CONTINUE;
40 }
41
42 Zlint_code Zlint_test_init_03::recv_gdu(Zlint *z, Z_GDU *gdu)
43 {
44     if (gdu->which == Z_GDU_Z3950 &&
45         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
46     {
47         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
48         int ver = z->initResponseGetVersion(init);
49         int result = init->result ? *init->result : 0;
50
51         if (ver < 2 || ver > 5)
52             z->msg_check_fail("%sgot version %d, expected 2-5", ver);
53         z->msg_check_ok();
54     }
55     else
56         z->msg_check_fail("did not receive init response as expected");
57     return TEST_FINISHED;
58 }
59
60