Skip to content
Permalink
Browse files
Convert all util tests to use gtest
  • Loading branch information
bblough committed Apr 29, 2018
1 parent 335280d commit 7ea329866d1c003be52d6534fb63ce290fca59c5
Showing 39 changed files with 1,614 additions and 1,452 deletions.
@@ -4,9 +4,9 @@
# 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.
@@ -15,14 +15,17 @@
TESTS = allocator_test
check_PROGRAMS = allocator_test
noinst_PROGRAMS = allocator_test
allocator_test_SOURCES = allocator_test.c ../util/create_env.c
allocator_test_SOURCES = allocator_test.cc

allocator_test_LDADD = \
$(top_builddir)/src/libaxutil.la
$(top_builddir)/src/libaxutil.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a


INCLUDES = -I$(top_builddir)/include \
-I ../../../axiom/include \
-I ../../../include \
-I ../../../test/cutest/include
-I $(GTEST_DIR)/include


@@ -15,17 +15,48 @@
* limitations under the License.
*/

#include <gtest/gtest.h>

#include <axutil_log_default.h>
#include <axutil_error_default.h>
#include <axiom_node.h>
#include <stdio.h>
#include <cut_defs.h>
#include "../util/create_env.h"

unsigned char buffer[1024];

void test_base64(axutil_env_t *env)
{
class TestAllocator: 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(TestAllocator, test_base64)
{

axis2_status_t status = AXIS2_FAILURE;
axutil_base64_binary_t *base64_binary;
axutil_base64_binary_t *plain_base64_binary;
@@ -34,74 +65,48 @@ void test_base64(axutil_env_t *env)
int plain_binary_len, b_len;
unsigned char * plain_binary = NULL;
FILE *in = fopen("test","rb");
CUT_ASSERT(in != NULL);
if (!in) return;

ASSERT_NE(in, nullptr);

plain_binary_len = fread(buffer,1,sizeof(buffer),in);
fclose(in);
plain_binary = buffer;
CUT_ASSERT(plain_binary_len != 0);
if (plain_binary_len == 0 ) return;

base64_binary = axutil_base64_binary_create(env);
CUT_ASSERT(base64_binary != NULL);
ASSERT_NE(plain_binary_len, 0);

base64_binary = axutil_base64_binary_create(m_env);
ASSERT_NE(base64_binary, nullptr);

plain_base64_binary = axutil_base64_binary_create_with_plain_binary(env,
plain_base64_binary = axutil_base64_binary_create_with_plain_binary(m_env,
plain_binary,
plain_binary_len);
CUT_ASSERT(plain_base64_binary != NULL);
ASSERT_NE(plain_base64_binary, nullptr);

encoded_binary = axutil_base64_binary_get_encoded_binary(plain_base64_binary,env);
CUT_ASSERT(encoded_binary != NULL);
encoded_binary = axutil_base64_binary_get_encoded_binary(plain_base64_binary, m_env);
ASSERT_NE(encoded_binary, nullptr);

status = axutil_base64_binary_set_plain_binary(base64_binary,env,plain_binary,
status = axutil_base64_binary_set_plain_binary(base64_binary,m_env,plain_binary,
plain_binary_len);
CUT_ASSERT(status == AXIS2_SUCCESS);
plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,env,&b_len);
CUT_ASSERT(plain_binary != NULL);
status = axutil_base64_binary_set_encoded_binary(base64_binary,env,encoded_binary);
CUT_ASSERT(status == AXIS2_SUCCESS);
get_binary = (unsigned char *) axutil_base64_binary_get_encoded_binary(base64_binary,env);
CUT_ASSERT(get_binary != NULL);
b_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,env);
CUT_ASSERT(b_len != 0);
axutil_base64_binary_free(base64_binary, env);
base64_binary = axutil_base64_binary_create_with_encoded_binary(env, encoded_binary);
CUT_ASSERT(base64_binary != NULL);
if (base64_binary != NULL)
ASSERT_EQ(status, AXIS2_SUCCESS);
plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,m_env,&b_len);
ASSERT_NE(plain_binary, nullptr);
status = axutil_base64_binary_set_encoded_binary(base64_binary,m_env,encoded_binary);
ASSERT_EQ(status, AXIS2_SUCCESS);
get_binary = (unsigned char *) axutil_base64_binary_get_encoded_binary(base64_binary,m_env);
ASSERT_NE(get_binary, nullptr);
b_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,m_env);
ASSERT_NE(b_len, 0);

axutil_base64_binary_free(base64_binary, m_env);
base64_binary = axutil_base64_binary_create_with_encoded_binary(m_env, encoded_binary);
ASSERT_NE(base64_binary, nullptr);
if (base64_binary != nullptr)
{
int binary_len;
get_binary = axutil_base64_binary_get_plain_binary(base64_binary,env, &binary_len);
CUT_ASSERT(binary_len == plain_binary_len);
CUT_ASSERT(memcmp(get_binary, plain_binary, plain_binary_len) == 0);
axutil_base64_binary_free(base64_binary, env);
get_binary = axutil_base64_binary_get_plain_binary(base64_binary,m_env, &binary_len);
ASSERT_EQ(binary_len, plain_binary_len);
ASSERT_EQ(memcmp(get_binary, plain_binary, plain_binary_len), 0);
axutil_base64_binary_free(base64_binary, m_env);
}

/* 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);

axutil_base64_binary_free(plain_base64_binary, env);
}

int main()
{
axutil_env_t *env = cut_setup_env("Base64");
CUT_ASSERT(env != NULL);
test_base64(env);
axutil_env_free(env);
CUT_RETURN_ON_FAILURE(-1);
return 0;
axutil_base64_binary_free(plain_base64_binary, m_env);
}








@@ -4,9 +4,9 @@
# 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.
@@ -15,15 +15,16 @@
TESTS = date_time_test
noinst_PROGRAMS = date_time_test
check_PROGRAMS = date_time_test
date_time_test_SOURCES = date_time_test.c ../util/create_env.c
date_time_test_SOURCES = date_time_test.cc

date_time_test_LDADD = \
$(top_builddir)/src/libaxutil.la
$(top_builddir)/src/libaxutil.la \
$(top_builddir)/$(GTEST)/libgtest.a \
$(top_builddir)/$(GTEST)/libgtest_main.a

INCLUDES = -I$(top_builddir)/include \
-I$(CUTEST_HOME)/include \
AM_CPPFLAGS = -I$(top_builddir)/include \
-I ../../../axiom/include \
-I ../../../include \
-I ../../../test/cutest/include
-I $(GTEST_DIR)/include


This file was deleted.

0 comments on commit 7ea3298

Please sign in to comment.