File: test_odrstack.c

package info (click to toggle)
yaz 5.37.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,568 kB
  • sloc: xml: 124,223; ansic: 73,221; sh: 5,738; tcl: 2,189; makefile: 1,274; yacc: 382
file content (80 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This file is part of the YAZ toolkit.
 * Copyright (C) Index Data
 * See the file LICENSE for details.
 */
#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <yaz/pquery.h>
#include <yaz/proto.h>
#include <yaz/test.h>

/** \brief build a 100 level query */
void test1(void)
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    char qstr[10000];
    int i;
    int ret;

    YAZ_CHECK(odr);
    YAZ_CHECK(parser);

    *qstr = '\0';
    for (i = 0; i<100; i++)
        strcat(qstr, "@and 1 ");
    strcat(qstr, "1");

    rpn_query = yaz_pqf_parse (parser, odr, qstr);
    YAZ_CHECK(rpn_query);

    ret = z_RPNQuery(odr, &rpn_query, 0, 0);
    YAZ_CHECK(ret);

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

/** \brief build a circular referenced query */
void test2(void)
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    int ret;

    YAZ_CHECK(odr);

    rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
    YAZ_CHECK(rpn_query);

    /* make the circular reference */
    rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;

    ret = z_RPNQuery(odr, &rpn_query, 0, 0);  /* should fail */
    YAZ_CHECK(!ret);

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

int main(int argc, char **argv)
{
    YAZ_CHECK_INIT(argc, argv);
    test1();
    test2();
    YAZ_CHECK_TERM;
}
/*
 * Local variables:
 * c-basic-offset: 4
 * c-file-style: "Stroustrup"
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */