Skip to content

Commit

Permalink
Convert core tests to use gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
bblough committed Apr 29, 2018
1 parent c547417 commit 8b97529
Show file tree
Hide file tree
Showing 20 changed files with 946 additions and 827 deletions.
1 change: 0 additions & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
# limitations under the License.
TESTS =
SUBDIRS = core
noinst_HEADERS = cutest/include/cut_defs.h cutest/include/cut_http_server.h
10 changes: 6 additions & 4 deletions test/core/addr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ check_PROGRAMS = test_addr
noinst_PROGRAMS = test_addr
SUBDIRS =
AM_CFLAGS = -g
test_addr_SOURCES = test_addr.c
test_addr_SOURCES = test_addr.cc

test_addr_LDADD = \
../../../util/src/libaxutil.la \
../../../axiom/src/om/libaxis2_axiom.la \
../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
$(top_builddir)/neethi/src/libneethi.la \
$(top_builddir)/src/core/engine/libaxis2_engine.la \
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a

INCLUDES = -I$(CUTEST_HOME)/include \
AM_CPPFLAGS = \
-I$(top_builddir)/src/xml/guththila \
-I$(top_builddir)/include \
-I ../../../util/include \
-I ../../../axiom/include \
-I ../../cutest/include
-I $(GTEST_DIR)/include

109 changes: 64 additions & 45 deletions test/core/addr/test_addr.c → test/core/addr/test_addr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>

#include <axis2_msg_info_headers.h>
#include <axutil_env.h>
#include <axutil_allocator.h>
#include <axutil_log_default.h>
#include <axutil_error_default.h>
#include <axis2_endpoint_ref.h>
#include <stdio.h>
#include <cut_defs.h>

void
axis2_test_msg_info_headers(axutil_env_t *env)

class TestAddr: public ::testing::Test
{

protected:
void SetUp()
{

m_allocator = axutil_allocator_init(NULL);
m_axis_log = axutil_log_create(m_allocator, NULL, NULL);
m_error = axutil_error_create(m_allocator);

m_env = axutil_env_create_with_error_log(m_allocator, m_error, m_axis_log);

}

void TearDown()
{
axutil_env_free(m_env);
}


axutil_allocator_t *m_allocator = NULL;
axutil_env_t *m_env = NULL;
axutil_error_t *m_error = NULL;
axutil_log_t *m_axis_log = NULL;

};

TEST_F(TestAddr, test_msg_info_headers)
{

axis2_endpoint_ref_t *to = NULL;
axis2_endpoint_ref_t *from = NULL;
axis2_endpoint_ref_t *reply_to = NULL;
Expand All @@ -35,63 +66,51 @@ axis2_test_msg_info_headers(axutil_env_t *env)
axis2_msg_info_headers_t *axis2_msg_info_headers = NULL;
axis2_char_t *action = "test action";
const axis2_char_t *get_action = NULL;
to = axis2_endpoint_ref_create(env, "to");
from = axis2_endpoint_ref_create(env, "from");
reply_to = axis2_endpoint_ref_create(env, "reply to");
fault_to = axis2_endpoint_ref_create(env, "fault to");
to = axis2_endpoint_ref_create(m_env, "to");
from = axis2_endpoint_ref_create(m_env, "from");
reply_to = axis2_endpoint_ref_create(m_env, "reply to");
fault_to = axis2_endpoint_ref_create(m_env, "fault to");

axis2_msg_info_headers = axis2_msg_info_headers_create(env, NULL, action);
CUT_ASSERT_PTR_NOT_EQUAL(axis2_msg_info_headers, NULL, 1);
status = axis2_msg_info_headers_set_to(axis2_msg_info_headers, env, to);
CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 1);
axis2_msg_info_headers = axis2_msg_info_headers_create(m_env, NULL, action);
ASSERT_NE(axis2_msg_info_headers, nullptr);
status = axis2_msg_info_headers_set_to(axis2_msg_info_headers, m_env, to);
ASSERT_EQ(status, AXIS2_SUCCESS);

axis2_endpoint_ref =
axis2_msg_info_headers_get_to(axis2_msg_info_headers, env);
CUT_ASSERT_PTR_NOT_EQUAL(axis2_endpoint_ref, NULL, 1);
axis2_msg_info_headers_get_to(axis2_msg_info_headers, m_env);
ASSERT_NE(axis2_endpoint_ref, nullptr);

