summaryrefslogtreecommitdiff
path: root/src/tests/esoap_model/esoap_model_test_esoap_model.c
blob: 2a7ed543ca3c2d8038ff5844deb729c92919f7e9 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "esoap_model_test_esoap_model.h"
#include "esoap_model_suite.h"

#include <Ecore.h>
#include <Eina.h>
#include <Esoap_Model.h>

#include <stdbool.h>

static void
_setup(void)
{
   int ret = esoap_model_init();
   ck_assert_int_ge(ret, 1);
}

static void
_teardown(void)
{
   int ret = esoap_model_shutdown();
   ck_assert_int_eq(ret, 0);
}

static Eina_Bool
_eo_event_load_status_cb(void *data,
                         Eo *obj EINA_UNUSED,
                         const Eo_Event_Description *desc EINA_UNUSED,
                         void *event_info EINA_UNUSED)
{
   Efl_Model_Load_Status expected_status = *((Efl_Model_Load_Status*)data);
   Efl_Model_Load load = *((Efl_Model_Load*)event_info);
   if ((load.status & expected_status) != expected_status)
     return EINA_TRUE;

   ecore_main_loop_quit();
   return EINA_FALSE;
}

static void
_wait_until_load_status(Efl_Model_Base *model, Efl_Model_Load_Status expected_status)
{
   Efl_Model_Load_Status actual_status;
   eo_do(model, actual_status = efl_model_load_status_get());
   if ((expected_status & actual_status) == expected_status) return;

   eo_do(model, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _eo_event_load_status_cb, &expected_status));
   ecore_main_loop_begin();
   eo_do(model, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _eo_event_load_status_cb, &expected_status));
}

static void
_check_value_type_cannot_have_children(Efl_Model_Base *model)
{
   Efl_Model_Base *child = eo_do_ret(model, child, efl_model_child_add());
   ck_assert_ptr_eq(NULL, child);
}

static void
_check_model_children_count_eq(Efl_Model_Base *model, unsigned int expected_children_count)
{
   unsigned int actual_children_count = 0;
   eo_do(model, efl_model_children_count_get(&actual_children_count));
   ck_assert_int_eq(expected_children_count, actual_children_count);
}

static void
_check_model_property_int_eq(Efl_Model_Base *model, const char *property, int64_t expected_value)
{
   const Eina_Value *value;
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_property_get(property, &value));
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_ne(NULL, value);

   const Eina_Value_Type *property_type = eina_value_type_get(value);
   ck_assert_ptr_eq(EINA_VALUE_TYPE_INT64, property_type);

   int64_t actual_value = 0;
   eina_value_get(value, &actual_value);
   ck_assert_int_eq(expected_value, actual_value);
}

static void
_check_model_property_str_eq(Efl_Model_Base *model, const char *property, const char *expected_value)
{
   const Eina_Value *value;
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_property_get(property, &value));
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_ne(NULL, value);

   const Eina_Value_Type *property_type = eina_value_type_get(value);
   fail_if(EINA_VALUE_TYPE_STRING != property_type && EINA_VALUE_TYPE_STRINGSHARE != property_type);

   const char *actual_value = NULL;
   eina_value_get(value, &actual_value);
   ck_assert_str_eq(expected_value, actual_value);
}

static Efl_Model_Base *
_efl_model_nth_child_get(Efl_Model_Base *model, unsigned int n)
{
   Eina_Accessor *accessor;
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_children_slice_get(n, 1, &accessor));
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_ne(NULL, accessor);
   Efl_Model_Base *child = NULL;
   Eina_Bool ret = eina_accessor_data_get(accessor, 0, (void**)&child);
   eina_accessor_free(accessor);
   ck_assert(ret);
   ck_assert_ptr_ne(NULL, child);
   return child;
}

static void
_check_model_load(Efl_Model_Base *model)
{
   eo_do(model, efl_model_load());
   _wait_until_load_status(model, EFL_MODEL_LOAD_STATUS_LOADED);
}

