aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-20 15:52:18 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-20 15:52:18 +0300
commit7f3dd0599ac3fb3a69c512b0ecfd043c67ca94ee (patch)
tree422bda7fdce2709ea0b4c67c42e6f9a7cecc4918 /tests
parent205d53a8e930d3fd126075ab083d316cc344ebaf (diff)
downloadeclat-7f3dd0599ac3fb3a69c512b0ecfd043c67ca94ee.tar.gz
eclat-7f3dd0599ac3fb3a69c512b0ecfd043c67ca94ee.tar.bz2
Parse returned XML into a grecs tree structure.
* lib/xmltree.c: New file. * lib/Makefile.am: Add new file. * lib/libeclat.h: Include expat.h and grecs.h (eclat_partial_tree_t): New typedef. (eclat_partial_tree_create,eclat_partial_tree_destroy) (eclat_partial_tree_finish,eclat_partial_tree_data_handler) (eclat_partial_tree_start_handler) (eclat_partial_tree_end_handler): New protos. * src/eclat.c (main): Initialize XML parser with eclat_partial_tree handlers and bind it to the CURL output handler. * tests/.gitignore: Add txml * tests/Makefile.am (TESTSUITE_AT): Add xml01.at Build txml * tests/testsuite.at: Include xml01.at * tests/txml.c: New file. * tests/xml01.at: New file.
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
@@ -3,6 +3,7 @@ atlocal
package.m4
testsuite
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
@@ -41,13 +41,14 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
hmac01.at\
hmac02.at\
hmac03.at\
testsuite.at\
- urlenc01.at
+ urlenc01.at\
+ xml01.at
TESTSUITE = $(srcdir)/testsuite
M4=m4
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): package.m4 $(TESTSUITE_AT)
@@ -66,14 +67,15 @@ check-local: atconfig atlocal $(TESTSUITE)
# Run the test suite on the *installed* tree.
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
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
@@ -21,10 +21,12 @@ m4_define([AT_SKIP_TEST],[exit 77])
AT_INIT
AT_BANNER([HMAC-SHA1])
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

Return to:

Send suggestions and report system problems to the System administrator.