summaryrefslogtreecommitdiffstats
path: root/util/test/stack/stack_test.c
blob: 833adc21eaaaa10a932b5766bfed1f37faa9fc10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
}