Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / test / api / t12.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 /** Create many databases */
21
22 #include "testlib.h"
23
24 static void tst(int argc, char **argv)
25 {
26     int i;
27     int no_db = 140;
28     ZebraService zs = tl_start_up(0, argc, argv);
29     ZebraHandle zh = zebra_open(zs, 0);
30
31     YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
32     YAZ_CHECK(zebra_init(zh) == ZEBRA_OK);
33     zebra_close(zh);
34
35     zh = zebra_open(zs, 0);
36     YAZ_CHECK(zh);
37     
38     YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK);
39
40     for (i = 0; i<no_db; i++)
41     {
42         char dbstr[20];
43         char rec_buf[100];
44
45         sprintf(dbstr, "%d", i);
46         YAZ_CHECK(zebra_select_database(zh, dbstr) == ZEBRA_OK);
47     
48         sprintf(rec_buf, "<gils><title>title %d</title></gils>\n", i);
49         zebra_add_record (zh, rec_buf, strlen(rec_buf));
50
51     }
52     YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
53
54     zebra_close(zh);
55     zh = zebra_open(zs, 0);
56     YAZ_CHECK(zh);
57     for (i = 0; i<=no_db; i++)
58     {
59         char dbstr[20];
60         char querystr[50];
61         sprintf(dbstr, "%d", i);
62         YAZ_CHECK(zebra_select_database(zh, dbstr) == ZEBRA_OK);
63
64         sprintf(querystr, "@attr 1=4 %d", i);
65         if (i == no_db)
66         {
67             YAZ_CHECK(tl_query_x(zh, querystr, 0, 109));
68         }
69         else
70         {
71             YAZ_CHECK(tl_query(zh, querystr, 1));
72         }
73     }
74     YAZ_CHECK(tl_close_down(zh, zs));
75 }
76
77 TL_MAIN
78
79 /*
80  * Local variables:
81  * c-basic-offset: 4
82  * indent-tabs-mode: nil
83  * End:
84  * vim: shiftwidth=4 tabstop=8 expandtab
85  */
86