Updates for yaz/ylog.h
[yazpp-moved-to-github.git] / zlint / test-init-04.cpp
1 /*
2  * Copyright (c) 2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: test-init-04.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 #define REFID_BUF1 "zlint\000check1"
13 #define REFID_LEN1 12
14
15 Zlint_test_init_04::Zlint_test_init_04()
16 {
17 }
18
19 Zlint_test_init_04::~Zlint_test_init_04()
20 {
21 }
22
23 Zlint_code Zlint_test_init_04::init(Zlint *z)
24 {
25     int len;
26     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
27     Z_InitRequest *init = apdu->u.initRequest;
28
29     z->msg_check_for("for referenceID for init");
30
31     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
32     init->referenceId = z->mk_refid(REFID_BUF1, REFID_LEN1);
33
34     int r = z->send_Z_PDU(apdu, &len);
35     if (r < 0)
36     {
37         z->msg_check_fail("unable to send init request");
38         return TEST_FINISHED;
39     }
40     return TEST_CONTINUE;
41 }
42
43 Zlint_code Zlint_test_init_04::recv_gdu(Zlint *z, Z_GDU *gdu)
44 {
45     if (gdu->which == Z_GDU_Z3950 &&
46         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
47     {
48         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
49         int ver = z->initResponseGetVersion(init);
50         int result = init->result ? *init->result : 0;
51         
52         if (!init->referenceId)
53             z->msg_check_fail("missing referenceID from init response");
54         else if (init->referenceId->len != REFID_LEN1
55                  || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1))
56             z->msg_check_fail("reference ID does not match");
57         z->msg_check_ok();
58     }
59     else
60         z->msg_check_fail("did not receive init response as expected");
61     return TEST_FINISHED;
62 }
63