df0d935b71738be2b3fedcd929cad3ef9cd35ba5
[idzebra-moved-to-github.git] / dfa / test_dfa.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #include <yaz/test.h>
21 #include <dfa.h>
22
23 int test_parse(struct DFA *dfa, const char *pattern)
24 {
25     int i;
26     const char *cp = pattern;
27     i = dfa_parse(dfa, &cp);
28     return i;
29 }
30     
31 static void tst(int argc, char **argv)
32 {
33     struct DFA *dfa = dfa_init();
34     YAZ_CHECK(dfa);
35
36     YAZ_CHECK_EQ(test_parse(dfa, ""), 1);
37     YAZ_CHECK_EQ(test_parse(dfa, "a"), 0);
38     YAZ_CHECK_EQ(test_parse(dfa, "ab"), 0);
39     YAZ_CHECK_EQ(test_parse(dfa, "(a)"), 0);
40     YAZ_CHECK_EQ(test_parse(dfa, "(a"), 1);
41     YAZ_CHECK_EQ(test_parse(dfa, "a)"), 3);
42     YAZ_CHECK_EQ(test_parse(dfa, "a\001)"), 0);
43     YAZ_CHECK_EQ(test_parse(dfa, "a\\x01"), 0);
44
45
46     YAZ_CHECK_EQ(test_parse(dfa, "(\x01\x02)(CEO3EQC/\\x01\\x0C\\x01\\x0C)"), 0);
47     dfa_delete(&dfa);
48     YAZ_CHECK(!dfa);
49 }
50
51 int main(int argc, char **argv)
52 {
53     YAZ_CHECK_INIT(argc, argv);
54     YAZ_CHECK_LOG();
55     tst(argc, argv);
56     YAZ_CHECK_TERM;
57 }
58
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66