2 * Copyright (c) 2004, Index Data.
3 * See the file LICENSE for details.
5 * $Id: zlint.cpp,v 1.12 2005-09-22 12:40:45 adam Exp $
11 #include <yaz/comstack.h>
12 #include <yaz/options.h>
13 #include <yaz/otherinfo.h>
14 #include <yaz/charneg.h>
19 Zlint_test::~Zlint_test()
27 Zlint_t(Zlint_test *t);
32 int m_test_number_sequence;
37 Zlint::Zlint(IPDU_Observable *the_PDU_Observable) :
38 Z_Assoc(the_PDU_Observable)
41 m_PDU_Observable = the_PDU_Observable;
60 void Zlint::set_host(const char *cp)
68 cs_get_host_args(m_host, &basep);
69 if (!basep || !*basep)
72 m_database = xstrdup(basep);
75 void Zlint::timeoutNotify()
79 if (m_cur_test->m_t->recv_fail(this, 2) != TEST_FINISHED)
90 void Zlint::failNotify()
94 if (m_cur_test->m_t->recv_fail(this, 1) != TEST_FINISHED)
105 void Zlint::connectNotify()
109 if (m_cur_test->m_t->init(this) != TEST_FINISHED)
115 void Zlint::recv_GDU(Z_GDU *gdu, int len)
119 int r = m_cur_test->m_t->recv_gdu(this, gdu);
120 if (r == TEST_CONTINUE)
122 if (r == TEST_REOPEN)
133 void Zlint::close_goto_next()
137 m_cur_test = m_cur_test->m_next;
143 IPDU_Observer *Zlint::sessionNotify(
144 IPDU_Observable *the_PDU_Observable, int fd)
149 Z_ReferenceId *Zlint::mk_refid(const char *buf, int len)
152 (Z_ReferenceId *) odr_malloc(odr_encode(), sizeof(*id));
153 id->size = id->len = len;
154 id->buf = (unsigned char*) odr_malloc(odr_encode(), len);
155 memcpy(id->buf, buf, len);
159 int Zlint::initResponseGetVersion(Z_InitResponse *init)
164 for (i = 0; i<12; i++)
165 if (ODR_MASK_GET(init->protocolVersion, no))
174 void Zlint::add_test(Zlint_test *t)
176 Zlint_t **d = &m_tests;
181 m_cur_test = m_tests;
184 void Zlint::msg_check_for(const char *fmt, ...)
186 m_cur_test->m_test_ok = 0;
187 m_cur_test->m_test_number_sequence++;
188 m_cur_test->m_test_reported = 0;
193 vsnprintf(buf, sizeof(buf), fmt, ap);
194 printf ("Checking %s .. ", buf);
198 void Zlint::msg_check_info(const char *fmt, ...)
203 vsnprintf(buf, sizeof(buf), fmt, ap);
204 printf (" %s\n", buf);
208 void Zlint::msg_check_ok()
210 if (!m_cur_test->m_test_reported)
212 m_cur_test->m_test_ok = 1;
213 m_cur_test->m_test_reported = 1;
218 void Zlint::msg_check_fail(const char *fmt, ...)
220 if (!m_cur_test->m_test_reported)
222 m_cur_test->m_test_ok = 0;
223 m_cur_test->m_test_reported = 1;
229 vsnprintf(buf, sizeof(buf), fmt, ap);
230 printf (" %s\n", buf);
234 void Zlint::msg_check_notapp()
236 if (!m_cur_test->m_test_reported)
238 m_cur_test->m_test_ok = 2;
239 m_cur_test->m_test_reported = 1;
240 printf ("Unsupported\n");
244 void Zlint::getDatabase(char ***db, int *num)
246 *db = (char**) odr_malloc(odr_encode(), 2*sizeof(char *));
247 (*db)[0] = m_database;
252 Zlint_t::Zlint_t(Zlint_test *t)
254 m_test_number_sequence = 0;
266 Zlint_code Zlint_test_simple::recv_fail(Zlint *z, int reason)
268 z->msg_check_fail("target closed connection");
269 return TEST_FINISHED;
274 * indent-tabs-mode: nil
276 * vim: shiftwidth=4 tabstop=8 expandtab