axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billblo...@apache.org
Subject svn commit: r1820510 - in /axis/axis2/c/core/trunk/axiom/test/xpath: Makefile.am test_xpath.c test_xpath.cc test_xpath_streaming.c test_xpath_streaming.cc
Date Sun, 07 Jan 2018 23:52:51 GMT
Author: billblough
Date: Sun Jan  7 23:52:51 2018
New Revision: 1820510

URL: http://svn.apache.org/viewvc?rev=1820510&view=rev
Log:
Switch axiom test_xpath* to use gtest

Added:
    axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc
      - copied, changed from r1820506, axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.c
    axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc
      - copied, changed from r1820506, axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.c
Removed:
    axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.c
    axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.c
Modified:
    axis/axis2/c/core/trunk/axiom/test/xpath/Makefile.am

Modified: axis/axis2/c/core/trunk/axiom/test/xpath/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/test/xpath/Makefile.am?rev=1820510&r1=1820509&r2=1820510&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/test/xpath/Makefile.am (original)
+++ axis/axis2/c/core/trunk/axiom/test/xpath/Makefile.am Sun Jan  7 23:52:51 2018
@@ -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

Copied: axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc (from r1820506, axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.c)
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc?p2=axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc&p1=axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.c&r1=1820506&r2=1820510&rev=1820510&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.c (original)
+++ axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath.cc Sun Jan  7 23:52:51 2018
@@ -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 *
 
     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 *
 
     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 *
         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
     axiom_document_t *document = NULL;
     axiom_node_t *root = NULL;
 
+
     /* Create parser */
     reader = axiom_xml_reader_create_for_file(env, file_name, NULL);
 

Copied: axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc (from r1820506, axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.c)
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc?p2=axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc&p1=axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.c&r1=1820506&r2=1820510&rev=1820510&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.c (original)
+++ axis/axis2/c/core/trunk/axiom/test/xpath/test_xpath_streaming.cc Sun Jan  7 23:52:51 2018
@@ -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>
@@ -47,6 +50,8 @@ void add_namespaces(const axutil_env_t *
 
 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 @@ char *ns_file = "test.ns";
 
 /*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
 {
-    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];
+    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 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 @@ void output_results(const axutil_env_t *
 
     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 @@ void output_results(const axutil_env_t *
         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);
         }



Mime
View raw message