Switch axiom test_xpath* to use gtest
diff --git a/axiom/test/xpath/Makefile.am b/axiom/test/xpath/Makefile.am
index cecbda2..e560dcd 100644
--- a/axiom/test/xpath/Makefile.am
+++ b/axiom/test/xpath/Makefile.am
@@ -12,25 +12,30 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-TESTS =
+TESTS = test_xpath test_xpath_streaming
noinst_PROGRAMS = test_xpath test_xpath_streaming
check_PROGRAMS = test_xpath test_xpath_streaming
SUBDIRS =
-test_xpath_SOURCES = test_xpath.c
+test_xpath_SOURCES = test_xpath.cc
-test_xpath_streaming_SOURCES = test_xpath_streaming.c
+test_xpath_streaming_SOURCES = test_xpath_streaming.cc
test_xpath_LDADD = ../../../util/src/libaxutil.la \
- $(top_builddir)/src/om/libaxis2_axiom.la \
- $(top_builddir)/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
- $(top_builddir)/src/xpath/libaxis2_xpath.la
+ $(top_builddir)/src/om/libaxis2_axiom.la \
+ $(top_builddir)/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+ $(top_builddir)/src/xpath/libaxis2_xpath.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
test_xpath_streaming_LDADD = ../../../util/src/libaxutil.la \
- $(top_builddir)/src/om/libaxis2_axiom.la \
- $(top_builddir)/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
- $(top_builddir)/src/xpath/libaxis2_xpath.la
+ $(top_builddir)/src/om/libaxis2_axiom.la \
+ $(top_builddir)/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+ $(top_builddir)/src/xpath/libaxis2_xpath.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
-INCLUDES = -I$(top_builddir)/include \
+AM_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_builddir)/src/parser \
-I ../../../include \
- -I ../../../util/include
+ -I ../../../util/include \
+ -I $(GTEST_DIR)/include
diff --git a/axiom/test/xpath/test_xpath.c b/axiom/test/xpath/test_xpath.cc
similarity index 83%
rename from axiom/test/xpath/test_xpath.c
rename to axiom/test/xpath/test_xpath.cc
index 05f90c8..b4af702 100644
--- a/axiom/test/xpath/test_xpath.c
+++ b/axiom/test/xpath/test_xpath.cc
@@ -21,6 +21,9 @@
cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /I %AXIS2C_HOME%\include /c *.c
link.exe /LIBPATH:%AXIS2C_HOME%\lib axutil.lib axiom.lib axis2_parser.lib axis2_engine.lib /OUT:test.exe *.obj
*/
+
+#include <gtest/gtest.h>
+
#include <stdio.h>
#include <axiom.h>
#include <axis2_util.h>
@@ -54,8 +57,34 @@
FILE *fcor;
/*FILE *ftemp;*/
-int main(int argc, char *argv[])
+
+/* FIXME
+ * These tests exercise code, but don't actually check that the output is
+ * correct. They didn't when they were in the old test format, either.
+ */
+
+class TestXPath: public ::testing::Test
{
+
+ protected:
+ void SetUp()
+ {
+ m_env = axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
+
+ }
+
+ void TearDown()
+ {
+ axutil_env_free(m_env);
+ }
+
+ axutil_env_t *m_env = NULL;
+
+};
+
+
+TEST_F(TestXPath, test_xpath) {
+
axiom_node_t *test_tree = NULL;
axis2_char_t *test_tree_str;
char *xml_file = "test.xml";
@@ -64,79 +93,49 @@
char *cor_file = "results.txt";
axiom_xpath_context_t *context = NULL;
- /* Create environment */
- axutil_env_t *env =
- axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
-
- /* Set input file */
- if (argc > 1)
- {
- printf("Usage: test [xml_file xpath_file namespaces_file results_file]\n\n");
- printf("\tLook at the example test case:");
- printf(" test.xml, test.xpath test.ns\n\n");
-
- if(argc > 4)
- {
- xml_file = argv[1];
- xpath_file = argv[2];
- ns_file = argv[3];
- cor_file = argv[4];
- }
- }
-
/*Create the request */
/* test_tree = build_test_xml(env); */
- test_tree = read_test_xml(env, (axis2_char_t *)xml_file);
+ test_tree = read_test_xml(m_env, (axis2_char_t *)xml_file);
fcor = fopen(cor_file, "r");
/*ftemp = fopen("temp.txt", "w");*/
- if (!fcor)
- {
- printf("Error opening file: %s\n", cor_file);
- }
+ ASSERT_NE(fcor, nullptr);
- if (test_tree)
- {
- test_tree_str = axiom_node_to_string(test_tree, env);
- printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
- AXIS2_FREE(env->allocator, test_tree_str);
+ ASSERT_NE(test_tree, nullptr);
- /* Create XPath Context */
- context = axiom_xpath_context_create(env, test_tree);
+ test_tree_str = axiom_node_to_string(test_tree, m_env);
+ printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ AXIS2_FREE(m_env->allocator, test_tree_str);
- /* Namespaces */
- add_namespaces(env, context, ns_file);
+ /* Create XPath Context */
+ context = axiom_xpath_context_create(m_env, test_tree);
- evaluate_expressions(env, context, xpath_file);
+ /* Namespaces */
+ add_namespaces(m_env, context, ns_file);
- test_tree_str = axiom_node_to_string(test_tree, env);
- printf("\n\nFinal XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
- AXIS2_FREE(env->allocator, test_tree_str);
- }
+ evaluate_expressions(m_env, context, xpath_file);
+
+ test_tree_str = axiom_node_to_string(test_tree, m_env);
+ printf("\n\nFinal XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ AXIS2_FREE(m_env->allocator, test_tree_str);
/* Freeing memory */
if (context)
{
- axiom_xpath_free_context(env, context);
+ axiom_xpath_free_context(m_env, context);
}
if (test_tree)
{
- axiom_node_free_tree(test_tree, env);
- }
-
- if (env)
- {
- axutil_env_free((axutil_env_t *) env);
+ axiom_node_free_tree(test_tree, m_env);
}
if(fcor)
{
- fclose(fcor);
+ fclose(fcor);
}
- return 0;
}
int readline(FILE *fin, char *str)
@@ -169,11 +168,7 @@
fin = fopen(file_name, "r");
- if (!fin)
- {
- printf("Error opening file: %s\n", file_name);
- return;
- }
+ ASSERT_NE(fin, nullptr);
/* Compiling XPath expression */
while (1)
@@ -210,11 +205,7 @@
fin = fopen(file_name, "r");
- if (!fin)
- {
- printf("Error opening file: %s\n", file_name);
- return;
- }
+ ASSERT_NE(fin, nullptr);
/* Compiling XPath expression */
while (1)
@@ -326,7 +317,7 @@
{
c = getc(fcor);
}
-
+
return 0;
}
}
@@ -351,11 +342,11 @@
for (i = 0; i < axutil_array_list_size(xpath_result->nodes, env); i++)
{
- xpath_result_node = axutil_array_list_get(xpath_result->nodes, env, i);
+ xpath_result_node = (axiom_xpath_result_node_t*) axutil_array_list_get(xpath_result->nodes, env, i);
if (xpath_result_node->type == AXIOM_XPATH_TYPE_NODE)
{
- result_node = xpath_result_node->value;
+ result_node = (axiom_node_t*) xpath_result_node->value;
ele = (axiom_element_t *)axiom_node_get_data_element(
result_node, env);
@@ -372,22 +363,22 @@
else if (xpath_result_node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)
{
result_str =
- axiom_attribute_get_localname(xpath_result_node->value, env);
+ axiom_attribute_get_localname((axiom_attribute*)xpath_result_node->value, env);
sprintf(temp_res, "%s = ", result_str);
strcat(result_set, temp_res);
result_str =
- axiom_attribute_get_value(xpath_result_node->value, env);
+ axiom_attribute_get_value((axiom_attribute*)xpath_result_node->value, env);
sprintf(temp_res, "\"%s\"\n", result_str);
strcat(result_set, temp_res);
}
else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NAMESPACE)
{
result_str =
- axiom_namespace_get_prefix(xpath_result_node->value, env);
+ axiom_namespace_get_prefix((axiom_namespace*)xpath_result_node->value, env);
sprintf(temp_res, "%s = ", result_str);
strcat(result_set, temp_res);
result_str =
- axiom_namespace_get_uri(xpath_result_node->value, env);
+ axiom_namespace_get_uri((axiom_namespace*)xpath_result_node->value, env);
sprintf(temp_res, "\"%s\"\n", result_str);
strcat(result_set, temp_res);
}
@@ -428,6 +419,7 @@
axiom_document_t *document = NULL;
axiom_node_t *root = NULL;
+
/* Create parser */
reader = axiom_xml_reader_create_for_file(env, file_name, NULL);
diff --git a/axiom/test/xpath/test_xpath_streaming.c b/axiom/test/xpath/test_xpath_streaming.cc
similarity index 86%
rename from axiom/test/xpath/test_xpath_streaming.c
rename to axiom/test/xpath/test_xpath_streaming.cc
index 6b64262..abf101c 100644
--- a/axiom/test/xpath/test_xpath_streaming.c
+++ b/axiom/test/xpath/test_xpath_streaming.cc
@@ -21,6 +21,9 @@
cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /I %AXIS2C_HOME%\include /c *.c
link.exe /LIBPATH:%AXIS2C_HOME%\lib axutil.lib axiom.lib axis2_parser.lib axis2_engine.lib /OUT:test.exe *.obj
*/
+
+#include <gtest/gtest.h>
+
#include <stdio.h>
#include <axiom.h>
#include <axis2_util.h>
@@ -47,6 +50,8 @@
int readline(FILE *fin, char *str);
+int compare_result(axis2_char_t *rs);
+
FILE *fcor;
char *xml_file = "test.xml";
char *xpath_file = "test.xpath";
@@ -55,64 +60,56 @@
/*FILE *ftemp;*/
-int main(int argc, char *argv[])
+/* FIXME
+ * These tests exercise code, but don't actually check that the output is
+ * correct. They didn't when they were in the old test format, either.
+ */
+
+class TestXPathStreaming: public ::testing::Test
{
+
+ protected:
+ void SetUp()
+ {
+ m_env = axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
+
+ }
+
+ void TearDown()
+ {
+ axutil_env_free(m_env);
+ }
+
+ axutil_env_t *m_env = NULL;
+
+};
+
+
+TEST_F(TestXPathStreaming, test_xpath_streaming) {
axiom_node_t *test_tree = NULL;
axis2_char_t *test_tree_str;
- /* Create environment */
- axutil_env_t *env =
- axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
-
- /* Set input file */
- if (argc > 1)
- {
- printf("Usage: test [xml_file xpath_file namespaces_file results_file]\n\n");
- printf("\tLook at the example test case:");
- printf(" test.xml, test.xpath test.ns\n\n");
-
- if(argc > 4)
- {
- xml_file = argv[1];
- xpath_file = argv[2];
- ns_file = argv[3];
- cor_file = argv[4];
- }
- }
-
/*Create the request */
- test_tree = read_test_xml(env, (axis2_char_t *)xml_file);
+ test_tree = read_test_xml(m_env, (axis2_char_t *)xml_file);
fcor = fopen(cor_file, "r");
/*ftemp = fopen("temp.txt", "w");*/
- if (!fcor)
- {
- printf("Error opening file: %s\n", cor_file);
- }
+ ASSERT_NE(fcor, nullptr);
- if (test_tree)
- {
- test_tree_str = axiom_node_to_string(test_tree, env);
- printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ ASSERT_NE(test_tree, nullptr);
- axiom_node_free_tree(test_tree, env);
+ test_tree_str = axiom_node_to_string(test_tree, m_env);
+ printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
- evaluate_expressions(env, xpath_file);
- }
+ axiom_node_free_tree(test_tree, m_env);
- /* Freeing memory */
- if (env)
- {
- axutil_env_free((axutil_env_t *) env);
- }
+ evaluate_expressions(m_env, xpath_file);
if(fcor)
{
- fclose(fcor);
+ fclose(fcor);
}
-
- return 0;
}
int readline(FILE *fin, char *str)
@@ -350,11 +347,11 @@
for (i = 0; i < axutil_array_list_size(xpath_result->nodes, env); i++)
{
- xpath_result_node = axutil_array_list_get(xpath_result->nodes, env, i);
+ xpath_result_node = (axiom_xpath_result_node_t*) axutil_array_list_get(xpath_result->nodes, env, i);
if (xpath_result_node->type == AXIOM_XPATH_TYPE_NODE)
{
- result_node = xpath_result_node->value;
+ result_node = (axiom_node_t*) xpath_result_node->value;
ele = (axiom_element_t *)axiom_node_get_data_element(
result_node, env);
@@ -370,22 +367,22 @@
else if (xpath_result_node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)
{
result_str =
- axiom_attribute_get_localname(xpath_result_node->value, env);
+ axiom_attribute_get_localname((axiom_attribute*)xpath_result_node->value, env);
sprintf(temp_res, "%s = ", result_str);
strcat(result_set, temp_res);
result_str =
- axiom_attribute_get_value(xpath_result_node->value, env);
+ axiom_attribute_get_value((axiom_attribute*)xpath_result_node->value, env);
sprintf(temp_res, "\"%s\"\n", result_str);
strcat(result_set, temp_res);
}
else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NAMESPACE)
{
result_str =
- axiom_namespace_get_prefix(xpath_result_node->value, env);
+ axiom_namespace_get_prefix((axiom_namespace*)xpath_result_node->value, env);
sprintf(temp_res, "%s = ", result_str);
strcat(result_set, temp_res);
result_str =
- axiom_namespace_get_uri(xpath_result_node->value, env);
+ axiom_namespace_get_uri((axiom_namespace*)xpath_result_node->value, env);
sprintf(temp_res, "\"%s\"\n", result_str);
strcat(result_set, temp_res);
}