Break long lines in debian/control
[idzebra-moved-to-github.git] / dfa / test_dfa.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <yaz/test.h>
24 #include <dfa.h>
25
26 int test_parse(struct DFA *dfa, const char *pattern)
27 {
28     int i;
29     const char *cp = pattern;
30     i = dfa_parse(dfa, &cp);
31     return i;
32 }
33     
34 static void tst(int argc, char **argv)
35 {
36     struct DFA *dfa = dfa_init();
37     YAZ_CHECK(dfa);
38
39     YAZ_CHECK_EQ(test_parse(dfa, ""), 1);
40     YAZ_CHECK_EQ(test_parse(dfa, "a"), 0);
41     YAZ_CHECK_EQ(test_parse(dfa, "ab"), 0);
42     YAZ_CHECK_EQ(test_parse(dfa, "(a)"), 0);
43     YAZ_CHECK_EQ(test_parse(dfa, "(a"), 1);
44     YAZ_CHECK_EQ(test_parse(dfa, "a)"), 3);
45     YAZ_CHECK_EQ(test_parse(dfa, "a\001)"), 0);
46     YAZ_CHECK_EQ(test_parse(dfa, "a\\x01"), 0);
47
48
49     YAZ_CHECK_EQ(test_parse(dfa, "(\x01\x02)(CEO3EQC/\\x01\\x0C\\x01\\x0C)"), 0);
50     dfa_delete(&dfa);
51     YAZ_CHECK(!dfa);
52 }
53
54 int main(int argc, char **argv)
55 {
56     YAZ_CHECK_INIT(argc, argv);
57     YAZ_CHECK_LOG();
58     tst(argc, argv);
59     YAZ_CHECK_TERM;
60 }
61
62 /*
63  * Local variables:
64  * c-basic-offset: 4
65  * c-file-style: "Stroustrup"
66  * indent-tabs-mode: nil
67  * End:
68  * vim: shiftwidth=4 tabstop=8 expandtab
69  */
70