summaryrefslogtreecommitdiffstats
path: root/guththila/tests
diff options
context:
space:
mode:
authorGravatar gmcdonald2010-02-13 01:32:03 +0000
committerGravatar gmcdonald2010-02-13 01:32:03 +0000
commit0425aadc78680e53000fd0108b540d6eca048516 (patch)
tree8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /guththila/tests
downloadaxis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz
axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'guththila/tests')
l---------guththila/tests/resources/om1
l---------guththila/tests/resources/soap1
-rwxr-xr-xguththila/tests/s13
-rw-r--r--guththila/tests/test.c200
-rw-r--r--guththila/tests/test.h23
-rw-r--r--guththila/tests/test_attribute.c84
6 files changed, 322 insertions, 0 deletions
diff --git a/guththila/tests/resources/om b/guththila/tests/resources/om
new file mode 120000
index 0000000..3bd0c61
--- /dev/null
+++ b/guththila/tests/resources/om
@@ -0,0 +1 @@
+../../../axiom/test/resources/xml/om/ \ No newline at end of file
diff --git a/guththila/tests/resources/soap b/guththila/tests/resources/soap
new file mode 120000
index 0000000..9674db5
--- /dev/null
+++ b/guththila/tests/resources/soap
@@ -0,0 +1 @@
+../../../axiom/test/resources/xml/soap \ No newline at end of file
diff --git a/guththila/tests/s b/guththila/tests/s
new file mode 100755
index 0000000..7e9f4f8
--- /dev/null
+++ b/guththila/tests/s
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+use strict;
+
+if ($ARGV[0] == 1)
+{
+ print "compiling writer\n";
+ system "gcc -Wall -g3 -O0 -o writer guththila_writer_main.c -L\$AXIS2C_HOME/lib -I\$AXIS2C_HOME/include -lguththila -laxis2_util";
+}
+else
+{
+ print "compiling reader tests \n";
+ system "gcc -Wall -g3 -O0 -o reader *.c \-L\$AXIS2C_HOME/lib \-I\$AXIS2C_HOME/include -lcheck -lguththila \-laxis2_util";
+}
diff --git a/guththila/tests/test.c b/guththila/tests/test.c
new file mode 100644
index 0000000..cebbe02
--- /dev/null
+++ b/guththila/tests/test.c
@@ -0,0 +1,200 @@
+#include <check.h>
+#include <guththila.h>
+#include "guththila_defines.h"
+#include "test.h"
+
+void
+setup(
+ void)
+{
+ allocator = axutil_allocator_init(NULL);
+ env = axutil_env_create(allocator);
+}
+
+void
+teardown(
+ void)
+{
+ guththila_reader_free(env, red);
+ guththila_free(env, parser);
+ axutil_env_free(env);
+}
+
+START_TEST(test_guththila)
+{
+ red = guththila_reader_create_for_file(env, "resources/om/axis.xml");
+ parser = guththila_create(env, red);
+ fail_if(red == NULL, "guththila reader failed");
+ fail_if(parser == NULL, "guththila parser failed");
+}
+
+END_TEST
+START_TEST(
+ test_guththila_start_element)
+{
+ int c = 0;
+ char *p;
+ red = guththila_reader_create_for_file(env, "resources/om/axis.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+
+ while((c != GUTHTHILA_START_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_START_ELEMENT), "no start element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "root"), "root element differed");
+ c = 0;
+
+ while((c != GUTHTHILA_START_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_START_ELEMENT), "no start element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "a"), "a element differed");
+
+ c = 0;
+ while((c != GUTHTHILA_START_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless(!strcmp(p, "b"), "b element differed");
+}
+
+END_TEST
+START_TEST(
+ test_guththila_empty_element)
+{
+ int c = 0;
+ char *p;
+ red = guththila_reader_create_for_file(env, "resources/om/axis.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+
+ while((c != GUTHTHILA_EMPTY_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_EMPTY_ELEMENT), "no empty element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "a.1"), "a.1 element differed");
+
+ c = 0;
+
+ while((c != GUTHTHILA_EMPTY_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_EMPTY_ELEMENT), "no empty element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "a.2"), "a.2 element differed");
+
+ c = 0;
+ while((c != GUTHTHILA_START_ELEMENT))
+ c = guththila_next(env, parser);
+
+ c = 0;
+ while((c != GUTHTHILA_EMPTY_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_EMPTY_ELEMENT), "no empty element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "b.1"), "b.1 element differed");
+}
+
+END_TEST
+START_TEST(
+ test_guththila_end_element)
+{
+ int c = 0;
+ char *p;
+ red = guththila_reader_create_for_file(env, "resources/om/axis.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+
+ while((c != GUTHTHILA_END_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_END_ELEMENT), "no end element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "a"), "a element differed");
+
+ c = 0;
+ while((c != GUTHTHILA_END_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_END_ELEMENT), "no endelement found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "b"), "b element differed");
+
+ c = 0;
+ while((c != GUTHTHILA_END_ELEMENT))
+ c = guththila_next(env, parser);
+ p = guththila_get_name(env, parser);
+ fail_unless((c == GUTHTHILA_END_ELEMENT), "no empty element found");
+ fail_if((p == NULL), "no name found");
+ fail_unless(!strcmp(p, "root"), "root element differed");
+}
+
+END_TEST
+START_TEST(
+ test_guththila_character)
+{
+ int c = 0;
+ int i = 0;
+ char *p;
+ red = guththila_reader_create_for_file(env, "resources/om/numbers.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+ while(i < 3)
+ {
+ if(c == GUTHTHILA_START_ELEMENT)
+ i++;
+ c = guththila_next(env, parser);
+ }
+
+ if(c == GUTHTHILA_CHARACTER)
+ p = guththila_get_value(env, parser);
+ fail_unless(!strcmp(p, "3"), "3 not found");
+
+ c = 0;
+ while((c != GUTHTHILA_CHARACTER) || (parser->is_whitespace))
+ c = guththila_next(env, parser);
+ p = guththila_get_value(env, parser);
+ fail_unless(!strcmp(p, "24"), "24 not found");
+
+}
+END_TEST Suite *
+guththila_suite(
+ void)
+{
+ Suite *s = suite_create("Guththila");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create("Core");
+ tcase_add_checked_fixture(tc_core, setup, teardown);
+ tcase_add_test(tc_core, test_guththila);
+ tcase_add_test(tc_core, test_guththila_start_element);
+ tcase_add_test(tc_core, test_guththila_empty_element);
+ tcase_add_test(tc_core, test_guththila_end_element);
+ tcase_add_test(tc_core, test_guththila_character);
+ suite_add_tcase(s, tc_core);
+ return s;
+}
+
+int
+main(
+ void)
+{
+ int number_failed;
+ Suite *s = guththila_suite();
+ Suite *att = guththila_attribute_suite();
+ SRunner *sr = srunner_create(s);
+ srunner_add_suite(sr, att);
+ srunner_set_log(sr, "guththila.log");
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/guththila/tests/test.h b/guththila/tests/test.h
new file mode 100644
index 0000000..93bebff
--- /dev/null
+++ b/guththila/tests/test.h
@@ -0,0 +1,23 @@
+#ifndef _GUTHTHILA_TESTS_
+#define _GUTHTHILA_TESTS_
+#include <check.h>
+#include <guththila.h>
+#include "guththila_defines.h"
+
+axutil_allocator_t *allocator;
+guththila_reader_t *red;
+axutil_env_t *env;
+guththila_t *parser;
+
+void setup(
+ void);
+void teardown(
+ void);
+
+Suite *guththila_suite(
+ void);
+
+Suite *guththila_attribute_suite(
+ void);
+
+#endif
diff --git a/guththila/tests/test_attribute.c b/guththila/tests/test_attribute.c
new file mode 100644
index 0000000..bd6c4b5
--- /dev/null
+++ b/guththila/tests/test_attribute.c
@@ -0,0 +1,84 @@
+#include <guththila.h>
+#include <check.h>
+#include "test.h"
+
+START_TEST(test_attribute)
+{
+ int count = 0;;
+ int c = 0;
+ guththila_attribute_t *att;
+ red = guththila_reader_create_for_file(env, "resources/om/evaluate.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+ while (!count)
+ {
+ c = guththila_next(env, parser);
+ count = guththila_get_attribute_count(env, parser);
+ if (count)
+ att = guththila_get_attribute(env, parser);
+ }
+ fail_if(count == 0, "guththila attribute count failed");
+ fail_unless(!strcmp
+ (guththila_get_attribute_name(env, parser, att), "color"),
+ "guththila attribute name failed");
+ fail_unless(!strcmp
+ (guththila_get_attribute_value(env, parser, att), "brown"),
+ "guththila attribute value failed");
+}
+
+END_TEST
+START_TEST(
+ test_attribute_prefix)
+{
+ int count = 0;
+ ;
+ int c = 0;
+ guththila_attribute_t *att;
+ red = guththila_reader_create_for_file(env, "resources/soap/soapmessage.xml");
+ parser = guththila_create(env, red);
+ guththila_read(env, parser);
+ c = guththila_next(env, parser);
+ while(!count)
+ {
+ c = guththila_next(env, parser);
+ count = guththila_get_attribute_count(env, parser);
+ if(count)
+ att = guththila_get_attribute(env, parser);
+ }
+ fail_if(count == 0, "guththila attribute count failed");
+ fail_unless(!strcmp(guththila_get_attribute_prefix(env, parser, att), "soapenv"),
+ "guththila attribute count failed");
+ fail_unless(!strcmp(guththila_get_attribute_name(env, parser, att), "mustUnderstand"),
+ "guththila attribute count failed");
+ fail_unless(!strcmp(guththila_get_attribute_value(env, parser, att), "0"),
+ "guththila attribute count failed");
+ count = 0;
+ while(!count)
+ {
+ c = guththila_next(env, parser);
+ count = guththila_get_attribute_count(env, parser);
+ if(count)
+ att = guththila_get_attribute(env, parser);
+ }
+ fail_unless(!strcmp(guththila_get_attribute_prefix(env, parser, att), "soapenv"),
+ "guththila attribute count failed");
+ fail_unless(!strcmp(guththila_get_attribute_name(env, parser, att), "mustUnderstand"),
+ "guththila attribute count failed");
+ fail_if(!strcmp(guththila_get_attribute_value(env, parser, att), "1"),
+ "guththila attribute count failed");
+}
+END_TEST Suite *
+guththila_attribute_suite(
+ void)
+{
+ Suite *s = suite_create("Guththila_attribute");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create("attribute");
+ tcase_add_checked_fixture(tc_core, setup, teardown);
+ tcase_add_test(tc_core, test_attribute);
+ tcase_add_test(tc_core, test_attribute_prefix);
+ suite_add_tcase(s, tc_core);
+ return s;
+}