X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=test%2Fcodec%2Ftstcodec.c;h=37562c6fa591ae35ea8d29302ee8aecc3fed6b01;hp=029cb50dc92c062463fca543e753992365af3bad;hb=97a7adeb9e5059463f039495cc01cfa448463a27;hpb=7ed734cd2fbccac903039ef91a9086763a39ace4 diff --git a/test/codec/tstcodec.c b/test/codec/tstcodec.c index 029cb50..37562c6 100644 --- a/test/codec/tstcodec.c +++ b/test/codec/tstcodec.c @@ -1,28 +1,231 @@ -#include "../index/index.h" +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 Index Data +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. -void tst_encode(int num) +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include +#include "../../index/index.h" + +char *prog = ""; + +int tst_encode(int num) { struct it_key key; int i; - void *codec_handle =iscz1_code_start(ISAMC_ENCODE); + void *codec_handle =iscz1_start(); + char *dst_buf = malloc(200 + num * 10); + char *dst = dst_buf; + if (!dst_buf) + { + printf ("%s: out of memory (num=%d)\n", prog, num); + return 10; + } + + for (i = 0; i dst_buf + num*10) + { + printf ("%s: i=%d size overflow\n", prog, i); + return 1; + } + } + iscz1_stop(codec_handle); + + codec_handle =iscz1_start(); + + if (1) + { + const char *src = dst_buf; + for (i = 0; i>8); + while (src0 != src) + { + printf (" %02X (%d decimal)", *src0, *src0); + src0++; + } + printf ("\n"); + return 3; + } + if (key.mem[1] != (i&255)) + { + printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n", + prog, i, key.mem[1], i&255); + while (src0 != src) + { + printf (" %02X (%d decimal)", *src0, *src0); + src0++; + } + printf ("\n"); + return 4; + } + } + } + + iscz1_stop(codec_handle); + free(dst_buf); + return 0; +} + +void tstcodec1(void) +{ + char buf[100]; + char *dst = buf; + const char *src; + struct it_key key1; + struct it_key key2; + void *codec_handle =iscz1_start(); + + memset(&key1, 0, sizeof(key1)); + memset(&key2, 0, sizeof(key2)); + + key1.len = 4; + key1.mem[0] = 4*65536+1016; + key1.mem[1] = 24339; + key1.mem[2] = 125060; + key1.mem[3] = 1; + + src = (char*) &key1; + dst = buf; + iscz1_encode(codec_handle, &dst, &src); + + iscz1_stop(codec_handle); + + codec_handle =iscz1_start(); + + dst = (char*) &key2; + src = buf; + + iscz1_decode(codec_handle, &dst, &src); + + iscz1_stop(codec_handle); + + if (memcmp(&key1, &key2, sizeof(key1))) + { + const char *cp1 = (char*) &key1; + const char *cp2 = (char*) &key2; + int i; + for (i = 0; i 1) + num = atoi(argv[1]); + if (num < 1 || num > 100000000) + num = 10000; + tstcodec1(); + ret = tstcodec2(500); + ret = tst_encode(num); + exit(ret); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +