2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: zlint.cpp,v 1.10 2005-06-08 13:28:06 adam Exp $
11 #include <yaz/comstack.h>
12 #include <yaz/options.h>
13 #include <yaz/otherinfo.h>
14 #include <yaz/charneg.h>
22 Zlint_t(Zlint_test *t);
27 int m_test_number_sequence;
32 Zlint::Zlint(IPDU_Observable *the_PDU_Observable) :
33 Z_Assoc(the_PDU_Observable)
36 m_PDU_Observable = the_PDU_Observable;
55 void Zlint::set_host(const char *cp)
63 cs_get_host_args(m_host, &basep);
64 if (!basep || !*basep)
67 m_database = xstrdup(basep);
70 void Zlint::timeoutNotify()
74 if (m_cur_test->m_t->recv_fail(this, 2) != TEST_FINISHED)
85 void Zlint::failNotify()
89 if (m_cur_test->m_t->recv_fail(this, 1) != TEST_FINISHED)
100 void Zlint::connectNotify()
104 if (m_cur_test->m_t->init(this) != TEST_FINISHED)
110 void Zlint::recv_GDU(Z_GDU *gdu, int len)
114 int r = m_cur_test->m_t->recv_gdu(this, gdu);
115 if (r == TEST_CONTINUE)
117 if (r == TEST_REOPEN)
128 void Zlint::close_goto_next()
132 m_cur_test = m_cur_test->m_next;
138 IPDU_Observer *Zlint::sessionNotify(
139 IPDU_Observable *the_PDU_Observable, int fd)
144 Z_ReferenceId *Zlint::mk_refid(const char *buf, int len)
147 (Z_ReferenceId *) odr_malloc(odr_encode(), sizeof(*id));
148 id->size = id->len = len;
149 id->buf = (unsigned char*) odr_malloc(odr_encode(), len);
150 memcpy(id->buf, buf, len);
154 int Zlint::initResponseGetVersion(Z_InitResponse *init)
159 for (i = 0; i<12; i++)
160 if (ODR_MASK_GET(init->protocolVersion, no))
169 void Zlint::add_test(Zlint_test *t)
171 Zlint_t **d = &m_tests;
176 m_cur_test = m_tests;
179 void Zlint::msg_check_for(const char *fmt, ...)
181 m_cur_test->m_test_ok = 0;
182 m_cur_test->m_test_number_sequence++;
183 m_cur_test->m_test_reported = 0;
188 vsnprintf(buf, sizeof(buf), fmt, ap);
189 printf ("Checking %s .. ", buf);
193 void Zlint::msg_check_info(const char *fmt, ...)
198 vsnprintf(buf, sizeof(buf), fmt, ap);
199 printf (" %s\n", buf);
203 void Zlint::msg_check_ok()
205 if (!m_cur_test->m_test_reported)
207 m_cur_test->m_test_ok = 1;
208 m_cur_test->m_test_reported = 1;
213 void Zlint::msg_check_fail(const char *fmt, ...)
215 if (!m_cur_test->m_test_reported)
217 m_cur_test->m_test_ok = 0;
218 m_cur_test->m_test_reported = 1;
224 vsnprintf(buf, sizeof(buf), fmt, ap);
225 printf (" %s\n", buf);
229 void Zlint::msg_check_notapp()
231 if (!m_cur_test->m_test_reported)
233 m_cur_test->m_test_ok = 2;
234 m_cur_test->m_test_reported = 1;
235 printf ("Unsupported\n");
239 void Zlint::getDatabase(char ***db, int *num)
241 *db = (char**) odr_malloc(odr_encode(), 2*sizeof(char *));
242 (*db)[0] = m_database;
247 Zlint_t::Zlint_t(Zlint_test *t)
249 m_test_number_sequence = 0;
261 Zlint_code Zlint_test_simple::recv_fail(Zlint *z, int reason)
263 z->msg_check_fail("target closed connection");
264 return TEST_FINISHED;