This test checks for bug #281 as well.
[idzebra-moved-to-github.git] / test / api / t6.c
1 /* $Id: t6.c,v 1.8 2005-04-20 10:20:32 adam Exp $
2    Copyright (C) 1995-2005
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 int main(int argc, char **argv)
28 {
29     int i;
30     ZebraService zs = start_up(0, argc, argv);
31     ZebraHandle zh = zebra_open(zs);
32
33     srand(17);
34     
35     zebra_select_database(zh, "Default");
36     zebra_init(zh);
37     zebra_close(zh);
38
39     for (i = 0; i<10; i++)
40     {
41         int l;
42
43         zh = zebra_open (zs);
44         zebra_select_database(zh, "Default");
45         
46         zebra_begin_trans (zh, 1);
47
48         for (l = 0; l<1000; l++)
49         {
50             char rec_buf[5120];
51             int j;
52             *rec_buf = '\0';
53             strcat(rec_buf, "<gils><title>");
54             if (i == 0)
55             {
56                 sprintf(rec_buf + strlen(rec_buf), "aaa");
57             }
58             else
59             {
60                 j = (rand() & 15) + 1;
61                 while (--j >= 0)
62                 {
63                     int c = 65 + (rand() & 15);
64                     sprintf(rec_buf + strlen(rec_buf), "%c", c);
65                 }
66             }
67             strcat(rec_buf, "</title><Control-Identifier>");
68             j = rand() & 31;
69             sprintf(rec_buf + strlen(rec_buf), "%d", j);
70             strcat(rec_buf, "</Control-Identifier></gils>");
71             zebra_add_record (zh, rec_buf, strlen(rec_buf));
72         }
73         zebra_end_trans(zh);
74         zebra_close(zh);
75     }
76     zh = zebra_open(zs);
77
78     zebra_select_database(zh, "Default");
79
80     zebra_set_resource(zh, "trunclimit", "2");
81
82     /* check massive truncation: bug #281 */
83     do_query(__LINE__, zh, "@attr 1=4 @attr 2=1 z", -1);
84
85     return close_down(zh, zs, 0);
86 }