summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorGravatar damitha2010-07-08 06:38:10 +0000
committerGravatar damitha2010-07-08 06:38:10 +0000
commitc8d5aeb5d3048e8a037f1884b59cef8adf7e25b2 (patch)
tree6edd50a5f63708b4c916614809082d9c1090b262 /util
parent4a01960cba446e046d5687279c024fa60b576d85 (diff)
downloadaxis2c-c8d5aeb5d3048e8a037f1884b59cef8adf7e25b2.tar.gz
axis2c-c8d5aeb5d3048e8a037f1884b59cef8adf7e25b2.tar.bz2
Added the simple test suite suggested in AXIS2C-1412
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@961590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util')
-rw-r--r--util/test/allocator/Makefile.am3
-rw-r--r--util/test/allocator/allocator_test.c161
-rw-r--r--util/test/date_time/Makefile.am4
-rw-r--r--util/test/date_time/date_time_test.c167
-rw-r--r--util/test/duration/Makefile.am4
-rw-r--r--util/test/duration/duration_test.c155
-rw-r--r--util/test/link_list/Makefile.am4
-rw-r--r--util/test/link_list/link_list_test.c112
-rw-r--r--util/test/properties/Makefile.am3
-rw-r--r--util/test/properties/property_test.c78
-rw-r--r--util/test/properties/test.doc4
-rw-r--r--util/test/rand/Makefile.am4
-rw-r--r--util/test/rand/rand_test.c64
-rw-r--r--util/test/stack/Makefile.am4
-rw-r--r--util/test/stack/stack_test.c76
-rw-r--r--util/test/string_util/Makefile.am4
-rw-r--r--util/test/string_util/string_util_test.c52
-rw-r--r--util/test/uri/Makefile.am4
-rw-r--r--util/test/uri/uri_test.c127
-rw-r--r--util/test/url/Makefile.am4
-rw-r--r--util/test/url/url_test.c115
-rw-r--r--util/test/util/Makefile.am6
-rw-r--r--util/test/util/test_log.c16
-rw-r--r--util/test/util/test_log.h2
-rw-r--r--util/test/util/test_md5.c2
-rw-r--r--util/test/util/test_string.c17
-rw-r--r--util/test/util/test_thread.c196
-rw-r--r--util/test/util/test_thread.h1
-rw-r--r--util/test/util/test_util.c145
-rw-r--r--util/test/utils/Makefile.am4
-rw-r--r--util/test/utils/utils_test.c36
31 files changed, 584 insertions, 990 deletions
diff --git a/util/test/allocator/Makefile.am b/util/test/allocator/Makefile.am
index 02dfa27..6c1aaca 100644
--- a/util/test/allocator/Makefile.am
+++ b/util/test/allocator/Makefile.am
@@ -8,6 +8,7 @@ allocator_test_LDADD = \
INCLUDES = -I$(top_builddir)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/allocator/allocator_test.c b/util/test/allocator/allocator_test.c
index 70e0bad..a2369d7 100644
--- a/util/test/allocator/allocator_test.c
+++ b/util/test/allocator/allocator_test.c
@@ -2,139 +2,82 @@
#include <axutil_error_default.h>
#include <axiom_node.h>
#include <stdio.h>
+#include <cut_defs.h>
#include "../util/create_env.h"
-int plain_binary_len;
-unsigned char *plain_binary ;
+unsigned char buffer[1024];
-/** @brief read binary
- * read the binary file
- */
-
-int read_binary()
-{
- unsigned char buffer[1024];
- FILE *in = fopen("test","rb");
- FILE *out = fopen("test.doc","w");
- int fwrite_result = 0;
-
- if (!(in && out))
- {
- fprintf (stderr, "unable to open streams\n");
- return -1;
- }
-
- while((plain_binary_len = fread(buffer,1,sizeof(buffer),in)) > 0)
- {
- fwrite_result = fwrite(buffer,1,plain_binary_len,out);
- }
-
- fclose(in);
- fclose(out);
- plain_binary = buffer;
- printf("%s",buffer);
- return plain_binary_len;
-}
-
-/** @brief test base64
- * create duration from values and retrieve values
- */
-axis2_status_t test_base64(axutil_env_t *env)
+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;
- char * get_binary = NULL;
- int binary_len;
+ unsigned char * get_binary = NULL;
+ int plain_binary_len, b_len;
unsigned char * plain_binary = NULL;
- read_binary();
-
+ 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);
- if(!base64_binary)
- {
- printf("The test axutil_base64_binary_create is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_base64_binary_create is successfull\n");
+ CUT_ASSERT(base64_binary != NULL);
plain_base64_binary = axutil_base64_binary_create_with_plain_binary(env,
plain_binary,
plain_binary_len);
- if(!plain_base64_binary)
- {
- printf("The test axutil_base64_binary_create_with_plain_binary is failed\n");
- axutil_base64_binary_free(plain_base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_create_with_plain_binary is successfull\n");
+ CUT_ASSERT(plain_base64_binary != NULL);
- encoded_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env);
- if(!encoded_binary)
- {
- printf("The test axutil_base64_binary_get_encoded_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary is successfull\n");
+ 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);
- if (status == AXIS2_SUCCESS)
- printf("The test axutil_base64_binary_set_plain_binary is successful\n");
- else
- printf("The test axutil_base64_binary_set_plain_binary failed\n") ;
-
- plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,env,&plain_binary_len);
- if(!plain_binary)
- {
- printf("The test axutil_base64_binary_get_plain_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_plain_binary is successfull\n" );
-
+ 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);
- if (status == AXIS2_SUCCESS)
- printf("The test axutil_base64_binary_set_encoded_binary is successful\n");
- else
- printf("The test axutil_base64_binary_set_encoded_binary failed\n");
-
- get_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env);
- if(!get_binary)
- {
- printf("The test axutil_base64_binary_get_encoded_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary is successfull\n");
-
- binary_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,env);
- if(!binary_len)
- {
- printf("The test axutil_base64_binary_get_encoded_binary_len is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary_len is successfull\n");
-
- return AXIS2_SUCCESS;
+ 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()
{
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
- env = create_environment();
- status = test_base64(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf("build failed");
- }
+ 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/date_time/Makefile.am b/util/test/date_time/Makefile.am
index 08d90d7..06a50ce 100644
--- a/util/test/date_time/Makefile.am
+++ b/util/test/date_time/Makefile.am
@@ -7,7 +7,9 @@ date_time_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/date_time/date_time_test.c b/util/test/date_time/date_time_test.c
index 53d5d8c..644bd78 100644
--- a/util/test/date_time/date_time_test.c
+++ b/util/test/date_time/date_time_test.c
@@ -4,12 +4,13 @@
#include <stdio.h>
#include <axutil_env.h>
#include "../util/create_env.h"
+#include <cut_defs.h>
/** @brief test_rand
* * deserialize and serialize the time
* */
-axis2_status_t test_date_time(axutil_env_t *env)
+void test_date_time(axutil_env_t *env)
{
axutil_date_time_t *date_time = NULL;
axutil_date_time_t *ref = NULL;
@@ -23,116 +24,78 @@ axis2_status_t test_date_time(axutil_env_t *env)
int year , month , date , hour , min , sec , msec;
date_time_offset = axutil_date_time_create_with_offset(env, 100);
- if(!date_time_offset)
- {
- printf("axutil_date_time_t creation failed.\n");
- return AXIS2_FAILURE;
- }
+ 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);
- if(!date_time)
- {
- printf("axutil_date_time_t creation failed.\n");
- return AXIS2_FAILURE;
- }
- status = axutil_date_time_deserialize_time(date_time, env, time_str);
- if(status)
- printf("axutil_date_time_t time string deserialization success.\n");
- status = axutil_date_time_deserialize_date(date_time, env, date_str);
- if(status)
- printf("axutil_date_time_t date string deserialization success.\n");
- status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str);
- if(status)
- printf("axutil_date_time_t date time string deserialization success.\n");
-
- ref = axutil_date_time_create(env);
- if(!ref)
- {
- printf("axutil_date_time_t creation failed.\n");
- return AXIS2_FAILURE;
- }
- compare_res = axutil_date_time_compare(date_time, env, ref);
- if(compare_res == AXIS2_DATE_TIME_COMP_RES_FAILURE)
- {
- printf("axutil_date_time comparison failed.\n");
- }
-
- status = axutil_date_time_deserialize_date_time(ref, env, date_time_str);
- if(status)
- printf("axutil_date_time_t date time string deserialization success.\n");
- compare_res = axutil_date_time_compare(date_time, env, ref);
- if(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL)
- {
- printf("axutil_date_time_t comparison success.");
- }
- status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799);
- if(status)
- {
- printf("axutil_date_time_t set date time success.\n");
- }
-
- t_str = axutil_date_time_serialize_time(date_time, env);
- if(!t_str)
- {
- printf("axutil_date_time_t time serialization failed.\n");
- }
- else
+ CUT_ASSERT(date_time != NULL);
+ if(date_time)
{
- printf("axutil_date_time_t Time: %s\n", t_str);
- }
- d_str = axutil_date_time_serialize_date(date_time, env);
- if(!d_str)
- {
- printf("axutil_date_time_t date serialization failed.\n");
- }
- else
- {
- printf("axutil_date_time_t Date: %s\n", d_str);
- }
- dt_str = axutil_date_time_serialize_date_time(date_time, env);
- if(!dt_str)
- {
- printf("axutil_date_time_t date time serialization failed.\n");
- }
- else
- {
- printf("axutil_date_time_t Date Time: %s\n", dt_str);
- }
- year = axutil_date_time_get_year(date_time,env);
- month=axutil_date_time_get_month(date_time,env);
- date = axutil_date_time_get_day(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);
- printf("axutil_date_time_t year: %d \n",year);
- printf("axutil_date_time_t month: %d \n",month);
- printf("axutil_date_time_t date: %d \n",date);
- printf("axutil_date_time_t hour: %d \n",hour);
- printf("axutil_date_time_t min: %d \n",min);
- printf("axutil_date_time_t sec: %d \n",sec);
- printf("axutil_date_time_t msec: %d \n",msec);
-
- axutil_date_time_free(date_time,env);
- axutil_date_time_free(ref, env);
- axutil_date_time_free(date_time_offset, env);
- return AXIS2_SUCCESS;
+ 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;
- int status = AXIS2_SUCCESS;
- env = create_environment();
- status = test_date_time(env);
- if(status != AXIS2_SUCCESS)
- {
- printf("axutil_date_time_t test failed");
- }
- else
+ env = cut_setup_env("Date Time");
+ CUT_ASSERT(env != NULL);
+ if (env)
{
- printf("axutil_date_time_t test successful");
+ test_date_time(env);
+ axutil_env_free(env);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/duration/Makefile.am b/util/test/duration/Makefile.am
index cab6dcd..fd24b2f 100644
--- a/util/test/duration/Makefile.am
+++ b/util/test/duration/Makefile.am
@@ -7,7 +7,9 @@ duration_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/duration/duration_test.c b/util/test/duration/duration_test.c
index c3fafe3..5de2974 100644
--- a/util/test/duration/duration_test.c
+++ b/util/test/duration/duration_test.c
@@ -1,10 +1,11 @@
#include <axutil_duration.h>
+#include <cut_defs.h>
#include "../util/create_env.h"
/** @brief test duration
* create duration from values and retrieve values
*/
-axis2_status_t test_duration(axutil_env_t *env)
+void test_duration(axutil_env_t *env)
{
axis2_status_t status = AXIS2_FAILURE;
axis2_char_t * duration_str = "P3Y12M23DT11H45M45.000000S";
@@ -17,13 +18,18 @@ axis2_status_t test_duration(axutil_env_t *env)
axutil_duration_t * duration_three;
axutil_duration_t * duration_four;
axis2_bool_t is_negative = AXIS2_FALSE;
- axis2_char_t * neg_str = "";
+ 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);
@@ -34,43 +40,38 @@ axis2_status_t test_duration(axutil_env_t *env)
is_negative = axutil_duration_get_is_negative(duration,env);
status = axutil_duration_deserialize_duration(duration_three,env,duration_str);
- if (status == AXIS2_SUCCESS)
- printf("The test 1 is successful\n");
- else
- printf("The test 1 failed\n");
+ CUT_ASSERT(status == AXIS2_SUCCESS);
status = axutil_duration_deserialize_duration(duration_four,env,duration_str1);
- if (status == AXIS2_SUCCESS)
- printf("The test 2 is successful\n");
- else
- printf("The test 2 failed\n");
- printf("Duration for test 3: %s\n", axutil_duration_serialize_duration(duration,env));
- printf("The test 3 is completed\n");
+ 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);
- if (status == AXIS2_SUCCESS)
- {
- printf("The test 4 is successful\n");
- }
- else
- {
- printf("The test 4 failed\n");
- }
+ 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);
- if (is_negative)
- neg_str = "(-) ";
- printf("Duration for test 5: %s%d-%d-%d %d:%d:%.0f\n",neg_str,year,month,day,hour,minute,second);
- printf("The test 5 is completed\n");
- return AXIS2_SUCCESS;
}
/** @brief set values
* set values for the duration and get the values
*/
-axis2_status_t set_values(axutil_env_t *env)
+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;
@@ -78,95 +79,65 @@ axis2_status_t set_values(axutil_env_t *env)
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);
- if (axutil_duration_set_is_negative(duration,env,AXIS2_TRUE) != AXIS2_SUCCESS)
+ 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 AXIS2_FAILURE;
+ 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 AXIS2_FAILURE;
+ return;
}
- if (axutil_duration_set_years(duration,env,5) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ status = axutil_duration_set_years(duration,env,5);
+ CUT_ASSERT(status == AXIS2_SUCCESS);
get_year = axutil_duration_get_years(duration,env);
- if (axutil_duration_set_months(duration,env,9) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ 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);
- if (axutil_duration_set_days(duration,env,29) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ 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);
- if (axutil_duration_set_hours(duration,env,59) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ 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);
- if (axutil_duration_set_mins(duration,env,21) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ 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);
- if (axutil_duration_set_seconds(duration,env,49) != AXIS2_SUCCESS)
- {
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
+ 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);
- printf("Duration for test 6: %d-%d-%d %d:%d:%.0f\n",get_year,get_month,get_day,get_hour,get_minute,get_second);
- printf("The test 6 is completed\n");
- if (!axutil_duration_compare(duration_one,duration,env))
- {
- printf("The test 7 failed\n");
- axutil_duration_free(duration,env);
- axutil_duration_free(duration_one,env);
- return AXIS2_FAILURE;
- }
- printf("The test 7 is successful\n");
+ 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);
- return AXIS2_SUCCESS;
}
int main()
{
- int status = AXIS2_SUCCESS;
-
- axutil_env_t *env = NULL;
- env = create_environment();
-
- status = test_duration(env);
- if(status == AXIS2_FAILURE)
- {
- printf("The test test_duration failed\n");
- }
- status = set_values(env);
- if(status == AXIS2_FAILURE)
- {
- printf("The test set_values failed\n");
- }
- axutil_env_free(env);
+ 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/link_list/Makefile.am b/util/test/link_list/Makefile.am
index 409d710..95e8d89 100644
--- a/util/test/link_list/Makefile.am
+++ b/util/test/link_list/Makefile.am
@@ -7,7 +7,9 @@ link_list_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/link_list/link_list_test.c b/util/test/link_list/link_list_test.c
index c32f360..d9c9a60 100644
--- a/util/test/link_list/link_list_test.c
+++ b/util/test/link_list/link_list_test.c
@@ -1,63 +1,83 @@
#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;
-axis2_status_t test_link_list(axutil_env_t *env,char * first_item,char * second_item,char * third_item,char *last_item,char *array)
+void test_link_list(axutil_env_t *env,char * first_item,char * second_item,char * third_item,char *last_item,char *array)
{
- linked_list = axutil_linked_list_create(env);
- if(linked_list)
- {
- printf("link list is created \n");
- }
- if(!linked_list)
- {
- printf("link list is not created ");
- }
- axutil_linked_list_add_first(linked_list,env,(void *)first_item);
- axutil_linked_list_contains(linked_list,env,(void *)second_item);
- axutil_linked_list_add(linked_list,env,(void *)third_item);
- axutil_linked_list_add_last(linked_list,env,(void *)last_item);
- int index_of_item = axutil_linked_list_index_of(linked_list,env,third_item);
- printf("The index of item is %d\n",index_of_item);
- int index_of_last_item = axutil_linked_list_last_index_of(linked_list,env,last_item);
- entry_t * entry = axutil_linked_list_get_entry(linked_list,env,0);
- printf("The index of last item is %d\n",index_of_last_item);
- void *get_item = axutil_linked_list_get(linked_list,env,1);
- printf("The get item is %s\n",(char *)get_item);
- axutil_linked_list_set(linked_list,env,1,(void *)array);
- axutil_linked_list_to_array(linked_list,env);
- axutil_linked_list_add_at_index(linked_list,env,1,(void *)second_item);
- axutil_linked_list_remove_at_index(linked_list,env,1);
- axutil_linked_list_check_bounds_inclusive(linked_list,env,1);
- axutil_linked_list_remove_entry(linked_list,env,entry);
- axutil_linked_list_remove_first(linked_list,env);
- axutil_linked_list_remove_last(linked_list,env);
- axutil_linked_list_remove(linked_list,env,(void *)third_item);
+ 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);
- if(index_of_item && index_of_last_item && get_item)
- {
- printf("The test is SUCCESS\n");
- }
- if(!index_of_item || !index_of_last_item || !get_item)
- {
- printf("The test is FAIL\n");
- }
- return AXIS2_SUCCESS;
}
int main()
{
- int status = AXIS2_SUCCESS;
- env = create_environment();
- status = test_link_list(env,"first entry","secnd entry","third entry","last entry" ,"test");
- if(status == AXIS2_FAILURE)
- {
- printf(" build failed");
+ 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);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/properties/Makefile.am b/util/test/properties/Makefile.am
index 69bb83b..2a385ea 100644
--- a/util/test/properties/Makefile.am
+++ b/util/test/properties/Makefile.am
@@ -8,6 +8,7 @@ property_test_LDADD = \
INCLUDES = -I$(top_builddir)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/properties/property_test.c b/util/test/properties/property_test.c
index e7e3a8f..45c45ba 100644
--- a/util/test/properties/property_test.c
+++ b/util/test/properties/property_test.c
@@ -1,13 +1,31 @@
-#include <stdio.h>
#include <axutil_env.h>
#include "../util/create_env.h"
+#include <axutil_string.h>
#include <axutil_properties.h>
-axis2_char_t *
-axutil_properties_read(
- FILE *input,
- const axutil_env_t *env);
-
+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
*/
@@ -15,7 +33,6 @@ axis2_status_t test_properties(axutil_env_t *env)
{
axutil_hash_t* all_properties = NULL;
axis2_status_t status = AXIS2_FAILURE;
- axis2_char_t* cur = NULL;
axis2_char_t* input_filename = "test.doc";
axutil_properties_t * properties = NULL;
axis2_status_t store_properties ;
@@ -23,70 +40,69 @@ axis2_status_t test_properties(axutil_env_t *env)
axis2_char_t * key = "key";
axis2_char_t * value = "value";
FILE *input = fopen("input.doc","rb");
- FILE *output = fopen("output.doc","rb");
- if (!(input && output))
+ 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_property_free(properties,env);
+ axutil_properties_free(properties,env);
return AXIS2_FAILURE;
}
else
printf("The the axutil_properties_create is successfull\n");
-
- cur = axutil_properties_read(input,env);
- if(!cur)
- {
- printf("Can't read properties\n");
- axutil_property_free(properties,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_properties_read 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") ;
-
-
- store_properties = axutil_properties_store(properties,env,output);
+
+ 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_property_free(properties,env);
+ 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_property_free(properties,env);
+ 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_property_free(properties,env);
+ axutil_properties_free(properties,env);
return AXIS2_FAILURE;
}
else
printf("The test axutil_properties_get_all is successfull\n");
- axutil_property_free(properties,env);
+ axutil_properties_free(properties,env);
return AXIS2_SUCCESS;
}
diff --git a/util/test/properties/test.doc b/util/test/properties/test.doc
index d687785..8e750ea 100644
--- a/util/test/properties/test.doc
+++ b/util/test/properties/test.doc
@@ -1 +1,5 @@
this use for test perposes
+
+key1=value1
+key2=value2
+key3=value3 \ No newline at end of file
diff --git a/util/test/rand/Makefile.am b/util/test/rand/Makefile.am
index 6c75e30..49c2f48 100644
--- a/util/test/rand/Makefile.am
+++ b/util/test/rand/Makefile.am
@@ -7,7 +7,9 @@ rand_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/rand/rand_test.c b/util/test/rand/rand_test.c
index 90c566b..71dc232 100644
--- a/util/test/rand/rand_test.c
+++ b/util/test/rand/rand_test.c
@@ -1,63 +1,43 @@
#include "../util/create_env.h"
+#include <axutil_rand.h>
+#include <cut_defs.h>
/** @brief test_rand
* create random variable and get it's value
*/
-axis2_status_t test_rand(axutil_env_t *env)
+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);
- if(!rand_number)
- {
- printf("Test axutil_rand failed\n");
- }
- else
- {
- printf("Test axutil_rand is successfull\n");
- printf("The random value is %d\n",rand_number);
- }
-
+ printf("rand_number : %d\n", rand_number);
rand_range = axutil_rand_with_range(&seed,start,end);
- if(rand_range == -1)
- {
- printf("Test axutil_rand_with_range failed\n");
- }
- else
- {
- printf("Test axutil_rand_with_range is successfull\n");
- printf("The random seed value is %d\n",rand_range);
- }
-
+ 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);
- if(!rand_value)
- {
- printf("The test axutil_rand_get_seed_value_based_on_time failed\n");
- }
- else
- {
- printf("Test axutil_rand_get_seed_value_based_on_time is successfull\n");
- printf("The random range is %d\n",rand_value);
- }
-
- return AXIS2_SUCCESS;
+ 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()
{
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
-
- env = create_environment();
- status = test_rand(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf("Test failed\n");
+ axutil_env_t *env = cut_setup_env("Rand");
+ CUT_ASSERT(env != NULL);
+ if (env) {
+ test_rand(env);
+ axutil_env_free(env);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/stack/Makefile.am b/util/test/stack/Makefile.am
index 10308c8..9b46290 100644
--- a/util/test/stack/Makefile.am
+++ b/util/test/stack/Makefile.am
@@ -7,7 +7,9 @@ stack_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/stack/stack_test.c b/util/test/stack/stack_test.c
index 833adc2..f294f72 100644
--- a/util/test/stack/stack_test.c
+++ b/util/test/stack/stack_test.c
@@ -1,71 +1,47 @@
#include "../util/create_env.h"
+#include <cut_defs.h>
#include <axutil_stack.h>
-axis2_status_t test_stack(axutil_env_t * env, char * value)
+void test_stack(axutil_env_t * env, char * value)
{
axutil_stack_t * stack = NULL;
axis2_status_t status = AXIS2_FAILURE;
- stack = axutil_stack_create(env);
void * get_value = NULL;
+
+ stack = axutil_stack_create(env);
+ CUT_ASSERT(stack != NULL);
if (!stack)
{
- printf("Creation of stack failed");
- return AXIS2_FAILURE;
+ return;
}
status = axutil_stack_push(stack,env,(void *)value);
- if (status != AXIS2_SUCCESS)
- {
- printf("Adding value to stack failed");
- axutil_stack_free(stack,env);
- return AXIS2_FAILURE;
- }
- if (axutil_stack_size(stack,env) != 1)
- {
- printf("Incorrect size of stack is reported");
- axutil_stack_free(stack,env);
- return AXIS2_FAILURE;
- }
- if (value != (char *)axutil_stack_get(stack,env))
- {
- printf("Stack returns incorrect object");
- axutil_stack_free(stack,env);
- return AXIS2_FAILURE;
- }
+ 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);
- printf("The value of stack is %s",(char *)get_value);
- if (value != (char *)axutil_stack_pop(stack,env))
- {
- printf("Stack returns incorrect object");
- axutil_stack_free(stack,env);
- return AXIS2_FAILURE;
- }
- if (axutil_stack_size(stack,env) != 0)
- {
- printf("Incorrect size of stack is reported");
- axutil_stack_free(stack,env);
- return AXIS2_FAILURE;
- }
- if(stack)
- {
- axutil_stack_free(stack,env);
- printf("The test is SUCCESSFUL\n");
- return AXIS2_SUCCESS;
- }
+ 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);
- return AXIS2_FAILURE;
+ /* 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";
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
- env = create_environment();
- status = test_stack(env,value);
- if(status != AXIS2_SUCCESS)
- {
- printf("The test failed");
+ axutil_env_t *env = cut_setup_env("Stack");
+ CUT_ASSERT(env != NULL);
+ if (env) {
+ test_stack(env,value);
+ axutil_env_free(env);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/string_util/Makefile.am b/util/test/string_util/Makefile.am
index 09ce78f..4b5ef1d 100644
--- a/util/test/string_util/Makefile.am
+++ b/util/test/string_util/Makefile.am
@@ -7,7 +7,9 @@ string_util_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/string_util/string_util_test.c b/util/test/string_util/string_util_test.c
index d9e0cb2..24bb42f 100644
--- a/util/test/string_util/string_util_test.c
+++ b/util/test/string_util/string_util_test.c
@@ -2,12 +2,13 @@
#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
*/
-axis2_status_t test_string(axutil_env_t *env)
+void test_string(axutil_env_t *env)
{
int delim = ' ';
void *token = NULL;
@@ -17,48 +18,47 @@ axis2_status_t test_string(axutil_env_t *env)
axis2_char_t * in = "this is a test string";
axutil_array_list_t * tokenize = axutil_tokenize(env, in, delim);
- if(tokenize)
- {
- token = axutil_array_list_get(tokenize,env,4);
- printf("The test axutil_tokenize is successfull\n");
- printf("The tokenize string is %s\n",(char *)token);
- }
- else
- return AXIS2_FAILURE;
+ 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);
- printf("The test axutil_first_token is successfull\n");
- printf("First token string is %s\n",(char *)first_token_string);
+ CUT_ASSERT(first_token_string != NULL);
+ CUT_ASSERT(strcmp(first_token_string, "is a test string") == 0);
}
- else
- return AXIS2_FAILURE;
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);
- printf("The test axutil_last_token is successfull\n");
- printf("Last token string is %s\n",(char *)last_token_string);
+ CUT_ASSERT(last_token_string != NULL);
+ CUT_ASSERT(strcmp(last_token_string, "string") == 0);
}
- else
- return AXIS2_FAILURE;
+
+ /* 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);
- return AXIS2_SUCCESS;
}
int main()
{
- axutil_env_t *env = NULL;
- int status = AXIS2_SUCCESS;
- env = create_environment();
- status = test_string(env);
- if(status == AXIS2_FAILURE)
- {
- printf("build failed");
+ axutil_env_t *env = cut_setup_env("String util");
+ CUT_ASSERT(env != NULL);
+ if (env) {
+ test_string(env);
+ axutil_env_free(env);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/uri/Makefile.am b/util/test/uri/Makefile.am
index 98475e8..9e82c7f 100644
--- a/util/test/uri/Makefile.am
+++ b/util/test/uri/Makefile.am
@@ -7,7 +7,9 @@ uri_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/uri/uri_test.c b/util/test/uri/uri_test.c
index 95ff453..cbb0e87 100644
--- a/util/test/uri/uri_test.c
+++ b/util/test/uri/uri_test.c
@@ -1,9 +1,10 @@
#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
* */
-axis2_status_t test_uri(axutil_env_t *env)
+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";
@@ -14,124 +15,64 @@ axis2_status_t test_uri(axutil_env_t *env)
axutil_uri_t * uri = NULL;
axutil_uri_t * clone = NULL;
axutil_uri_t * rel = NULL;
- axis2_char_t * protocol = NULL;
- axis2_char_t * server = NULL;
- axis2_char_t * path = NULL;
axis2_port_t scheme_port;
axis2_port_t port;
+ axis2_char_t * str;
hostinfo = axutil_uri_parse_hostinfo(env,host);
- if(hostinfo)
- {
- printf("The host information of uri is %s\n",axutil_uri_to_string(hostinfo,env,0));
- }
- else
- {
- printf("Test hostinfo faild\n");
- }
+ CUT_ASSERT_PTR_NOT_EQUAL(hostinfo, NULL, 0);
scheme_port = axutil_uri_port_of_scheme(scheme_str);
- if(scheme_port)
- {
- printf("port of scheme is %u\n", scheme_port);
- }
- else
- {
- printf("Test port failed\n");
- }
+ CUT_ASSERT_INT_NOT_EQUAL(scheme_port, 0, 0);
uri = axutil_uri_parse_string(env,uri_str);
- if(uri)
- {
- printf("The uri is %s\n",axutil_uri_to_string(uri,env,0));
- axutil_uri_free(uri, env);
- }
- else
- {
- return AXIS2_FAILURE;
- }
+ 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);
- if(base)
- {
- printf("The base of uri is %s\n",axutil_uri_to_string(base,env,0));
- }
- else
+ CUT_ASSERT_PTR_NOT_EQUAL(base, NULL, 0);
+ if (base)
{
- printf("Test base failed\n");
+ 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);
- if(clone)
+ CUT_ASSERT_PTR_NOT_EQUAL(clone, NULL, 0);
+ if (clone)
{
- printf("The clone of uri is %s\n",axutil_uri_to_string(clone,env,0));
+ 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);
- }
- else
- {
- printf("Test clone failed");
- }
-
- rel = axutil_uri_resolve_relative(env,base,clone);
- if(rel)
- {
- printf("The resolved relative uri is %s\n",axutil_uri_to_string(rel,env,0));
- }
- else
- {
- printf("Test resolve relative failed");
- }
+ }
- protocol = axutil_uri_get_protocol(uri,env);
- if (!protocol)
+ rel = axutil_uri_resolve_relative(env,base,uri);
+ CUT_ASSERT_PTR_NOT_EQUAL(rel, NULL, 0);
+ if (rel)
{
- axutil_uri_free(uri,env);
- return AXIS2_FAILURE;
+ str = axutil_uri_to_string(rel,env,0);
+ CUT_ASSERT_STR_EQUAL(str, "http://user:XXXXXXXX@example.com/foo?bar#item5", 0);
}
- server = axutil_uri_get_server(uri,env);
- if (!server)
- {
- axutil_uri_free(uri,env);
- return AXIS2_FAILURE;
- }
-
- port = axutil_uri_get_port(uri,env);
- if (!port)
- {
- axutil_uri_free(uri,env);
- return AXIS2_FAILURE;
- }
-
- path = axutil_uri_get_path(uri,env);
- if (!path)
- {
- axutil_uri_free(uri,env);
- return AXIS2_FAILURE;
- }
-
- printf("The protocol is %s\n",protocol);
- printf("The server is %s \n",server);
- printf("The port is %u \n",port);
- printf("The path is %s\n",path);
axutil_uri_free(uri,env);
- return AXIS2_SUCCESS;
}
int main()
{
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
-
- env = create_environment();
- status = test_uri(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf("The Test failed");
+ axutil_env_t *env = cut_setup_env("Uri");
+ CUT_ASSERT(env != NULL);
+ if (env) {
+ test_uri(env);
+ axutil_env_free(env);
}
- axutil_env_free(env);
-
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}
diff --git a/util/test/url/Makefile.am b/util/test/url/Makefile.am
index ff7b8fb..cade661 100644
--- a/util/test/url/Makefile.am
+++ b/util/test/url/Makefile.am
@@ -7,7 +7,9 @@ url_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/url/url_test.c b/util/test/url/url_test.c
index 65f93da..69c88d8 100644
--- a/util/test/url/url_test.c
+++ b/util/test/url/url_test.c
@@ -1,11 +1,12 @@
#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
*/
-axis2_status_t test_url(axutil_env_t *env)
+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";
@@ -20,109 +21,41 @@ axis2_status_t test_url(axutil_env_t *env)
axis2_status_t status;
url = axutil_url_parse_string(env,url_str);
- if(url)
- {
- printf("The url is created \n");
- }
- else
- {
- return AXIS2_FAILURE;
- }
-
- status = axutil_url_set_protocol(url,env,set_protocol);
-
- if (status == AXIS2_SUCCESS)
- printf("The test 1 is successful\n");
- else
- printf("The test 1 failed\n") ;
-
- status = axutil_url_set_server(url,env,set_server);
-
- if (status == AXIS2_SUCCESS)
- printf("The test 2 is successful\n");
- else
- printf("The test 2 failed\n") ;
-
- status = axutil_url_set_port(url,env,set_port);
-
- if (status == AXIS2_SUCCESS)
- printf("The test 3 is successful\n");
- else
- printf("The test 3 failed\n") ;
-
- status = axutil_url_set_path(url,env,set_path);
-
- if (status == AXIS2_SUCCESS)
- printf("The test 4 is successful\n");
- else
- printf("The test 4 failed\n") ;
-
+ 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);
-
- if (!get_protocol)
- {
- axutil_url_free(url,env);
- return AXIS2_FAILURE;
- }
- else
- {
- printf("The protocol is %s\n",get_protocol);
- }
+ 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);
- if (!get_server)
- {
- axutil_url_free(url,env);
- return AXIS2_FAILURE;
- }
- else
- {
- printf("The server is %s\n",get_server);
- }
-
get_port = axutil_url_get_port(url,env);
-
- if (!get_port)
- {
- axutil_url_free(url,env);
- return AXIS2_FAILURE;
- }
- else
- {
- printf("The port is %d\n",get_port);
- }
+ CUT_ASSERT_INT_EQUAL(get_port,set_port,0);
get_path = axutil_url_get_path(url,env);
-
- if (!get_path)
- {
- axutil_url_free(url,env);
- return AXIS2_FAILURE;
- }
- else
- {
- printf("The path is %s\n",get_path);
- }
+ CUT_ASSERT_STR_EQUAL(get_path, set_path, 0);
axutil_url_free(url,env);
- return AXIS2_SUCCESS;
}
int main()
{
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
-
- env = create_environment();
- status = test_url(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf("Test failed");
- }
- axutil_env_free(env);
-
+ 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/util/Makefile.am b/util/test/util/Makefile.am
index 201ab25..079e1f5 100644
--- a/util/test/util/Makefile.am
+++ b/util/test/util/Makefile.am
@@ -6,11 +6,13 @@ noinst_HEADERS = test_log.h \
test_md5.h
check_PROGRAMS = test_util test_thread
SUBDIRS =
-test_util_SOURCES = test_util.c test_log.c test_string.c test_md5.c
+test_util_SOURCES = test_util.c test_log.c test_md5.c create_env.c
test_thread_SOURCES = test_thread.c
test_util_LDADD = $(top_builddir)/src/libaxutil.la
test_thread_LDADD = $(top_builddir)/src/libaxutil.la
-INCLUDES = -I$(top_builddir)/include
+INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
+ -I ../../../cutest/include
diff --git a/util/test/util/test_log.c b/util/test/util/test_log.c
index 4539b4e..195b756 100644
--- a/util/test/util/test_log.c
+++ b/util/test/util/test_log.c
@@ -21,26 +21,30 @@
#include <axutil_log.h>
#include <axutil_log_default.h>
#include <axutil_allocator.h>
-#include <test_log.h>
+#include "test_log.h"
#include <string.h>
-const axutil_env_t *
+
+axutil_env_t *
create_env_with_error_log(
)
{
+ axutil_env_t *env = NULL;
+ axutil_log_t *log22 = NULL;
+ axutil_error_t *error = NULL;
axutil_allocator_t *allocator = axutil_allocator_init(NULL);
if (!allocator)
{
printf("allocator is NULL\n");
return NULL;
}
- axutil_error_t *error = axutil_error_create(allocator);
+ error = axutil_error_create(allocator);
if (!error)
{
printf("cannot create error\n");
return NULL;
}
- axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL);
+ log22 = axutil_log_create(allocator, NULL, NULL);
if (!log22)
{
printf("cannot create log\n");
@@ -51,7 +55,7 @@ create_env_with_error_log(
*/
log22->level = AXIS2_LOG_LEVEL_DEBUG;
/* log22->enabled = 0; */
- const axutil_env_t *env =
+ env =
axutil_env_create_with_error_log(allocator, error, log22);
if (!env)
{
@@ -161,8 +165,8 @@ void
run_test_log(
)
{
- printf("\n####start of run_test_log test suite\n\n");
const axutil_env_t *env = create_env_with_error_log();
+ printf("\n####start of run_test_log test suite\n\n");
if (!env)
return;
test_axutil_log_write(env);
diff --git a/util/test/util/test_log.h b/util/test/util/test_log.h
index d88669e..123df03 100644
--- a/util/test/util/test_log.h
+++ b/util/test/util/test_log.h
@@ -23,7 +23,7 @@
void run_test_log(
);
-const axutil_env_t *create_env_with_error_log(
+axutil_env_t *create_env_with_error_log(
);
void test_axutil_log_write(
const axutil_env_t * env);
diff --git a/util/test/util/test_md5.c b/util/test/util/test_md5.c
index 7c360ce..6defd46 100644
--- a/util/test/util/test_md5.c
+++ b/util/test/util/test_md5.c
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-#include <test_md5.h>
+#include "test_md5.h"
#include <stdio.h>
#include <axutil_string.h>
#include <axutil_md5.h>
diff --git a/util/test/util/test_string.c b/util/test/util/test_string.c
index d4d7bbc..709a96a 100644
--- a/util/test/util/test_string.c
+++ b/util/test/util/test_string.c
@@ -28,10 +28,7 @@ test_strltrim(
axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
axis2_char_t *trimmed = NULL;
trimmed = axutil_strltrim(env, s, " \t\r\n");
- if (0 == axutil_strcmp(trimmed, "abcd efgh "))
- printf("axutil_strltrim successful\n");
- else
- printf("axutil_strltrim failed [%s]\n", trimmed);
+ CUT_ASSERT_STR_EQUAL(trimmed, "abcd efgh ", 0);
if (trimmed)
AXIS2_FREE(env->allocator, trimmed);
if (s)
@@ -42,13 +39,10 @@ void
test_strrtrim(
const axutil_env_t * env)
{
- axis2_char_t *s = axutil_strdup(env, "abcd efgh ");
+ axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
axis2_char_t *trimmed = NULL;
trimmed = axutil_strrtrim(env, s, " \t\r\n");
- if (0 == axutil_strcmp(trimmed, " abcd efgh"))
- printf("axutil_strrtrim successful\n");
- else
- printf("axutil_strrtrim failed [%s]\n", trimmed);
+ CUT_ASSERT_STR_EQUAL(trimmed, " abcd efgh", 0);
if (trimmed)
AXIS2_FREE(env->allocator, trimmed);
if (s)
@@ -62,10 +56,7 @@ test_strtrim(
axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
axis2_char_t *trimmed = NULL;
trimmed = axutil_strtrim(env, s, " \t\r\n");
- if (0 == axutil_strcmp(trimmed, "abcd efgh"))
- printf("axutil_strtrim successful\n");
- else
- printf("axutil_strtrim failed [%s]\n", trimmed);
+ CUT_ASSERT_STR_EQUAL(trimmed, "abcd efgh", 0);
if (trimmed)
AXIS2_FREE(env->allocator, trimmed);
if (s)
diff --git a/util/test/util/test_thread.c b/util/test/util/test_thread.c
index cbdead5..4bddd7f 100644
--- a/util/test/util/test_thread.c
+++ b/util/test/util/test_thread.c
@@ -24,13 +24,14 @@
#include <axutil_allocator.h>
#include <axutil_utils.h>
#include "test_thread.h"
-#include <unistd.h>
+#include <cut_defs.h>
const axutil_env_t *env = NULL;
static axutil_thread_mutex_t *thread_lock = NULL;
static axutil_thread_once_t *control = NULL;
static int x = 0;
static int value = 0;
+static int param_data;
static axutil_thread_t *t1 = NULL;
static axutil_thread_t *t2 = NULL;
@@ -55,19 +56,14 @@ test_thread_init(
allocator = env->allocator;
control = axutil_thread_once_init(allocator);
-
- if (control)
- printf("success - test_thread_init - axutil_thread_once_init \n");
- else
- printf("failure - test_thread_init - axutil_thread_once_init \n");
+ CUT_ASSERT_PTR_NOT_EQUAL(control, NULL, 0);
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);
- if (thread_lock)
- printf("success - test_thread_init - axutil_thread_mutex_create \n");
- else
- printf("failure - test_thread_init - axutil_thread_mutex_create \n");
}
void *AXIS2_CALL
@@ -75,12 +71,12 @@ test_function(
axutil_thread_t * td,
void *param)
{
- int i;
- i = *((int *) param);
+ int i = *((int *) param);
printf("thread data = %d \n", i);
-
+ param_data = i;
+
axutil_thread_once(control, init_func);
-
+ CUT_ASSERT(value==1);
axutil_thread_mutex_lock(thread_lock);
printf("x = %d \n", ++x);
axutil_thread_mutex_unlock(thread_lock);
@@ -102,38 +98,26 @@ test_axutil_thread_create(
allocator = env->allocator;
i = 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);
+ AXIS2_SLEEP(1);
+ CUT_ASSERT_INT_EQUAL(param_data, *i, 0);
- if (t1)
- printf("success - test_axutil_thread_create - axutil_thread_create \n");
- else
- printf("failure - test_axutil_thread_create - axutil_thread_create \n");
j = AXIS2_MALLOC(allocator, sizeof(int));
*j = 25;
-
+ param_data = -1;
t2 = axutil_thread_create(allocator, NULL, test_function, (void *) j);
-
- if (t2)
- printf("success - test_axutil_thread_create - axutil_thread_create \n");
- else
- printf("failure - test_axutil_thread_create - axutil_thread_create \n");
+ CUT_ASSERT_PTR_NOT_EQUAL(t2, NULL, 0);
+ AXIS2_SLEEP(1);
+ CUT_ASSERT_INT_EQUAL(param_data, *j, 0);
rv = axutil_thread_join(t1);
-
- if (AXIS2_SUCCESS == rv)
- printf("success - test_axutil_thread_create - axutil_thread_join \n");
- else
- printf
- ("failure - test_thread_init - test_axutil_thread_create - axutil_thread_join \n");
+ CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 0);
rv = axutil_thread_join(t2);
-
- if (AXIS2_SUCCESS == rv)
- printf("success - test_axutil_thread_create - axutil_thread_join \n");
- else
- printf
- ("failure - test_thread_init - test_axutil_thread_create - axutil_thread_join \n");
+ CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 0);
}
@@ -143,8 +127,6 @@ test_function2(
void *param)
{
printf("thread \n");
- /*axutil_thread_exit(td, env->allocator); */
-
return (void *) 1;
}
@@ -158,49 +140,18 @@ test_axutil_thread_detach(
allocator = env->allocator;
attr = axutil_threadattr_create(allocator);
- if (!attr)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
+ CUT_ASSERT_PTR_NOT_EQUAL(attr, NULL, 1);
rv = axutil_threadattr_detach_set(attr, 1);
-
- if (AXIS2_SUCCESS != rv)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
+ CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 1);
t3 = axutil_thread_create(allocator, attr, test_function2, NULL);
-
- if (!t3)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
+ CUT_ASSERT_PTR_NOT_EQUAL(t3, NULL, 1);
/*
* thread is already detached - should return AXIS2_FAILURE
*/
rv = axutil_thread_detach(t3);
-
- if (AXIS2_FAILURE != rv)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
-
- /*
- * thread is already detached - should return AXIS2_FAILURE
- * cannot join detached threads
- */
- /*rv = axutil_thread_join(t3); */
- if (AXIS2_FAILURE != rv)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
- printf("success - test_axutil_thread_detach\n");
-}
+ CUT_ASSERT_INT_EQUAL(rv, AXIS2_FAILURE, 1);
+ }
void
test_axutil_thread_detach2(
@@ -212,63 +163,29 @@ test_axutil_thread_detach2(
allocator = env->allocator;
attr = axutil_threadattr_create(allocator);
- if (!attr)
- {
- printf("failure - test_axutil_thread_detach2\n");
- return;
- }
+ CUT_ASSERT_PTR_NOT_EQUAL(attr, NULL, 1);
t4 = axutil_thread_create(allocator, attr, test_function2, NULL);
-
- if (!t4)
- {
- printf("failure - test_axutil_thread_detach2\n");
- return;
- }
-
+ CUT_ASSERT_PTR_NOT_EQUAL(t4, NULL, 1);
/*
* thread is not detached yet - should return AXIS2_SUCCESS
*/
rv = axutil_thread_detach(t4);
-
- if (AXIS2_SUCCESS != rv)
- {
- printf("failure - test_axutil_thread_detach\n");
- return;
- }
-
- /*
- * thread is already detached - should return AXIS2_FAILURE
- * cannot join detached threads
- */
- /*rv = axutil_thread_join(t4); */
- if (AXIS2_FAILURE != rv)
- {
- printf("failure - test_axutil_thread_detach2\n");
- return;
- }
- printf("success - test_axutil_thread_detach2\n");
+ CUT_ASSERT_INT_EQUAL(rv, AXIS2_SUCCESS, 1);
}
void
check_locks(
)
{
- if (2 == x)
- printf("success - check_locks \n");
- else
- printf("failure - check_locks \n");
-
+ CUT_ASSERT_INT_EQUAL(x, 2, 0);
}
void
check_thread_once(
)
{
- if (1 == value)
- printf("success - check_thread_once \n");
- else
- printf("failure - check_thread_once \n");
+ CUT_ASSERT_INT_EQUAL(value, 1, 0);
}
void
@@ -291,55 +208,16 @@ run_test_thread(
axutil_thread_mutex_destroy(thread_lock);
}
-const axutil_env_t *
-create_env_with_error_log(
- )
-{
- axutil_error_t *error = NULL;
- axutil_log_t *log22 = NULL;
- const axutil_env_t *env = NULL;
- axutil_allocator_t *allocator = axutil_allocator_init(NULL);
- if (!allocator)
- {
- printf("allocator is NULL\n");
- return NULL;
- }
- error = axutil_error_create(allocator);
- if (!error)
- {
- printf("cannot create error\n");
- return NULL;
- }
-
- log22 = axutil_log_create(allocator, NULL, "test123.log");
- if (!log22)
- {
- printf("cannot create log\n");
- return NULL;
- }
- /*
- * allow all types of logs
- */
- log22->level = AXIS2_LOG_LEVEL_DEBUG;
- /* log22->enabled = 0; */
- env = axutil_env_create_with_error_log(allocator, error, log22);
- if (!env)
- {
- printf("cannot create env with error and log\n");
- return NULL;
- }
- return env;
-}
-
int
main(
void)
{
- env = create_env_with_error_log();
-
- if (!env)
- return -1;
- run_test_thread(env);
-
+ 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_thread.h b/util/test/util/test_thread.h
index 17d4e7b..9ca1aaf 100644
--- a/util/test/util/test_thread.h
+++ b/util/test/util/test_thread.h
@@ -19,6 +19,7 @@
#ifndef TEST_LOG_H
#define TEST_LOG_H
+#include <platforms/axutil_platform_auto_sense.h>
#include <axutil_env.h>
#include <axutil_thread.h>
diff --git a/util/test/util/test_util.c b/util/test/util/test_util.c
index df9649c..aa2c5bb 100644
--- a/util/test/util/test_util.c
+++ b/util/test/util/test_util.c
@@ -27,27 +27,24 @@
#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_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;
-const axutil_env_t *
-test_init(
- )
-{
- axutil_allocator_t *allocator = axutil_allocator_init(NULL);
- axutil_error_t *error = axutil_error_create(allocator);
- const axutil_env_t *env = axutil_env_create_with_error(allocator, error);
- return env;
-}
-
-int
+void
test_hash_get(
const axutil_env_t * env)
{
@@ -64,15 +61,6 @@ test_hash_get(
char *key2 = "key2";
char *key3 = "key3";
char *key4 = "key4";
- int cnt = 0;
- axis2_char_t ***rettt = NULL;
- axis2_status_t stat = AXIS2_FAILURE;
- stat = axutil_parse_rest_url_for_params(env, "ech{a}tring", "/echoString?text=Hello%20World%21", &cnt, &rettt);
- stat = axutil_parse_rest_url_for_params(env, "{a}ny/mor/sum", "echoStringmany/mor/sum", &cnt, &rettt);
-/* rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}re/{b}?", "/echoString/more/sum/?");
- rettt = axutil_parse_rest_url_for_params(env, "/ech{c}tring{a}more/{b}/", "/echoStringma/nymore/sum?");
- rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}?{c}", "echoString/many/more/sum/");
- rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}/?", "echoString/many/more/sum/?test=");*/
a1 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
a2 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
@@ -99,17 +87,17 @@ test_hash_get(
printf("\n %s \n", ((a *) v)->value);
}
- printf("\n demo get %s ",
- ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value);
+ CUT_ASSERT_STR_EQUAL(
+ ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value, "value1", 0);
- printf("\n demo get %s ",
- ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value);
+ CUT_ASSERT_STR_EQUAL(
+ ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value, "value2", 0);
- printf("\n demo get %s ",
- ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value);
+ CUT_ASSERT_STR_EQUAL(
+ ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value, "value3", 0);
- printf("\n demo get %s \n",
- ((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value);
+ 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);
@@ -120,22 +108,15 @@ test_hash_get(
AXIS2_FREE(env->allocator, a2);
AXIS2_FREE(env->allocator, a3);
AXIS2_FREE(env->allocator, a4);
- return 0;
}
void
-test_axutil_dir_handler_list_service_or_module_dirs(
- )
+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;
- axutil_allocator_t *allocator = axutil_allocator_init(NULL);
- axutil_error_t *error = axutil_error_create(allocator);
- axutil_log_t *log = axutil_log_create(allocator, NULL, NULL);
- const axutil_env_t *env =
- axutil_env_create_with_error_log(allocator, error, log);
axis2_char_t *pathname = axutil_strdup(env, "/tmp/test/");
@@ -165,13 +146,9 @@ test_axutil_dir_handler_list_service_or_module_dirs(
* This test is intended to test whether given two files are equal or not.
* Spaces and new lines are ignored in comparing
*/
-int
-test_file_diff(
+void test_file_diff(
const axutil_env_t * env)
{
- /* axis2_char_t *expected_file_name = axutil_strdup("expected", env);
- axis2_char_t *actual_file_name = axutil_strdup("actual", env); */
- return 0;
}
void
@@ -183,7 +160,8 @@ test_array_list(
int size;
al = axutil_array_list_create(env, 1);
- printf("list size %d\n", axutil_array_list_size(al, env));
+ 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");
@@ -215,13 +193,12 @@ test_array_list(
axutil_array_list_remove(al, env, 2);
entry = (a *) axutil_array_list_get(al, env, 0);
- printf("entry->value:%s\n", entry->value);
+ CUT_ASSERT_STR_EQUAL(entry->value, "value1", 0);
entry = (a *) axutil_array_list_get(al, env, 2);
- printf("entry->value:%s\n", entry->value);
+ CUT_ASSERT_STR_EQUAL(entry->value, "value7", 0);
size = axutil_array_list_size(al, env);
- printf("list size %d\n", axutil_array_list_size(al, env));
-
+ CUT_ASSERT_INT_EQUAL(size, 5, 0);
}
void
@@ -240,46 +217,27 @@ test_uuid_gen(
}
void
-test_log_write(
- )
+test_log_write(void)
{
- char msg[20];
- printf("start of test_log_write\n\n");
+ axutil_error_t *error = NULL;
+ axutil_log_t *log22 = NULL;
+ axutil_env_t *env = NULL;
axutil_allocator_t *allocator = axutil_allocator_init(NULL);
- if (!allocator)
- {
- printf("allocator is NULL\n");
- return;
- }
- axutil_error_t *error = axutil_error_create(allocator);
- if (!error)
- {
- printf("cannot create error\n");
- return;
- }
- axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL);
- if (!log22)
- {
- printf("cannot create log\n");
- return;
- }
+ 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;
-
- const axutil_env_t *env =
- axutil_env_create_with_error_log(allocator, error, log22);
- if (!env)
- {
- printf("cannot create env with error and log\n");
- return;
- }
- strcpy(msg, "abcd test123");
+ 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);
- printf("end of test_log_write \n\n");
+ axutil_env_free(env);
}
@@ -287,18 +245,21 @@ int
main(
void)
{
- const axutil_env_t *env = test_init();
- 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();
- axutil_allocator_t *allocator = env->allocator;
-
-/* axutil_env_free(env);*/
- axutil_allocator_free(allocator);
+ 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/utils/Makefile.am b/util/test/utils/Makefile.am
index 0fbcc8d..99d3dc3 100644
--- a/util/test/utils/Makefile.am
+++ b/util/test/utils/Makefile.am
@@ -7,7 +7,9 @@ utils_test_LDADD = \
$(top_builddir)/src/libaxutil.la
INCLUDES = -I$(top_builddir)/include \
+ -I$(CUTEST_HOME)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/utils/utils_test.c b/util/test/utils/utils_test.c
index 2bbf67f..d75a4cd 100644
--- a/util/test/utils/utils_test.c
+++ b/util/test/utils/utils_test.c
@@ -1,45 +1,35 @@
#include "../util/create_env.h"
#include <axutil_utils.h>
+#include <cut_defs.h>
-axutil_env_t *env = NULL;
-axis2_char_t * request = "This is a requset";
-axis2_char_t * s = "<root>This is a & '""xml string</root>";
+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
*/
-axis2_status_t test_utils()
+void test_utils(axutil_env_t *env)
{
axis2_char_t **op, *quote_string;
int hexit;
- env = create_environment();
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);
- printf("The quote string is%s\n",(char *)quote_string);
+ CUT_ASSERT_STR_EQUAL(quote_string, "&lt;root&gt;This is a &amp; in xml string&lt;/root&gt;", 0);
hexit = axutil_hexit(c);
- printf("%d\n",hexit);
- if(op && quote_string)
- {
- printf("The test is SUCCESS\n");
- }
- if(!op || !quote_string)
- {
- printf("The test is FAIL");
- }
- return AXIS2_SUCCESS;
+ CUT_ASSERT_INT_EQUAL(hexit,12, 0);
}
int main()
{
- int status = AXIS2_SUCCESS;
- env = create_environment();
- status = test_utils();
- if(status == AXIS2_FAILURE)
- {
- printf(" test failed");
+ axutil_env_t *env = cut_setup_env("util");
+ CUT_ASSERT(env != NULL);
+ if (env) {
+ test_utils(env);
+ axutil_env_free(env);
}
- axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}