Initialize Tizen 2.3
[framework/api/application.git] / TC / testcase / utc_storage.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. 
15  */
16
17
18
19 #include <tet_api.h>
20 #include <app.h>
21
22
23 static void startup(void);
24 static void cleanup(void);
25
26 void (*tet_startup)(void) = startup;
27 void (*tet_cleanup)(void) = cleanup;
28
29 static void utc_storage_foreach_device_supported_positive(void);
30 static void utc_storage_foreach_device_supported_negative(void);
31 static void utc_storage_get_root_directory_positive(void);
32 static void utc_storage_get_root_directory_negative1(void);
33 static void utc_storage_get_root_directory_negative2(void);
34 static void utc_storage_get_type_positive(void);
35 static void utc_storage_get_type_negative1(void);
36 static void utc_storage_get_type_negative2(void);
37 static void utc_storage_get_state_positive(void);
38 static void utc_storage_get_state_negative1(void);
39 static void utc_storage_get_state_negative2(void);
40 static void utc_storage_get_total_space_positive(void);
41 static void utc_storage_get_total_space_negative1(void);
42 static void utc_storage_get_total_space_negative2(void);
43 static void utc_storage_get_available_space_positive(void);
44 static void utc_storage_get_available_space_negative1(void);
45 static void utc_storage_get_available_space_negative2(void);
46
47 static void utc_storage_set_state_changed_cb_positive(void);
48 static void utc_storage_set_state_changed_cb_negative1(void);
49 static void utc_storage_set_state_changed_cb_negative2(void);
50
51 static void utc_storage_unset_state_changed_cb_positive(void);
52 static void utc_storage_unset_state_changed_cb_negative(void);
53
54 struct tet_testlist tet_testlist[] = {
55         {utc_storage_foreach_device_supported_positive, 1},
56         {utc_storage_foreach_device_supported_negative, 2},
57         {utc_storage_get_root_directory_positive, 1},
58         {utc_storage_get_root_directory_negative1, 2},
59         {utc_storage_get_root_directory_negative2, 2},
60         {utc_storage_get_type_positive, 1},
61         {utc_storage_get_type_negative1, 2},
62         {utc_storage_get_type_negative2, 2},
63         {utc_storage_get_state_positive, 1},
64         {utc_storage_get_state_negative1, 2},
65         {utc_storage_get_state_negative2, 2},
66         {utc_storage_get_total_space_positive, 1},
67         {utc_storage_get_total_space_negative1, 2},
68         {utc_storage_get_total_space_negative2, 2},
69         {utc_storage_get_available_space_positive, 1},
70         {utc_storage_get_available_space_negative1, 2},
71         {utc_storage_get_available_space_negative2, 2},
72         {utc_storage_set_state_changed_cb_positive, 1},
73         {utc_storage_set_state_changed_cb_negative1, 2},
74         {utc_storage_set_state_changed_cb_negative2, 2},
75         {utc_storage_unset_state_changed_cb_positive, 1},
76         {utc_storage_unset_state_changed_cb_negative, 2},
77         {NULL, 0},
78 };
79
80 static int internal_storage_id;
81
82 bool get_internal_storage(int storage, storage_type_e type,  storage_state_e state, const char *path, void *user_data)
83 {
84         if (type == STORAGE_TYPE_INTERNAL) {
85                 internal_storage_id = storage;
86                 return false;
87         }
88
89         return true;
90 }
91
92 static void startup(void)
93 {
94         storage_foreach_device_supported(get_internal_storage, NULL);
95 }
96
97
98 static void cleanup(void)
99 {
100         /* end of TC */
101
102 }
103
104 bool get_storage_device(int storage, storage_type_e type, storage_state_e state,
105                         const char *path, void *user_data)
106 {
107         return true;
108 }
109
110 static void utc_storage_foreach_device_supported_positive(void)
111 {
112         int err;
113
114         err = storage_foreach_device_supported(get_storage_device, NULL);
115
116         if (err == STORAGE_ERROR_NONE) {
117                 dts_pass("utc_storage_foreach_device_supported_positive", "passed");
118         } else {
119                 dts_fail("utc_storage_foreach_device_supported_positive", "failed");
120         }
121
122 }
123
124 static void utc_storage_foreach_device_supported_negative(void)
125 {
126         int err;
127
128         err = storage_foreach_device_supported(NULL, NULL);
129
130         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
131                 dts_pass("utc_storage_foreach_device_supported_positive", "passed");
132         } else {
133                 dts_fail("utc_storage_foreach_device_supported_positive", "failed");
134         }
135 }
136
137 static void utc_storage_get_root_directory_positive(void)
138 {
139         int err;
140         char* path;
141         err = storage_get_root_directory(internal_storage_id, &path);
142
143         if ((err == STORAGE_ERROR_NONE) && (path != NULL)) {
144                 dts_pass("utc_storage_get_root_directory_positive", "passed");
145         } else {
146                 dts_fail("utc_storage_get_root_directory_positive", "failed");
147         }
148 }
149
150 static void utc_storage_get_root_directory_negative1(void)
151 {
152         int err;
153         char* path;
154         err = storage_get_root_directory(10, &path);
155
156         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
157                 dts_pass("utc_storage_get_root_directory_negative1", "passed");
158         } else {
159                 dts_fail("utc_storage_get_root_directory_negative1", "failed");
160         }
161 }
162
163 static void utc_storage_get_root_directory_negative2(void)
164 {
165         int err;
166         
167         err = storage_get_root_directory(internal_storage_id, NULL);
168
169         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
170                 dts_pass("utc_storage_get_root_directory_negative2", "passed");
171         } else {
172                 dts_fail("utc_storage_get_root_directory_negative2", "failed");
173         }
174 }
175
176 static void utc_storage_get_type_positive(void)
177 {
178         int err;
179         storage_type_e type;
180
181         err = storage_get_type(internal_storage_id, &type);
182
183         if ((err == STORAGE_ERROR_NONE) && (type == STORAGE_TYPE_INTERNAL)) {
184                 dts_pass("utc_storage_get_type_positive", "passed");
185         } else {
186                 dts_fail("utc_storage_get_type_positive", "failed");
187         }
188 }
189
190 static void utc_storage_get_type_negative1(void)
191 {
192         int err;
193         storage_type_e type;
194         err = storage_get_type(10, &type);
195
196         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
197                 dts_pass("utc_storage_get_type_negative1", "passed");
198         } else {
199                 dts_fail("utc_storage_get_type_negative1", "failed");
200         }
201 }
202
203 static void utc_storage_get_type_negative2(void)
204 {
205         int err;
206         err = storage_get_type(internal_storage_id, NULL);
207
208         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
209                 dts_pass("utc_storage_get_type_negative2", "passed");
210         } else {
211                 dts_fail("utc_storage_get_type_negative2", "failed");
212         }
213 }
214
215
216 static void utc_storage_get_state_positive(void)
217 {
218         int err;
219         storage_state_e state;
220
221         err = storage_get_state(internal_storage_id, &state);
222
223         if ((err == STORAGE_ERROR_NONE) && (state == STORAGE_STATE_MOUNTED)) {
224                 dts_pass("utc_storage_get_state_positive", "passed");
225         } else {
226                 dts_fail("utc_storage_get_state_positive", "failed");
227         }
228 }
229
230 static void utc_storage_get_state_negative1(void)
231 {
232         int err;
233         storage_state_e state;
234         err = storage_get_state(10, &state);
235
236         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
237                 dts_pass("utc_storage_get_state_negative1", "passed");
238         } else {
239                 dts_fail("utc_storage_get_state_negative1", "failed");
240         }
241 }
242
243 static void utc_storage_get_state_negative2(void)
244 {
245         int err;
246         err = storage_get_state(internal_storage_id, NULL);
247
248         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
249                 dts_pass("utc_storage_get_state_negative2", "passed");
250         } else {
251                 dts_fail("utc_storage_get_state_negative2", "failed");
252         }
253 }
254
255
256 static void utc_storage_get_total_space_positive(void)
257 {
258         int err;
259         unsigned long long size;
260
261         err = storage_get_total_space(internal_storage_id, &size);
262
263         if (err == STORAGE_ERROR_NONE) {
264                 dts_pass("utc_storage_get_total_space_positive", "passed");
265         } else {
266                 dts_fail("utc_storage_get_total_space_positive", "failed");
267         }
268 }
269
270 static void utc_storage_get_total_space_negative1(void)
271 {
272         int err;
273         unsigned long long size;
274         err = storage_get_total_space(10, &size);
275
276         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
277                 dts_pass("utc_storage_get_total_space_negative1", "passed");
278         } else {
279                 dts_fail("utc_storage_get_total_space_negative1", "failed");
280         }
281 }
282
283 static void utc_storage_get_total_space_negative2(void)
284 {
285         int err;
286         err = storage_get_total_space(internal_storage_id, NULL);
287
288         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
289                 dts_pass("utc_storage_get_total_space_negative2", "passed");
290         } else {
291                 dts_fail("utc_storage_get_total_space_negative2", "failed");
292         }
293 }
294
295
296 static void utc_storage_get_available_space_positive(void)
297 {
298         int err;
299         unsigned long long size;
300
301         err = storage_get_available_space(internal_storage_id, &size);
302
303         if (err == STORAGE_ERROR_NONE) {
304                 dts_pass("utc_storage_get_available_space_positive", "passed");
305         } else {
306                 dts_fail("utc_storage_get_available_space_positive", "failed");
307         }
308 }
309
310 static void utc_storage_get_available_space_negative1(void)
311 {
312         int err;
313         unsigned long long size;
314         err = storage_get_available_space(10, &size);
315
316         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
317                 dts_pass("utc_storage_get_available_space_negative1", "passed");
318         } else {
319                 dts_fail("utc_storage_get_available_space_negative1", "failed");
320         }
321 }
322
323 static void utc_storage_get_available_space_negative2(void)
324 {
325         int err;
326         err = storage_get_available_space(internal_storage_id, NULL);
327
328         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
329                 dts_pass("utc_storage_get_available_space_negative2", "passed");
330         } else {
331                 dts_fail("utc_storage_get_available_space_negative2", "failed");
332         }
333 }
334
335 static void dts_storage_state_changed_cb(int storage, storage_state_e state, void *user_data)
336 {
337
338 }
339
340 static void utc_storage_set_state_changed_cb_positive(void)
341 {
342         int err;
343
344         err = storage_set_state_changed_cb(0, dts_storage_state_changed_cb, NULL);
345
346         if (err == STORAGE_ERROR_NONE) {
347                 dts_pass("utc_storage_set_state_changed_cb_positive", "passed");
348         } else {
349                 dts_fail("utc_storage_set_state_changed_cb_positive", "failed");
350         }
351 }
352
353 static void utc_storage_set_state_changed_cb_negative1(void)
354 {
355         int err;
356
357         err = storage_set_state_changed_cb(-1, dts_storage_state_changed_cb, NULL);
358
359         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
360                 dts_pass("utc_storage_set_state_changed_cb_negative1", "passed");
361         } else {
362                 dts_fail("utc_storage_set_state_changed_cb_negative1", "failed");
363         }
364 }
365
366 static void utc_storage_set_state_changed_cb_negative2(void)
367 {
368         int err;
369
370         err = storage_set_state_changed_cb(0, NULL, NULL);
371
372         if (err == STORAGE_ERROR_INVALID_PARAMETER) {
373                 dts_pass("utc_storage_set_state_changed_cb_negative2", "passed");
374         } else {
375                 dts_fail("utc_storage_set_state_changed_cb_negative2", "failed");
376         }
377 }
378
379 static void utc_storage_unset_state_changed_cb_positive(void)
380 {
381         int err;
382
383         storage_set_state_changed_cb(0, dts_storage_state_changed_cb, NULL);
384
385         err = storage_unset_state_changed_cb(0);
386
387         if (err == STORAGE_ERROR_NONE) {
388                 dts_pass("utc_storage_unset_state_changed_cb_positive", "passed");
389         } else {
390                 dts_fail("utc_storage_unset_state_changed_cb_positive", "failed");
391         }
392 }
393
394 static void utc_storage_unset_state_changed_cb_negative(void)
395 {
396         int err;
397
398         err = storage_unset_state_changed_cb(-1);
399
400         if (err == STORAGE_ERROR_NOT_SUPPORTED) {
401                 dts_pass("utc_storage_unset_state_changed_cb_negative", "passed");
402         } else {
403                 dts_fail("utc_storage_unset_state_changed_cb_negative", "failed");
404         }
405 }
406