Fixed bug #687: Missing log lines. Immediate logging (i.e. flush) is no
[yaz-moved-to-github.git] / test / tstodrstack.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: tstodrstack.c,v 1.5 2006-10-04 16:59:34 mike Exp $
6  *
7  */
8 #include <stdlib.h>
9 #include <yaz/pquery.h>
10 #include <yaz/proto.h>
11 #include <yaz/test.h>
12
13 /** \brief build a 100 level query */
14 void test1(void)
15 {
16     ODR odr = odr_createmem(ODR_ENCODE);
17     YAZ_PQF_Parser parser = yaz_pqf_create();
18     Z_RPNQuery *rpn_query;
19     char qstr[10000];
20     int i;
21     int ret;
22
23     YAZ_CHECK(odr);
24     YAZ_CHECK(parser);
25
26     *qstr = '\0';
27     for (i = 0; i<100; i++)
28         strcat(qstr, "@and 1 ");
29     strcat(qstr, "1");
30
31     rpn_query = yaz_pqf_parse (parser, odr, qstr);
32     YAZ_CHECK(rpn_query);
33
34     ret = z_RPNQuery(odr, &rpn_query, 0, 0);
35     YAZ_CHECK(ret);
36
37     yaz_pqf_destroy(parser);
38     odr_destroy(odr);
39 }
40
41 /** \brief build a circular referenced query */
42 void test2(void)
43 {
44     ODR odr = odr_createmem(ODR_ENCODE);
45     YAZ_PQF_Parser parser = yaz_pqf_create();
46     Z_RPNQuery *rpn_query;
47     int ret;
48
49     YAZ_CHECK(odr);
50
51     rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
52     YAZ_CHECK(rpn_query);
53
54     /* make the circular reference */
55     rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;
56
57     ret = z_RPNQuery(odr, &rpn_query, 0, 0);  /* should fail */
58     YAZ_CHECK(!ret);
59
60     yaz_pqf_destroy(parser);
61     odr_destroy(odr);
62 }
63
64 int main(int argc, char **argv)
65 {
66     YAZ_CHECK_INIT(argc, argv);
67     test1();
68     test2();
69     YAZ_CHECK_TERM;
70 }
71 /*
72  * Local variables:
73  * c-basic-offset: 4
74  * indent-tabs-mode: nil
75  * End:
76  * vim: shiftwidth=4 tabstop=8 expandtab
77  */