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