23f2cefe7ce047d14458b6adb3e4abe631b3367c
[idzebra-moved-to-github.git] / test / api / t6.c
1 /* $Id: t6.c,v 1.5 2004-10-29 13:02:39 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /** t6.c Insert a number of randomly generated words */
24
25 #include "testlib.h"
26
27         
28 int main(int argc, char **argv)
29 {
30     int i;
31     ZebraService zs = start_up(0, argc, argv);
32     ZebraHandle  zh = zebra_open (zs);
33
34     
35     srand(17);
36     
37     zebra_select_database(zh, "Default");
38     zebra_init(zh);
39     zebra_close(zh);
40
41     for (i = 0; i<100; i++)
42     {
43         char rec_buf[5120];
44         int j;
45
46         zh = zebra_open (zs);
47         zebra_select_database(zh, "Default");
48         
49         zebra_begin_trans (zh, 1);
50
51         *rec_buf = '\0';
52         strcat(rec_buf, "<gils><title>");
53         j = (rand() & 15) + 1;
54         while (--j >= 0)
55         {
56             int c = 65 + (rand() & 15);
57             sprintf(rec_buf + strlen(rec_buf), "%c ", c);
58         }
59         strcat(rec_buf, "</title><Control-Identifier>");
60         j = rand() & 31;
61         sprintf(rec_buf + strlen(rec_buf), "%d", j);
62         strcat(rec_buf, "</Control-Identifier></gils>");
63         zebra_add_record (zh, rec_buf, strlen(rec_buf));
64
65         zebra_end_trans (zh);
66         zebra_close(zh);
67     }
68
69     return close_down(0 /*zh*/ ,zs,0);
70 }