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
20 #include <idzebra/bfile.h>
24 static void sort_add_cstr(zebra_sort_index_t si, const char *str,
27 WRBUF w = wrbuf_alloc();
30 zebra_sort_add(si, section_id, w);
34 static void tst1(zebra_sort_index_t si)
36 zint sysno = 12; /* just some sysno */
37 int my_type = 2; /* just some type ID */
38 WRBUF w = wrbuf_alloc();
40 zebra_sort_type(si, my_type);
42 zebra_sort_sysno(si, sysno);
43 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
45 sort_add_cstr(si, "abcde1", 0);
47 zebra_sort_sysno(si, sysno);
48 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
49 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
51 zebra_sort_sysno(si, sysno+1);
52 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
54 zebra_sort_sysno(si, sysno-1);
55 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
57 zebra_sort_sysno(si, sysno);
58 zebra_sort_delete(si, 0);
59 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
61 zebra_sort_type(si, my_type);
63 zebra_sort_sysno(si, sysno);
64 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 0);
67 sort_add_cstr(si, "abcde1", 0);
69 zebra_sort_sysno(si, sysno);
70 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w), 1);
71 YAZ_CHECK(!strcmp(wrbuf_cstr(w), "abcde1"));
73 zebra_sort_sysno(si, sysno);
74 zebra_sort_delete(si, 0);
79 static void tst2(zebra_sort_index_t si)
81 zint sysno = 15; /* just some sysno */
82 int my_type = 2; /* just some type ID */
85 zebra_sort_type(si, my_type);
87 for (sysno = 1; sysno < 50; sysno++)
89 zint input_section_id = 12345;
90 zint output_section_id = 0;
91 WRBUF w1 = wrbuf_alloc();
92 WRBUF w2 = wrbuf_alloc();
93 zebra_sort_sysno(si, sysno);
94 YAZ_CHECK_EQ(zebra_sort_read(si, 0, w2), 0);
96 for (i = 0; i < 600; i++) /* 600 * 6 < max size =4K */
97 wrbuf_write(w1, "12345", 6);
99 zebra_sort_add(si, input_section_id, w1);
101 zebra_sort_sysno(si, sysno);
103 YAZ_CHECK_EQ(zebra_sort_read(si, &output_section_id, w2), 1);
105 YAZ_CHECK_EQ(wrbuf_len(w1), wrbuf_len(w2));
106 YAZ_CHECK(!memcmp(wrbuf_buf(w1), wrbuf_buf(w2), wrbuf_len(w2)));
107 YAZ_CHECK_EQ(input_section_id, output_section_id);
113 static void tst(int argc, char **argv)
115 BFiles bfs = bfs_create(".:50M", 0);
116 zebra_sort_index_t si;
122 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_FLAT);
127 zebra_sort_close(si);
133 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_ISAMB);
138 zebra_sort_close(si);
144 si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_MULTI);
150 zebra_sort_close(si);
161 * c-file-style: "Stroustrup"
162 * indent-tabs-mode: nil
164 * vim: shiftwidth=4 tabstop=8 expandtab