Happy new year
[yazpp-moved-to-github.git] / zlint / test-init-04.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 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 #define REFID_BUF1 "zlint\000check1"
14 #define REFID_LEN1 12
15
16 Zlint_test_init_04::Zlint_test_init_04()
17 {
18 }
19
20 Zlint_test_init_04::~Zlint_test_init_04()
21 {
22 }
23
24 Zlint_code Zlint_test_init_04::init(Zlint *z)
25 {
26     int len;
27     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
28     Z_InitRequest *init = apdu->u.initRequest;
29
30     z->msg_check_for("for referenceID for init");
31
32     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
33     init->referenceId = z->mk_refid(REFID_BUF1, REFID_LEN1);
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_04::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->referenceId)
52             z->msg_check_fail("missing referenceID from init response");
53         else if (init->referenceId->len != REFID_LEN1
54                  || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1))
55             z->msg_check_fail("reference ID does not match");
56         z->msg_check_ok();
57     }
58     else
59         z->msg_check_fail("did not receive init response as expected");
60     return TEST_FINISHED;
61 }
62
63 /*
64  * Local variables:
65  * c-basic-offset: 4
66  * c-file-style: "Stroustrup"
67  * indent-tabs-mode: nil
68  * End:
69  * vim: shiftwidth=4 tabstop=8 expandtab
70  */
71