Added other sort index test.
[idzebra-moved-to-github.git] / test / api / test_sortidx.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17
18 */
19
20 #include <idzebra/bfile.h>
21 #include <sortidx.h>
22 #include "testlib.h"
23
24 static void tst1(zebra_sort_index_t si)
25 {
26     zint sysno = 12; /* just some sysno */
27     int my_type = 2; /* just some type ID */
28     char read_buf[SORT_IDX_ENTRYSIZE];
29
30     zebra_sort_type(si, my_type);
31
32     zebra_sort_sysno(si, sysno);
33     YAZ_CHECK_EQ(zebra_sort_read(si, read_buf), 0);
34
35     zebra_sort_add(si, "abcde1", 6);
36
37     zebra_sort_sysno(si, sysno);
38     YAZ_CHECK_EQ(zebra_sort_read(si, read_buf), 1);
39     YAZ_CHECK(!strcmp(read_buf, "abcde1"));
40
41     zebra_sort_sysno(si, sysno+1);
42     YAZ_CHECK_EQ(zebra_sort_read(si, read_buf), 0);
43
44     zebra_sort_sysno(si, sysno-1);
45     YAZ_CHECK_EQ(zebra_sort_read(si, read_buf), 0);
46
47     zebra_sort_sysno(si, sysno);
48     zebra_sort_delete(si);
49     YAZ_CHECK_EQ(zebra_sort_read(si, read_buf), 0);
50 }
51
52 static void tst(int argc, char **argv)
53 {
54     BFiles bfs = bfs_create(".:50M", 0);
55     zebra_sort_index_t si;
56
57     YAZ_CHECK(bfs);
58     if (bfs)
59     {
60         bf_reset(bfs);
61         si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_ISAMB);
62         YAZ_CHECK(si);
63         if (si)
64         {
65             tst1(si);
66             zebra_sort_close(si);
67         }
68     }
69
70     if (bfs)
71     {
72         bf_reset(bfs);
73         si = zebra_sort_open(bfs, 1, ZEBRA_SORT_TYPE_FLAT);
74         YAZ_CHECK(si);
75         if (si)
76         {
77             tst1(si);
78             zebra_sort_close(si);
79         }
80     }
81     if (bfs)
82         bfs_destroy(bfs);
83 }
84
85 TL_MAIN
86 /*
87  * Local variables:
88  * c-basic-offset: 4
89  * indent-tabs-mode: nil
90  * End:
91  * vim: shiftwidth=4 tabstop=8 expandtab
92  */
93