aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/testsuite.at4
-rw-r--r--tests/txml.c88
-rw-r--r--tests/xml01.at63
5 files changed, 160 insertions, 4 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 9a2f830..99d3c9c 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,3 +6,4 @@ testsuite.dir
6testsuite.log 6testsuite.log
7thmac 7thmac
8turlenc 8turlenc
9txml
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6d95607..82cae7e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,7 +44,8 @@ TESTSUITE_AT = \
44 hmac02.at\ 44 hmac02.at\
45 hmac03.at\ 45 hmac03.at\
46 testsuite.at\ 46 testsuite.at\
47 urlenc01.at 47 urlenc01.at\
48 xml01.at
48 49
49TESTSUITE = $(srcdir)/testsuite 50TESTSUITE = $(srcdir)/testsuite
50M4=m4 51M4=m4
@@ -69,10 +70,11 @@ check-local: atconfig atlocal $(TESTSUITE)
69 70
70noinst_PROGRAMS = \ 71noinst_PROGRAMS = \
71 thmac\ 72 thmac\
72 turlenc 73 turlenc\
74 txml
73 75
74LDADD = ../lib/libeclat.a ../grecs/src/libgrecs.a 76LDADD = ../lib/libeclat.a ../grecs/src/libgrecs.a
75INCLUDES = -I$(top_srcdir)/lib 77INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib
76 78
77 79
78 80
diff --git a/tests/testsuite.at b/tests/testsuite.at
index c368490..f40b8a7 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -24,7 +24,9 @@ m4_include(hmac01.at)
24m4_include(hmac02.at) 24m4_include(hmac02.at)
25m4_include(hmac03.at) 25m4_include(hmac03.at)
26 26
27AT_BANNER([URL encode]) 27AT_BANNER([URL Encode])
28m4_include([urlenc01.at]) 28m4_include([urlenc01.at])
29 29
30AT_BANNER([XML Processing])
31m4_include([xml01.at])
30# End of testsuite.at 32# End of testsuite.at
diff --git a/tests/txml.c b/tests/txml.c
new file mode 100644
index 0000000..e00abc2
--- /dev/null
+++ b/tests/txml.c
@@ -0,0 +1,88 @@
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 <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include "libeclat.h"
22
23int
24main(int argc, char **argv)
25{
26 XML_Parser parser;
27 eclat_partial_tree_t part;
28 FILE *fp;
29 char buffer[128];
30 size_t size;
31 const char *filename;
32 struct grecs_node *tree;
33
34 if (argc > 2) {
35 fprintf(stderr, "usage: %s [string]\n", argv[0]);
36 return 1;
37 }
38
39 if (argc == 1 || strcmp(argv[1], "-") == 0) {
40 fp = stdin;
41 filename = "<stdin>";
42 } else {
43 filename = argv[1];
44 fp = fopen(filename, "r");
45 if (!fp) {
46 perror(filename);
47 return 1;
48 }
49 }
50
51 parser = XML_ParserCreate("UTF-8");
52 if (!parser) {
53 fprintf(stderr, "cannot create XML parser\n");
54 return 1;
55 }
56
57 XML_SetElementHandler(parser,
58 eclat_partial_tree_start_handler,
59 eclat_partial_tree_end_handler);
60 XML_SetCharacterDataHandler(parser,
61 eclat_partial_tree_data_handler);
62 part = eclat_partial_tree_create();
63 XML_SetUserData(parser, part);
64
65 while ((size = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
66 enum XML_Status status;
67
68 status = XML_Parse(parser, buffer, size, 0);
69 if (status == XML_STATUS_ERROR) {
70 enum XML_Error error = XML_GetErrorCode(parser);
71 int line = XML_GetCurrentLineNumber(parser);
72 int column = XML_GetCurrentColumnNumber(parser);
73
74 fprintf(stderr, "%s:%d:%d: %s\n",
75 filename, line, column, XML_ErrorString(error));
76 return 1;
77 }
78 }
79 XML_Parse(parser, "", 0, 1);
80
81 tree = eclat_partial_tree_finish(part);
82
83 grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stdout);
84 fputc('\n', stdout);
85 grecs_tree_free(tree);
86
87 return 0;
88}
diff --git a/tests/xml01.at b/tests/xml01.at
new file mode 100644
index 0000000..01d7df4
--- /dev/null
+++ b/tests/xml01.at
@@ -0,0 +1,63 @@
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
17AT_SETUP([xml01])
18AT_KEYWORDS([xml xml01])
19
20AT_DATA([input],[<?xml version="1.0" encoding="UTF-8"?>
21<DescribeTagsResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/">
22 <requestId>beefdead-57rt-ffea-e4ac-deadbeefbeef</requestId>
23 <tagSet>
24 <item>
25 <resourceId>i-00000000</resourceId>
26 <resourceType>instance</resourceType>
27 <key>foo</key>
28 <value>bar</value>
29 </item>
30 <item>
31 <resourceId>i-11111111</resourceId>
32 <resourceType>instance</resourceType>
33 <key>baz</key>
34 <value>quux</value>
35 </item>
36 <item>
37 <resourceId>i-22222222</resourceId>
38 <resourceType>instance</resourceType>
39 <key>Name</key>
40 <value>test</value>
41 </item>
42 </tagSet>
43</DescribeTagsResponse>
44])
45
46AT_CHECK([txml input],
47[0],
48[.DescribeTagsResponse.requestId: "beefdead-57rt-ffea-e4ac-deadbeefbeef"
49.DescribeTagsResponse.tagSet.item.resourceId: "i-00000000"
50.DescribeTagsResponse.tagSet.item.resourceType: "instance"
51.DescribeTagsResponse.tagSet.item.key: "foo"
52.DescribeTagsResponse.tagSet.item.value: "bar"
53.DescribeTagsResponse.tagSet.item.resourceId: "i-11111111"
54.DescribeTagsResponse.tagSet.item.resourceType: "instance"
55.DescribeTagsResponse.tagSet.item.key: "baz"
56.DescribeTagsResponse.tagSet.item.value: "quux"
57.DescribeTagsResponse.tagSet.item.resourceId: "i-22222222"
58.DescribeTagsResponse.tagSet.item.resourceType: "instance"
59.DescribeTagsResponse.tagSet.item.key: "Name"
60.DescribeTagsResponse.tagSet.item.value: "test"
61])
62
63AT_CLEANUP

Return to:

Send suggestions and report system problems to the System administrator.