summaryrefslogtreecommitdiffstats
path: root/util/test/properties/property_test.c
blob: 639f32ce8f8dfeb788b8904c5021aff9c217dbd2 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* 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 <axutil_env.h>
#include "../util/create_env.h"
#include <axutil_string.h>
#include <axutil_properties.h>

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
  */
axis2_status_t test_properties(axutil_env_t *env)
{ 
    axutil_hash_t* all_properties = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    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","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_properties_free(properties,env);
        return AXIS2_FAILURE;
    }
    else
    printf("The the axutil_properties_create 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") ;
		
    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_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_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_properties_free(properties,env);
        return AXIS2_FAILURE;
    }
    else
    printf("The test axutil_properties_get_all is successfull\n");
    
    axutil_properties_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;
}