2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: test-init-05.cpp,v 1.1 2004-03-25 23:14:07 adam Exp $
12 #define REFID_BUF1 "zlint\000check1"
14 #define REFID_BUF2 "zlint\000check2"
17 Zlint_test_init_05::Zlint_test_init_05()
19 m_init_response_no = 0;
22 Zlint_test_init_05::~Zlint_test_init_05()
26 Zlint_code Zlint_test_init_05::init(Zlint *z)
29 Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
30 Z_InitRequest *init = apdu->u.initRequest;
32 z->msg_check_for("for double init");
34 /* send double init with differnet refID's */
35 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
36 ODR_MASK_SET(init->options, Z_Options_concurrentOperations);
37 init->referenceId = z->mk_refid(REFID_BUF1, REFID_LEN1);
39 int r = z->send_Z_PDU(apdu, &len);
42 z->msg_check_fail("unable to send init request");
46 apdu = z->create_Z_PDU(Z_APDU_initRequest);
47 init = apdu->u.initRequest;
49 ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
50 ODR_MASK_SET(init->options, Z_Options_concurrentOperations);
52 init->referenceId = z->mk_refid(REFID_BUF2, REFID_LEN2);
54 r = z->send_Z_PDU(apdu, &len);
57 z->msg_check_fail("unable to send init request");
63 Zlint_code Zlint_test_init_05::recv_gdu(Zlint *z, Z_GDU *gdu)
65 if (gdu->which == Z_GDU_Z3950 &&
66 gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
68 Z_InitResponse *init = gdu->u.z3950->u.initResponse;
69 int ver = z->initResponseGetVersion(init);
70 int result = init->result ? *init->result : 0;
72 if (m_init_response_no == 0)
74 if (!init->referenceId)
76 z->msg_check_fail("missing referenceID from "
77 "first init response");
80 else if (init->referenceId->len != REFID_LEN1
81 || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1))
83 z->msg_check_fail("reference ID does not match from "
84 "first init response");
90 if (!init->referenceId)
91 z->msg_check_fail("missing referenceID from "
92 "second init response");
93 else if (init->referenceId->len != REFID_LEN2
94 || memcmp(init->referenceId->buf, REFID_BUF2, REFID_LEN2))
95 z->msg_check_fail("reference ID does not match from "
96 "second init response");
101 z->msg_check_fail("init rejected (result false)");
102 return TEST_FINISHED;
106 if (m_init_response_no == 0)
108 m_init_response_no++;
109 return TEST_CONTINUE;
116 z->msg_check_fail("did not receive init response as expected");
117 return TEST_FINISHED;