diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/forlan01.at | 77 | ||||
-rw-r--r-- | tests/testsuite.at | 4 | ||||
-rw-r--r-- | tests/tforlan.c | 100 |
5 files changed, 184 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 99d3c9c..8b76ee0 100644 --- a/tests/.gitignore +++ b/tests/.gitignore | |||
@@ -4,6 +4,7 @@ package.m4 | |||
4 | testsuite | 4 | testsuite |
5 | testsuite.dir | 5 | testsuite.dir |
6 | testsuite.log | 6 | testsuite.log |
7 | tforlan | ||
7 | thmac | 8 | thmac |
8 | turlenc | 9 | turlenc |
9 | txml | 10 | txml |
diff --git a/tests/Makefile.am b/tests/Makefile.am index 82cae7e..4d567b3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -40,6 +40,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac | |||
40 | ## ------------ ## | 40 | ## ------------ ## |
41 | 41 | ||
42 | TESTSUITE_AT = \ | 42 | TESTSUITE_AT = \ |
43 | forlan01.at\ | ||
43 | hmac01.at\ | 44 | hmac01.at\ |
44 | hmac02.at\ | 45 | hmac02.at\ |
45 | hmac03.at\ | 46 | hmac03.at\ |
@@ -69,6 +70,7 @@ check-local: atconfig atlocal $(TESTSUITE) | |||
69 | # $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin | 70 | # $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin |
70 | 71 | ||
71 | noinst_PROGRAMS = \ | 72 | noinst_PROGRAMS = \ |
73 | tforlan\ | ||
72 | thmac\ | 74 | thmac\ |
73 | turlenc\ | 75 | turlenc\ |
74 | txml | 76 | txml |
diff --git a/tests/forlan01.at b/tests/forlan01.at new file mode 100644 index 0000000..cf826e9 --- /dev/null +++ b/tests/forlan01.at | |||
@@ -0,0 +1,77 @@ | |||
1 | # This file is part of Eclat -*- Autotest -*- | ||
2 | # Copyright (C) 2012 Sergey Poznyakoff | ||
3 | # | ||
4 | # Eclat is free software; you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation; either version 3, or (at your option) | ||
7 | # any later version. | ||
8 | # | ||
9 | # Eclat is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with Eclat. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | AT_SETUP([dump]) | ||
18 | AT_KEYWORDS([forlan forlan01]) | ||
19 | |||
20 | AT_DATA([input],[// test format for DescribeTags | ||
21 | if (.DescribeTagsResponse) { | ||
22 | if (.DescribeTagsResponse.tagSet.item.resourceId[[i-deadbeef]] && | ||
23 | parent(last).key[[hostname]]) | ||
24 | print(parent(last).value); | ||
25 | } else if (.Response.Errors) | ||
26 | error(.Response.Errors.Error.Message); | ||
27 | else | ||
28 | dump(); | ||
29 | ]) | ||
30 | |||
31 | AT_CHECK([tforlan -D input], | ||
32 | [0], | ||
33 | [0001: COND | ||
34 | 0002: NODE | ||
35 | 0003: COMP ABS | ||
36 | 0004: LIT: "DescribeTagsResponse" | ||
37 | 0005: IFTRUE 0001 | ||
38 | 0006: COND | ||
39 | 0007: AND | ||
40 | 0008: NODE | ||
41 | 0009: COMP ABS | ||
42 | 0010: LIT: "DescribeTagsResponse" | ||
43 | 0011: LIT: "tagSet" | ||
44 | 0012: LIT: "item" | ||
45 | 0013: TEST: resourceId[[i-deadbeef]] | ||
46 | 0014: NODE | ||
47 | 0015: COMP | ||
48 | 0016: CALL: parent | ||
49 | 0017: LAST | ||
50 | 0018: TEST: key[[hostname]] | ||
51 | 0019: IFTRUE 0006 | ||
52 | 0020: CALL: print | ||
53 | 0021: COMP | ||
54 | 0022: CALL: parent | ||
55 | 0023: LAST | ||
56 | 0024: LIT: "value" | ||
57 | 0025: IFFALSE 0006 | ||
58 | 0026: IFFALSE 0001 | ||
59 | 0027: COND | ||
60 | 0028: NODE | ||
61 | 0029: COMP ABS | ||
62 | 0030: LIT: "Response" | ||
63 | 0031: LIT: "Errors" | ||
64 | 0032: IFTRUE 0027 | ||
65 | 0033: CALL: error | ||
66 | 0034: COMP ABS | ||
67 | 0035: LIT: "Response" | ||
68 | 0036: LIT: "Errors" | ||
69 | 0037: LIT: "Error" | ||
70 | 0038: LIT: "Message" | ||
71 | 0039: IFFALSE 0027 | ||
72 | 0040: CALL: dump | ||
73 | ]) | ||
74 | |||
75 | AT_CLEANUP | ||
76 | |||
77 | |||
diff --git a/tests/testsuite.at b/tests/testsuite.at index f40b8a7..81e91f4 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at | |||
@@ -29,4 +29,8 @@ m4_include([urlenc01.at]) | |||
29 | 29 | ||
30 | AT_BANNER([XML Processing]) | 30 | AT_BANNER([XML Processing]) |
31 | m4_include([xml01.at]) | 31 | m4_include([xml01.at]) |
32 | |||
33 | AT_BANNER([Forlan]) | ||
34 | m4_include([forlan01.at]) | ||
35 | |||
32 | # End of testsuite.at | 36 | # End of testsuite.at |
diff --git a/tests/tforlan.c b/tests/tforlan.c new file mode 100644 index 0000000..9fc3495 --- /dev/null +++ b/tests/tforlan.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* This file is part of Eclat. | ||
2 | Copyright (C) 2012 Sergey Poznyakoff. | ||
3 | |||
4 | Eclat is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Eclat is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include <config.h> | ||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <unistd.h> | ||
21 | #ifdef HAVE_GETOPT_H | ||
22 | # include <getopt.h> | ||
23 | #endif | ||
24 | #include <errno.h> | ||
25 | #include <sysexits.h> | ||
26 | #include <libeclat.h> | ||
27 | #include "forlan.h" | ||
28 | #include <sys/stat.h> | ||
29 | |||
30 | void | ||
31 | usage() | ||
32 | { | ||
33 | printf("usage: %s [-dD] FILE [INPUT]\n"); | ||
34 | } | ||
35 | |||
36 | int | ||
37 | main(int argc, char **argv) | ||
38 | { | ||
39 | FILE *fp; | ||
40 | char *buf; | ||
41 | size_t len; | ||
42 | struct stat st; | ||
43 | struct grecs_locus_point pt; | ||
44 | int rc; | ||
45 | int dump_option = 0; | ||
46 | |||
47 | set_program_name(argv[0]); | ||
48 | forlan_init(); | ||
49 | |||
50 | while ((rc = getopt(argc, argv, "Dd:h")) != EOF) | ||
51 | switch (rc) { | ||
52 | case 'D': | ||
53 | dump_option++; | ||
54 | break; | ||
55 | |||
56 | case 'd': | ||
57 | if (parse_debug_level(optarg)) | ||
58 | die(EX_USAGE, "bad debug category or level"); | ||
59 | break; | ||
60 | |||
61 | case 'h': | ||
62 | usage(); | ||
63 | return 0; | ||
64 | |||
65 | default: | ||
66 | exit(EX_USAGE); | ||
67 | } | ||
68 | argc -= optind; | ||
69 | argv += optind; | ||
70 | |||
71 | |||
72 | if (argc == 0 || argc > 2) | ||
73 | die(EX_USAGE, "one or two arguments expected"); | ||
74 | if (stat(argv[0], &st)) | ||
75 | die(EX_UNAVAILABLE, "cannot stat input file \"%s\": %s", | ||
76 | argv[0], strerror(errno)); | ||
77 | len = st.st_size; | ||
78 | buf = grecs_malloc(len); | ||
79 | fp = fopen(argv[0], "r"); | ||
80 | if (!fp) | ||
81 | die(EX_UNAVAILABLE, "cannot open input file \"%s\": %s", | ||
82 | argv[0], strerror(errno)); | ||
83 | if (fread(buf, len, 1, fp) != 1) | ||
84 | die(EX_UNAVAILABLE, "error reading from \"%s\": %s", | ||
85 | argv[0], strerror(errno)); | ||
86 | fclose(fp); | ||
87 | |||
88 | pt.file = argv[0]; | ||
89 | pt.line = 1; | ||
90 | pt.col = 0; | ||
91 | |||
92 | rc = forlan_parse(buf, len, &pt); | ||
93 | if (rc == 0) { | ||
94 | if (dump_option) | ||
95 | forlan_dump_tree(stdout, forlan_parse_tree); | ||
96 | forlan_node_free(forlan_parse_tree); | ||
97 | } | ||
98 | return rc ? EX_UNAVAILABLE : 0; | ||
99 | } | ||
100 | |||