status = axis2_msg_info_headers_set_from(axis2_msg_info_headers, env, from);
CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 1);
status = axis2_msg_info_headers_set_from(axis2_msg_info_headers, m_env, from);
ASSERT_EQ(status, AXIS2_SUCCESS);

axis2_endpoint_ref =
axis2_msg_info_headers_get_from(axis2_msg_info_headers, env);
CUT_ASSERT_PTR_NOT_EQUAL(axis2_endpoint_ref, NULL, 1);
axis2_msg_info_headers_get_from(axis2_msg_info_headers, m_env);
ASSERT_NE(axis2_endpoint_ref, nullptr);

axis2_endpoint_ref =
axis2_msg_info_headers_get_reply_to(axis2_msg_info_headers, env);
CUT_ASSERT_PTR_EQUAL(axis2_endpoint_ref, NULL, 0);
axis2_msg_info_headers_get_reply_to(axis2_msg_info_headers, m_env);
ASSERT_EQ(axis2_endpoint_ref, nullptr);

status =
axis2_msg_info_headers_set_reply_to(axis2_msg_info_headers, env, reply_to);
CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 1);
axis2_msg_info_headers_set_reply_to(axis2_msg_info_headers, m_env, reply_to);
ASSERT_EQ(status, AXIS2_SUCCESS);
axis2_endpoint_ref =
axis2_msg_info_headers_get_reply_to(axis2_msg_info_headers, env);
CUT_ASSERT_PTR_NOT_EQUAL(axis2_endpoint_ref, NULL, 1);
axis2_msg_info_headers_get_reply_to(axis2_msg_info_headers, m_env);
ASSERT_NE(axis2_endpoint_ref, nullptr);
status =
axis2_msg_info_headers_set_fault_to(axis2_msg_info_headers, env, fault_to);
CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
axis2_msg_info_headers_set_fault_to(axis2_msg_info_headers, m_env, fault_to);
ASSERT_EQ(status, AXIS2_SUCCESS);

axis2_endpoint_ref =
axis2_msg_info_headers_get_fault_to(axis2_msg_info_headers, env);
CUT_ASSERT_PTR_NOT_EQUAL(axis2_endpoint_ref, NULL, 0);
axis2_msg_info_headers_get_fault_to(axis2_msg_info_headers, m_env);
ASSERT_NE(axis2_endpoint_ref, nullptr);

get_action = axis2_msg_info_headers_get_action(axis2_msg_info_headers, env);
CUT_ASSERT_STR_EQUAL(get_action, action, 0);

status =
axis2_msg_info_headers_set_action(axis2_msg_info_headers, env, action);
CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
get_action = axis2_msg_info_headers_get_action(axis2_msg_info_headers, m_env);
ASSERT_STREQ(get_action, action);

axis2_msg_info_headers_free(axis2_msg_info_headers, env);
}
status =
axis2_msg_info_headers_set_action(axis2_msg_info_headers, m_env, action);
ASSERT_EQ(status, AXIS2_SUCCESS);

int main()
{
axutil_env_t *env = cut_setup_env("Core Addr");
CUT_ASSERT(env != NULL);
if (env) {
axis2_test_msg_info_headers(env);
axutil_env_free(env);
}
CUT_RETURN_ON_FAILURE(-1);
return 0;
axis2_msg_info_headers_free(axis2_msg_info_headers, m_env);
}
28 changes: 17 additions & 11 deletions test/core/clientapi/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,36 @@ noinst_PROGRAMS = test_client test_clientapi test_svc_client_handler_count
check_PROGRAMS = test_client test_clientapi test_svc_client_handler_count
SUBDIRS =
AM_CFLAGS = -g -pthread
test_client_SOURCES = test_client.c
test_clientapi_SOURCES = test_clientapi.c
test_svc_client_handler_count_SOURCES = test_svc_client_handler_count.c
test_client_SOURCES = test_client.cc
test_clientapi_SOURCES = test_clientapi.cc
test_svc_client_handler_count_SOURCES = test_svc_client_handler_count.cc

