diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 8 | ||||
-rw-r--r-- | tests/testsuite.at | 4 | ||||
-rw-r--r-- | tests/txml.c | 88 | ||||
-rw-r--r-- | tests/xml01.at | 63 |
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 testsuite.log thmac turlenc +txml 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 = \ hmac02.at\ hmac03.at\ testsuite.at\ - urlenc01.at + urlenc01.at\ + xml01.at TESTSUITE = $(srcdir)/testsuite M4=m4 @@ -69,10 +70,11 @@ check-local: atconfig atlocal $(TESTSUITE) noinst_PROGRAMS = \ thmac\ - turlenc + turlenc\ + txml LDADD = ../lib/libeclat.a ../grecs/src/libgrecs.a -INCLUDES = -I$(top_srcdir)/lib +INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib 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) m4_include(hmac02.at) m4_include(hmac03.at) -AT_BANNER([URL encode]) +AT_BANNER([URL Encode]) m4_include([urlenc01.at]) +AT_BANNER([XML Processing]) +m4_include([xml01.at]) # 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 @@ +/* This file is part of Eclat. + Copyright (C) 2012 Sergey Poznyakoff. + + Eclat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Eclat is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "libeclat.h" + +int +main(int argc, char **argv) +{ + XML_Parser parser; + eclat_partial_tree_t part; + FILE *fp; + char buffer[128]; + size_t size; + const char *filename; + struct grecs_node *tree; + + if (argc > 2) { + fprintf(stderr, "usage: %s [string]\n", argv[0]); + return 1; + } + + if (argc == 1 || strcmp(argv[1], "-") == 0) { + fp = stdin; + filename = "<stdin>"; + } else { + filename = argv[1]; + fp = fopen(filename, "r"); + if (!fp) { + perror(filename); + return 1; + } + } + + parser = XML_ParserCreate("UTF-8"); + if (!parser) { + fprintf(stderr, "cannot create XML parser\n"); + return 1; + } + + XML_SetElementHandler(parser, + eclat_partial_tree_start_handler, + eclat_partial_tree_end_handler); + XML_SetCharacterDataHandler(parser, + eclat_partial_tree_data_handler); + part = eclat_partial_tree_create(); + XML_SetUserData(parser, part); + + while ((size = fread(buffer, 1, sizeof(buffer), fp)) > 0) { + enum XML_Status status; + + status = XML_Parse(parser, buffer, size, 0); + if (status == XML_STATUS_ERROR) { + enum XML_Error error = XML_GetErrorCode(parser); + int line = XML_GetCurrentLineNumber(parser); + int column = XML_GetCurrentColumnNumber(parser); + + fprintf(stderr, "%s:%d:%d: %s\n", + filename, line, column, XML_ErrorString(error)); + return 1; + } + } + XML_Parse(parser, "", 0, 1); + + tree = eclat_partial_tree_finish(part); + + grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stdout); + fputc('\n', stdout); + grecs_tree_free(tree); + + return 0; +} 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 @@ +# This file is part of Eclat -*- Autotest -*- +# Copyright (C) 2012 Sergey Poznyakoff +# +# Eclat is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Eclat is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Eclat. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([xml01]) +AT_KEYWORDS([xml xml01]) + +AT_DATA([input],[<?xml version="1.0" encoding="UTF-8"?> +<DescribeTagsResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/"> + <requestId>beefdead-57rt-ffea-e4ac-deadbeefbeef</requestId> + <tagSet> + <item> + <resourceId>i-00000000</resourceId> + <resourceType>instance</resourceType> + <key>foo</key> + <value>bar</value> + </item> + <item> + <resourceId>i-11111111</resourceId> + <resourceType>instance</resourceType> + <key>baz</key> + <value>quux</value> + </item> + <item> + <resourceId>i-22222222</resourceId> + <resourceType>instance</resourceType> + <key>Name</key> + <value>test</value> + </item> + </tagSet> +</DescribeTagsResponse> +]) + +AT_CHECK([txml input], +[0], +[.DescribeTagsResponse.requestId: "beefdead-57rt-ffea-e4ac-deadbeefbeef" +.DescribeTagsResponse.tagSet.item.resourceId: "i-00000000" +.DescribeTagsResponse.tagSet.item.resourceType: "instance" +.DescribeTagsResponse.tagSet.item.key: "foo" +.DescribeTagsResponse.tagSet.item.value: "bar" +.DescribeTagsResponse.tagSet.item.resourceId: "i-11111111" +.DescribeTagsResponse.tagSet.item.resourceType: "instance" +.DescribeTagsResponse.tagSet.item.key: "baz" +.DescribeTagsResponse.tagSet.item.value: "quux" +.DescribeTagsResponse.tagSet.item.resourceId: "i-22222222" +.DescribeTagsResponse.tagSet.item.resourceType: "instance" +.DescribeTagsResponse.tagSet.item.key: "Name" +.DescribeTagsResponse.tagSet.item.value: "test" +]) + +AT_CLEANUP |