in most existing tests now.
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: test.h,v 1.2 2006-01-27 18:58:57 adam Exp $
+ * $Id: test.h,v 1.3 2006-01-29 21:59:12 adam Exp $
*/
#ifndef YAZ_TEST_H
}
#define YAZ_CHECK_INIT(argc, argv) yaz_check_init1(&argc, &argv)
+#define YAZ_CHECK_TERM yaz_check_term1(); return 0
YAZ_BEGIN_CDECL
YAZ_EXPORT void yaz_check_init1(int *argc, char ***argv);
+YAZ_EXPORT void yaz_check_term1(void);
YAZ_EXPORT void yaz_check_print1(int type, const char *file, int line,
const char *expr);
YAZ_END_CDECL
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: test.c,v 1.2 2006-01-27 19:01:56 adam Exp $
+ * $Id: test.c,v 1.3 2006-01-29 21:59:13 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
+#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <yaz/test.h>
-static FILE *test_fout = 0; /* can't init this to stderr on some systems */
-static int test_number = 0;
-static int test_verbose = 0;
+static FILE *test_fout = 0; /* can't use '= stdout' on some systems */
+static int test_total = 0;
+static int test_failed = 0;
+static int test_verbose = 1;
+static char *test_prog = 0;
+
+static FILE *get_file()
+{
+ if (test_fout)
+ return test_fout;
+ return stdout;
+}
+
+static char *progname(char *argv0)
+{
+ char *cp = strrchr(argv0, '/');
+ if (cp)
+ return cp+1;
+ cp = strrchr(argv0, '\\');
+ if (cp)
+ return cp+1;
+ return argv0;
+}
void yaz_check_init1(int *argc_p, char ***argv_p)
{
int argc = *argc_p;
char **argv = *argv_p;
+ test_prog = progname(argv[0]);
+
for (i = 1; i<argc; i++)
{
if (strlen(argv[i]) >= 7 && !memcmp(argv[i], "--test-", 7))
{
fprintf(stderr,
"--test-help help\n"
- "--test-verbose level verbose; 0=quiet; 1=normal; 2=more\n"
- "--test-file fname output to fname\n");
+ "--test-file fname output to fname\n"
+ "--test-verbose level verbose level\n"
+ " 0=Quiet. Only exit code tells what's wrong\n"
+ " 1=Report+Summary only if tests fail.\n"
+ " 2=Report failures. Print summary always\n"
+ " 3=Report + summary always\n"
+ );
exit(0);
}
else
--i;
*argc_p -= i;
*argv_p += i;
- if (!test_fout)
- test_fout = stdout; /* by default, set output to this */
+}
+
+void yaz_check_term1(void)
+{
+ /* summary */
+ if (test_failed)
+ {
+ if (test_verbose >= 1)
+ fprintf(get_file(), "%d out of %d tests failed for program %s\n",
+ test_failed, test_total, test_prog);
+ }
+ else
+ {
+ if (test_verbose >= 2)
+ fprintf(get_file(), "%d tests passed for program %s\n",
+ test_total, test_prog);
+ }
+ if (test_fout)
+ fclose(test_fout);
+ if (test_failed)
+ exit(1);
+ exit(0);
}
void yaz_check_print1(int type, const char *file, int line, const char *expr)
{
const char *msg = "unknown";
- test_number++;
+ test_total++;
switch(type)
{
case YAZ_TEST_TYPE_FAIL:
+ test_failed++;
msg = "failed";
if (test_verbose < 1)
return;
break;
case YAZ_TEST_TYPE_OK:
msg = "OK";
- if (test_verbose < 2)
+ if (test_verbose < 3)
return;
break;
}
- fprintf(test_fout, "%s:%d %s: %s\n", file, line, msg, expr);
+ fprintf(get_file(), "%s:%d %s: %s\n", file, line, msg, expr);
}
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstccl.c,v 1.9 2005-06-25 15:46:07 adam Exp $
+ * $Id: tstccl.c,v 1.10 2006-01-29 21:59:13 adam Exp $
*/
/* CCL test */
-#include <stdlib.h>
#include <string.h>
#include <yaz/ccl.h>
+#include <yaz/test.h>
struct ccl_tst {
char *query;
{0, 0}
};
-void tst1(int pass, int *number_of_errors)
+void tst1(int pass)
{
CCL_parser parser = ccl_parser_create ();
CCL_bibset bibset = ccl_qual_mk();
int i;
char tstline[128];
+ YAZ_CHECK(parser);
+ YAZ_CHECK(bibset);
switch(pass)
{
case 0:
);
break;
default:
- exit(23);
+ YAZ_CHECK(0);
}
parser->bibset = bibset;
ccl_token_del (token_list);
if (rpn)
{
+ /* parse ok. check that result is there and match */
WRBUF wrbuf = wrbuf_alloc();
ccl_pquery(wrbuf, rpn);
- if (!query_str[i].result)
+ /* check expect a result and that it matches */
+ YAZ_CHECK(query_str[i].result);
+ if (query_str[i].result)
{
- printf ("Failed %s\n", query_str[i].query);
- printf (" got: %s:\n", wrbuf_buf(wrbuf));
- printf (" expected failure\n");
- (*number_of_errors)++;
- }
- else if (strcmp(wrbuf_buf(wrbuf), query_str[i].result))
- {
- printf ("Failed %s\n", query_str[i].query);
- printf (" got: %s:\n", wrbuf_buf(wrbuf));
- printf (" expected:%s:\n", query_str[i].result);
- (*number_of_errors)++;
+ YAZ_CHECK(!strcmp(wrbuf_buf(wrbuf), query_str[i].result));
}
ccl_rpn_delete(rpn);
wrbuf_free(wrbuf, 1);
}
- else if (query_str[i].result)
+ else
{
- printf ("Failed %s\n", query_str[i].query);
- printf (" got failure\n");
- printf (" expected:%s:\n", query_str[i].result);
- (*number_of_errors)++;
+ /* parse failed. So we expect no result either */
+ YAZ_CHECK(!query_str[i].result);
}
}
ccl_parser_destroy (parser);
int main(int argc, char **argv)
{
- int number_of_errors = 0;
- tst1(0, &number_of_errors);
- if (number_of_errors)
- exit(1);
- tst1(1, &number_of_errors);
- if (number_of_errors)
- exit(1);
- tst1(2, &number_of_errors);
- if (number_of_errors)
- exit(1);
- exit(0);
+ YAZ_CHECK_INIT(argc, argv);
+ tst1(0);
+ tst1(1);
+ tst1(2);
+ YAZ_CHECK_TERM;
}
/*
* Local variables:
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tsticonv.c,v 1.12 2005-10-28 18:36:59 adam Exp $
+ * $Id: tsticonv.c,v 1.13 2006-01-29 21:59:13 adam Exp $
*/
#if HAVE_CONFIG_H
#include <ctype.h>
#include <yaz/yaz-util.h>
+#include <yaz/test.h>
static int compare_buffers(char *msg, int no,
int expect_len, const char *expect_buf,
int got_len, const char *got_buf)
{
- int i;
if (expect_len == got_len
&& !memcmp(expect_buf, got_buf, expect_len))
return 1;
- printf("tsticonv test=%s i=%d failed\n", msg, no);
- printf("off got exp\n");
- for (i = 0; i<got_len || i<expect_len; i++)
+
+ if (0) /* use 1 see how the buffers differ (for debug purposes) */
{
- char got_char[10];
- char expect_char[10];
-
- if (i < got_len)
- sprintf(got_char, "%02X", got_buf[i]);
- else
- sprintf(got_char, "? ");
-
- if (i < expect_len)
- sprintf(expect_char, "%02X", expect_buf[i]);
- else
- sprintf(expect_char, "? ");
-
- printf("%02d %s %s %c\n",
- i, got_char, expect_char, got_buf[i] == expect_buf[i] ?
- ' ' : '*');
-
+ int i;
+ printf("tsticonv test=%s i=%d failed\n", msg, no);
+ printf("off got exp\n");
+ for (i = 0; i<got_len || i<expect_len; i++)
+ {
+ char got_char[10];
+ char expect_char[10];
+
+ if (i < got_len)
+ sprintf(got_char, "%02X", got_buf[i]);
+ else
+ sprintf(got_char, "? ");
+
+ if (i < expect_len)
+ sprintf(expect_char, "%02X", expect_buf[i]);
+ else
+ sprintf(expect_char, "? ");
+
+ printf("%02d %s %s %c\n",
+ i, got_char, expect_char, got_buf[i] == expect_buf[i] ?
+ ' ' : '*');
+
+ }
}
- exit(1);
+ return 0;
}
/* some test strings in ISO-8859-1 format */
{
int i;
yaz_iconv_t cd;
+ int ret;
cd = yaz_iconv_open("ISO-8859-1", "MARC8");
+ YAZ_CHECK(cd);
if (!cd)
- {
- printf("tsticonv 10 yaz_iconv_open failed\n");
- exit(10);
- }
+ return;
for (i = 0; iso_8859_1_a[i]; i++)
{
size_t r;
size_t outbytesleft = sizeof(outbuf0);
r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+ YAZ_CHECK(r != (size_t)(-1));
if (r == (size_t) (-1))
- {
- int e = yaz_iconv_error(cd);
+ break;
- printf ("tsticonv 11 i=%d e=%d\n", i, e);
- exit(11);
- }
- compare_buffers("tsticonv 11", i,
- strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
- outbuf - outbuf0, outbuf0);
+ ret = compare_buffers("tsticonv 11", i,
+ strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
+ outbuf - outbuf0, outbuf0);
+ YAZ_CHECK(ret);
}
yaz_iconv_close(cd);
}
}
};
int i;
+ int ret;
yaz_iconv_t cd;
cd = yaz_iconv_open("UCS4", "MARC8");
+ YAZ_CHECK(cd);
if (!cd)
- {
- printf ("tsticonv 20 yaz_iconv_open failed\n");
- exit(20);
- }
+ return;
for (i = 0; ar[i].len; i++)
{
size_t r;
if (r == (size_t) (-1))
{
int e = yaz_iconv_error(cd);
+ YAZ_CHECK(e == YAZ_ICONV_E2BIG);
if (e != YAZ_ICONV_E2BIG)
- {
- printf ("tsticonv 21 i=%d e=%d\n", i, e);
- exit(21);
- }
+ return;
}
else
break;
}
- compare_buffers("tsticonv 22", i,
- expect_len, ar[i].ucs4_b,
- outbuf - outbuf0, outbuf0);
+ ret = compare_buffers("tsticonv 22", i,
+ expect_len, ar[i].ucs4_b,
+ outbuf - outbuf0, outbuf0);
+ YAZ_CHECK(ret);
}
yaz_iconv_close(cd);
}
};
int i;
+ int ret;
yaz_iconv_t cd;
cd = yaz_iconv_open("UTF8", "UCS4");
+ YAZ_CHECK(cd);
if (!cd)
- {
- printf ("tsticonv 30 yaz_iconv_open failed\n");
- exit(30);
- }
+ return;
for (i = 0; ucs4_c[i]; i++)
{
size_t r;
size_t outbytesleft = sizeof(outbuf0);
r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+ YAZ_CHECK(r != (size_t) (-1));
if (r == (size_t) (-1))
- {
- int e = yaz_iconv_error(cd);
-
- printf ("tsticonv 31 i=%d e=%d\n", i, e);
- exit(31);
- }
- compare_buffers("tsticonv 32", i,
- strlen(utf8_c[i]), utf8_c[i],
- outbuf - outbuf0, outbuf0);
+ return;
+ ret = compare_buffers("tsticonv 32", i,
+ strlen(utf8_c[i]), utf8_c[i],
+ outbuf - outbuf0, outbuf0);
+ YAZ_CHECK(ret);
}
yaz_iconv_close(cd);
}
static void dconvert(int mandatory, const char *tmpcode)
{
int i;
+ int ret;
yaz_iconv_t cd;
for (i = 0; iso_8859_1_a[i]; i++)
{
size_t outbytesleft = sizeof(outbuf0);
cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
+ YAZ_CHECK(cd || !mandatory);
if (!cd)
- {
- if (!mandatory)
- return;
- printf ("tsticonv code=%s i=%d 1\n", tmpcode, i);
- exit(1);
- }
+ return;
r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
- if (r == (size_t)(-1))
- {
- int e = yaz_iconv_error(cd);
-
- printf ("tsticonv code=%s i=%d 2 e=%d\n", tmpcode, i, e);
- exit(2);
- }
+ YAZ_CHECK(r != (size_t) (-1));
yaz_iconv_close(cd);
+ if (r == (size_t) (-1))
+ return;
cd = yaz_iconv_open("ISO-8859-1", tmpcode);
+ YAZ_CHECK(cd || !mandatory);
if (!cd)
- {
- if (!mandatory)
- return;
- printf ("tsticonv code=%s i=%d 3\n", tmpcode, i);
- exit(3);
- }
+ return;
inbuf = outbuf0;
inbytesleft = sizeof(outbuf0) - outbytesleft;
outbuf = outbuf1;
outbytesleft = sizeof(outbuf1);
r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
- if (r == (size_t)(-1)) {
- int e = yaz_iconv_error(cd);
-
- printf ("tsticonv code=%s i=%d 4 e=%d\n", tmpcode, i, e);
- exit(4);
+ YAZ_CHECK(r != (size_t) (-1));
+ if (r != (size_t)(-1))
+ {
+ ret = compare_buffers("dconvert", i,
+ strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
+ sizeof(outbuf1) - outbytesleft, outbuf1);
+ YAZ_CHECK(ret);
}
- compare_buffers("dconvert", i,
- strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
- sizeof(outbuf1) - outbytesleft, outbuf1);
yaz_iconv_close(cd);
}
}
int main (int argc, char **argv)
{
+ YAZ_CHECK_INIT(argc, argv);
dconvert(1, "UTF-8");
dconvert(1, "ISO-8859-1");
dconvert(1, "UCS4");
tst_marc8_to_iso_8859_1();
tst_marc8_to_ucs4b();
tst_ucs4b_to_utf8();
- exit(0);
+ YAZ_CHECK_TERM;
}
/*
* Local variables:
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
-
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstmatchstr.c,v 1.4 2005-06-25 15:46:07 adam Exp $
+ * $Id: tstmatchstr.c,v 1.5 2006-01-29 21:59:13 adam Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <yaz/yaz-iconv.h>
-
-struct {
- char *s1;
- char *s2;
- int res;
-} comp_strings[] = {
- { "x", "x", 0 },
- { "x", "X", 0 },
- { "a", "b", 1 },
- { "b", "a", 1 },
- { "aa","a", 1 },
- { "a-", "a", 1 },
- { "A-b", "ab", 0},
- { "A--b", "ab", 1},
- { "A--b", "a-b", 1},
- { "A--b", "a--b", 0},
- { "a123", "a?", 0},
- {"a123", "a1.3", 0},
- {"a123", "..?", 0},
- {"a123", "a1.", 1},
- {"a123", "a...", 0},
- {0, 0, 0} };
+#include <yaz/test.h>
int main (int argc, char **argv)
{
- int i;
- for (i = 0; comp_strings[i].s1; i++)
- {
- int got = yaz_matchstr(comp_strings[i].s1,comp_strings[i].s2);
- if (got > 0)
- got = 1;
- else if (got < 0)
- got = -1;
- if (got != comp_strings[i].res)
- {
- printf ("tststr %d got=%d res=%d\n", i,
- got, comp_strings[i].res);
- exit(1);
- }
- }
- exit(0);
+ YAZ_CHECK_INIT(argc, argv);
+
+ YAZ_CHECK(yaz_matchstr("x", "x") == 0);
+ YAZ_CHECK(yaz_matchstr("x", "X") == 0);
+ YAZ_CHECK(yaz_matchstr("a", "b") > 0);
+ YAZ_CHECK(yaz_matchstr("b", "a") > 0);
+ YAZ_CHECK(yaz_matchstr("aa","a") > 0);
+ YAZ_CHECK(yaz_matchstr("a-", "a") > 0);
+ YAZ_CHECK(yaz_matchstr("A-b", "ab") == 0);
+ YAZ_CHECK(yaz_matchstr("A--b", "ab") > 0);
+ YAZ_CHECK(yaz_matchstr("A--b", "a-b") > 0);
+ YAZ_CHECK(yaz_matchstr("A--b", "a--b") == 0);
+ YAZ_CHECK(yaz_matchstr("a123", "a?") == 0);
+ YAZ_CHECK(yaz_matchstr("a123", "a1.3") == 0);
+ YAZ_CHECK(yaz_matchstr("a123", "..?") == 0);
+ YAZ_CHECK(yaz_matchstr("a123", "a1.") > 0);
+ YAZ_CHECK(yaz_matchstr("a123", "a...") == 0);
+
+ YAZ_CHECK_TERM;
}
/*
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstnmem.c,v 1.5 2005-06-25 15:46:07 adam Exp $
+ * $Id: tstnmem.c,v 1.6 2006-01-29 21:59:13 adam Exp $
*/
#if HAVE_CONFIG_H
#include <ctype.h>
#include <yaz/nmem.h>
+#include <yaz/test.h>
-int main (int argc, char **argv)
+void tst(void)
{
- void *cp;
NMEM n;
int j;
+ char *cp;
nmem_init();
n = nmem_create();
- if (!n)
- exit (1);
+ YAZ_CHECK(n);
+
for (j = 1; j<500; j++)
{
cp = nmem_malloc(n, j);
- if (!cp)
- exit(2);
+ YAZ_CHECK(cp);
if (sizeof(long) >= j)
*(long*) cp = 123L;
#if HAVE_LONG_LONG
for (j = 2000; j<20000; j+= 2000)
{
cp = nmem_malloc(n, j);
- if (!cp)
- exit(3);
+ YAZ_CHECK(cp);
}
nmem_destroy(n);
nmem_exit();
- exit(0);
+}
+
+int main (int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ tst();
+ YAZ_CHECK_TERM;
}
/*
* Local variables:
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstodr.c,v 1.7 2005-08-22 20:34:23 adam Exp $
+ * $Id: tstodr.c,v 1.8 2006-01-29 21:59:13 adam Exp $
*
*/
#include <stdlib.h>
#include <yaz/oid.h>
#include "tstodrcodec.h"
+#include <yaz/test.h>
+
#define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
void tst_MySequence1(ODR encode, ODR decode)
{
+ int ret;
char *ber_buf;
int ber_len;
Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
Yc_MySequence *t;
+ YAZ_CHECK(s);
s->first = odr_intdup(encode, 12345);
s->second = odr_malloc(encode, sizeof(*s->second));
s->second->buf = (unsigned char *) "hello";
s->myoid = odr_getoidbystr(decode, MYOID);
- if (!yc_MySequence(encode, &s, 0, 0))
- exit(1);
+ ret = yc_MySequence(encode, &s, 0, 0);
+ YAZ_CHECK(ret);
+ if (!ret)
+ return;
ber_buf = odr_getbuf(encode, &ber_len, 0);
odr_setbuf(decode, ber_buf, ber_len, 0);
- if (!yc_MySequence(decode, &t, 0, 0))
- exit(2);
- if (!t->first || *t->first != 12345)
- exit(3);
- if (!t->second || !t->second->buf || t->second->len != 5)
- exit(4);
- if (memcmp(t->second->buf, "hello", t->second->len))
- exit(5);
- if (!t->third || *t->third != 1)
- exit(6);
- if (!t->fourth)
- exit(7);
- if (!t->fifth || *t->fifth != YC_MySequence_enum1)
- exit(8);
- if (!t->myoid)
- exit(9);
- else
+ ret = yc_MySequence(decode, &t, 0, 0);
+ YAZ_CHECK(ret);
+ if (!ret)
+ return;
+
+ YAZ_CHECK(t);
+
+ YAZ_CHECK(t->first && *t->first == 12345);
+
+ YAZ_CHECK(t->second && t->second->buf && t->second->len == 5);
+
+ YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 &&
+ memcmp(t->second->buf, "hello", t->second->len) == 0);
+
+ YAZ_CHECK(t->third && *t->third == 1);
+
+ YAZ_CHECK(t->fourth);
+
+ YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1);
+
+ YAZ_CHECK(t->myoid);
+ if (t->myoid)
{
int *myoid = odr_getoidbystr(decode, MYOID);
- struct oident *oident;
- if (oid_oidcmp(myoid, t->myoid))
- exit(10);
- oident = oid_getentbyoid(t->myoid);
+ YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0);
}
}
void tst_MySequence2(ODR encode, ODR decode)
{
+ int ret;
Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
+ YAZ_CHECK(s);
s->first = 0; /* deliberately miss this .. */
s->second = odr_malloc(encode, sizeof(*s->second));
s->second->buf = (unsigned char *) "hello";
s->fifth = odr_intdup(encode, YC_MySequence_enum1);
s->myoid = odr_getoidbystr(encode, MYOID);
- if (yc_MySequence(encode, &s, 0, 0)) /* should fail */
- exit(9);
- if (odr_geterror(encode) != OREQUIRED)
- exit(10);
- if (strcmp(odr_getelement(encode), "first"))
- exit(11);
+ ret = yc_MySequence(encode, &s, 0, 0); /* should fail */
+ YAZ_CHECK(!ret);
+
+ YAZ_CHECK(odr_geterror(encode) == OREQUIRED);
+
+ YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0);
odr_reset(encode);
- if (odr_geterror(encode) != ONONE)
- exit(12);
- if (strcmp(odr_getelement(encode), ""))
- exit(13);
+ YAZ_CHECK(odr_geterror(encode) == ONONE);
+
+ YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0);
}
void tst_MySequence3(ODR encode, ODR decode)
}
}
-int main(int argc, char **argv)
+static void tst(void)
{
ODR odr_encode = odr_createmem(ODR_ENCODE);
ODR odr_decode = odr_createmem(ODR_DECODE);
+ YAZ_CHECK(odr_encode);
+ YAZ_CHECK(odr_decode);
+
tst_MySequence1(odr_encode, odr_decode);
tst_MySequence2(odr_encode, odr_decode);
tst_MySequence3(odr_encode, odr_decode);
odr_destroy(odr_encode);
odr_destroy(odr_decode);
- exit(0);
}
+
+int main(int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ tst();
+ YAZ_CHECK_TERM;
+}
+
/*
* Local variables:
* c-basic-offset: 4
+/*
+ * Copyright (C) 1995-2005, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: tstodrstack.c,v 1.4 2006-01-29 21:59:13 adam Exp $
+ *
+ */
#include <stdlib.h>
#include <yaz/pquery.h>
#include <yaz/proto.h>
+#include <yaz/test.h>
/** \brief build a 100 level query */
void test1()
Z_RPNQuery *rpn_query;
char qstr[10000];
int i;
+ int ret;
+
+ YAZ_CHECK(odr);
+ YAZ_CHECK(parser);
*qstr = '\0';
for (i = 0; i<100; i++)
strcat(qstr, "1");
rpn_query = yaz_pqf_parse (parser, odr, qstr);
+ YAZ_CHECK(rpn_query);
- if (!rpn_query)
- exit(1);
-
- if (!z_RPNQuery(odr, &rpn_query, 0, 0))
- {
- odr_perror(odr, "Encoding query");
- exit(1);
- }
+ ret = z_RPNQuery(odr, &rpn_query, 0, 0);
+ YAZ_CHECK(ret);
yaz_pqf_destroy(parser);
odr_destroy(odr);
ODR odr = odr_createmem(ODR_ENCODE);
YAZ_PQF_Parser parser = yaz_pqf_create();
Z_RPNQuery *rpn_query;
+ int ret;
- rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
+ YAZ_CHECK(odr);
- if (!rpn_query)
- exit(1);
+ rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
+ YAZ_CHECK(rpn_query);
/* make the circular reference */
rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;
- if (z_RPNQuery(odr, &rpn_query, 0, 0)) /* should fail */
- exit(2);
+ ret = z_RPNQuery(odr, &rpn_query, 0, 0); /* should fail */
+ YAZ_CHECK(!ret);
yaz_pqf_destroy(parser);
odr_destroy(odr);
int main(int argc, char **argv)
{
+ YAZ_CHECK_INIT(argc, argv);
test1();
test2();
- exit(0);
+ YAZ_CHECK_TERM;
}
/*
* Local variables:
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstsoap1.c,v 1.4 2005-08-22 20:34:23 adam Exp $
+ * $Id: tstsoap1.c,v 1.5 2006-01-29 21:59:13 adam Exp $
*/
#include <stdlib.h>
#if HAVE_XML2
#include <libxml/parser.h>
#endif
+#include <yaz/test.h>
-int main(int argc, char **argv)
+void tst()
{
#if HAVE_XML2
- LIBXML_TEST_VERSION;
-
- if (argc <= 1)
- {
- xmlChar *buf_out;
- int len_out;
- xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
+ xmlChar *buf_out;
+ int len_out;
+ xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
+ YAZ_CHECK(doc);
#if 0
- const char *val = "jordbær"; /* makes xmlDocDumpMemory hang .. */
+ const char *val = "jordbær"; /* makes xmlDocDumpMemory hang .. */
#else
- const char *val = "jordbaer"; /* OK */
+ const char *val = "jordbaer"; /* OK */
#endif
- xmlNodePtr top = xmlNewNode(0, BAD_CAST "top");
-
- xmlNewTextChild(top, 0, BAD_CAST "sub", BAD_CAST val);
- xmlDocSetRootElement(doc, top);
-
- xmlDocDumpMemory(doc, &buf_out, &len_out);
+ xmlNodePtr top = xmlNewNode(0, BAD_CAST "top");
+ YAZ_CHECK(top);
+
+ xmlNewTextChild(top, 0, BAD_CAST "sub", BAD_CAST val);
+ xmlDocSetRootElement(doc, top);
+
+ xmlDocDumpMemory(doc, &buf_out, &len_out);
#if 0
- printf("%*s", len_out, buf_out);
+ printf("%*s", len_out, buf_out);
+#endif
+
+
+/* HAVE_XML2 */
#endif
- }
+}
+
+int main(int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+#if HAVE_XML2
+ LIBXML_TEST_VERSION;
#endif
- return 0;
+ tst();
+ YAZ_CHECK_TERM;
}
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstsoap2.c,v 1.2 2005-06-25 15:46:07 adam Exp $
+ * $Id: tstsoap2.c,v 1.3 2006-01-29 21:59:13 adam Exp $
*/
#include <stdlib.h>
#if HAVE_XML2
#include <libxml/parser.h>
+#include <yaz/test.h>
#include <yaz/srw.h>
#include <yaz/soap.h>
Z_SRW_PDU *sr = yaz_srw_get(o, Z_SRW_searchRetrieve_request);
Z_SOAP *p = odr_malloc(o, sizeof(*p));
+ YAZ_CHECK(o);
+ YAZ_CHECK(sr);
+ YAZ_CHECK(p);
#if 0
sr->u.request->query.cql = "jordbær";
#else
ret = z_soap_codec_enc(o, &p, &content_buf, &content_len, h, charset);
odr_destroy(o);
- if (ret)
- {
- printf("z_soap_codec_enc failed\n");
- exit(1);
- }
+ YAZ_CHECK(ret == 0); /* codec failed ? */
}
#endif
int main(int argc, char **argv)
{
+ YAZ_CHECK_INIT(argc, argv);
#if HAVE_XML2
- LIBXML_TEST_VERSION
- if (argc <= 1)
- {
- tst_srw();
- }
+ LIBXML_TEST_VERSION;
+ tst_srw();
#endif
- return 0;
+ YAZ_CHECK_TERM;
}
/*
* Local variables:
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstwrbuf.c,v 1.4 2005-06-25 15:46:07 adam Exp $
+ * $Id: tstwrbuf.c,v 1.5 2006-01-29 21:59:13 adam Exp $
*/
#include <stdlib.h>
#include <stdio.h>
#include <yaz/wrbuf.h>
+#include <yaz/test.h>
-int main (int argc, char **argv)
+static void tstwrbuf(void)
{
int step;
WRBUF wr = wrbuf_alloc();
+ YAZ_CHECK(wr);
+
wrbuf_free(wr, 1);
wr = wrbuf_alloc();
+ YAZ_CHECK(wr);
+
for (step = 1; step < 65; step++)
{
int i, j, k;
cp = wrbuf_buf(wr);
len = wrbuf_len(wr);
- if (len != step * (step-1) / 2)
- {
- printf ("tstwrbuf 1 %d len=%d\n", step, len);
- exit(1);
- }
+ YAZ_CHECK(len == step * (step-1) / 2);
k = 0;
for (j = 1; j<step; j++)
for (i = 0; i<j; i++)
{
- if (cp[k] != i+1)
- {
- printf ("tstwrbuf 2 %d k=%d\n", step, k);
- exit(1);
- }
+ YAZ_CHECK(cp[k] == i+1);
k++;
}
wrbuf_rewind(wr);
}
wrbuf_free(wr, 1);
- exit(0);
+}
+
+int main (int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ tstwrbuf();
+ YAZ_CHECK_TERM;
}
/*
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstxmlquery.c,v 1.3 2006-01-27 19:04:15 adam Exp $
+ * $Id: tstxmlquery.c,v 1.4 2006-01-29 21:59:13 adam Exp $
*/
#include <stdlib.h>
pqf2xml_text("@attr 1=4 computer");
- exit(0);
- return 0;
+ YAZ_CHECK_TERM;
}
/*