1 /* This file is part of the Zebra server.
2 Copyright (C) 1995-2008 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <idzebra/bfile.h>
24 static void sort_add_cstr(zebra_sort_index_t si, const char *str)
26 WRBUF w = wrbuf_alloc();
29 zebra_sort_add(si, w);
33 static void tst1(zebra_sort_index_t si)
35 zint sysno = 12; /* just some sysno */
36 int my_type = 2; /* just some type ID */
37 WRBUF w = wrbuf_alloc();
39 zebra_sort_type(si, my_type);
41 zebra_sort_sysno(si, sysno);
42 YAZ_CHECK_EQ(zebra_sort_read(si, w), 0);
44 sort_add_cstr(si, "abcde1");
46 zebra_sort_sysno(si, sysno);
47 YAZ_CHECK_EQ(zebra_sort_read(si, w), 1);
48 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
50 zebra_sort_sysno(si, sysno+1);
51 YAZ_CHECK_EQ(zebra_sort_read(si, w), 0);
53 zebra_sort_sysno(si, sysno-1);
54 YAZ_CHECK_EQ(zebra_sort_read(si, w), 0);
56 zebra_sort_sysno(si, sysno);
57 zebra_sort_delete(si);
58 YAZ_CHECK_EQ(zebra_sort_read(si, w), 0);
60 zebra_sort_type(si, my_type);
62 zebra_sort_sysno(si, sysno);
63 YAZ_CHECK_EQ(zebra_sort_read(si, w), 0);
66 sort_add_cstr(si, "abcde1");
68 zebra_sort_sysno(si, sysno);
69 YAZ_CHECK_EQ(zebra_sort_read(si, w), 1);
70 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
72 zebra_sort_sysno(si, sysno);
73 zebra_sort_delete(si);
78 static void tst2(zebra_sort_index_t si)
80 zint sysno = 15; /* just some sysno */
81 int my_type = 2; /* just some type ID */
84 zebra_sort_type(si, my_type);
86 for (sysno = 1; sysno < 50; sysno++)
88 WRBUF w1 = wrbuf_alloc();
89 WRBUF w2 = wrbuf_alloc();
90 zebra_sort_sysno(si, sysno);
91 YAZ_CHECK_EQ(zebra_sort_read(si, w2), 0);
93 for (i = 0; i < 600; i++) /* 600 * 6 < max size =4K */
94 wrbuf_write(w1, "12345", 6);
96 zebra_sort_add(si, w1);
98 zebra_sort_sysno(si, sysno);
100 YAZ_CHECK_EQ(zebra_sort_read(si, w2), 1);
102 YAZ_CHECK_EQ(wrbuf_len(w1), wrbuf_len(w2));
103 YAZ_CHECK(!memcmp(wrbuf_buf(w1), wrbuf_buf(w2), wrbuf_len(w2)));
109 static void tst(int argc, char **argv)
111 BFiles bfs = bfs_create(".:50M", 0);
112 zebra_sort_index_t si;
118 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_FLAT);
123 zebra_sort_close(si);
129 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_ISAMB);
134 zebra_sort_close(si);
140 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_MULTI);
146 zebra_sort_close(si);
157 * indent-tabs-mode: nil
159 * vim: shiftwidth=4 tabstop=8 expandtab