axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billblo...@apache.org
Subject svn commit: r1831748 - in /axis/axis2/c/core/trunk/guththila/tests: Makefile.am test_stack.cc
Date Thu, 17 May 2018 03:20:12 GMT
Author: billblough
Date: Thu May 17 03:20:12 2018
New Revision: 1831748

URL: http://svn.apache.org/viewvc?rev=1831748&view=rev
Log:
Improve test coverage for guththila_stack

Added:
    axis/axis2/c/core/trunk/guththila/tests/test_stack.cc
Modified:
    axis/axis2/c/core/trunk/guththila/tests/Makefile.am

Modified: axis/axis2/c/core/trunk/guththila/tests/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/tests/Makefile.am?rev=1831748&r1=1831747&r2=1831748&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/guththila/tests/Makefile.am (original)
+++ axis/axis2/c/core/trunk/guththila/tests/Makefile.am Thu May 17 03:20:12 2018
@@ -12,9 +12,9 @@
 # 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 = test_guththila test_attribute
-noinst_PROGRAMS = test_guththila test_attribute
-check_PROGRAMS = test_guththila test_attribute
+TESTS = test_guththila test_attribute test_stack
+noinst_PROGRAMS = test_guththila test_attribute test_stack
+check_PROGRAMS = test_guththila test_attribute test_stack
 SUBDIRS =
 
 test_guththila_SOURCES = test_guththila.cc
@@ -35,4 +35,12 @@ test_attribute_LDADD = \
 				 $(top_builddir)/src/libguththila.la \
 				 ../../util/src/libaxutil.la \
 				 $(top_builddir)/$(GTEST)/libgtest.a \
+				 $(top_builddir)/$(GTEST)/libgtest_main.a
+
+test_stack_SOURCES = test_stack.cc
+
+test_stack_LDADD = \
+				 $(top_builddir)/src/libguththila.la \
+				 ../../util/src/libaxutil.la \
+				 $(top_builddir)/$(GTEST)/libgtest.a \
 				 $(top_builddir)/$(GTEST)/libgtest_main.a

Added: axis/axis2/c/core/trunk/guththila/tests/test_stack.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/tests/test_stack.cc?rev=1831748&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/guththila/tests/test_stack.cc (added)
+++ axis/axis2/c/core/trunk/guththila/tests/test_stack.cc Thu May 17 03:20:12 2018
@@ -0,0 +1,98 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* 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.
+*/
+
+#include <gtest/gtest.h>
+
+#include <guththila.h>
+
+
+class TestStack: public ::testing::Test
+{
+
+    protected:
+        void SetUp()
+        {
+            m_allocator = axutil_allocator_init(NULL);
+            ASSERT_NE(m_allocator, nullptr);
+            m_env = axutil_env_create(m_allocator);
+            ASSERT_NE(m_env, nullptr);
+            m_stack = (guththila_stack_t*) AXIS2_MALLOC(m_allocator, sizeof(guththila_stack_t));
+            ASSERT_NE(m_stack, nullptr);
+        }
+
+        void TearDown()
+        {
+            guththila_stack_free(m_stack, m_env);
+            axutil_env_free(m_env);
+        }
+
+        axutil_allocator_t *m_allocator;
+        axutil_env_t *m_env;
+        guththila_stack_t *m_stack;
+};
+
+
+TEST_F(TestStack, test_stack) {
+
+
+    int status;
+
+    status = guththila_stack_init(m_stack, m_env);
+    ASSERT_EQ(status, GUTHTHILA_SUCCESS);
+
+    ASSERT_TRUE(guththila_stack_is_empty(m_stack, m_env));
+
+    /* default max is 16 elements, so this will force a reallocation */
+    const char * abc = "abcdefghijklmnopqrstuvwxyz";
+    const char * p;
+    for (p = abc; *p != 0; ++p)
+    {
+        status = guththila_stack_push(m_stack, (void*)p, m_env);
+        /* push returns the index of the top element */
+        ASSERT_EQ(status, p-abc);
+    }
+
+    ASSERT_FALSE(guththila_stack_is_empty(m_stack, m_env));
+    ASSERT_EQ((char*)guththila_stack_peek(m_stack, m_env), (p-1));
+
+    status = guththila_stack_del_top(m_stack, m_env);
+    ASSERT_EQ(status, GUTHTHILA_SUCCESS);
+    ASSERT_EQ((char*)guththila_stack_peek(m_stack, m_env), (p-2));
+
+    status = guththila_stack_del_top(m_stack, m_env);
+    ASSERT_EQ(status, GUTHTHILA_SUCCESS);
+    ASSERT_EQ((char*)guththila_stack_peek(m_stack, m_env), (p-3));
+
+    ASSERT_EQ((char*)guththila_stack_get_by_index(m_stack, 0, m_env), abc);
+    ASSERT_EQ((char*)guththila_stack_get_by_index(m_stack, 10, m_env), abc+10);
+    ASSERT_EQ((char*)guththila_stack_get_by_index(m_stack, 23, m_env), p-3);
+
+
+    for (p = p-3; p >= abc; --p)
+    {
+        ASSERT_EQ((char*)guththila_stack_pop(m_stack, m_env), p);
+    }
+
+    ASSERT_TRUE(guththila_stack_is_empty(m_stack, m_env));
+
+
+    /* Test that un_init/re_init */
+    guththila_stack_un_init(m_stack, m_env);
+    status = guththila_stack_init(m_stack, m_env);
+    ASSERT_EQ(status, GUTHTHILA_SUCCESS);
+
+}



Mime
View raw message