From 38d29054baec012561d8a69ade2a55d6bee22c00 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 23 Apr 2003 20:34:08 +0000 Subject: [PATCH] Test cases for nmem, iconv --- util/Makefile.am | 14 ++++- util/siconvtst.c | 181 ------------------------------------------------------ util/tsticonv.c | 94 ++++++++++++++++++++++++++++ util/tstnmem.c | 44 +++++++++++++ util/yaziconv.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 330 insertions(+), 184 deletions(-) delete mode 100644 util/siconvtst.c create mode 100644 util/tsticonv.c create mode 100644 util/tstnmem.c create mode 100644 util/yaziconv.c diff --git a/util/Makefile.am b/util/Makefile.am index 237aa9c..ce94b0d 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,10 +1,10 @@ ## Copyright (C) 1994-2003, Index Data ## All rights reserved. -## $Id: Makefile.am,v 1.16 2003-02-18 14:28:52 adam Exp $ +## $Id: Makefile.am,v 1.17 2003-04-23 20:34:08 adam Exp $ noinst_LTLIBRARIES = libutil.la -#lib_LTLIBRARIES = libyazthread.la +TESTS = tsticonv tstnmem bin_SCRIPTS = yaz-comp @@ -14,11 +14,19 @@ AM_CPPFLAGS=-I$(top_srcdir)/include noinst_PROGRAMS = marcdump yaziconv +EXTRA_PROGRAMS = tsticonv tstnmem + marcdump_LDADD = libutil.la marcdump_SOURCES = marcdump.c yaziconv_LDADD = libutil.la -yaziconv_SOURCES = siconvtst.c +yaziconv_SOURCES = yaziconv.c + +tsticonv_LDADD = libutil.la +tsticonv_SOURCES = tsticonv.c + +tstnmem_LDADD = libutil.la +tstnmem_SOURCES = tstnmem.c marc8.c: charconv.sgm charconv.tcl cd $(srcdir); ./charconv.tcl -p marc8 -s 50 charconv.sgm marc8.c diff --git a/util/siconvtst.c b/util/siconvtst.c deleted file mode 100644 index 9f7038e..0000000 --- a/util/siconvtst.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 1997-2003, Index Data - * See the file LICENSE for details. - * - * $Id: siconvtst.c,v 1.8 2003-01-06 08:20:28 adam Exp $ - */ - -#if HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include - -#define CHUNK_IN 64 -#define CHUNK_OUT 64 - -void convert (FILE *inf, yaz_iconv_t cd, int verbose) -{ - char inbuf0[CHUNK_IN], *inbuf = inbuf0; - char outbuf0[CHUNK_OUT], *outbuf = outbuf0; - size_t inbytesleft = CHUNK_IN; - size_t outbytesleft = CHUNK_OUT; - int mustread = 1; - - while (1) - { - size_t r; - if (mustread) - { - r = fread (inbuf, 1, inbytesleft, inf); - if (inbytesleft != r) - { - if (ferror(inf)) - { - fprintf (stderr, "yaziconv: error reading file\n"); - exit (6); - } - if (r == 0) - { - if (outbuf != outbuf0) - fwrite (outbuf0, 1, outbuf - outbuf0, stdout); - break; - } - inbytesleft = r; - } - } - if (verbose > 1) - { - fprintf (stderr, "yaz_iconv: inbytesleft=%d outbytesleft=%d\n", - inbytesleft, outbytesleft); - - } - r = yaz_iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - if (r == (size_t)(-1)) - { - int e = yaz_iconv_error(cd); - if (e == YAZ_ICONV_EILSEQ) - { - fprintf (stderr, "invalid sequence\n"); - return ; - } - else if (e == YAZ_ICONV_EINVAL) /* incomplete input */ - { - size_t i; - for (i = 0; i +#endif + +#include +#include +#include + +#include + +const char *buf[] = { + "ax" , + "\330", + "eneb\346r", + 0 }; + +static dconvert(int mandatory, const char *tmpcode) +{ + int i; + yaz_iconv_t cd; + for (i = 0; buf[i]; i++) + { + int j; + size_t r; + char *inbuf = (char*) buf[i]; + size_t inbytesleft = strlen(inbuf); + char outbuf0[24]; + char outbuf1[10]; + char *outbuf = outbuf0; + size_t outbytesleft = sizeof(outbuf0); + + cd = yaz_iconv_open(tmpcode, "ISO-8859-1"); + if (!cd) + { + if (!mandatory) + return; + printf ("tsticonv 1\n"); + exit(1); + } + r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (r == (size_t)(-1)) + { + int e = yaz_iconv_error(cd); + + printf ("tsticonv 2 e=%d\n", e); + exit(2); + } + yaz_iconv_close(cd); + + cd = yaz_iconv_open("ISO-8859-1", tmpcode); + if (!cd) + { + if (!mandatory) + return; + printf ("tsticonv 3\n"); + exit(3); + } + 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 4 e=%d\n", e); + exit(4); + } + if (strlen(buf[i]) == (sizeof(outbuf1) - outbytesleft) && + memcmp(outbuf1, buf[i], strlen(buf[i]))) + { + printf ("tsticonv 5\n"); + exit(5); + } + yaz_iconv_close(cd); + } +} + +int main (int argc, char **argv) +{ + dconvert(1, "UTF-8"); + dconvert(1, "ISO-8859-1"); + dconvert(1, "UCS4"); + dconvert(0, "CP865"); + exit (0); +} diff --git a/util/tstnmem.c b/util/tstnmem.c new file mode 100644 index 0000000..c8b0569 --- /dev/null +++ b/util/tstnmem.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002-2003, Index Data + * See the file LICENSE for details. + * + * $Id: tstnmem.c,v 1.1 2003-04-23 20:34:08 adam Exp $ + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include + +int main (int argc, char **argv) +{ + void *cp; + NMEM n; + int j; + + nmem_init(); + n = nmem_create(); + if (!n) + exit (1); + for (j = 1; j<500; j++) + { + cp = nmem_malloc(n, j); + if (!cp) + exit(2); + } + + for (j = 2000; j<20000; j+= 2000) + { + cp = nmem_malloc(n, j); + if (!cp) + exit(3); + } + nmem_destroy(n); + nmem_exit(); + exit(0); +} diff --git a/util/yaziconv.c b/util/yaziconv.c new file mode 100644 index 0000000..958aa9a --- /dev/null +++ b/util/yaziconv.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 1997-2003, Index Data + * See the file LICENSE for details. + * + * $Id: yaziconv.c,v 1.1 2003-04-23 20:34:08 adam Exp $ + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include + +#define CHUNK_IN 64 +#define CHUNK_OUT 64 + +void convert (FILE *inf, yaz_iconv_t cd, int verbose) +{ + char inbuf0[CHUNK_IN], *inbuf = inbuf0; + char outbuf0[CHUNK_OUT], *outbuf = outbuf0; + size_t inbytesleft = CHUNK_IN; + size_t outbytesleft = CHUNK_OUT; + int mustread = 1; + + while (1) + { + size_t r; + if (mustread) + { + r = fread (inbuf, 1, inbytesleft, inf); + if (inbytesleft != r) + { + if (ferror(inf)) + { + fprintf (stderr, "yaziconv: error reading file\n"); + exit (6); + } + if (r == 0) + { + if (outbuf != outbuf0) + fwrite (outbuf0, 1, outbuf - outbuf0, stdout); + break; + } + inbytesleft = r; + } + } + if (verbose > 1) + { + fprintf (stderr, "yaz_iconv: inbytesleft=%d outbytesleft=%d\n", + inbytesleft, outbytesleft); + + } + r = yaz_iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (r == (size_t)(-1)) + { + int e = yaz_iconv_error(cd); + if (e == YAZ_ICONV_EILSEQ) + { + fprintf (stderr, "invalid sequence\n"); + return ; + } + else if (e == YAZ_ICONV_EINVAL) /* incomplete input */ + { + size_t i; + for (i = 0; i