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