1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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
23 #include <idzebra/bfile.h>
27 static void sort_add_cstr(zebra_sort_index_t si, const char *str,
30 WRBUF w = wrbuf_alloc();
33 zebra_sort_add(si, section_id, w);
37 static void tst1(zebra_sort_index_t si)
39 zint sysno = 12; /* just some sysno */
40 int my_type = 2; /* just some type ID */
41 WRBUF w = wrbuf_alloc();
43 zebra_sort_type(si, my_type);
45 zebra_sort_sysno(si, sysno);
46 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
48 sort_add_cstr(si, "abcde1", 0);
50 zebra_sort_sysno(si, sysno);
51 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
52 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
54 zebra_sort_sysno(si, sysno+1);
55 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
57 zebra_sort_sysno(si, sysno-1);
58 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
60 zebra_sort_sysno(si, sysno);
61 zebra_sort_delete(si, 0);
62 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
64 zebra_sort_type(si, my_type);
66 zebra_sort_sysno(si, sysno);
67 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
70 sort_add_cstr(si, "abcde1", 0);
72 zebra_sort_sysno(si, sysno);
73 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
74 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
76 zebra_sort_sysno(si, sysno);
77 zebra_sort_delete(si, 0);
82 static void tst2(zebra_sort_index_t si)
84 zint sysno = 15; /* just some sysno */
85 int my_type = 2; /* just some type ID */
88 zebra_sort_type(si, my_type);
90 for (sysno = 1; sysno < 50; sysno++)
92 zint input_section_id = 12345;
93 zint output_section_id = 0;
94 WRBUF w1 = wrbuf_alloc();
95 WRBUF w2 = wrbuf_alloc();
96 zebra_sort_sysno(si, sysno);
97 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w2), 0);
99 for (i = 0; i < 600; i++) /* 600 * 6 < max size =4K */
100 wrbuf_write(w1, "12345", 6);
102 zebra_sort_add(si, input_section_id, w1);
104 zebra_sort_sysno(si, sysno);
106 YAZ_CHECK_EQ(zebra_sort_read(si, &output_section_id, w2), 1);
108 YAZ_CHECK_EQ(wrbuf_len(w1), wrbuf_len(w2));
109 YAZ_CHECK(!memcmp(wrbuf_buf(w1), wrbuf_buf(w2), wrbuf_len(w2)));
110 YAZ_CHECK_EQ(input_section_id, output_section_id);
116 static void tst(int argc, char **argv)
118 BFiles bfs = bfs_create(".:50M", 0);
119 zebra_sort_index_t si;
125 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_FLAT);
130 zebra_sort_close(si);
136 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_ISAMB);
141 zebra_sort_close(si);
147 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_MULTI);
153 zebra_sort_close(si);
164 * c-file-style: "Stroustrup"
165 * indent-tabs-mode: nil
167 * vim: shiftwidth=4 tabstop=8 expandtab