static void
_check_model_properties(Efl_Model_Base *model, const char *expected_properties[])
{
   Eina_Array *properties = NULL;
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_properties_get(&properties));
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_ne(NULL, properties);

   unsigned int actual_properties_count = eina_array_count(properties);

   unsigned int expected_properties_count = 0;
   const char *expected_property = NULL;
   while ((expected_property = *expected_properties++))
     {
        const char *actual_property = eina_array_data_get(properties,
                                                          expected_properties_count);
        ck_assert_str_eq(expected_property, actual_property);
        ++expected_properties_count;
        ck_assert_int_le(expected_properties_count, actual_properties_count);
     }

   ck_assert_int_eq(expected_properties_count, actual_properties_count);
}

static void
_check_properties_count_eq(Efl_Model_Base *model, unsigned int expected_properties_count)
{
   Eina_Array *properties = NULL;
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_properties_get(&properties));
   ck_assert_int_ne(EFL_MODEL_LOAD_STATUS_ERROR, status);
   if (!expected_properties_count && !properties)
     return;

   ck_assert_ptr_ne(NULL, properties);

   unsigned int actual_properties_count = eina_array_count(properties);
   ck_assert_int_eq(expected_properties_count, actual_properties_count);
}

static Esoap_Model *
_create_esoap_model()
{
   Efl_Model_Base *esoap = eo_add(ESOAP_MODEL_CLASS, NULL,
     esoap_model_constructor("http://127.0.0.1:9090/axis2/services/echo",
                            "http://ws.apache.org/axis2/c/samples/echoString"));
   ck_assert_ptr_ne(NULL, esoap);
   return esoap;
}

START_TEST(smoke)
{
   Efl_Model_Base *esoap = _create_esoap_model();
   eo_unref(esoap);
}
END_TEST

static void
_check_string_property_set(Efl_Model_Base *model, const char *property, const char *v)
{
   Eina_Value value;
   eina_value_setup(&value, EINA_VALUE_TYPE_STRING);
   eina_value_set(&value, v);
   Efl_Model_Load_Status status;
   eo_do(model, status = efl_model_property_set(property, &value));
   eina_value_flush(&value);
   ck_assert(EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES & status);
}

START_TEST(load_children)
{
   Efl_Model_Base *esoap = _create_esoap_model();

   eo_do(esoap, efl_model_properties_load());
   _wait_until_load_status(esoap, EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);

   _check_string_property_set(esoap, "esoap:Envelope@xmlns:esoap", "http://www.w3.org/2003/05/esoap-envelope");
   _check_string_property_set(esoap, "esoap:Envelope@esoap:encodingStyle", "http://www.w3.org/2001/12/esoap-encoding");
   _check_string_property_set(esoap, "esoap:Envelope/esoap:Body/ns1:echoString@xmlns:ns1", "http://ws.apache.org/axis2/services/echo");
   _check_string_property_set(esoap, "esoap:Envelope/esoap:Body/ns1:echoString/ns1:text", "Hello World!");

   // make the call loading the children
   eo_do(esoap, efl_model_children_load());
   _wait_until_load_status(esoap, EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN);

   _check_model_children_count_eq(esoap, 1);

   Efl_Model_Base *child = _efl_model_nth_child_get(esoap, 1);
   _check_model_load(child);

   _check_model_properties(child, (const char*[]){
     "esoapenv:Envelope@xmlns:esoapenv",
     "esoapenv:Envelope/esoapenv:Body/ns1:echoString@xmlns:ns1",
     "esoapenv:Envelope/esoapenv:Body/ns1:echoString/text",
     NULL});

   _check_model_property_str_eq(child, "esoapenv:Envelope@xmlns:esoapenv", "http://www.w3.org/2003/05/esoap-envelope");
   _check_model_property_str_eq(child, "esoapenv:Envelope/esoapenv:Body/ns1:echoString@xmlns:ns1", "http://ws.apache.org/axis2/c/samples");
   _check_model_property_str_eq(child, "esoapenv:Envelope/esoapenv:Body/ns1:echoString/text", "Hello World!");

   eo_unref(esoap);
}
END_TEST

void
esoap_model_test_esoap_model(TCase *tc)
{
   tcase_add_checked_fixture(tc, _setup, _teardown);
   tcase_add_test(tc, smoke);
   tcase_add_test(tc, load_children);
}