diff options
author | gmcdonald | 2010-02-13 01:32:03 +0000 |
---|---|---|
committer | gmcdonald | 2010-02-13 01:32:03 +0000 |
commit | 0425aadc78680e53000fd0108b540d6eca048516 (patch) | |
tree | 8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /util/test | |
download | axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2 |
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util/test')
50 files changed, 2486 insertions, 0 deletions
diff --git a/util/test/Makefile.am b/util/test/Makefile.am new file mode 100644 index 0000000..cfbf7f6 --- /dev/null +++ b/util/test/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = util allocator date_time duration link_list properties rand stack string_util uri url utils + diff --git a/util/test/allocator/Makefile.am b/util/test/allocator/Makefile.am new file mode 100644 index 0000000..02dfa27 --- /dev/null +++ b/util/test/allocator/Makefile.am @@ -0,0 +1,13 @@ +TESTS = allocator_test +check_PROGRAMS = allocator_test +noinst_PROGRAMS = allocator_test +allocator_test_SOURCES = allocator_test.c ../util/create_env.c + +allocator_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/allocator/allocator_test.c b/util/test/allocator/allocator_test.c new file mode 100644 index 0000000..70e0bad --- /dev/null +++ b/util/test/allocator/allocator_test.c @@ -0,0 +1,147 @@ +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_node.h> +#include <stdio.h> +#include "../util/create_env.h" + +int plain_binary_len; +unsigned char *plain_binary ; + +/** @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) +{ + 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 * plain_binary = NULL; + read_binary(); + + 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"); + + 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"); + + 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"); + + 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" ); + + 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; +} + +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_free(env); + return 0; +} + + + + + + + + diff --git a/util/test/allocator/build.sh b/util/test/allocator/build.sh new file mode 100644 index 0000000..e5dabf2 --- /dev/null +++ b/util/test/allocator/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc allocator_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o allocator_test diff --git a/util/test/allocator/test b/util/test/allocator/test Binary files differnew file mode 100755 index 0000000..919cd65 --- /dev/null +++ b/util/test/allocator/test diff --git a/util/test/allocator/test.doc b/util/test/allocator/test.doc Binary files differnew file mode 100644 index 0000000..919cd65 --- /dev/null +++ b/util/test/allocator/test.doc diff --git a/util/test/date_time/Makefile.am b/util/test/date_time/Makefile.am new file mode 100644 index 0000000..08d90d7 --- /dev/null +++ b/util/test/date_time/Makefile.am @@ -0,0 +1,13 @@ +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_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/date_time/build.sh b/util/test/date_time/build.sh new file mode 100644 index 0000000..5236acd --- /dev/null +++ b/util/test/date_time/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc date_time_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o date_time_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/date_time/date_time_test.c b/util/test/date_time/date_time_test.c new file mode 100644 index 0000000..553fada --- /dev/null +++ b/util/test/date_time/date_time_test.c @@ -0,0 +1,138 @@ +#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" + +/** @brief test_rand + * * deserialize and serialize the time + * */ + +axis2_status_t 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); + if(!date_time_offset) + { + printf("axutil_date_time_t creation failed.\n"); + return AXIS2_FAILURE; + } + 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 + { + 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_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); + 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; +} + +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 + { + printf("axutil_date_time_t test successful"); + } + axutil_env_free(env); + return 0; +} + diff --git a/util/test/duration/Makefile.am b/util/test/duration/Makefile.am new file mode 100644 index 0000000..cab6dcd --- /dev/null +++ b/util/test/duration/Makefile.am @@ -0,0 +1,13 @@ +TESTS = duration_test +check_PROGRAMS = duration_test +noinst_PROGRAMS = duration_test +duration_test_SOURCES = duration_test.c ../util/create_env.c + +duration_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/duration/build.sh b/util/test/duration/build.sh new file mode 100644 index 0000000..ef2771e --- /dev/null +++ b/util/test/duration/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc duration_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o duration_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/duration/duration_test.c b/util/test/duration/duration_test.c new file mode 100644 index 0000000..c3fafe3 --- /dev/null +++ b/util/test/duration/duration_test.c @@ -0,0 +1,172 @@ +#include <axutil_duration.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) +{ + 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 * neg_str = ""; + + duration = axutil_duration_create_from_values(env,AXIS2_TRUE,3,12,23,11,45,45.00); + duration_one = axutil_duration_create_from_values(env,AXIS2_FALSE,7,11,2,23,11,50.00); + duration_two = axutil_duration_create_from_string(env,duration_str); + duration_three = axutil_duration_create(env); + duration_four = axutil_duration_create(env); + + 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); + if (status == AXIS2_SUCCESS) + printf("The test 1 is successful\n"); + else + printf("The test 1 failed\n"); + 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"); + 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"); + } + 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) +{ + 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); + duration_one = axutil_duration_create_from_values(env,AXIS2_TRUE,5,9,29,59,21,49); + + if (axutil_duration_set_is_negative(duration,env,AXIS2_TRUE) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + is_negative = axutil_duration_get_is_negative(duration,env); + if (!is_negative) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + + if (axutil_duration_set_years(duration,env,5) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + 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; + } + 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; + } + 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; + } + 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; + } + 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; + } + 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"); + 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); + return 0; +} diff --git a/util/test/link_list/Makefile.am b/util/test/link_list/Makefile.am new file mode 100644 index 0000000..409d710 --- /dev/null +++ b/util/test/link_list/Makefile.am @@ -0,0 +1,13 @@ +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_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/link_list/build.sh b/util/test/link_list/build.sh new file mode 100644 index 0000000..154b0d3 --- /dev/null +++ b/util/test/link_list/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc link_list_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o link_list_test diff --git a/util/test/link_list/link_list_test.c b/util/test/link_list/link_list_test.c new file mode 100644 index 0000000..c32f360 --- /dev/null +++ b/util/test/link_list/link_list_test.c @@ -0,0 +1,69 @@ +#include <axutil_linked_list.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) +{ + 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); + 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_free(env); + return 0; +} + + + + + + + diff --git a/util/test/properties/Makefile.am b/util/test/properties/Makefile.am new file mode 100644 index 0000000..69bb83b --- /dev/null +++ b/util/test/properties/Makefile.am @@ -0,0 +1,13 @@ +TESTS = property_test +check_PROGRAMS = property_test +noinst_PROGRAMS = property_test +property_test_SOURCES = property_test.c ../util/create_env.c + +property_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/properties/build.sh b/util/test/properties/build.sh new file mode 100644 index 0000000..9948fc6 --- /dev/null +++ b/util/test/properties/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +gcc property_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o property_test + + + + diff --git a/util/test/properties/input.doc b/util/test/properties/input.doc new file mode 100644 index 0000000..67fd61d --- /dev/null +++ b/util/test/properties/input.doc @@ -0,0 +1 @@ +This is the content of the input file diff --git a/util/test/properties/output.doc b/util/test/properties/output.doc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/util/test/properties/output.doc diff --git a/util/test/properties/property_test.c b/util/test/properties/property_test.c new file mode 100644 index 0000000..e7e3a8f --- /dev/null +++ b/util/test/properties/property_test.c @@ -0,0 +1,117 @@ +#include <stdio.h> +#include <axutil_env.h> +#include "../util/create_env.h" +#include <axutil_properties.h> + +axis2_char_t * +axutil_properties_read( + FILE *input, + const axutil_env_t *env); + +/** @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* cur = NULL; + 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","rb"); + if (!(input && output)) + { + return AXIS2_FAILURE; + } + + properties = axutil_properties_create(env); + if(!properties) + { + printf("Properties are not created\n"); + axutil_property_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); + if(!store_properties) + { + printf("Can not store the properties\n"); + axutil_property_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); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_load is successfull\n"); + + all_properties = axutil_properties_get_all(properties,env); + if(!all_properties) + { + printf("Can't call properties_get_all\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_get_all is successfull\n"); + + axutil_property_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/test.doc b/util/test/properties/test.doc new file mode 100644 index 0000000..d687785 --- /dev/null +++ b/util/test/properties/test.doc @@ -0,0 +1 @@ +this use for test perposes diff --git a/util/test/rand/Makefile.am b/util/test/rand/Makefile.am new file mode 100644 index 0000000..6c75e30 --- /dev/null +++ b/util/test/rand/Makefile.am @@ -0,0 +1,13 @@ +TESTS = rand_test +check_PROGRAMS = rand_test +noinst_PROGRAMS = rand_test +rand_test_SOURCES = rand_test.c ../util/create_env.c + +rand_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/rand/build.sh b/util/test/rand/build.sh new file mode 100644 index 0000000..ee98324 --- /dev/null +++ b/util/test/rand/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc rand_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o rand_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/rand/rand_test.c b/util/test/rand/rand_test.c new file mode 100644 index 0000000..90c566b --- /dev/null +++ b/util/test/rand/rand_test.c @@ -0,0 +1,64 @@ +#include "../util/create_env.h" + +/** @brief test_rand + * create random variable and get it's value + */ + +axis2_status_t 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); + } + + 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); + } + + 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; +} + +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_free(env); + return 0; +} + + diff --git a/util/test/stack/Makefile.am b/util/test/stack/Makefile.am new file mode 100644 index 0000000..10308c8 --- /dev/null +++ b/util/test/stack/Makefile.am @@ -0,0 +1,13 @@ +TESTS = stack_test +check_PROGRAMS = stack_test +noinst_PROGRAMS = stack_test +stack_test_SOURCES = stack_test.c ../util/create_env.c + +stack_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/stack/build.sh b/util/test/stack/build.sh new file mode 100644 index 0000000..8ca7aff --- /dev/null +++ b/util/test/stack/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc stack_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o stack_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/stack/stack_test.c b/util/test/stack/stack_test.c new file mode 100644 index 0000000..833adc2 --- /dev/null +++ b/util/test/stack/stack_test.c @@ -0,0 +1,71 @@ +#include "../util/create_env.h" +#include <axutil_stack.h> + +axis2_status_t 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; + if (!stack) + { + printf("Creation of stack failed"); + return AXIS2_FAILURE; + } + 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; + } + 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; + } + + return AXIS2_FAILURE; +} +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_free(env); + return 0; +} + diff --git a/util/test/string_util/Makefile.am b/util/test/string_util/Makefile.am new file mode 100644 index 0000000..09ce78f --- /dev/null +++ b/util/test/string_util/Makefile.am @@ -0,0 +1,13 @@ +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 + +string_util_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/string_util/build.sh b/util/test/string_util/build.sh new file mode 100644 index 0000000..504ca27 --- /dev/null +++ b/util/test/string_util/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc string_util_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o string_util_test diff --git a/util/test/string_util/string_util_test.c b/util/test/string_util/string_util_test.c new file mode 100644 index 0000000..d9e0cb2 --- /dev/null +++ b/util/test/string_util/string_util_test.c @@ -0,0 +1,66 @@ +#include <string.h> +#include "../util/create_env.h" +#include <axutil_string_util.h> +#include <axutil_array_list.h> + +/** @brief test string + * tokenize a string + */ + +axis2_status_t 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); + 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; + + first_token = axutil_first_token(env,in,delim); + 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); + } + else + return AXIS2_FAILURE; + + last_token = axutil_last_token(env,in,delim); + 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); + } + else + return AXIS2_FAILURE; + + 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_free(env); + return 0; +} + + + diff --git a/util/test/uri/Makefile.am b/util/test/uri/Makefile.am new file mode 100644 index 0000000..98475e8 --- /dev/null +++ b/util/test/uri/Makefile.am @@ -0,0 +1,13 @@ +TESTS = uri_test +check_PROGRAMS = uri_test +noinst_PROGRAMS = uri_test +uri_test_SOURCES = uri_test.c ../util/create_env.c + +uri_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/uri/build.sh b/util/test/uri/build.sh new file mode 100644 index 0000000..4239290 --- /dev/null +++ b/util/test/uri/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc uri_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o uri_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/uri/uri_test.c b/util/test/uri/uri_test.c new file mode 100644 index 0000000..95ff453 --- /dev/null +++ b/util/test/uri/uri_test.c @@ -0,0 +1,140 @@ +#include <axutil_uri.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) +{ + 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_char_t * protocol = NULL; + axis2_char_t * server = NULL; + axis2_char_t * path = NULL; + axis2_port_t scheme_port; + axis2_port_t port; + + 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"); + } + + 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"); + } + + 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; + } + + 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 + { + printf("Test base failed\n"); + } + + clone = axutil_uri_clone(uri,env); + if(clone) + { + printf("The clone of uri is %s\n",axutil_uri_to_string(clone,env,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) + { + axutil_uri_free(uri,env); + return AXIS2_FAILURE; + } + + 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_free(env); + + return 0; +} + + + + diff --git a/util/test/url/Makefile.am b/util/test/url/Makefile.am new file mode 100644 index 0000000..ff7b8fb --- /dev/null +++ b/util/test/url/Makefile.am @@ -0,0 +1,13 @@ +TESTS = url_test +noinst_PROGRAMS = url_test +check_PROGRAMS = url_test +url_test_SOURCES = url_test.c ../util/create_env.c + +url_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/url/build.sh b/util/test/url/build.sh new file mode 100644 index 0000000..455a8a9 --- /dev/null +++ b/util/test/url/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc url_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o url_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/url/url_test.c b/util/test/url/url_test.c new file mode 100644 index 0000000..65f93da --- /dev/null +++ b/util/test/url/url_test.c @@ -0,0 +1,130 @@ +#include <axutil_url.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) +{ + 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); + 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") ; + + 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); + } + + get_server = axutil_url_get_server(url,env); + + 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); + } + + 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); + } + + 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); + + return 0; +} + + + diff --git a/util/test/util/Makefile.am b/util/test/util/Makefile.am new file mode 100644 index 0000000..4d3a701 --- /dev/null +++ b/util/test/util/Makefile.am @@ -0,0 +1,20 @@ +TESTS = test_thread test_util +noinst_PROGRAMS = test_util test_thread +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_string.c test_md5.c +test_thread_SOURCES = test_thread.c + +test_util_LDADD = \ + $(top_builddir)/src/libaxutil.la \ + -lpthread + +test_thread_LDADD = \ + $(top_builddir)/src/libaxutil.la \ + -lpthread + +INCLUDES = -I$(top_builddir)/include diff --git a/util/test/util/create_env.c b/util/test/util/create_env.c new file mode 100644 index 0000000..5a26182 --- /dev/null +++ b/util/test/util/create_env.c @@ -0,0 +1,17 @@ +#include "create_env.h" + +axutil_env_t * create_environment() +{ + axutil_allocator_t *allocator = NULL; + axutil_log_t *log = NULL; + axutil_error_t *error = NULL; + axutil_env_t *env = NULL; + allocator = axutil_allocator_init(NULL); + log = axutil_log_create(allocator, NULL, NULL); + + error = axutil_error_create(allocator); + env = axutil_env_create_with_error_log(allocator, error, log); + return env; +} + + diff --git a/util/test/util/create_env.h b/util/test/util/create_env.h new file mode 100644 index 0000000..e3ea7b8 --- /dev/null +++ b/util/test/util/create_env.h @@ -0,0 +1,10 @@ +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <stdio.h> +#include <axutil_env.h> + +axutil_env_t * create_environment(); + + + + diff --git a/util/test/util/test_log.c b/util/test/util/test_log.c new file mode 100644 index 0000000..4539b4e --- /dev/null +++ b/util/test/util/test_log.c @@ -0,0 +1,182 @@ + +/* + * 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_log_default.h> +#include <axutil_allocator.h> +#include <test_log.h> +#include <string.h> +const axutil_env_t * +create_env_with_error_log( + ) +{ + 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); + if (!error) + { + printf("cannot create error\n"); + return NULL; + } + + axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL); + if (!log22) + { + printf("cannot create log\n"); + return NULL; + } + /* + * allow all types of logs + */ + log22->level = AXIS2_LOG_LEVEL_DEBUG; + /* log22->enabled = 0; */ + 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 NULL; + } + return env; +} + +void +test_axutil_log_write( + const axutil_env_t * env) +{ + char msg[32]; + printf("\n####start of test_axutil_log_write\n\n"); + strcpy(msg, "abcd test123"); + printf("\n####end of test_axutil_log_write\n\n"); +} + +void +test_axutil_log_debug( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_degug\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log_debug test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_debug\n\n"); +} + +void +test_axutil_log_debug_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_degug_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "this should not be logged log_debug test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_debug_off\n\n"); +} + +void +test_axutil_log_info( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_info\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_INFO(env->log, "log_info test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_info\n\n"); +} + +void +test_axutil_log_info_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_info_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_INFO(env->log, "this should not be logged log_info test %s %d", + "foo", 1); + printf("\n####end of test_axutil_log_info_off\n\n"); +} + +void +test_axutil_log_warning( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_warning\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log_warning test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_warning\n\n"); +} + +void +test_axutil_log_warning_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_warning_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, + "this should not be logged log_warning test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_warning_off\n\n"); +} + +/*no need to sent log level, should always log*/ +void +test_axutil_log_error( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_error\n\n"); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log_error test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_error\n\n"); +} + +/*no need to sent log level, should always log*/ +void +test_axutil_log_critical( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_critical\n\n"); + AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log_critical test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_critical\n\n"); +} + +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(); + if (!env) + return; + test_axutil_log_write(env); + test_axutil_log_debug(env); + test_axutil_log_debug_off(env); + + test_axutil_log_info(env); + test_axutil_log_info_off(env); + + test_axutil_log_warning(env); + test_axutil_log_warning_off(env); + + test_axutil_log_error(env); + + test_axutil_log_critical(env); + printf("\n####end of run_test_log test suite \n\n"); +} diff --git a/util/test/util/test_log.h b/util/test/util/test_log.h new file mode 100644 index 0000000..d88669e --- /dev/null +++ b/util/test/util/test_log.h @@ -0,0 +1,47 @@ + +/* +* 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. +*/ + +#ifndef _TEST_LOG_H_ +#define _TEST_LOG_H_ + +#include <axutil_env.h> + +void run_test_log( +); +const axutil_env_t *create_env_with_error_log( +); +void test_axutil_log_write( + const axutil_env_t * env); +void test_axutil_log_debug( + const axutil_env_t * env); +void test_axutil_log_debug_off( + const axutil_env_t * env); +void test_axutil_log_info( + const axutil_env_t * env); +void test_axutil_log_info_off( + const axutil_env_t * env); +void test_axutil_log_warning( + const axutil_env_t * env); +void test_axutil_log_warning_off( + const axutil_env_t * env); +void test_axutil_log_error( + const axutil_env_t * env); +void test_axutil_log_critical( + const axutil_env_t * env); + +#endif /* _TEST_LOG_H_ */ diff --git a/util/test/util/test_md5.c b/util/test/util/test_md5.c new file mode 100644 index 0000000..7c360ce --- /dev/null +++ b/util/test/util/test_md5.c @@ -0,0 +1,55 @@ + +/* + * 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 <test_md5.h> +#include <stdio.h> +#include <axutil_string.h> +#include <axutil_md5.h> + +/* Digests a string and prints the result. + */ +static void MDString (char * string, const axutil_env_t * env) +{ + axutil_md5_ctx_t * context; + unsigned char digest[16]; + unsigned int i; + unsigned int len = axutil_strlen(string); + + context = axutil_md5_ctx_create(env); + axutil_md5_update(context, env, string, len); + axutil_md5_final(context, env, digest); + axutil_md5_ctx_free(context, env); + + printf ("MD%d (\"%s\") = ", 5, string); + for (i = 0; i < 16; i++) + printf ("%02x", digest[i]); + printf ("\n"); +} + +void test_md5(const axutil_env_t *env) +{ + 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); +} diff --git a/util/test/util/test_md5.h b/util/test/util/test_md5.h new file mode 100644 index 0000000..215a096 --- /dev/null +++ b/util/test/util/test_md5.h @@ -0,0 +1,27 @@ + +/* +* 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. +*/ + +#ifndef _TEST_MD5_H_ +#define _TEST_MD5_H_ + +#include <axutil_env.h> + +void test_md5( + const axutil_env_t * env); + +#endif /* _TEST_MD5_H_ */ diff --git a/util/test/util/test_string.c b/util/test/util/test_string.c new file mode 100644 index 0000000..d4d7bbc --- /dev/null +++ b/util/test/util/test_string.c @@ -0,0 +1,84 @@ + +/* + * 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"); + if (0 == axutil_strcmp(trimmed, "abcd efgh ")) + printf("axutil_strltrim successful\n"); + else + printf("axutil_strltrim failed [%s]\n", trimmed); + 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"); + if (0 == axutil_strcmp(trimmed, " abcd efgh")) + printf("axutil_strrtrim successful\n"); + else + printf("axutil_strrtrim failed [%s]\n", trimmed); + 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"); + if (0 == axutil_strcmp(trimmed, "abcd efgh")) + printf("axutil_strtrim successful\n"); + else + printf("axutil_strtrim failed [%s]\n", trimmed); + 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_thread.c b/util/test/util/test_thread.c new file mode 100644 index 0000000..e10b5b7 --- /dev/null +++ b/util/test/util/test_thread.c @@ -0,0 +1,345 @@ + +/* + * 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 <string.h> +#include <axutil_error_default.h> +#include <axutil_log.h> +#include <axutil_log_default.h> +#include <axutil_allocator.h> +#include <axutil_utils.h> +#include "test_thread.h" +#include <unistd.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 axutil_thread_t *t1 = NULL; +static axutil_thread_t *t2 = NULL; + +/*for detach tests*/ +static axutil_thread_t *t3 = NULL; +static axutil_thread_t *t4 = NULL; + +void +init_func( + void) +{ + value++; +} + +void +thread_init( + const axutil_env_t * env) +{ + axutil_allocator_t *allocator = NULL; + + allocator = env->allocator; + + control = axutil_thread_once_init(allocator); + + if (control) + printf("success - thread_init - axutil_thread_once_init \n"); + else + printf("failure - thread_init - axutil_thread_once_init \n"); + + thread_lock = + axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT); + + if (thread_lock) + printf("success - thread_init - axutil_thread_mutex_create \n"); + else + printf("failure - thread_init - axutil_thread_mutex_create \n"); +} + +void *AXIS2_CALL +test_function( + axutil_thread_t * td, + void *param) +{ + int i; + i = *((int *) param); + printf("thread data = %d \n", i); + + axutil_thread_once(control, init_func); + + axutil_thread_mutex_lock(thread_lock); + printf("x = %d \n", ++x); + axutil_thread_mutex_unlock(thread_lock); + + /*axutil_thread_exit(td, env->allocator); */ + + return (void *) 1; +} + +void +test_axutil_thread_create( + const axutil_env_t * env) +{ + axis2_status_t rv = AXIS2_FAILURE; + axutil_allocator_t *allocator = NULL; + int *i = NULL, + *j = NULL; + + allocator = env->allocator; + i = AXIS2_MALLOC(allocator, sizeof(int)); + *i = 5; + t1 = axutil_thread_create(allocator, NULL, test_function, (void *) i); + + 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; + + 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"); + + rv = axutil_thread_join(t1); + + if (AXIS2_SUCCESS == rv) + printf("success - test_axutil_thread_create - axutil_thread_join \n"); + else + printf + ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n"); + + rv = axutil_thread_join(t2); + + if (AXIS2_SUCCESS == rv) + printf("success - test_axutil_thread_create - axutil_thread_join \n"); + else + printf + ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n"); + +} + +void *AXIS2_CALL +test_function2( + axutil_thread_t * td, + void *param) +{ + printf("thread \n"); + /*axutil_thread_exit(td, env->allocator); */ + + return (void *) 1; +} + +void +test_axutil_thread_detach( + const axutil_env_t * env) +{ + axutil_threadattr_t *attr = NULL; + axutil_allocator_t *allocator = NULL; + axis2_status_t rv = AXIS2_FAILURE; + + allocator = env->allocator; + attr = axutil_threadattr_create(allocator); + if (!attr) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + rv = axutil_threadattr_detach_set(attr, 1); + + if (AXIS2_SUCCESS != rv) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + t3 = axutil_thread_create(allocator, attr, test_function2, NULL); + + if (!t3) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + + /* + * 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"); +} + +void +test_axutil_thread_detach2( + const axutil_env_t * env) +{ + axutil_threadattr_t *attr = NULL; + axutil_allocator_t *allocator = NULL; + axis2_status_t rv = AXIS2_FAILURE; + + allocator = env->allocator; + attr = axutil_threadattr_create(allocator); + if (!attr) + { + printf("failure - test_axutil_thread_detach2\n"); + return; + } + + t4 = axutil_thread_create(allocator, attr, test_function2, NULL); + + if (!t4) + { + printf("failure - test_axutil_thread_detach2\n"); + return; + } + + /* + * 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"); +} + +void +check_locks( + ) +{ + if (2 == x) + printf("success - check_locks \n"); + else + printf("failure - check_locks \n"); + +} + +void +check_thread_once( + ) +{ + if (1 == value) + printf("success - check_thread_once \n"); + else + printf("failure - check_thread_once \n"); +} + +void +run_test_thread( + const axutil_env_t * env) +{ + thread_init(env); + test_axutil_thread_create(env); + check_locks(); + check_thread_once(); + test_axutil_thread_detach(env); + test_axutil_thread_detach2(env); + +#if defined (WIN32) + Sleep(1000); /*to give time for detached threads to execute */ +#else + sleep(2); +#endif + + 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); + + return 0; +} diff --git a/util/test/util/test_thread.h b/util/test/util/test_thread.h new file mode 100644 index 0000000..b006b3f --- /dev/null +++ b/util/test/util/test_thread.h @@ -0,0 +1,50 @@ + +/* +* 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. +*/ + +#ifndef TEST_LOG_H +#define TEST_LOG_H + +#include <axutil_env.h> +#include <axutil_thread.h> + +void init_func( + void); +void thread_init( + const axutil_env_t * env); +void *AXIS2_CALL +test_function( + axutil_thread_t * td, + void *param); +void test_axutil_thread_create( + const axutil_env_t * env); +void *AXIS2_CALL +test_function2( + axutil_thread_t * td, + void *param); +void test_axutil_thread_detach( + const axutil_env_t * env); +void test_axutil_thread_detach2( + const axutil_env_t * env); +void check_locks( +); + +/*call this method from main*/ +void run_test_thread( + const axutil_env_t * env); + +#endif diff --git a/util/test/util/test_util.c b/util/test/util/test_util.c new file mode 100644 index 0000000..dd37710 --- /dev/null +++ b/util/test/util/test_util.c @@ -0,0 +1,304 @@ + +/* + * 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 "axutil_log.h" +#include "test_thread.h" +#include <test_log.h> + +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 +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"; + 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)); + 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); + } + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s \n", + ((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value); + + 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); + return 0; +} + +void +test_axutil_dir_handler_list_service_or_module_dirs( + ) +{ + 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/"); + + 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 + */ +int +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 +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); + printf("list size %d\n", axutil_array_list_size(al, env)); + + 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); + printf("entry->value:%s\n", entry->value); + + entry = (a *) axutil_array_list_get(al, env, 2); + printf("entry->value:%s\n", entry->value); + size = axutil_array_list_size(al, env); + printf("list size %d\n", axutil_array_list_size(al, env)); + +} + +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( + ) +{ + char msg[10]; + printf("start of test_log_write\n\n"); + 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; + } + 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"); + + 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"); + +} + +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); + return 0; +} diff --git a/util/test/utils/Makefile.am b/util/test/utils/Makefile.am new file mode 100644 index 0000000..0fbcc8d --- /dev/null +++ b/util/test/utils/Makefile.am @@ -0,0 +1,13 @@ +TESTS = utils_test +check_PROGRAMS = utils_test +noinst_PROGRAMS = utils_test +utils_test_SOURCES = utils_test.c ../util/create_env.c + +utils_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/utils/build.sh b/util/test/utils/build.sh new file mode 100644 index 0000000..09e7ef6 --- /dev/null +++ b/util/test/utils/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc utils_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o utils_test diff --git a/util/test/utils/utils_test.c b/util/test/utils/utils_test.c new file mode 100644 index 0000000..2bbf67f --- /dev/null +++ b/util/test/utils/utils_test.c @@ -0,0 +1,47 @@ +#include "../util/create_env.h" +#include <axutil_utils.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 c = 'c'; + +/** @brief test utils + * test quote string + */ + +axis2_status_t test_utils() +{ + axis2_char_t **op, *quote_string; + int hexit; + env = create_environment(); + op = axutil_parse_request_url_for_svc_and_op(env,request); + quote_string = axutil_xml_quote_string(env,s,1); + printf("The quote string is%s\n",(char *)quote_string); + 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; +} +int main() +{ + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_utils(); + if(status == AXIS2_FAILURE) + { + printf(" test failed"); + } + axutil_env_free(env); + return 0; +} + + + |