Convert all util tests to use gtest
diff --git a/util/test/allocator/Makefile.am b/util/test/allocator/Makefile.am
index ac9a558..734cb69 100644
--- a/util/test/allocator/Makefile.am
+++ b/util/test/allocator/Makefile.am
@@ -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
diff --git a/util/test/allocator/allocator_test.c b/util/test/allocator/allocator_test.c
deleted file mode 100644
index e696022..0000000
--- a/util/test/allocator/allocator_test.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-* 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 <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)
-{
- axis2_status_t status = AXIS2_FAILURE;
- axutil_base64_binary_t *base64_binary;
- axutil_base64_binary_t *plain_base64_binary;
- const char *encoded_binary;
- unsigned char * get_binary = NULL;
- int plain_binary_len, b_len;
- unsigned char * plain_binary = NULL;
- FILE *in = fopen("test","rb");
- CUT_ASSERT(in != NULL);
- if (!in) return;
-
- 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);
-
- plain_base64_binary = axutil_base64_binary_create_with_plain_binary(env,
- plain_binary,
- plain_binary_len);
- CUT_ASSERT(plain_base64_binary != NULL);
-
- encoded_binary = axutil_base64_binary_get_encoded_binary(plain_base64_binary,env);
- CUT_ASSERT(encoded_binary != NULL);
-
- status = axutil_base64_binary_set_plain_binary(base64_binary,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)
- {
- 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);
- }
-
- /* 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;
-}
-
-
-
-
-
-
-
-
diff --git a/util/test/allocator/allocator_test.cc b/util/test/allocator/allocator_test.cc
new file mode 100644
index 0000000..b678f4e
--- /dev/null
+++ b/util/test/allocator/allocator_test.cc
@@ -0,0 +1,112 @@
+/*
+* 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 <axutil_log_default.h>
+#include <axutil_error_default.h>
+#include <axiom_node.h>
+#include <stdio.h>
+#include "../util/create_env.h"
+
+unsigned char buffer[1024];
+
+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;
+ const char *encoded_binary;
+ unsigned char * get_binary = NULL;
+ int plain_binary_len, b_len;
+ unsigned char * plain_binary = NULL;
+ FILE *in = fopen("test","rb");
+ ASSERT_NE(in, nullptr);
+
+ plain_binary_len = fread(buffer,1,sizeof(buffer),in);
+ fclose(in);
+ plain_binary = buffer;
+ 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(m_env,
+ plain_binary,
+ plain_binary_len);
+ ASSERT_NE(plain_base64_binary, nullptr);
+
+ 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,m_env,plain_binary,
+ plain_binary_len);
+ 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,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);
+ }
+
+ axutil_base64_binary_free(plain_base64_binary, m_env);
+}
+
diff --git a/util/test/date_time/Makefile.am b/util/test/date_time/Makefile.am
index c34e0bb..2f4e608 100644
--- a/util/test/date_time/Makefile.am
+++ b/util/test/date_time/Makefile.am
@@ -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
diff --git a/util/test/date_time/date_time_test.c b/util/test/date_time/date_time_test.c
deleted file mode 100644
index 11469f1..0000000
--- a/util/test/date_time/date_time_test.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
-* 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 <axutil_date_time.h>
-#include <time.h>
-#include <axutil_date_time_util.h>
-#include <stdio.h>
-#include <axutil_env.h>
-#include "../util/create_env.h"
-#include <cut_defs.h>
-
-/** @brief test_rand
- * * deserialize and serialize the time
- * */
-
-void test_date_time(axutil_env_t *env)
-{
- axutil_date_time_t *date_time = NULL;
- axutil_date_time_t *ref = NULL;
- axutil_date_time_t *date_time_offset = NULL;
- axis2_char_t *time_str = "22:45:12";
- axis2_char_t *date_str = "2000-12-12";
- axis2_char_t *date_time_str = "2000-11-11T12:30:24";
- axis2_status_t status = AXIS2_FAILURE;
- axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE;
- axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL;
- int year , month , date , hour , min , sec , msec;
-
- date_time_offset = axutil_date_time_create_with_offset(env, 100);
- CUT_ASSERT(date_time_offset != NULL);
- if (date_time_offset != NULL) axutil_date_time_free(date_time_offset, env);
- date_time = axutil_date_time_create(env);
- CUT_ASSERT(date_time != NULL);
- if(date_time)
- {
- status = axutil_date_time_deserialize_time(date_time, env, time_str);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- status = axutil_date_time_deserialize_date(date_time, env, date_str);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str);
- CUT_ASSERT(status == AXIS2_SUCCESS);
-
- ref = axutil_date_time_create(env);
- CUT_ASSERT(ref != NULL);
- if(ref)
- {
- compare_res = axutil_date_time_compare(date_time, env, ref);
- CUT_ASSERT(compare_res != AXIS2_DATE_TIME_COMP_RES_FAILURE);
-
- status = axutil_date_time_deserialize_date_time(ref, env, date_time_str);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- compare_res = axutil_date_time_compare(date_time, env, ref);
- CUT_ASSERT(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL);
- axutil_date_time_free(ref, env);
- }
- status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799);
- CUT_ASSERT(status == AXIS2_SUCCESS);
-
- t_str = axutil_date_time_serialize_time(date_time, env);
- CUT_ASSERT(t_str != NULL);
- d_str = axutil_date_time_serialize_date(date_time, env);
- CUT_ASSERT(d_str != NULL);
- dt_str = axutil_date_time_serialize_date_time(date_time, env);
- CUT_ASSERT(d_str != NULL);
- year = axutil_date_time_get_year(date_time,env);
- month=axutil_date_time_get_month(date_time,env);
- date = axutil_date_time_get_date(date_time,env);
- hour = axutil_date_time_get_hour(date_time,env);
- min = axutil_date_time_get_minute(date_time,env);
- sec = axutil_date_time_get_second(date_time,env);
- msec = axutil_date_time_get_msec(date_time,env);
- CUT_ASSERT(year == 2008);
- CUT_ASSERT(month == 1);
- CUT_ASSERT(date == 8);
- CUT_ASSERT(hour == 12);
- CUT_ASSERT(min == 18);
- CUT_ASSERT(sec == 57);
- CUT_ASSERT(msec == 799);
-
- /* 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_date_time_free(date_time,env);
- }
-}
-
-int main()
-{
- axutil_env_t *env = NULL;
- env = cut_setup_env("Date Time");
- CUT_ASSERT(env != NULL);
- if (env)
- {
- test_date_time(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
diff --git a/util/test/date_time/date_time_test.cc b/util/test/date_time/date_time_test.cc
new file mode 100644
index 0000000..37d4538
--- /dev/null
+++ b/util/test/date_time/date_time_test.cc
@@ -0,0 +1,127 @@
+/*
+* 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 <axutil_date_time.h>
+#include <time.h>
+#include <axutil_date_time_util.h>
+#include <stdio.h>
+#include <axutil_env.h>
+#include "../util/create_env.h"
+
+class TestDateTime: 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;
+
+};
+
+
+/** @brief test_rand
+ * * deserialize and serialize the time
+ * */
+
+TEST_F(TestDateTime, test_date_time) {
+
+ axutil_date_time_t *date_time = NULL;
+ axutil_date_time_t *ref = NULL;
+ axutil_date_time_t *date_time_offset = NULL;
+ axis2_char_t *time_str = "22:45:12";
+ axis2_char_t *date_str = "2000-12-12";
+ axis2_char_t *date_time_str = "2000-11-11T12:30:24";
+ axis2_status_t status = AXIS2_FAILURE;
+ axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE;
+ axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL;
+ int year , month , day, hour , min , sec , msec;
+
+ date_time_offset = axutil_date_time_create_with_offset(m_env, 100);
+ ASSERT_NE(date_time_offset, nullptr);
+ if (date_time_offset != nullptr) axutil_date_time_free(date_time_offset, m_env);
+ date_time = axutil_date_time_create(m_env);
+ ASSERT_NE(date_time, nullptr);
+ if(date_time)
+ {
+ status = axutil_date_time_deserialize_time(date_time, m_env, time_str);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_date_time_deserialize_date(date_time, m_env, date_str);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_date_time_deserialize_date_time(date_time, m_env, date_time_str);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+ ref = axutil_date_time_create(m_env);
+ ASSERT_NE(ref, nullptr);
+ if(ref)
+ {
+ compare_res = axutil_date_time_compare(date_time, m_env, ref);
+ ASSERT_NE(compare_res, AXIS2_DATE_TIME_COMP_RES_FAILURE);
+
+ status = axutil_date_time_deserialize_date_time(ref, m_env, date_time_str);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ compare_res = axutil_date_time_compare(date_time, m_env, ref);
+ ASSERT_EQ(compare_res, AXIS2_DATE_TIME_COMP_RES_EQUAL);
+ axutil_date_time_free(ref, m_env);
+ }
+ status = axutil_date_time_set_date_time(date_time, m_env, 2008, 1, 8, 12, 18, 57, 799);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+ t_str = axutil_date_time_serialize_time(date_time, m_env);
+ ASSERT_NE(t_str, nullptr);
+ d_str = axutil_date_time_serialize_date(date_time, m_env);
+ ASSERT_NE(d_str, nullptr);
+ dt_str = axutil_date_time_serialize_date_time(date_time, m_env);
+ ASSERT_NE(dt_str, nullptr);
+ year = axutil_date_time_get_year(date_time, m_env);
+ month=axutil_date_time_get_month(date_time, m_env);
+ day = axutil_date_time_get_day(date_time, m_env);
+ hour = axutil_date_time_get_hour(date_time, m_env);
+ min = axutil_date_time_get_minute(date_time, m_env);
+ sec = axutil_date_time_get_second(date_time, m_env);
+ msec = axutil_date_time_get_msec(date_time, m_env);
+ ASSERT_EQ(year, 2008);
+ ASSERT_EQ(month, 1);
+ ASSERT_EQ(day, 8);
+ ASSERT_EQ(hour, 12);
+ ASSERT_EQ(min, 18);
+ ASSERT_EQ(sec, 57);
+ ASSERT_EQ(msec, 799);
+
+ axutil_date_time_free(date_time,m_env);
+ }
+}
+
diff --git a/util/test/duration/Makefile.am b/util/test/duration/Makefile.am
index b9d489d..b0dacb4 100644
--- a/util/test/duration/Makefile.am
+++ b/util/test/duration/Makefile.am
@@ -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 = duration_test
check_PROGRAMS = duration_test
noinst_PROGRAMS = duration_test
-duration_test_SOURCES = duration_test.c ../util/create_env.c
+duration_test_SOURCES = duration_test.cc
duration_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
diff --git a/util/test/duration/duration_test.c b/util/test/duration/duration_test.c
deleted file mode 100644
index 4af0c4b..0000000
--- a/util/test/duration/duration_test.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
-* 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 <axutil_duration.h>
-#include <cut_defs.h>
-#include "../util/create_env.h"
-
-/** @brief test duration
- * create duration from values and retrieve values
- */
-void test_duration(axutil_env_t *env)
-{
- axis2_status_t status = AXIS2_FAILURE;
- axis2_char_t * duration_str = "P3Y12M23DT11H45M45.000000S";
- axis2_char_t * duration_str1 = "-P3Y12M23DT11H45M45.000000S";
- int year,month,day,hour,minute;
- double second;
- axutil_duration_t * duration;
- axutil_duration_t * duration_one;
- axutil_duration_t * duration_two;
- axutil_duration_t * duration_three;
- axutil_duration_t * duration_four;
- axis2_bool_t is_negative = AXIS2_FALSE;
- axis2_char_t *serialize, *serialize1;
-
- duration = axutil_duration_create_from_values(env,AXIS2_TRUE,3,12,23,11,45,45.00);
- CUT_ASSERT(duration != NULL);
- duration_one = axutil_duration_create_from_values(env,AXIS2_FALSE,7,11,2,23,11,50.00);
- CUT_ASSERT(duration_one != NULL);
- duration_two = axutil_duration_create_from_string(env,duration_str);
- CUT_ASSERT(duration_two != NULL);
- duration_three = axutil_duration_create(env);
- CUT_ASSERT(duration_three != NULL);
- duration_four = axutil_duration_create(env);
- CUT_ASSERT(duration_four != NULL);
-
- year = axutil_duration_get_years(duration,env);
- month = axutil_duration_get_months(duration,env);
- day = axutil_duration_get_days(duration,env);
- hour = axutil_duration_get_hours(duration,env);
- minute = axutil_duration_get_mins(duration,env);
- second = axutil_duration_get_seconds(duration,env);
- is_negative = axutil_duration_get_is_negative(duration,env);
-
- status = axutil_duration_deserialize_duration(duration_three,env,duration_str);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- status = axutil_duration_deserialize_duration(duration_four,env,duration_str1);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- serialize = axutil_duration_serialize_duration(duration_three,env);
- CUT_ASSERT(serialize != NULL);
- CUT_ASSERT(strcmp(duration_str, serialize) == 0);
- serialize1 = axutil_duration_serialize_duration(duration_four,env);
- CUT_ASSERT(serialize1 != NULL);
- CUT_ASSERT(strcmp(duration_str1, serialize1) == 0);
- status = axutil_duration_set_duration(duration,env,AXIS2_TRUE,3,12,23,11,45,56.00);
- CUT_ASSERT(status == AXIS2_SUCCESS);
-
- /* 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_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- axutil_duration_free(duration_two,env);
- axutil_duration_free(duration_three,env);
- axutil_duration_free(duration_four,env);
-}
-
-/** @brief set values
- * set values for the duration and get the values
- */
-void set_values(axutil_env_t *env)
-{
- axis2_status_t status;
- axutil_duration_t * duration;
- axutil_duration_t * duration_one;
- int get_year,get_month,get_day,get_hour,get_minute;
- axis2_bool_t is_negative;
- double get_second;
-
- duration = axutil_duration_create(env);
- CUT_ASSERT(duration != NULL);
- if ( duration == NULL ) return;
- duration_one = axutil_duration_create_from_values(env,AXIS2_TRUE,5,9,29,59,21,49);
- CUT_ASSERT(duration_one != NULL);
-
- status = axutil_duration_set_is_negative(duration,env,AXIS2_TRUE);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- if (status != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return;
- }
- is_negative = axutil_duration_get_is_negative(duration,env);
- CUT_ASSERT(is_negative == AXIS2_TRUE);
- if (!is_negative)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return;
- }
-
- status = axutil_duration_set_years(duration,env,5);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_year = axutil_duration_get_years(duration,env);
- CUT_ASSERT(get_year == 5);
- status = axutil_duration_set_months(duration,env,9);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_month = axutil_duration_get_months(duration,env);
- CUT_ASSERT(get_month == 9);
- status = axutil_duration_set_days(duration,env,29);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_day = axutil_duration_get_days(duration,env);
- CUT_ASSERT(get_day == 29);
- status = axutil_duration_set_hours(duration,env,59);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_hour = axutil_duration_get_hours(duration,env);
- CUT_ASSERT(get_hour == 59);
- status = axutil_duration_set_mins(duration,env,21);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_minute = axutil_duration_get_mins(duration,env);
- CUT_ASSERT(get_minute == 21);
- status = axutil_duration_set_seconds(duration,env,49);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_second = axutil_duration_get_seconds(duration,env);
- CUT_ASSERT(get_second == 49);
- CUT_ASSERT(axutil_duration_compare(duration_one,duration,env));
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
-}
-int main()
-{
- axutil_env_t *env = cut_setup_env("Duration");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_duration(env);
- set_values(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
diff --git a/util/test/duration/duration_test.cc b/util/test/duration/duration_test.cc
new file mode 100644
index 0000000..db28b1d
--- /dev/null
+++ b/util/test/duration/duration_test.cc
@@ -0,0 +1,162 @@
+/*
+* 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 <axutil_duration.h>
+#include "../util/create_env.h"
+
+
+class TestDuration: 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;
+
+};
+
+
+/** @brief test duration
+ * create duration from values and retrieve values
+ */
+
+TEST_F(TestDuration, test_duration) {
+
+ axis2_status_t status = AXIS2_FAILURE;
+ axis2_char_t * duration_str = "P3Y12M23DT11H45M45.000000S";
+ axis2_char_t * duration_str1 = "-P3Y12M23DT11H45M45.000000S";
+ int year,month,day,hour,minute;
+ double second;
+ axutil_duration_t * duration;
+ axutil_duration_t * duration_one;
+ axutil_duration_t * duration_two;
+ axutil_duration_t * duration_three;
+ axutil_duration_t * duration_four;
+ axis2_bool_t is_negative = AXIS2_FALSE;
+ axis2_char_t *serialize, *serialize1;
+
+ duration = axutil_duration_create_from_values(m_env,AXIS2_TRUE,3,12,23,11,45,45.00);
+ ASSERT_NE(duration, nullptr);
+ duration_one = axutil_duration_create_from_values(m_env,AXIS2_FALSE,7,11,2,23,11,50.00);
+ ASSERT_NE(duration_one, nullptr);
+ duration_two = axutil_duration_create_from_string(m_env,duration_str);
+ ASSERT_NE(duration_two, nullptr);
+ duration_three = axutil_duration_create(m_env);
+ ASSERT_NE(duration_three, nullptr);
+ duration_four = axutil_duration_create(m_env);
+ ASSERT_NE(duration_four, nullptr);
+
+ year = axutil_duration_get_years(duration, m_env);
+ month = axutil_duration_get_months(duration, m_env);
+ day = axutil_duration_get_days(duration, m_env);
+ hour = axutil_duration_get_hours(duration, m_env);
+ minute = axutil_duration_get_mins(duration, m_env);
+ second = axutil_duration_get_seconds(duration, m_env);
+ is_negative = axutil_duration_get_is_negative(duration, m_env);
+
+ status = axutil_duration_deserialize_duration(duration_three, m_env,duration_str);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_duration_deserialize_duration(duration_four, m_env,duration_str1);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ serialize = axutil_duration_serialize_duration(duration_three, m_env);
+ ASSERT_NE(serialize, nullptr);
+ ASSERT_STREQ(duration_str, serialize);
+ serialize1 = axutil_duration_serialize_duration(duration_four, m_env);
+ ASSERT_NE(serialize1, nullptr);
+ ASSERT_STREQ(duration_str1, serialize1);
+ status = axutil_duration_set_duration(duration,m_env,AXIS2_TRUE,3,12,23,11,45,56.00);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+
+ axutil_duration_free(duration, m_env);
+ axutil_duration_free(duration_one, m_env);
+ axutil_duration_free(duration_two, m_env);
+ axutil_duration_free(duration_three, m_env);
+ axutil_duration_free(duration_four, m_env);
+}
+
+/** @brief set values
+ * set values for the duration and get the values
+ */
+TEST_F(TestDuration, test_set_values) {
+
+ axis2_status_t status;
+ axutil_duration_t * duration;
+ axutil_duration_t * duration_one;
+ int get_year,get_month,get_day,get_hour,get_minute;
+ axis2_bool_t is_negative;
+ double get_second;
+
+ duration = axutil_duration_create(m_env);
+ ASSERT_NE(duration, nullptr);
+ duration_one = axutil_duration_create_from_values(m_env,AXIS2_TRUE,5,9,29,59,21,49);
+ ASSERT_NE(duration_one, nullptr);
+
+ status = axutil_duration_set_is_negative(duration,m_env,AXIS2_TRUE);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+ is_negative = axutil_duration_get_is_negative(duration, m_env);
+ ASSERT_EQ(is_negative, AXIS2_TRUE);
+
+ status = axutil_duration_set_years(duration, m_env,5);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_year = axutil_duration_get_years(duration, m_env);
+ ASSERT_EQ(get_year, 5);
+ status = axutil_duration_set_months(duration, m_env,9);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_month = axutil_duration_get_months(duration, m_env);
+ ASSERT_EQ(get_month, 9);
+ status = axutil_duration_set_days(duration, m_env,29);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_day = axutil_duration_get_days(duration, m_env);
+ ASSERT_EQ(get_day, 29);
+ status = axutil_duration_set_hours(duration, m_env,59);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_hour = axutil_duration_get_hours(duration, m_env);
+ ASSERT_EQ(get_hour, 59);
+ status = axutil_duration_set_mins(duration, m_env,21);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_minute = axutil_duration_get_mins(duration, m_env);
+ ASSERT_EQ(get_minute, 21);
+ status = axutil_duration_set_seconds(duration, m_env,49);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_second = axutil_duration_get_seconds(duration, m_env);
+ ASSERT_EQ(get_second, 49);
+ ASSERT_TRUE(axutil_duration_compare(duration_one,duration, m_env));
+ axutil_duration_free(duration, m_env);
+ axutil_duration_free(duration_one, m_env);
+}
diff --git a/util/test/link_list/Makefile.am b/util/test/link_list/Makefile.am
index 706f93e..5545013 100644
--- a/util/test/link_list/Makefile.am
+++ b/util/test/link_list/Makefile.am
@@ -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 = link_list_test
check_PROGRAMS = link_list_test
noinst_PROGRAMS = link_list_test
-link_list_test_SOURCES = link_list_test.c ../util/create_env.c
+link_list_test_SOURCES = link_list_test.cc
link_list_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
diff --git a/util/test/link_list/link_list_test.c b/util/test/link_list/link_list_test.c
deleted file mode 100644
index d5640ff..0000000
--- a/util/test/link_list/link_list_test.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
-* 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 <axutil_linked_list.h>
-#include <cut_defs.h>
-#include "../util/create_env.h"
-
-axutil_env_t *env = NULL;
-axutil_linked_list_t * linked_list = NULL;
-entry_t *entry = NULL;
-
-void test_link_list(axutil_env_t *env,char * first_item,char * second_item,char * third_item,char *last_item,char *array)
-{
- int index_of_item;
- int index_of_last_item;
- entry_t * entry;
- void *get_item;
- axis2_status_t status;
- axis2_bool_t bresult;
- void **array_from_list;
-
- linked_list = axutil_linked_list_create(env);
- CUT_ASSERT(linked_list != NULL);
- if (!linked_list) return;
- status = axutil_linked_list_add_first(linked_list,env,(void *)first_item);
- CUT_ASSERT(status = AXIS2_SUCCESS);
- bresult = axutil_linked_list_contains(linked_list,env,(void *)second_item);
- CUT_ASSERT(bresult == AXIS2_FALSE);
- status = axutil_linked_list_add(linked_list,env,(void *)third_item);
- CUT_ASSERT(status = AXIS2_SUCCESS);
- status = axutil_linked_list_add_last(linked_list,env,(void *)last_item);
- CUT_ASSERT(status = AXIS2_SUCCESS);
- CUT_ASSERT(axutil_linked_list_size(linked_list,env) == 3);
- index_of_item = axutil_linked_list_index_of(linked_list,env,third_item);
- CUT_ASSERT(index_of_item == 1);
- index_of_last_item = axutil_linked_list_last_index_of(linked_list,env,last_item);
- CUT_ASSERT(index_of_last_item == 2);
- entry = axutil_linked_list_get_entry(linked_list,env,0);
- CUT_ASSERT(entry != NULL);
- get_item = axutil_linked_list_get(linked_list,env,1);
- CUT_ASSERT(get_item != NULL);
- CUT_ASSERT(strcmp((char*)get_item, third_item) == 0);
- get_item = axutil_linked_list_set(linked_list,env,1,(void *)array);
- CUT_ASSERT(get_item != NULL);
- CUT_ASSERT(strcmp((char*)get_item, third_item) == 0);
- array_from_list = axutil_linked_list_to_array(linked_list,env);
- CUT_ASSERT(array_from_list != NULL);
- status = axutil_linked_list_add_at_index(linked_list,env,1,(void *)second_item);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_item = axutil_linked_list_remove_at_index(linked_list,env,1);
- CUT_ASSERT(get_item != NULL);
- bresult = axutil_linked_list_check_bounds_inclusive(linked_list,env,1);
- CUT_ASSERT(bresult == AXIS2_TRUE);
- status = axutil_linked_list_remove_entry(linked_list,env,entry);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- get_item = axutil_linked_list_remove_first(linked_list,env);
- CUT_ASSERT(get_item != NULL);
- get_item = axutil_linked_list_remove_last(linked_list,env);
- CUT_ASSERT(get_item != NULL);
- CUT_ASSERT(axutil_linked_list_size(linked_list,env) == 0);
-
- bresult = axutil_linked_list_remove(linked_list,env,(void *)third_item);
- CUT_ASSERT(bresult == AXIS2_FALSE);
-
- /* 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_linked_list_free(linked_list,env);
-}
-
-int main()
-{
- axutil_env_t *env = cut_setup_env("Link list");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_link_list(env,"first entry","secnd entry","third entry","last entry" ,"test");
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
-
-
-
-
-
diff --git a/util/test/link_list/link_list_test.cc b/util/test/link_list/link_list_test.cc
new file mode 100644
index 0000000..e415410
--- /dev/null
+++ b/util/test/link_list/link_list_test.cc
@@ -0,0 +1,114 @@
+/*
+* 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 <axutil_linked_list.h>
+#include "../util/create_env.h"
+
+
+class TestLinkedList: 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(TestLinkedList, test_link_list)
+{
+ char *first_item = "first entry";
+ char *second_item = "secnd entry";
+ char *third_item = "third entry";
+ char *last_item = "last entry";
+ char *array = "test";
+
+ axutil_linked_list_t * linked_list = NULL;
+ int index_of_item;
+ int index_of_last_item;
+ entry_t * entry;
+ void *get_item;
+ axis2_status_t status;
+ axis2_bool_t bresult;
+ void **array_from_list;
+
+ linked_list = axutil_linked_list_create(m_env);
+ ASSERT_NE(linked_list, nullptr);
+ status = axutil_linked_list_add_first(linked_list,m_env,(void *)first_item);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ bresult = axutil_linked_list_contains(linked_list,m_env,(void *)second_item);
+ ASSERT_EQ(bresult, AXIS2_FALSE);
+ status = axutil_linked_list_add(linked_list,m_env,(void *)third_item);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_linked_list_add_last(linked_list,m_env,(void *)last_item);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ ASSERT_EQ(axutil_linked_list_size(linked_list,m_env), 3);
+ index_of_item = axutil_linked_list_index_of(linked_list,m_env,third_item);
+ ASSERT_EQ(index_of_item, 1);
+ index_of_last_item = axutil_linked_list_last_index_of(linked_list,m_env,last_item);
+ ASSERT_EQ(index_of_last_item, 2);
+ entry = axutil_linked_list_get_entry(linked_list,m_env,0);
+ ASSERT_NE(entry, nullptr);
+ get_item = axutil_linked_list_get(linked_list,m_env,1);
+ ASSERT_NE(get_item, nullptr);
+ ASSERT_EQ(strcmp((char*)get_item, third_item), 0);
+ get_item = axutil_linked_list_set(linked_list,m_env,1,(void *)array);
+ ASSERT_NE(get_item, nullptr);
+ ASSERT_EQ(strcmp((char*)get_item, third_item), 0);
+ array_from_list = axutil_linked_list_to_array(linked_list,m_env);
+ ASSERT_NE(array_from_list, nullptr);
+ status = axutil_linked_list_add_at_index(linked_list,m_env,1,(void *)second_item);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_item = axutil_linked_list_remove_at_index(linked_list,m_env,1);
+ ASSERT_NE(get_item, nullptr);
+ bresult = axutil_linked_list_check_bounds_inclusive(linked_list,m_env,1);
+ ASSERT_EQ(bresult, AXIS2_TRUE);
+ status = axutil_linked_list_remove_entry(linked_list,m_env,entry);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ get_item = axutil_linked_list_remove_first(linked_list,m_env);
+ ASSERT_NE(get_item, nullptr);
+ get_item = axutil_linked_list_remove_last(linked_list,m_env);
+ ASSERT_NE(get_item, nullptr);
+ ASSERT_EQ(axutil_linked_list_size(linked_list,m_env), 0);
+
+ bresult = axutil_linked_list_remove(linked_list,m_env,(void *)third_item);
+ ASSERT_EQ(bresult, AXIS2_FALSE);
+
+ axutil_linked_list_free(linked_list,m_env);
+}
+
diff --git a/util/test/properties/Makefile.am b/util/test/properties/Makefile.am
index 6304468..0d91018 100644
--- a/util/test/properties/Makefile.am
+++ b/util/test/properties/Makefile.am
@@ -4,25 +4,26 @@
# 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.
TESTS = property_test
-check_PROGRAMS = property_test
-noinst_PROGRAMS = property_test
-property_test_SOURCES = property_test.c ../util/create_env.c
+check_PROGRAMS = property_test
+noinst_PROGRAMS = property_test
+property_test_SOURCES = property_test.cc
property_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 \
+AM_CPPFLAGS = -I$(top_builddir)/include \
-I ../../../axiom/include \
-I ../../../include \
- -I ../../../cutest/include
-
+ -I $(GTEST_DIR)/include
diff --git a/util/test/properties/property_test.c b/util/test/properties/property_test.c
deleted file mode 100644
index 639f32c..0000000
--- a/util/test/properties/property_test.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
-* 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 <axutil_env.h>
-#include "../util/create_env.h"
-#include <axutil_string.h>
-#include <axutil_properties.h>
-
-void printProperties(axutil_properties_t * properties, axutil_env_t *env)
-{
- axutil_hash_t* all_properties = NULL;
- all_properties = axutil_properties_get_all(properties,env);
- if(all_properties)
- {
- axutil_hash_index_t *hi = NULL;
- axis2_char_t *key = NULL;
- axis2_char_t *value = NULL;
- for(hi = axutil_hash_first(all_properties, env); hi; hi = axutil_hash_next(env, hi))
- {
- axutil_hash_this(hi, (void *)&key, NULL, (void *)&value);
- if(key)
- {
- if(!value)
- {
- value = axutil_strdup(env, "");
- }
- printf("%s=%s\n", key, value);
- }
- }
- }
-}
-/** @brief test properties
- * read file and give the output
- */
-axis2_status_t test_properties(axutil_env_t *env)
-{
- axutil_hash_t* all_properties = NULL;
- axis2_status_t status = AXIS2_FAILURE;
- axis2_char_t* input_filename = "test.doc";
- axutil_properties_t * properties = NULL;
- axis2_status_t store_properties ;
- axis2_status_t load_properties ;
- axis2_char_t * key = "key";
- axis2_char_t * value = "value";
- FILE *input = fopen("input.doc","rb");
- FILE *output = fopen("output.doc","wb");
-
- if (!input)
- {
- printf("Can't open input.doc\n");
- return AXIS2_FAILURE;
- }
- if (!output)
- {
- printf("Can't open output.doc\n");
- return AXIS2_FAILURE;
- }
-
- properties = axutil_properties_create(env);
- if(!properties)
- {
- printf("Properties are not created\n");
- axutil_properties_free(properties,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The the axutil_properties_create is successfull\n");
- status = axutil_properties_set_property(properties,env, key, value);
- if (status == AXIS2_SUCCESS)
- printf("The test axutil_properties_set_property is successful\n");
- else
- printf("The test axutil_properties_set_property failed\n") ;
-
- printProperties(properties, env);
- store_properties = AXIS2_SUCCESS;
-/* Not used, program aborts on Windows with MSVC (Visual Studio 2008 Express Edition)
- store_properties = axutil_properties_store(properties,env,output);
- if(!store_properties)
- {
- printf("Can not store the properties\n");
- axutil_properties_free(properties,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_properties_store is successfull\n");
-*/
- load_properties = axutil_properties_load(properties,env,input_filename);
- if(!load_properties)
- {
- printf("Properties can't be loaded\n");
- axutil_properties_free(properties,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_properties_load is successfull\n");
- printProperties(properties, env);
-
- all_properties = axutil_properties_get_all(properties,env);
- if(!all_properties)
- {
- printf("Can't call properties_get_all\n");
- axutil_properties_free(properties,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_properties_get_all is successfull\n");
-
- axutil_properties_free(properties,env);
-
- return AXIS2_SUCCESS;
-}
-
-int main()
-{
- axutil_env_t *env = NULL;
- int status = AXIS2_SUCCESS;
- env = create_environment();
- status = test_properties(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf(" The test is failed\n");
- }
-
- axutil_env_free(env);
- return 0;
-}
-
-
-
-
-
-
-
-
-
diff --git a/util/test/properties/property_test.cc b/util/test/properties/property_test.cc
new file mode 100644
index 0000000..3845e57
--- /dev/null
+++ b/util/test/properties/property_test.cc
@@ -0,0 +1,128 @@
+/*
+* 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 <axutil_env.h>
+#include "../util/create_env.h"
+#include <axutil_string.h>
+#include <axutil_properties.h>
+
+void printProperties(axutil_properties_t * properties, axutil_env_t *env)
+{
+ axutil_hash_t* all_properties = NULL;
+ all_properties = axutil_properties_get_all(properties,env);
+ if(all_properties)
+ {
+ axutil_hash_index_t *hi = NULL;
+ axis2_char_t *key = NULL;
+ axis2_char_t *value = NULL;
+ for(hi = axutil_hash_first(all_properties, env); hi; hi = axutil_hash_next(env, hi))
+ {
+ axutil_hash_this(hi, (const void **)&key, NULL, (void **)&value);
+ if(key)
+ {
+ if(!value)
+ {
+ value = (axis2_char_t *) axutil_strdup(env, "");
+ }
+ printf("%s=%s\n", key, value);
+ }
+ }
+ }
+}
+
+class TestProperties: 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;
+
+};
+
+
+/** @brief test properties
+ * read file and give the output
+ */
+TEST_F(TestProperties, test_properties)
+{
+ axutil_hash_t* all_properties = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
+ axis2_char_t* input_filename = "test.doc";
+ axutil_properties_t * properties = NULL;
+ axis2_status_t store_properties ;
+ axis2_status_t load_properties ;
+ axis2_char_t * key = "key";
+ axis2_char_t * value = "value";
+ FILE *input = fopen("input.doc","rb");
+ FILE *output = fopen("output.doc","wb");
+
+ ASSERT_NE(input, nullptr);
+ ASSERT_NE(output, nullptr);
+
+ properties = axutil_properties_create(m_env);
+ ASSERT_NE(properties, nullptr);
+
+ status = axutil_properties_set_property(properties,m_env, key, value);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+ printProperties(properties, m_env);
+
+ store_properties = AXIS2_SUCCESS;
+/* Not used, program aborts on Windows with MSVC (Visual Studio 2008 Express Edition)
+ store_properties = axutil_properties_store(properties,env,output);
+ if(!store_properties)
+ {
+ printf("Can not store the properties\n");
+ axutil_properties_free(properties,env);
+ return AXIS2_FAILURE;
+ }
+ else
+ printf("The test axutil_properties_store is successfull\n");
+*/
+ load_properties = axutil_properties_load(properties,m_env,input_filename);
+ ASSERT_NE(load_properties, 0);
+
+ printProperties(properties, m_env);
+
+ all_properties = axutil_properties_get_all(properties,m_env);
+ ASSERT_NE(all_properties, nullptr);
+
+ axutil_properties_free(properties,m_env);
+
+}
+
diff --git a/util/test/rand/Makefile.am b/util/test/rand/Makefile.am
index f5c527e..61913e1 100644
--- a/util/test/rand/Makefile.am
+++ b/util/test/rand/Makefile.am
@@ -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 = rand_test
check_PROGRAMS = rand_test
noinst_PROGRAMS = rand_test
-rand_test_SOURCES = rand_test.c ../util/create_env.c
+rand_test_SOURCES = rand_test.cc
rand_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
diff --git a/util/test/rand/rand_test.c b/util/test/rand/rand_test.c
deleted file mode 100644
index e94a74a..0000000
--- a/util/test/rand/rand_test.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-* 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 "../util/create_env.h"
-#include <axutil_rand.h>
-#include <cut_defs.h>
-
-/** @brief test_rand
- * create random variable and get it's value
- */
-
-void test_rand(axutil_env_t *env)
-{
- int rand_number,rand_value,start = 2,end = 8,rand_range;
- unsigned seed = 10;
-
- rand_number = axutil_rand(&seed);
- printf("rand_number : %d\n", rand_number);
- rand_range = axutil_rand_with_range(&seed,start,end);
- printf("rand_range : %d\n", rand_range);
- CUT_ASSERT(rand_range != -1);
- CUT_ASSERT(rand_range >= start && rand_range <= end);
- rand_value = axutil_rand_get_seed_value_based_on_time(env);
- printf("rand_based_on_time : %d\n", rand_value);
-
- /* 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()
-{
- axutil_env_t *env = cut_setup_env("Rand");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_rand(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
diff --git a/util/test/rand/rand_test.cc b/util/test/rand/rand_test.cc
new file mode 100644
index 0000000..fcbcf90
--- /dev/null
+++ b/util/test/rand/rand_test.cc
@@ -0,0 +1,73 @@
+/*
+* 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 "../util/create_env.h"
+#include <axutil_rand.h>
+
+class TestRand: 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;
+
+};
+
+
+/** @brief test_rand
+ * create random variable and get it's value
+ */
+
+TEST_F(TestRand, test_rand)
+{
+
+ int rand_number,rand_value,start = 2,end = 8,rand_range;
+ unsigned seed = 10;
+
+ rand_number = axutil_rand(&seed);
+ printf("rand_number : %d\n", rand_number);
+ rand_range = axutil_rand_with_range(&seed,start,end);
+ printf("rand_range : %d\n", rand_range);
+ ASSERT_NE(rand_range, -1);
+ ASSERT_GE(rand_range, start);
+ ASSERT_LE(rand_range, end);
+ rand_value = axutil_rand_get_seed_value_based_on_time(m_env);
+ printf("rand_based_on_time : %d\n", rand_value);
+
+
+}
diff --git a/util/test/stack/Makefile.am b/util/test/stack/Makefile.am
index ed1b08f..62268b2 100644
--- a/util/test/stack/Makefile.am
+++ b/util/test/stack/Makefile.am
@@ -4,26 +4,27 @@
# 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.
TESTS = stack_test
-check_PROGRAMS = stack_test
-noinst_PROGRAMS = stack_test
-stack_test_SOURCES = stack_test.c ../util/create_env.c
+check_PROGRAMS = stack_test
+noinst_PROGRAMS = stack_test
+stack_test_SOURCES = stack_test.cc
stack_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
diff --git a/util/test/stack/stack_test.c b/util/test/stack/stack_test.c
deleted file mode 100644
index 09e8d41..0000000
--- a/util/test/stack/stack_test.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-* 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 "../util/create_env.h"
-#include <cut_defs.h>
-#include <axutil_stack.h>
-
-void test_stack(axutil_env_t * env, char * value)
-{
- axutil_stack_t * stack = NULL;
- axis2_status_t status = AXIS2_FAILURE;
- void * get_value = NULL;
-
- stack = axutil_stack_create(env);
- CUT_ASSERT(stack != NULL);
- if (!stack)
- {
- return;
- }
- status = axutil_stack_push(stack,env,(void *)value);
- CUT_ASSERT(status == AXIS2_SUCCESS);
- CUT_ASSERT(axutil_stack_size(stack,env) == 1);
- CUT_ASSERT(value == (char *)axutil_stack_get(stack,env));
- get_value = axutil_stack_get_at(stack,env,0);
- CUT_ASSERT(strcmp(value,get_value) == 0);
- CUT_ASSERT(strcmp(value,(char *)axutil_stack_pop(stack,env)) == 0);
- CUT_ASSERT(axutil_stack_size(stack,env) == 0);
-
- /* 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_stack_free(stack,env);
-}
-int main()
-{
- char value[10] = "test\n";
- axutil_env_t *env = cut_setup_env("Stack");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_stack(env,value);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
diff --git a/util/test/stack/stack_test.cc b/util/test/stack/stack_test.cc
new file mode 100644
index 0000000..673458c
--- /dev/null
+++ b/util/test/stack/stack_test.cc
@@ -0,0 +1,71 @@
+/*
+* 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 "../util/create_env.h"
+#include <axutil_stack.h>
+
+class TestStack: 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(TestStack, test_om_build)
+{
+ axutil_stack_t * stack = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
+ void * get_value = NULL;
+ char value[10] = "test\n";
+
+ stack = axutil_stack_create(m_env);
+ ASSERT_NE(stack, nullptr);
+ status = axutil_stack_push(stack,m_env,(void *)value);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ ASSERT_EQ(axutil_stack_size(stack,m_env), 1);
+ ASSERT_EQ(value, (char *)axutil_stack_get(stack,m_env));
+ get_value = axutil_stack_get_at(stack,m_env,0);
+ ASSERT_STREQ(value,(const char *)get_value);
+ ASSERT_STREQ(value,(char *)axutil_stack_pop(stack,m_env));
+ ASSERT_EQ(axutil_stack_size(stack,m_env), 0);
+
+ axutil_stack_free(stack,m_env);
+}
+
diff --git a/util/test/string_util/Makefile.am b/util/test/string_util/Makefile.am
index 6910171..c380073 100644
--- a/util/test/string_util/Makefile.am
+++ b/util/test/string_util/Makefile.am
@@ -4,26 +4,27 @@
# 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.
TESTS = string_util_test
-noinst_PROGRAMS = string_util_test
-check_PROGRAMS = string_util_test
-string_util_test_SOURCES = string_util_test.c ../util/create_env.c
+noinst_PROGRAMS = string_util_test
+check_PROGRAMS = string_util_test
+string_util_test_SOURCES = string_util_test.cc
string_util_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
diff --git a/util/test/string_util/string_util_test.c b/util/test/string_util/string_util_test.c
deleted file mode 100644
index 2006971..0000000
--- a/util/test/string_util/string_util_test.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-* 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 <string.h>
-#include "../util/create_env.h"
-#include <axutil_string_util.h>
-#include <axutil_array_list.h>
-#include <cut_defs.h>
-
-/** @brief test string
- * tokenize a string
- */
-
-void test_string(axutil_env_t *env)
-{
- int delim = ' ';
- void *token = NULL;
- void *last_token_string = NULL;
- void *first_token_string = NULL;
- axutil_array_list_t * first_token, * last_token;
- axis2_char_t * in = "this is a test string";
-
- axutil_array_list_t * tokenize = axutil_tokenize(env, in, delim);
- CUT_ASSERT(tokenize != NULL);
- if(!tokenize) return;
- token = axutil_array_list_get(tokenize,env,4);
- CUT_ASSERT(token != NULL);
- CUT_ASSERT(strcmp(token, "string") == 0);
-
- first_token = axutil_first_token(env,in,delim);
- CUT_ASSERT(first_token != NULL);
- if(first_token)
- {
- first_token_string = axutil_array_list_get(first_token,env,1);
- CUT_ASSERT(first_token_string != NULL);
- CUT_ASSERT(strcmp(first_token_string, "is a test string") == 0);
- }
-
- last_token = axutil_last_token(env,in,delim);
- CUT_ASSERT(last_token != NULL);
- if(last_token)
- {
- last_token_string = axutil_array_list_get(last_token,env,1);
- CUT_ASSERT(last_token_string != NULL);
- CUT_ASSERT(strcmp(last_token_string, "string") == 0);
- }
-
- /* 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()
-{
- axutil_env_t *env = cut_setup_env("String util");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_string(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
-
diff --git a/util/test/string_util/string_util_test.cc b/util/test/string_util/string_util_test.cc
new file mode 100644
index 0000000..e1b5a16
--- /dev/null
+++ b/util/test/string_util/string_util_test.cc
@@ -0,0 +1,92 @@
+/*
+* 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 <string.h>
+#include "../util/create_env.h"
+#include <axutil_string_util.h>
+#include <axutil_array_list.h>
+
+class TestString: 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;
+
+};
+
+
+/** @brief test string
+ * tokenize a string
+ */
+
+TEST_F(TestString, test_string)
+{
+ int delim = ' ';
+ void *token = NULL;
+ void *last_token_string = NULL;
+ void *first_token_string = NULL;
+ axutil_array_list_t * first_token, * last_token;
+ axis2_char_t * in = "this is a test string";
+
+ axutil_array_list_t * tokenize = axutil_tokenize(m_env, in, delim);
+ ASSERT_NE(tokenize, nullptr);
+ token = axutil_array_list_get(tokenize,m_env,4);
+ ASSERT_NE(token, nullptr);
+ ASSERT_STREQ((const char *)token, "string");
+
+ first_token = axutil_first_token(m_env,in,delim);
+ ASSERT_NE(first_token, nullptr);
+ if(first_token)
+ {
+ first_token_string = axutil_array_list_get(first_token,m_env,1);
+ ASSERT_NE(first_token_string, nullptr);
+ ASSERT_STREQ((const char *)first_token_string, "is a test string");
+ }
+
+ last_token = axutil_last_token(m_env,in,delim);
+ ASSERT_NE(last_token, nullptr);
+ if(last_token)
+ {
+ last_token_string = axutil_array_list_get(last_token,m_env,1);
+ ASSERT_NE(last_token_string, nullptr);
+ ASSERT_STREQ((const char *)last_token_string, "string");
+ }
+
+}
diff --git a/util/test/uri/Makefile.am b/util/test/uri/Makefile.am
index dfac9a8..00dd8b0 100644
--- a/util/test/uri/Makefile.am
+++ b/util/test/uri/Makefile.am
@@ -4,26 +4,27 @@
# 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.
TESTS = uri_test
-check_PROGRAMS = uri_test
-noinst_PROGRAMS = uri_test
-uri_test_SOURCES = uri_test.c ../util/create_env.c
+check_PROGRAMS = uri_test
+noinst_PROGRAMS = uri_test
+uri_test_SOURCES = uri_test.cc
uri_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
diff --git a/util/test/uri/uri_test.c b/util/test/uri/uri_test.c
deleted file mode 100644
index 1449cd3..0000000
--- a/util/test/uri/uri_test.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-* 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 <axutil_uri.h>
-#include <cut_defs.h>
-#include "../util/create_env.h"
-/** @brief test uri
- * * create URI and get the values of it's components
- * */
-void test_uri(axutil_env_t *env)
-{
- axis2_char_t * uri_str = "http://user:pass@example.com:80/foo?bar#item5";
- axis2_char_t * host = "home.netscape.com:443";
- axis2_char_t * uri_str_base = "http://user:pass@example.com:80/foo?bar";
- axis2_char_t * scheme_str = "http";
- axutil_uri_t * base = NULL;
- axutil_uri_t * hostinfo = NULL;
- axutil_uri_t * uri = NULL;
- axutil_uri_t * clone = NULL;
- axutil_uri_t * rel = NULL;
- axis2_port_t scheme_port;
- axis2_port_t port;
- axis2_char_t * str;
-
- hostinfo = axutil_uri_parse_hostinfo(env,host);
- CUT_ASSERT_PTR_NOT_EQUAL(hostinfo, NULL, 0);
-
- scheme_port = axutil_uri_port_of_scheme(scheme_str);
- CUT_ASSERT_INT_NOT_EQUAL(scheme_port, 0, 0);
-
- uri = axutil_uri_parse_string(env,uri_str);
- CUT_ASSERT_PTR_NOT_EQUAL(uri, NULL, 0);
- str = axutil_uri_get_protocol(uri,env);
- CUT_ASSERT_STR_EQUAL(str, "http", 0);
- port = axutil_uri_get_port(uri,env);
- CUT_ASSERT_INT_EQUAL(port, 80, 0);
- str = axutil_uri_get_path(uri,env);
- CUT_ASSERT_STR_EQUAL(str, "/foo", 0);
- str = axutil_uri_get_host(uri,env);
- CUT_ASSERT_STR_EQUAL(str, "example.com", 0);
-
- base = axutil_uri_parse_string(env,uri_str_base);
- CUT_ASSERT_PTR_NOT_EQUAL(base, NULL, 0);
- if (base)
- {
- str = axutil_uri_to_string(base,env,0);
- CUT_ASSERT_STR_EQUAL(str, "http://user:XXXXXXXX@example.com/foo?bar", 0);
- }
-
- clone = axutil_uri_clone(uri,env);
- CUT_ASSERT_PTR_NOT_EQUAL(clone, NULL, 0);
- if (clone)
- {
- str = axutil_uri_to_string(clone,env,0);
- CUT_ASSERT_STR_EQUAL(str, "http://user:XXXXXXXX@example.com/foo?bar#item5", 0);
- axutil_uri_free(clone,env);
- }
-
- rel = axutil_uri_resolve_relative(env,base,uri);
- CUT_ASSERT_PTR_NOT_EQUAL(rel, NULL, 0);
- if (rel)
- {
- str = axutil_uri_to_string(rel,env,0);
- CUT_ASSERT_STR_EQUAL(str, "http://user:XXXXXXXX@example.com/foo?bar#item5", 0);
- }
-
- axutil_uri_free(uri,env);
-}
-
-int main()
-{
- axutil_env_t *env = cut_setup_env("Uri");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_uri(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
-
-
diff --git a/util/test/uri/uri_test.cc b/util/test/uri/uri_test.cc
new file mode 100644
index 0000000..1204feb
--- /dev/null
+++ b/util/test/uri/uri_test.cc
@@ -0,0 +1,112 @@
+/*
+* 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 <axutil_uri.h>
+#include "../util/create_env.h"
+
+class TestURI: 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;
+
+};
+
+/** @brief test uri
+ * * create URI and get the values of it's components
+ * */
+TEST_F(TestURI, test_uri)
+{
+ axis2_char_t * uri_str = "http://user:pass@example.com:80/foo?bar#item5";
+ axis2_char_t * host = "home.netscape.com:443";
+ axis2_char_t * uri_str_base = "http://user:pass@example.com:80/foo?bar";
+ axis2_char_t * scheme_str = "http";
+ axutil_uri_t * base = NULL;
+ axutil_uri_t * hostinfo = NULL;
+ axutil_uri_t * uri = NULL;
+ axutil_uri_t * clone = NULL;
+ axutil_uri_t * rel = NULL;
+ axis2_port_t scheme_port;
+ axis2_port_t port;
+ axis2_char_t * str;
+
+ hostinfo = axutil_uri_parse_hostinfo(m_env,host);
+ ASSERT_NE(hostinfo, nullptr);
+
+ scheme_port = axutil_uri_port_of_scheme(scheme_str);
+ ASSERT_NE(scheme_port, 0);
+
+ uri = axutil_uri_parse_string(m_env,uri_str);
+ ASSERT_NE(uri, nullptr);
+ str = axutil_uri_get_protocol(uri,m_env);
+ ASSERT_STREQ(str, "http");
+ port = axutil_uri_get_port(uri,m_env);
+ ASSERT_EQ(port, 80);
+ str = axutil_uri_get_path(uri,m_env);
+ ASSERT_STREQ(str, "/foo");
+ str = axutil_uri_get_host(uri,m_env);
+ ASSERT_STREQ(str, "example.com");
+
+ base = axutil_uri_parse_string(m_env,uri_str_base);
+ ASSERT_NE(base, nullptr);
+ if (base)
+ {
+ str = axutil_uri_to_string(base,m_env,0);
+ ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar");
+ }
+
+ clone = axutil_uri_clone(uri,m_env);
+ ASSERT_NE(clone, nullptr);
+ if (clone)
+ {
+ str = axutil_uri_to_string(clone,m_env,0);
+ ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar#item5");
+ axutil_uri_free(clone,m_env);
+ }
+
+ rel = axutil_uri_resolve_relative(m_env,base,uri);
+ ASSERT_NE(rel, nullptr);
+ if (rel)
+ {
+ str = axutil_uri_to_string(rel,m_env,0);
+ ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar#item5");
+ }
+
+ axutil_uri_free(uri,m_env);
+}
diff --git a/util/test/url/Makefile.am b/util/test/url/Makefile.am
index c5f6c70..d2e37bd 100644
--- a/util/test/url/Makefile.am
+++ b/util/test/url/Makefile.am
@@ -4,26 +4,27 @@
# 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.
TESTS = url_test
-noinst_PROGRAMS = url_test
-check_PROGRAMS = url_test
-url_test_SOURCES = url_test.c ../util/create_env.c
+noinst_PROGRAMS = url_test
+check_PROGRAMS = url_test
+url_test_SOURCES = url_test.cc
url_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
diff --git a/util/test/url/url_test.c b/util/test/url/url_test.c
deleted file mode 100644
index 0c47a16..0000000
--- a/util/test/url/url_test.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-* 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 <axutil_url.h>
-#include <cut_defs.h>
-#include "../util/create_env.h"
-
-/** @brief test url
- * create URL and get the values of it's components
- */
-
-void test_url(axutil_env_t *env)
-{
- axutil_url_t * url;
- axis2_char_t *url_str = "https://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12386356";
- axis2_char_t *set_server = "www.yahoo.com";
- axis2_char_t *set_protocol = "file";
- axis2_char_t *set_path = "/bar/";
- axis2_port_t set_port = 80;
- axis2_char_t *get_protocol;
- axis2_char_t *get_server;
- axis2_port_t get_port;
- axis2_char_t *get_path;
- axis2_status_t status;
-
- url = axutil_url_parse_string(env,url_str);
- CUT_ASSERT_PTR_NOT_EQUAL(url, NULL, 1);
-
- status = axutil_url_set_protocol(url,env,set_protocol);
- CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
- status = axutil_url_set_server(url,env,set_server);
- CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
- status = axutil_url_set_port(url,env,set_port);
- CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
- status = axutil_url_set_path(url,env,set_path);
- CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
-
- get_protocol = axutil_url_get_protocol(url,env);
- CUT_ASSERT_STR_EQUAL(get_protocol, set_protocol, 0);
-
- get_server = axutil_url_get_server(url,env);
- CUT_ASSERT_STR_EQUAL(get_server, "www.yahoo.com:80", 0);
-
- get_port = axutil_url_get_port(url,env);
- CUT_ASSERT_INT_EQUAL(get_port,set_port,0);
-
- get_path = axutil_url_get_path(url,env);
- CUT_ASSERT_STR_EQUAL(get_path, set_path, 0);
-
- axutil_url_free(url,env);
-}
-
-int main()
-{
- axutil_env_t *env = cut_setup_env("Url");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_url(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
-
diff --git a/util/test/url/url_test.cc b/util/test/url/url_test.cc
new file mode 100644
index 0000000..6d5c4b6
--- /dev/null
+++ b/util/test/url/url_test.cc
@@ -0,0 +1,96 @@
+/*
+* 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 <axutil_url.h>
+#include "../util/create_env.h"
+
+class TestURL: 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;
+
+};
+
+
+
+/** @brief test url
+ * create URL and get the values of it's components
+ */
+TEST_F(TestURL, test_url)
+{
+ axutil_url_t * url;
+ axis2_char_t *url_str = "https://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12386356";
+ axis2_char_t *set_server = "www.yahoo.com";
+ axis2_char_t *set_protocol = "file";
+ axis2_char_t *set_path = "/bar/";
+ axis2_port_t set_port = 80;
+ axis2_char_t *get_protocol;
+ axis2_char_t *get_server;
+ axis2_port_t get_port;
+ axis2_char_t *get_path;
+ axis2_status_t status;
+
+ url = axutil_url_parse_string(m_env,url_str);
+ ASSERT_NE(url, nullptr);
+
+ status = axutil_url_set_protocol(url,m_env,set_protocol);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_url_set_server(url,m_env,set_server);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_url_set_port(url,m_env,set_port);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+ status = axutil_url_set_path(url,m_env,set_path);
+ ASSERT_EQ(status, AXIS2_SUCCESS);
+
+ get_protocol = axutil_url_get_protocol(url,m_env);
+ ASSERT_STREQ(get_protocol, set_protocol);
+
+ get_server = axutil_url_get_server(url,m_env);
+ ASSERT_STREQ(get_server, "www.yahoo.com:80");
+
+ get_port = axutil_url_get_port(url,m_env);
+ ASSERT_EQ(get_port,set_port);
+
+ get_path = axutil_url_get_path(url,m_env);
+ ASSERT_STREQ(get_path, set_path);
+
+ axutil_url_free(url,m_env);
+}
+
diff --git a/util/test/util/Makefile.am b/util/test/util/Makefile.am
index 0f04995..169fc08 100644
--- a/util/test/util/Makefile.am
+++ b/util/test/util/Makefile.am
@@ -4,30 +4,43 @@
# 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.
TESTS = test_thread test_util
-noinst_PROGRAMS = test_util test_thread
+noinst_PROGRAMS = test_util test_thread test_md5 test_string
noinst_HEADERS = test_log.h \
test_thread.h \
create_env.h\
test_md5.h
check_PROGRAMS = test_util test_thread
SUBDIRS =
-test_util_SOURCES = test_util.c test_log.c test_md5.c create_env.c
-test_thread_SOURCES = test_thread.c
+test_util_SOURCES = test_util.cc test_log.cc
+test_thread_SOURCES = test_thread.cc
+test_md5_SOURCES = test_md5.cc
+test_string_SOURCES = test_string.cc
-test_util_LDADD = $(top_builddir)/src/libaxutil.la
+test_util_LDADD = $(top_builddir)/src/libaxutil.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
-test_thread_LDADD = $(top_builddir)/src/libaxutil.la
+test_thread_LDADD = $(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 \
- -I ../../../test/cutest/include
-EXTRA_DIST = test_string.c
+test_md5_LDADD = $(top_builddir)/src/libaxutil.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
+
+test_string_LDADD = $(top_builddir)/src/libaxutil.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
+
+AM_CPPFLAGS = -I$(top_builddir)/include \
+ -I $(GTEST_DIR)/include
+
diff --git a/util/test/util/test_log.c b/util/test/util/test_log.cc
similarity index 100%
rename from util/test/util/test_log.c
rename to util/test/util/test_log.cc
diff --git a/util/test/util/test_md5.c b/util/test/util/test_md5.cc
similarity index 62%
rename from util/test/util/test_md5.c
rename to util/test/util/test_md5.cc
index 6defd46..423d88e 100644
--- a/util/test/util/test_md5.c
+++ b/util/test/util/test_md5.cc
@@ -16,10 +16,15 @@
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include "test_md5.h"
#include <stdio.h>
#include <axutil_string.h>
#include <axutil_md5.h>
+#include <axutil_log_default.h>
+#include <axutil_log.h>
+#include <axutil_error_default.h>
/* Digests a string and prints the result.
*/
@@ -41,15 +46,44 @@
printf ("\n");
}
-void test_md5(const axutil_env_t *env)
+class TestMD5: 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(TestMD5, test_md5)
+{
+
printf ("\nMD5 test suite:\n");
printf ("test confirmation: Rivest, R., \"The MD5 Message-Digest Algorithm\", RFC 1321, April 1992.\n");
- MDString ("", env);
- MDString ("a", env);
- MDString ("abc", env);
- MDString ("message digest", env);
- MDString ("abcdefghijklmnopqrstuvwxyz", env);
- MDString ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", env);
- MDString ("12345678901234567890123456789012345678901234567890123456789012345678901234567890", env);
+ MDString ("", m_env);
+ MDString ("a", m_env);
+ MDString ("abc", m_env);
+ MDString ("message digest", m_env);
+ MDString ("abcdefghijklmnopqrstuvwxyz", m_env);
+ MDString ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", m_env);
+ MDString ("12345678901234567890123456789012345678901234567890123456789012345678901234567890", m_env);
}
diff --git a/util/test/util/test_string.c b/util/test/util/test_string.c
deleted file mode 100644
index 709a96a..0000000
--- a/util/test/util/test_string.c
+++ /dev/null
@@ -1,75 +0,0 @@
-
-/*
- * 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 <stdio.h>
-#include <axutil_error_default.h>
-#include <axutil_log.h>
-#include <axutil_string.h>
-
-void
-test_strltrim(
- const axutil_env_t * env)
-{
- axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
- axis2_char_t *trimmed = NULL;
- trimmed = axutil_strltrim(env, s, " \t\r\n");
- CUT_ASSERT_STR_EQUAL(trimmed, "abcd efgh ", 0);
- if (trimmed)
- AXIS2_FREE(env->allocator, trimmed);
- if (s)
- AXIS2_FREE(env->allocator, s);
-}
-
-void
-test_strrtrim(
- const axutil_env_t * env)
-{
- axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
- axis2_char_t *trimmed = NULL;
- trimmed = axutil_strrtrim(env, s, " \t\r\n");
- CUT_ASSERT_STR_EQUAL(trimmed, " abcd efgh", 0);
- if (trimmed)
- AXIS2_FREE(env->allocator, trimmed);
- if (s)
- AXIS2_FREE(env->allocator, s);
-}
-
-void
-test_strtrim(
- const axutil_env_t * env)
-{
- axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
- axis2_char_t *trimmed = NULL;
- trimmed = axutil_strtrim(env, s, " \t\r\n");
- CUT_ASSERT_STR_EQUAL(trimmed, "abcd efgh", 0);
- if (trimmed)
- AXIS2_FREE(env->allocator, trimmed);
- if (s)
- AXIS2_FREE(env->allocator, s);
-}
-
-void
-run_test_string(
- axutil_env_t * env)
-{
- if (!env)
- return;
- test_strltrim(env);
- test_strrtrim(env);
- test_strtrim(env);
-}
diff --git a/util/test/util/test_string.cc b/util/test/util/test_string.cc
new file mode 100644
index 0000000..485b410
--- /dev/null
+++ b/util/test/util/test_string.cc
@@ -0,0 +1,92 @@
+
+/*
+ * 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 <stdio.h>
+#include <axutil_error_default.h>
+#include <axutil_log.h>
+#include <axutil_log_default.h>
+#include <axutil_string.h>
+
+class TestString: 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(TestString, test_strltrim)
+{
+
+ axis2_char_t *s = (axis2_char_t*) axutil_strdup(m_env, " abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strltrim(m_env, s, " \t\r\n");
+ ASSERT_STREQ(trimmed, "abcd efgh ");
+ if (trimmed)
+ AXIS2_FREE(m_env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(m_env->allocator, s);
+}
+
+TEST_F(TestString, test_strrtrim)
+{
+ axis2_char_t *s = (axis2_char_t*) axutil_strdup(m_env, " abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strrtrim(m_env, s, " \t\r\n");
+ ASSERT_STREQ(trimmed, " abcd efgh");
+ if (trimmed)
+ AXIS2_FREE(m_env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(m_env->allocator, s);
+}
+
+TEST_F(TestString, test_strtrim)
+{
+ axis2_char_t *s = (axis2_char_t*) axutil_strdup(m_env, " abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strtrim(m_env, s, " \t\r\n");
+ ASSERT_STREQ(trimmed, "abcd efgh");
+ if (trimmed)
+ AXIS2_FREE(m_env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(m_env->allocator, s);
+}
diff --git a/util/test/util/test_thread.c b/util/test/util/test_thread.cc
similarity index 72%
rename from util/test/util/test_thread.c
rename to util/test/util/test_thread.cc
index 4bddd7f..5a73ba4 100644
--- a/util/test/util/test_thread.c
+++ b/util/test/util/test_thread.cc
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include <stdio.h>
#include <string.h>
#include <axutil_error_default.h>
@@ -24,7 +26,6 @@
#include <axutil_allocator.h>
#include <axutil_utils.h>
#include "test_thread.h"
-#include <cut_defs.h>
const axutil_env_t *env = NULL;
static axutil_thread_mutex_t *thread_lock = NULL;
@@ -56,14 +57,11 @@
allocator = env->allocator;
control = axutil_thread_once_init(allocator);
- CUT_ASSERT_PTR_NOT_EQUAL(control, NULL, 0);
+ ASSERT_NE(control, nullptr);
thread_lock =
axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT);
- CUT_ASSERT_PTR_NOT_EQUAL(thread_lock, NULL, 0);
- /* To avoid warning of not using cut_str_equal */
- CUT_ASSERT_STR_EQUAL("", "", 0);
-
+ ASSERT_NE(thread_lock, nullptr);
}
void *AXIS2_CALL
@@ -74,9 +72,9 @@
int i = *((int *) param);
printf("thread data = %d \n", i);
param_data = i;
-
+
axutil_thread_once(control, init_func);
- CUT_ASSERT(value==1);
+ EXPECT_EQ(value, 1);
axutil_thread_mutex_lock(thread_lock);
printf("x = %d \n", ++x);
axutil_thread_mutex_unlock(thread_lock);
@@ -96,28 +94,28 @@
*j = NULL;
allocator = env->allocator;
- i = AXIS2_MALLOC(allocator, sizeof(int));
+ i = (int*)AXIS2_MALLOC(allocator, sizeof(int));
*i = 5;
param_data = -1;
t1 = axutil_thread_create(allocator, NULL, test_function, (void *) i);
- CUT_ASSERT_PTR_NOT_EQUAL(t1, NULL, 0);
+ ASSERT_NE(t1, nullptr);
AXIS2_SLEEP(1);
- CUT_ASSERT_INT_EQUAL(param_data, *i, 0);
+ ASSERT_EQ(param_data, *i);
- j = AXIS2_MALLOC(allocator, sizeof(int));
+ j = (int*)AXIS2_MALLOC(allocator, sizeof(int));
*j = 25;
param_data = -1;
t2 = axutil_thread_create(allocator, NULL, test_function, (void *) j);
- CUT_ASSERT_PTR_NOT_EQUAL(t2, NULL, 0);
+ ASSERT_NE(t2, nullptr);
AXIS2_SLEEP(1);
- CUT_ASSERT_INT_EQUAL(param_data, *j, 0);
+ ASSERT_EQ(param_data, *j);
rv = axutil_thread_join(t1);
- CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 0);
+ ASSERT_EQ(rv, AXIS2_SUCCESS);
rv = axutil_thread_join(t2);
- CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 0);
+ ASSERT_EQ(rv, AXIS2_SUCCESS);
}
@@ -140,17 +138,17 @@
allocator = env->allocator;
attr = axutil_threadattr_create(allocator);
- CUT_ASSERT_PTR_NOT_EQUAL(attr, NULL, 1);
+ ASSERT_NE(attr, nullptr);
rv = axutil_threadattr_detach_set(attr, 1);
- CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 1);
+ ASSERT_EQ(rv, AXIS2_SUCCESS);
t3 = axutil_thread_create(allocator, attr, test_function2, NULL);
- CUT_ASSERT_PTR_NOT_EQUAL(t3, NULL, 1);
+ ASSERT_NE(t3, nullptr);
/*
* thread is already detached - should return AXIS2_FAILURE
*/
rv = axutil_thread_detach(t3);
- CUT_ASSERT_INT_EQUAL(rv, AXIS2_FAILURE, 1);
+ ASSERT_EQ(rv, AXIS2_FAILURE);
}
void
@@ -163,41 +161,69 @@
allocator = env->allocator;
attr = axutil_threadattr_create(allocator);
- CUT_ASSERT_PTR_NOT_EQUAL(attr, NULL, 1);
+ ASSERT_NE(attr, nullptr);
t4 = axutil_thread_create(allocator, attr, test_function2, NULL);
- CUT_ASSERT_PTR_NOT_EQUAL(t4, NULL, 1);
+ ASSERT_NE(t4, nullptr);
/*
* thread is not detached yet - should return AXIS2_SUCCESS
*/
rv = axutil_thread_detach(t4);
- CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 1);
+ ASSERT_EQ(rv, AXIS2_SUCCESS);
}
void
check_locks(
)
{
- CUT_ASSERT_INT_EQUAL(x, 2, 0);
+ ASSERT_EQ(x, 2);
}
void
check_thread_once(
)
{
- CUT_ASSERT_INT_EQUAL(value, 1, 0);
+ ASSERT_EQ(value, 1);
}
-void
-run_test_thread(
- const axutil_env_t * env)
+class TestThread: public ::testing::Test
{
- test_thread_init(env);
- test_axutil_thread_create(env);
+
+ 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(TestThread, test_thread)
+{
+
+ test_thread_init(m_env);
+ test_axutil_thread_create(m_env);
check_locks();
check_thread_once();
- test_axutil_thread_detach(env);
- test_axutil_thread_detach2(env);
+ test_axutil_thread_detach(m_env);
+ test_axutil_thread_detach2(m_env);
#if defined (WIN32)
Sleep(1000); /*to give time for detached threads to execute */
@@ -207,17 +233,3 @@
axutil_thread_mutex_destroy(thread_lock);
}
-
-int
-main(
- void)
-{
- axutil_env_t *env = cut_setup_env("util thread");
- CUT_ASSERT(env != NULL);
- if (env) {
- run_test_thread(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
diff --git a/util/test/util/test_util.c b/util/test/util/test_util.c
deleted file mode 100644
index aa2c5bb..0000000
--- a/util/test/util/test_util.c
+++ /dev/null
@@ -1,265 +0,0 @@
-
-/*
- * 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 <stdio.h>
-#include <axutil_hash.h>
-#include <axutil_string.h>
-#include <axutil_error_default.h>
-#include <axutil_array_list.h>
-#include <platforms/axutil_platform_auto_sense.h>
-#include <axutil_uuid_gen.h>
-#include <axutil_log_default.h>
-#include <axutil_log.h>
-#include <axutil_dir_handler.h>
-#include <axutil_file.h>
-#include <cut_defs.h>
-#include "axutil_log.h"
-#include "test_thread.h"
-#include "test_log.h"
-#include "test_md5.h"
-#include "test_string.c"
-
-extern void
-run_test_string(
- axutil_env_t * env);
-
-typedef struct a
-{
- axis2_char_t *value;
-}
-a;
-
-void
-test_hash_get(
- const axutil_env_t * env)
-{
- axutil_hash_t *ht;
- a *a1,
- *a2,
- *a3,
- *a4;
-
- axutil_hash_index_t *i = 0;
- void *v = NULL;
-
- char *key1 = "key1";
- char *key2 = "key2";
- char *key3 = "key3";
- char *key4 = "key4";
-
- a1 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- a2 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- a3 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- a4 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
-
- a1->value = axutil_strdup(env, "value1");
- a2->value = axutil_strdup(env, "value2");
- a3->value = axutil_strdup(env, "value3");
- a4->value = axutil_strdup(env, "value4");
-
- ht = axutil_hash_make(env);
-
- axutil_hash_set(ht, key1, AXIS2_HASH_KEY_STRING, a1);
- axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
- axutil_hash_set(ht, key3, AXIS2_HASH_KEY_STRING, a3);
- axutil_hash_set(ht, key4, AXIS2_HASH_KEY_STRING, a4);
-
- axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, NULL);
- axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
- for (i = axutil_hash_first(ht, env); i; i = axutil_hash_next(env, i))
- {
- axutil_hash_this(i, NULL, NULL, &v);
- printf("\n %s \n", ((a *) v)->value);
- }
-
- CUT_ASSERT_STR_EQUAL(
- ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value, "value1", 0);
-
- CUT_ASSERT_STR_EQUAL(
- ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value, "value2", 0);
-
- CUT_ASSERT_STR_EQUAL(
- ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value, "value3", 0);
-
- CUT_ASSERT_STR_EQUAL(
- ((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value, "value4", 0);
-
- axutil_hash_free(ht, env);
- AXIS2_FREE(env->allocator, a1->value);
- AXIS2_FREE(env->allocator, a2->value);
- AXIS2_FREE(env->allocator, a3->value);
- AXIS2_FREE(env->allocator, a4->value);
- AXIS2_FREE(env->allocator, a1);
- AXIS2_FREE(env->allocator, a2);
- AXIS2_FREE(env->allocator, a3);
- AXIS2_FREE(env->allocator, a4);
-}
-
-void
-test_axutil_dir_handler_list_service_or_module_dirs(axutil_env_t *env)
-{
- int i,
- isize;
- axutil_file_t *file = NULL;
- axis2_char_t *filename = NULL;
-
- axis2_char_t *pathname = axutil_strdup(env, "/tmp/test/");
-
- axutil_array_list_t *arr_folders =
- axutil_dir_handler_list_service_or_module_dirs(env, pathname);
- if (arr_folders == NULL)
- {
- printf("List of folders is NULL\n");
- return;
- }
-
- isize = axutil_array_list_size(arr_folders, env);
- printf("Folder array size = %d \n", isize);
-
- for (i = 0; i < isize; ++i)
- {
- file = (axutil_file_t *) axutil_array_list_get(arr_folders, env, i);
- filename = axutil_file_get_name(file, env);
- printf("filename = %s \n", filename);
- }
- printf
- ("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n");
-
-}
-
-/**
- * This test is intended to test whether given two files are equal or not.
- * Spaces and new lines are ignored in comparing
- */
-void test_file_diff(
- const axutil_env_t * env)
-{
-}
-
-void
-test_array_list(
- const axutil_env_t * env)
-{
- axutil_array_list_t *al;
- a *entry = NULL;
- int size;
-
- al = axutil_array_list_create(env, 1);
- CUT_ASSERT_PTR_NOT_EQUAL(al, NULL, 1);
- CUT_ASSERT_INT_EQUAL(axutil_array_list_size(al, env), 0, 0);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value1");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value2");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value3");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value4");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value5");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value6");
- axutil_array_list_add(al, env, (void *) entry);
-
- entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
- entry->value = axutil_strdup(env, "value7");
- axutil_array_list_set(al, env, 3, (void *) entry);
- axutil_array_list_remove(al, env, 2);
-
- entry = (a *) axutil_array_list_get(al, env, 0);
- CUT_ASSERT_STR_EQUAL(entry->value, "value1", 0);
-
- entry = (a *) axutil_array_list_get(al, env, 2);
- CUT_ASSERT_STR_EQUAL(entry->value, "value7", 0);
- size = axutil_array_list_size(al, env);
- CUT_ASSERT_INT_EQUAL(size, 5, 0);
-}
-
-void
-test_uuid_gen(
- const axutil_env_t * env)
-{
- char *uuid = NULL;
- printf("starting uuid_gen test...\n");
- uuid = axutil_uuid_gen(env);
- printf("Generated UUID 1:%s\n", uuid);
- AXIS2_FREE(env->allocator, uuid);
- uuid = axutil_uuid_gen(env);
- printf("Generated UUID 2:%s\n", uuid);
- AXIS2_FREE(env->allocator, uuid);
- printf("finished uuid_gen test...\n");
-}
-
-void
-test_log_write(void)
-{
- axutil_error_t *error = NULL;
- axutil_log_t *log22 = NULL;
- axutil_env_t *env = NULL;
- axutil_allocator_t *allocator = axutil_allocator_init(NULL);
- CUT_ASSERT_PTR_NOT_EQUAL(allocator, NULL, 1);
- error = axutil_error_create(allocator);
- CUT_ASSERT_PTR_NOT_EQUAL(error, NULL, 1);
- log22 = axutil_log_create(allocator, NULL, NULL);
- CUT_ASSERT_PTR_NOT_EQUAL(log22, NULL, 1);
- log22->level = AXIS2_LOG_LEVEL_DEBUG;
- env = axutil_env_create_with_error_log(allocator, error, log22);
- CUT_ASSERT_PTR_NOT_EQUAL(env, NULL, 1);
-
- AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log1 %s", "test1");
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log2 %d", 2);
- AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log3 %s", "test3");
- AXIS2_LOG_INFO(env->log, AXIS2_LOG_SI, "log4 %s %s", "info1", "info2");
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log5 %s %d", "test", 5);
- axutil_env_free(env);
-
-}
-
-int
-main(
- void)
-{
- axutil_env_t *env = cut_setup_env("util");
- CUT_ASSERT(env != NULL);
- if (env)
- {
- test_hash_get(env);
- test_file_diff(env);
- test_array_list(env);
- test_uuid_gen(env);
- test_md5(env);
- run_test_log();
- run_test_string(env);
- test_axutil_dir_handler_list_service_or_module_dirs(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
diff --git a/util/test/util/test_util.cc b/util/test/util/test_util.cc
new file mode 100644
index 0000000..1096324
--- /dev/null
+++ b/util/test/util/test_util.cc
@@ -0,0 +1,261 @@
+
+/*
+ * 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 <stdio.h>
+#include <axutil_hash.h>
+#include <axutil_string.h>
+#include <axutil_error_default.h>
+#include <axutil_array_list.h>
+#include <platforms/axutil_platform_auto_sense.h>
+#include <axutil_uuid_gen.h>
+#include <axutil_log_default.h>
+#include <axutil_log.h>
+#include <axutil_dir_handler.h>
+#include <axutil_file.h>
+#include "axutil_log.h"
+#include "test_thread.h"
+#include "test_log.h"
+#include "test_md5.h"
+
+extern void
+run_test_string(
+ axutil_env_t * env);
+
+typedef struct a
+{
+ axis2_char_t *value;
+}
+a;
+
+class TestUtil: 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(TestUtil, test_hash_get)
+{
+
+ axutil_hash_t *ht;
+ a *a1,
+ *a2,
+ *a3,
+ *a4;
+
+ axutil_hash_index_t *i = 0;
+ void *v = NULL;
+
+ char *key1 = "key1";
+ char *key2 = "key2";
+ char *key3 = "key3";
+ char *key4 = "key4";
+
+ a1 = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ a2 = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ a3 = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ a4 = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+
+ a1->value = (axis2_char_t*) axutil_strdup(m_env, "value1");
+ a2->value = (axis2_char_t*) axutil_strdup(m_env, "value2");
+ a3->value = (axis2_char_t*) axutil_strdup(m_env, "value3");
+ a4->value = (axis2_char_t*) axutil_strdup(m_env, "value4");
+
+ ht = axutil_hash_make(m_env);
+
+ axutil_hash_set(ht, key1, AXIS2_HASH_KEY_STRING, a1);
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
+ axutil_hash_set(ht, key3, AXIS2_HASH_KEY_STRING, a3);
+ axutil_hash_set(ht, key4, AXIS2_HASH_KEY_STRING, a4);
+
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, NULL);
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
+ for (i = axutil_hash_first(ht, m_env); i; i = axutil_hash_next(m_env, i))
+ {
+ axutil_hash_this(i, NULL, NULL, &v);
+ printf("\n %s \n", ((a *) v)->value);
+ }
+
+ ASSERT_STREQ(((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value, "value1");
+ ASSERT_STREQ(((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value, "value2");
+ ASSERT_STREQ(((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value, "value3");
+ ASSERT_STREQ(((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value, "value4");
+
+ axutil_hash_free(ht, m_env);
+ AXIS2_FREE(m_env->allocator, a1->value);
+ AXIS2_FREE(m_env->allocator, a2->value);
+ AXIS2_FREE(m_env->allocator, a3->value);
+ AXIS2_FREE(m_env->allocator, a4->value);
+ AXIS2_FREE(m_env->allocator, a1);
+ AXIS2_FREE(m_env->allocator, a2);
+ AXIS2_FREE(m_env->allocator, a3);
+ AXIS2_FREE(m_env->allocator, a4);
+}
+
+TEST_F(TestUtil, test_axutil_dir_handler_list_service_or_module_dirs)
+{
+ int i,
+ isize;
+ axutil_file_t *file = NULL;
+ axis2_char_t *filename = NULL;
+
+ axis2_char_t *pathname = (axis2_char_t*) axutil_strdup(m_env, "/tmp/test/");
+
+ axutil_array_list_t *arr_folders =
+ axutil_dir_handler_list_service_or_module_dirs(m_env, pathname);
+ if (arr_folders == NULL)
+ {
+ printf("List of folders is NULL\n");
+ return;
+ }
+
+ isize = axutil_array_list_size(arr_folders, m_env);
+ printf("Folder array size = %d \n", isize);
+
+ for (i = 0; i < isize; ++i)
+ {
+ file = (axutil_file_t *) axutil_array_list_get(arr_folders, m_env, i);
+ filename = axutil_file_get_name(file, m_env);
+ printf("filename = %s \n", filename);
+ }
+ printf
+ ("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n");
+
+}
+
+/**
+ * This test is intended to test whether given two files are equal or not.
+ * Spaces and new lines are ignored in comparing
+ */
+TEST_F(TestUtil, test_file_diff)
+{
+ /* TODO */
+}
+
+TEST_F(TestUtil, test_array_list)
+{
+
+ axutil_array_list_t *al;
+ a *entry = NULL;
+ int size;
+
+ al = axutil_array_list_create(m_env, 1);
+ ASSERT_NE(al, nullptr);
+ ASSERT_EQ(axutil_array_list_size(al, m_env), 0);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value1");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value2");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value3");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value4");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value5");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value6");
+ axutil_array_list_add(al, m_env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
+ entry->value = (axis2_char_t*) axutil_strdup(m_env, "value7");
+ axutil_array_list_set(al, m_env, 3, (void *) entry);
+ axutil_array_list_remove(al, m_env, 2);
+
+ entry = (a *) axutil_array_list_get(al, m_env, 0);
+ ASSERT_STREQ(entry->value, "value1");
+
+ entry = (a *) axutil_array_list_get(al, m_env, 2);
+ ASSERT_STREQ(entry->value, "value7");
+ size = axutil_array_list_size(al, m_env);
+ ASSERT_EQ(size, 5);
+}
+
+
+TEST_F(TestUtil, test_uuid_gen)
+{
+ char *uuid = NULL;
+ printf("starting uuid_gen test...\n");
+ uuid = axutil_uuid_gen(m_env);
+ printf("Generated UUID 1:%s\n", uuid);
+ AXIS2_FREE(m_env->allocator, uuid);
+ uuid = axutil_uuid_gen(m_env);
+ printf("Generated UUID 2:%s\n", uuid);
+ AXIS2_FREE(m_env->allocator, uuid);
+ printf("finished uuid_gen test...\n");
+}
+
+
+TEST_F(TestUtil, test_log_write)
+{
+ axutil_error_t *error = NULL;
+ axutil_log_t *log22 = NULL;
+ axutil_env_t *env = NULL;
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ ASSERT_NE(allocator, nullptr);
+ error = axutil_error_create(allocator);
+ ASSERT_NE(error, nullptr);
+ log22 = axutil_log_create(allocator, NULL, NULL);
+ ASSERT_NE(log22, nullptr);
+ log22->level = AXIS2_LOG_LEVEL_DEBUG;
+ env = axutil_env_create_with_error_log(allocator, error, log22);
+ ASSERT_NE(env, nullptr);
+
+ AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log1 %s", "test1");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log2 %d", 2);
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log3 %s", "test3");
+ AXIS2_LOG_INFO(env->log, AXIS2_LOG_SI, "log4 %s %s", "info1", "info2");
+ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log5 %s %d", "test", 5);
+ axutil_env_free(env);
+
+}
+
diff --git a/util/test/utils/Makefile.am b/util/test/utils/Makefile.am
index a102afd..42c274e 100644
--- a/util/test/utils/Makefile.am
+++ b/util/test/utils/Makefile.am
@@ -4,26 +4,27 @@
# 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.
TESTS = utils_test
-check_PROGRAMS = utils_test
-noinst_PROGRAMS = utils_test
-utils_test_SOURCES = utils_test.c ../util/create_env.c
+check_PROGRAMS = utils_test
+noinst_PROGRAMS = utils_test
+utils_test_SOURCES = utils_test.cc
utils_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
diff --git a/util/test/utils/utils_test.c b/util/test/utils/utils_test.c
deleted file mode 100644
index 76cde51..0000000
--- a/util/test/utils/utils_test.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-* 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 "../util/create_env.h"
-#include <axutil_utils.h>
-#include <cut_defs.h>
-
-axis2_char_t * request = "This is a request";
-axis2_char_t * s = "<root>This is a & in xml string</root>";
-axis2_char_t c = 'c';
-
-/** @brief test utils
- * test quote string
- */
-
-void test_utils(axutil_env_t *env)
-{
- axis2_char_t **op, *quote_string;
- int hexit;
- op = axutil_parse_request_url_for_svc_and_op(env,request);
- CUT_ASSERT_PTR_NOT_EQUAL(op, NULL, 0);
- quote_string = axutil_xml_quote_string(env,s,1);
- CUT_ASSERT_STR_EQUAL(quote_string, "<root>This is a & in xml string</root>", 0);
- hexit = axutil_hexit(c);
- CUT_ASSERT_INT_EQUAL(hexit,12, 0);
-}
-int main()
-{
- axutil_env_t *env = cut_setup_env("util");
- CUT_ASSERT(env != NULL);
- if (env) {
- test_utils(env);
- axutil_env_free(env);
- }
- CUT_RETURN_ON_FAILURE(-1);
- return 0;
-}
-
-
-
diff --git a/util/test/utils/utils_test.cc b/util/test/utils/utils_test.cc
new file mode 100644
index 0000000..8cb2d80
--- /dev/null
+++ b/util/test/utils/utils_test.cc
@@ -0,0 +1,71 @@
+/*
+* 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 "../util/create_env.h"
+#include <axutil_utils.h>
+
+class TestUtils: 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;
+
+};
+
+
+/** @brief test utils
+ * test quote string
+ */
+
+TEST_F(TestUtils, test_utils)
+{
+
+ axis2_char_t * request = "This is a request";
+ axis2_char_t * s = "<root>This is a & in xml string</root>";
+ axis2_char_t c = 'c';
+ axis2_char_t **op, *quote_string;
+ int hexit;
+ op = axutil_parse_request_url_for_svc_and_op(m_env,request);
+ ASSERT_NE(op, nullptr);
+ quote_string = axutil_xml_quote_string(m_env,s,1);
+ ASSERT_STREQ(quote_string, "<root>This is a & in xml string</root>");
+ hexit = axutil_hexit(c);
+ ASSERT_EQ(hexit, 12);
+}
+