2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: zlint.cpp,v 1.8 2004-12-13 20:50:54 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(IYaz_PDU_Observable *the_PDU_Observable) :
33 Yaz_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 IYaz_PDU_Observer *Zlint::sessionNotify(
139 IYaz_PDU_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))
164 yaz_log(YLOG_WARN, "%sbad formatted version");
171 void Zlint::add_test(Zlint_test *t)
173 Zlint_t **d = &m_tests;
178 m_cur_test = m_tests;
181 void Zlint::msg_check_for(const char *fmt, ...)
183 m_cur_test->m_test_ok = 0;
184 m_cur_test->m_test_number_sequence++;
185 m_cur_test->m_test_reported = 0;
190 vsnprintf(buf, sizeof(buf), fmt, ap);
191 printf ("Checking %s .. ", buf);
195 void Zlint::msg_check_info(const char *fmt, ...)
200 vsnprintf(buf, sizeof(buf), fmt, ap);
201 printf (" %s\n", buf);
205 void Zlint::msg_check_ok()
207 if (!m_cur_test->m_test_reported)
209 m_cur_test->m_test_ok = 1;
210 m_cur_test->m_test_reported = 1;
215 void Zlint::msg_check_fail(const char *fmt, ...)
217 if (!m_cur_test->m_test_reported)
219 m_cur_test->m_test_ok = 0;
220 m_cur_test->m_test_reported = 1;
226 vsnprintf(buf, sizeof(buf), fmt, ap);
227 printf (" %s\n", buf);
231 void Zlint::msg_check_notapp()
233 if (!m_cur_test->m_test_reported)
235 m_cur_test->m_test_ok = 2;
236 m_cur_test->m_test_reported = 1;
237 printf ("Unsupported\n");
241 void Zlint::getDatabase(char ***db, int *num)
243 *db = (char**) odr_malloc(odr_encode(), 2*sizeof(char *));
244 (*db)[0] = m_database;
249 Zlint_t::Zlint_t(Zlint_test *t)
251 m_test_number_sequence = 0;
263 Zlint_code Zlint_test_simple::recv_fail(Zlint *z, int reason)
265 z->msg_check_fail("target closed connection");
266 return TEST_FINISHED;