test_clientapi_LDADD = \
../../../util/src/libaxutil.la \
../../../axiom/src/om/libaxis2_axiom.la \
../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
$(top_builddir)/neethi/src/libneethi.la \
$(top_builddir)/neethi/src/libneethi.la \
-lpthread \
$(top_builddir)/src/core/engine/libaxis2_engine.la \
$(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la \
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a

test_client_LDADD = \
../../../util/src/libaxutil.la \
../../../axiom/src/om/libaxis2_axiom.la \
../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
$(top_builddir)/neethi/src/libneethi.la \
$(top_builddir)/neethi/src/libneethi.la \
-lpthread \
$(top_builddir)/src/core/engine/libaxis2_engine.la \
$(top_builddir)/src/core/transport/http/util/libaxis2_http_util.la \
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
$(top_builddir)/src/core/transport/http/receiver/libaxis2_http_receiver.la \
$(top_builddir)/src/core/transport/http/receiver/libaxis2_http_receiver.la \
$(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la \
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a

test_svc_client_handler_count_LDADD = \
../../../util/src/libaxutil.la \
Expand All @@ -52,10 +56,12 @@ test_svc_client_handler_count_LDADD = \
-lpthread \
$(top_builddir)/src/core/engine/libaxis2_engine.la \
$(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la \
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la
$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a


INCLUDES = -I$(CUTEST_HOME)/include \
AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_builddir)/src/core/description \
-I$(top_builddir)/src/core/context \
Expand All @@ -66,5 +72,5 @@ INCLUDES = -I$(CUTEST_HOME)/include \
-I ../../../util/include \
-I ../../../neethi/include \
-I ../../../axiom/include \
-I ../../cutest/include
-I $(GTEST_DIR)/include

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* limitations under the License.
*/

#include <gtest/gtest.h>

#include <platforms/axutil_platform_auto_sense.h>
#include <axis2_const.h>
#include <cut_defs.h>
#include <cut_http_server.h>
#include "../../cutest/include/cut_http_server.h"

#if defined (WIN32)
#define bcopy(s, d, n) memcpy(d, s, n)
Expand All @@ -35,70 +36,63 @@ int write_to_socket(

/* End of function prototypes */

void
error(
const char *msg)
{
perror(msg);
exit(-1);
}

void
axis2_test_temp(axutil_env_t *env)
class TestClient: public ::testing::Test
{
/* To avoid warning of not using cut_ptr_equal */
CUT_ASSERT_PTR_EQUAL(NULL, NULL, 0);
/* To avoid warning of not using cut_int_equal */
CUT_ASSERT_INT_EQUAL(0, 0, 0);
/* To avoid warning of not using cut_str_equal */
CUT_ASSERT_STR_EQUAL("", "", 0);
}

int
main(
int argc,
char *argv[])
protected:
void SetUp()
{

m_allocator = axutil_allocator_init(NULL);
m_axis_log = axutil_log_create(m_allocator, NULL, NULL);
m_error = axutil_error_create(m_allocator);

m_env = axutil_env_create_with_error_log(m_allocator, m_error, m_axis_log);

}

void TearDown()
{
axutil_env_free(m_env);
}


axutil_allocator_t *m_allocator = NULL;
axutil_env_t *m_env = NULL;
axutil_error_t *m_error = NULL;
axutil_log_t *m_axis_log = NULL;

};

/* Note: This test fails unless you have a deployed axis2c instance running the
* echo service on the appropriate port, and AXIS2C_HOME defined in your
* environment */
TEST_F(TestClient, test_client)
{
const axis2_char_t *hostname = "localhost";
const axis2_char_t *port = "9090";
const axis2_char_t *filename = "echo.xml";
const axis2_char_t *endpoint = "/axis2/services/echo/echo";
axutil_env_t *env = NULL;

#ifndef WIN32
int c;
extern char *optarg;
int server_status;

server_status = ut_start_http_server(m_env);
ASSERT_EQ(server_status, 0);
write_to_socket(hostname, port, filename, endpoint);
ut_stop_http_server(m_env);

while ((c = getopt(argc, argv, ":h:p:f:e:")) != -1)
{
switch (c)
{
case 'h':
hostname = optarg;
break;
case 'p':
port = optarg;
break;
case 'f':
filename = optarg;
break;
case 'e':
endpoint = optarg;
break;
}
}
#endif
env = cut_setup_env("test HTTP server");
CUT_ASSERT(env != NULL);
if ( ut_start_http_server(env) != 0 ) return -1;
write_to_socket(hostname, port, filename, endpoint);
ut_stop_http_server(env);

axis2_test_temp(env);
CUT_RETURN_ON_FAILURE(-1);
return 0;
}

void
error(
const char *msg)
{
perror(msg);
exit(-1);
}


#define TEST_BUF_LEN 4999
int
write_to_socket(
Expand Down
Loading

0 comments on commit 8b97529

Please sign in to comment.