summaryrefslogtreecommitdiffstats
path: root/util/test/link_list
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/test/link_list
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/test/link_list')
-rw-r--r--util/test/link_list/Makefile.am4
-rw-r--r--util/test/link_list/link_list_test.c112
2 files changed, 69 insertions, 47 deletions
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;
}