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