1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/* This file is part of the Zebra server.
Copyright (C) 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.
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
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <idzebra/bfile.h>
#include <sortidx.h>
#include "testlib.h"
static void sort_add_cstr(zebra_sort_index_t si, const char *str,
zint section_id)
{
WRBUF w = wrbuf_alloc();
wrbuf_puts(w, str);
wrbuf_putc(w, '\0');
zebra_sort_add(si, section_id, w);
wrbuf_destroy(w);
}
static void tst1(zebra_sort_index_t si)
{
zint sysno = 12; /* just some sysno */
int my_type = 2; /* just some type ID */
WRBUF w = wrbuf_alloc();
zebra_sort_type(si, my_type);
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
sort_add_cstr(si, "abcde1", 0);
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
zebra_sort_sysno(si, sysno+1);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
zebra_sort_sysno(si, sysno-1);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
zebra_sort_sysno(si, sysno);
zebra_sort_delete(si, 0);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
zebra_sort_type(si, my_type);
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
wrbuf_rewind(w);
sort_add_cstr(si, "abcde1", 0);
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
zebra_sort_sysno(si, sysno);
zebra_sort_delete(si, 0);
wrbuf_destroy(w);
}
static void tst2(zebra_sort_index_t si)
{
zint sysno = 15; /* just some sysno */
int my_type = 2; /* just some type ID */
int i;
zebra_sort_type(si, my_type);
for (sysno = 1; sysno < 50; sysno++)
{
zint input_section_id = 12345;
zint output_section_id = 0;
WRBUF w1 = wrbuf_alloc();
WRBUF w2 = wrbuf_alloc();
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w2), 0);
for (i = 0; i < 600; i++) /* 600 * 6 < max size =4K */
wrbuf_write(w1, "12345", 6);
zebra_sort_add(si, input_section_id, w1);
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, &output_section_id, w2), 1);
YAZ_CHECK_EQ(wrbuf_len(w1), wrbuf_len(w2));
YAZ_CHECK(!memcmp(wrbuf_buf(w1), wrbuf_buf(w2), wrbuf_len(w2)));
YAZ_CHECK_EQ(input_section_id, output_section_id);
wrbuf_destroy(w1);
wrbuf_destroy(w2);
}
}
static void tst(int argc, char **argv)
{
BFiles bfs = bfs_create(".:50M", 0);
zebra_sort_index_t si;
YAZ_CHECK(bfs);
if (bfs)
{
bf_reset(bfs);
si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_FLAT);
YAZ_CHECK(si);
if (si)
{
tst1(si);
zebra_sort_close(si);
}
}
if (bfs)
{
bf_reset(bfs);
si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_ISAMB);
YAZ_CHECK(si);
if (si)
{
tst1(si);
zebra_sort_close(si);
}
}
if (bfs)
{
bf_reset(bfs);
si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_MULTI);
YAZ_CHECK(si);
if (si)
{
tst1(si);
tst2(si);
zebra_sort_close(si);
}
}
if (bfs)
bfs_destroy(bfs);
}
TL_MAIN
/*
* Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
|