diff options
Diffstat (limited to 'util/test/stack')
-rw-r--r-- | util/test/stack/Makefile.am | 4 | ||||
-rw-r--r-- | util/test/stack/stack_test.c | 76 |
2 files changed, 29 insertions, 51 deletions
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; } |