434a5a1d93a37e13537d073600dc0a350c702ae6
[yazpp-moved-to-github.git] / zlint / test-init-04.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2009 Index Data and Mike Taylor
3  * See the file LICENSE for details.
4  */
5
6 #include <yaz/log.h>
7
8 #include <zlint.h>
9
10 #define REFID_BUF1 "zlint\000check1"
11 #define REFID_LEN1 12
12
13 Zlint_test_init_04::Zlint_test_init_04()
14 {
15 }
16
17 Zlint_test_init_04::~Zlint_test_init_04()
18 {
19 }
20
21 Zlint_code Zlint_test_init_04::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 referenceID for init");
28
29     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
30     init->referenceId = z->mk_refid(REFID_BUF1, REFID_LEN1);
31
32     int r = z->send_Z_PDU(apdu, &len);
33     if (r < 0)
34     {
35         z->msg_check_fail("unable to send init request");
36         return TEST_FINISHED;
37     }
38     return TEST_CONTINUE;
39 }
40
41 Zlint_code Zlint_test_init_04::recv_gdu(Zlint *z, Z_GDU *gdu)
42 {
43     if (gdu->which == Z_GDU_Z3950 &&
44         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
45     {
46         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
47         
48         if (!init->referenceId)
49             z->msg_check_fail("missing referenceID from init response");
50         else if (init->referenceId->len != REFID_LEN1
51                  || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1))
52             z->msg_check_fail("reference ID does not match");
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 /*
61  * Local variables:
62  * c-basic-offset: 4
63  * indent-tabs-mode: nil
64  * End:
65  * vim: shiftwidth=4 tabstop=8 expandtab
66  */
67