Skip to content
Permalink
Browse files
Switch axiom test_xpath* to use gtest
  • Loading branch information
bblough committed Jan 7, 2018
1 parent 9917ee0 commit 4ac967be34d5804e69662b9cba27d2ee764debd3
Showing 3 changed files with 116 additions and 122 deletions.
@@ -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
@@ -21,6 +21,9 @@ Compiling For Windows:
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 @@ int readline(FILE *fin, char *str);
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 @@ int main(int argc, char *argv[])
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 @@ void add_namespaces(const axutil_env_t *env,

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 @@ void evaluate_expressions(

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 @@ int compare_result(axis2_char_t *rs)
{
c = getc(fcor);
}

return 0;
}
}
@@ -351,11 +342,11 @@ void output_results(const axutil_env_t *env,

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 @@ void output_results(const axutil_env_t *env,
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_node_t *read_test_xml(const axutil_env_t *env, axis2_char_t *file_name)
axiom_document_t *document = NULL;
axiom_node_t *root = NULL;


/* Create parser */
reader = axiom_xml_reader_create_for_file(env, file_name, NULL);

0 comments on commit 4ac967b

Please sign in to comment.