2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: zlint.cpp,v 1.5 2004-03-25 23:14:07 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)
62 cs_get_host_args(m_host, &basep);
63 if (!basep || !*basep)
66 m_database = xstrdup(basep);
69 void Zlint::timeoutNotify()
73 if (m_cur_test->m_t->recv_fail(this, 2) != TEST_FINISHED)
83 void Zlint::failNotify()
87 if (m_cur_test->m_t->recv_fail(this, 1) != TEST_FINISHED)
97 void Zlint::connectNotify()
101 if (m_cur_test->m_t->init(this) != TEST_FINISHED)
107 void Zlint::recv_GDU(Z_GDU *gdu, int len)
111 int r = m_cur_test->m_t->recv_gdu(this, gdu);
112 if (r == TEST_CONTINUE)
114 if (r == TEST_REOPEN)
124 void Zlint::close_goto_next()
128 m_cur_test = m_cur_test->m_next;
133 IYaz_PDU_Observer *Zlint::sessionNotify(
134 IYaz_PDU_Observable *the_PDU_Observable, int fd)
139 Z_ReferenceId *Zlint::mk_refid(const char *buf, int len)
142 (Z_ReferenceId *) odr_malloc(odr_encode(), sizeof(*id));
143 id->size = id->len = len;
144 id->buf = (unsigned char*) odr_malloc(odr_encode(), len);
145 memcpy(id->buf, buf, len);
149 int Zlint::initResponseGetVersion(Z_InitResponse *init)
154 for (i = 0; i<12; i++)
155 if (ODR_MASK_GET(init->protocolVersion, no))
159 yaz_log(LOG_WARN, "%sbad formatted version");
166 void Zlint::add_test(Zlint_test *t)
168 Zlint_t **d = &m_tests;
173 m_cur_test = m_tests;
176 void Zlint::msg_check_for(const char *fmt, ...)
178 m_cur_test->m_test_ok = 0;
179 m_cur_test->m_test_number_sequence++;
180 m_cur_test->m_test_reported = 0;
185 vsnprintf(buf, sizeof(buf), fmt, ap);
186 printf ("Checking %s .. ", buf);
190 void Zlint::msg_check_info(const char *fmt, ...)
195 vsnprintf(buf, sizeof(buf), fmt, ap);
196 printf (" %s\n", buf);
200 void Zlint::msg_check_ok()
202 if (!m_cur_test->m_test_reported)
204 m_cur_test->m_test_ok = 1;
205 m_cur_test->m_test_reported = 1;
210 void Zlint::msg_check_fail(const char *fmt, ...)
212 if (!m_cur_test->m_test_reported)
214 m_cur_test->m_test_ok = 0;
215 m_cur_test->m_test_reported = 1;
221 vsnprintf(buf, sizeof(buf), fmt, ap);
222 printf (" %s\n", buf);
226 void Zlint::msg_check_notapp()
228 if (!m_cur_test->m_test_reported)
230 m_cur_test->m_test_ok = 2;
231 m_cur_test->m_test_reported = 1;
232 printf ("Unsupported\n");
236 void Zlint::getDatabase(char ***db, int *num)
238 *db = (char**) odr_malloc(odr_encode(), 2*sizeof(char *));
239 (*db)[0] = m_database;
244 Zlint_t::Zlint_t(Zlint_test *t)
246 m_test_number_sequence = 0;
258 Zlint_code Zlint_test_simple::recv_fail(Zlint *z, int reason)
260 z->msg_check_fail("target closed connection");
261 return TEST_FINISHED;