Tizen 2.4.0 rev3 SDK Public Release
[framework/location/maps-service.git] / test / src / api / maps_place_test.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
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 #include "maps_place_test.h"
18 #include "maps_place_plugin.h"
19 #include "maps_place_category.h"
20 #include "maps_place_attribute_plugin.h"
21 #include "maps_error.h"
22 #include <glib.h>
23 #include "maps_place_private.h"
24 #include "maps_util.h"
25
26  /* int maps_place_create(maps_place_h* place); */
27 /* int maps_place_destroy(maps_place_h place); */
28 void utc_maps_place_create_p(void)
29 {
30         maps_place_h place = NULL;
31         int error = maps_place_create(&place);
32         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
33         g_assert(place);
34
35         error = maps_place_destroy(place);
36         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
37 }
38
39 void utc_maps_place_create_n(void)
40 {
41         int error = maps_place_create(NULL);
42         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
43
44         error = maps_place_destroy(NULL);
45         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
46 }
47
48 /*----------------------------------------------------------------------------*/
49 static int __utc_put_to_hashtable(const char* feature_str,
50         maps_string_hashtable_h t)
51 {
52         if (!feature_str || !t)
53                 return MAPS_ERROR_INVALID_PARAMETER;
54         return maps_string_hashtable_set(t, feature_str, feature_str);
55 }
56
57 class test_env
58 {
59  public:
60         maps_place_h p;
61         int iteration;
62  public:
63          test_env():p(NULL), iteration(0)
64         {
65                 const int error = maps_place_create(&p);
66                  g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
67                  g_assert(p);
68
69                 maps_string_hashtable_h data_supported = NULL;
70                 if (maps_string_hashtable_create(&data_supported) !=
71                         MAPS_ERROR_NONE)
72                          return;
73
74                  __utc_put_to_hashtable(_S(MAPS_PLACE_ADDRESS), data_supported);
75                  __utc_put_to_hashtable(_S(MAPS_PLACE_RATING), data_supported);
76                  __utc_put_to_hashtable(_S(MAPS_PLACE_CATEGORIES),
77                         data_supported);
78                  __utc_put_to_hashtable(_S(MAPS_PLACE_ATTRIBUTES),
79                         data_supported);
80                  __utc_put_to_hashtable(_S(MAPS_PLACE_CONTACTS),
81                         data_supported);
82                  __utc_put_to_hashtable(_S(MAPS_PLACE_EDITORIALS),
83                         data_supported);
84                  __utc_put_to_hashtable(_S(MAPS_PLACE_REVIEWS), data_supported);
85                  __utc_put_to_hashtable(_S(MAPS_PLACE_IMAGE), data_supported);
86                  __utc_put_to_hashtable(_S(MAPS_PLACE_SUPPLIER),
87                         data_supported);
88                  __utc_put_to_hashtable(_S(MAPS_PLACE_RELATED), data_supported);
89
90                  _maps_place_set_supported_data(p, data_supported);
91                  maps_string_hashtable_destroy(data_supported);
92
93         }
94         ~test_env()
95         {
96                 const int error = maps_place_destroy(p);
97                 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
98         }
99 };
100
101 /*----------------------------------------------------------------------------*/
102
103 /* int maps_place_clone(const maps_place_h origin, maps_place_h* cloned); */
104 void utc_maps_place_clone_p(void)
105 {
106         test_env e;
107
108         maps_place_h cloned = NULL;
109         int error = maps_place_clone(e.p, &cloned);
110         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
111         g_assert(cloned);
112
113         /* TODO: it is better to add meaningful values to the origin and check
114         *  if they are clonned correctly */
115
116         error = maps_place_destroy(cloned);
117         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
118 }
119
120 void utc_maps_place_clone_n(void)
121 {
122         test_env e;
123
124         maps_place_h cloned = NULL;
125         int error = maps_place_clone(e.p, NULL);
126         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
127
128         error = maps_place_clone(NULL, &cloned);
129         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
130 }
131
132 /* int maps_place_set_id(maps_place_h place, const char* id); */
133 /* int maps_place_get_id(maps_place_h place, char** id); */
134 void utc_maps_place_set_id_p(void)
135 {
136         test_env e;
137
138         int error = maps_place_set_id(e.p, "place_id_1");
139         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
140
141         char* id = NULL;
142         error = maps_place_get_id(e.p, &id);
143         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
144         g_assert_cmpstr(id, ==, "place_id_1");
145         g_free(id);
146 }
147
148 void utc_maps_place_set_id_n(void)
149 {
150         test_env e;
151
152         int error = maps_place_set_id(NULL, "place_id_1");
153         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
154
155         error = maps_place_set_id(e.p, NULL);
156         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
157
158         char* id = NULL;
159         error = maps_place_get_id(NULL, &id);
160         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
161
162         error = maps_place_get_id(e.p, NULL);
163         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
164 }
165
166 /* int maps_place_set_name(maps_place_h place, const char* name); */
167 /* int maps_place_get_name(maps_place_h place, char** name); */
168 void utc_maps_place_set_name_p(void)
169 {
170         test_env e;
171
172         int error = maps_place_set_name(e.p, "place_name");
173         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
174
175         char* name = NULL;
176         error = maps_place_get_name(e.p, &name);
177         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
178         g_assert_cmpstr(name, ==, "place_name");
179         g_free(name);
180 }
181
182 void utc_maps_place_set_name_n(void)
183 {
184         test_env e;
185
186         int error = maps_place_set_name(NULL, "place_name");
187         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
188
189         error = maps_place_set_name(e.p, NULL);
190         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
191
192         char* name = NULL;
193         error = maps_place_get_name(NULL, &name);
194         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
195
196         error = maps_place_get_name(e.p, NULL);
197         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
198 }
199
200 /* int maps_place_set_uri(maps_place_h place, const char* uri); */
201 /* int maps_place_get_uri(maps_place_h place, char** uri); */
202 void utc_maps_place_set_uri_p(void)
203 {
204         test_env e;
205
206         int error = maps_place_set_uri(e.p, "place_uri");
207         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
208
209         char* uri = NULL;
210         error = maps_place_get_uri(e.p, &uri);
211         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
212         g_assert_cmpstr(uri, ==, "place_uri");
213         g_free(uri);
214 }
215
216 void utc_maps_place_set_uri_n(void)
217 {
218         test_env e;
219
220         int error = maps_place_set_uri(NULL, "place_uri");
221         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
222
223         error = maps_place_set_uri(e.p, NULL);
224         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
225
226         char* uri = NULL;
227         error = maps_place_get_uri(NULL, &uri);
228         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
229
230         error = maps_place_get_uri(e.p, NULL);
231         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
232 }
233
234 /* int maps_place_set_location(maps_place_h place,
235 *  maps_coordinates_h location); */
236 /* int maps_place_get_location(maps_place_h place,
237 *  maps_coordinates_h* location); */
238 void utc_maps_place_set_location_p(void)
239 {
240         test_env e;
241
242         maps_coordinates_h location = NULL;
243         int error = maps_coordinates_create(44.4, 22.2, &location);
244         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
245         g_assert(location);
246
247         error = maps_place_set_location(e.p, location);
248         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
249
250         maps_coordinates_h location_obtained = NULL;
251         error = maps_place_get_location(e.p, &location_obtained);
252         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
253         g_assert(location_obtained);
254
255         double lat = .0, lon = .0;
256
257         error = maps_coordinates_get_latitude(location_obtained, &lat);
258         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
259         error = maps_coordinates_get_longitude(location_obtained, &lon);
260         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
261
262
263         g_assert_cmpfloat(44.4, ==, lat);
264         g_assert_cmpfloat(22.2, ==, lon);
265
266         error = maps_coordinates_destroy(location);
267         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
268
269         maps_coordinates_destroy(location_obtained);
270 }
271
272 void utc_maps_place_set_location_n(void)
273 {
274         test_env e;
275
276         maps_coordinates_h location = NULL;
277         int error = maps_coordinates_create(44.4, 22.2, &location);
278         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
279         g_assert(location);
280
281         error = maps_place_set_location(NULL, location);
282         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
283
284         error = maps_place_set_location(e.p, NULL);
285         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
286
287         maps_coordinates_h location_obtained = NULL;
288         error = maps_place_get_location(NULL, &location_obtained);
289         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
290
291         error = maps_place_get_location(e.p, NULL);
292         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
293
294         error = maps_coordinates_destroy(location);
295         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
296 }
297
298 /* int maps_place_set_categories(maps_place_h place,
299 *  maps_item_list_h* categories); */
300 /* int maps_place_foreach_category(maps_place_h place,
301 *  maps_place_categories_cb callback, void* user_data); */
302 /* typedef bool (*maps_place_categories_cb)(
303 *  const maps_place_category_h category, void* user_data); */
304 static bool __utc_maps_place_categories_cb(int index, int total,
305         const maps_place_category_h category, void* user_data)
306 {
307         g_assert(category);
308         test_env* e = (test_env*) user_data;
309         g_assert(e);
310
311         e->iteration++;
312
313         maps_place_category_destroy(category);
314
315         return true;
316 }
317
318 void utc_maps_place_set_category_p(void)
319 {
320         test_env e;
321
322         maps_item_list_h categories = NULL;
323         int error = maps_item_list_create(&categories);
324         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
325         g_assert(categories);
326
327         maps_place_category_h category = NULL;
328         error = maps_place_category_create(&category);
329         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
330         g_assert(category);
331
332         error = maps_item_list_append(categories, category,
333                 maps_place_category_clone);
334         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
335
336         /* test start --------------------------------- */
337         error = maps_place_set_categories(e.p, categories);
338         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
339
340         error = maps_place_foreach_category(e.p, __utc_maps_place_categories_cb,
341                 &e);
342         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
343         g_assert_cmpint(e.iteration, ==, 1);
344         /* test finish --------------------------------- */
345
346         error = maps_place_category_destroy(category);
347         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
348
349         error = maps_item_list_remove_all(categories,
350                 maps_place_category_destroy);
351         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
352
353         error = maps_item_list_destroy(categories);
354         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
355 }
356
357 void utc_maps_place_set_category_n(void)
358 {
359         test_env e;
360
361         maps_item_list_h categories = NULL;
362         int error = maps_item_list_create(&categories);
363         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
364         g_assert(categories);
365
366         maps_place_category_h category = NULL;
367         error = maps_place_category_create(&category);
368         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
369         g_assert(category);
370
371         error = maps_item_list_append(categories, category,
372                 maps_place_category_clone);
373         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
374
375         /* test start --------------------------------- */
376         error = maps_place_set_categories(NULL, categories);
377         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
378
379         error = maps_place_set_categories(e.p, NULL);
380         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
381
382         error = maps_place_foreach_category(NULL,
383                 __utc_maps_place_categories_cb, &e);
384         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
385         g_assert_cmpint(e.iteration, ==, 0);
386
387         error = maps_place_foreach_category(e.p, NULL, &e);
388         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
389         g_assert_cmpint(e.iteration, ==, 0);
390         /* test finish --------------------------------- */
391
392         error = maps_place_category_destroy(category);
393         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
394
395         error = maps_item_list_remove_all(categories,
396                 maps_place_category_destroy);
397         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
398
399         error = maps_item_list_destroy(categories);
400         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
401 }
402
403 /* int maps_place_set_attributes(maps_place_h place, GList* attributes); */
404 /* int maps_place_foreach_attribute(maps_place_h place,
405 *  maps_place_attributes_cb callback, void* user_data); */
406 static bool __utc_maps_place_attributes_cb(int index, int total,
407         const maps_place_attribute_h attribute, void* user_data)
408 {
409         g_assert(attribute);
410         test_env* e = (test_env*) user_data;
411         g_assert(e);
412
413         e->iteration++;
414
415         maps_place_attribute_destroy(attribute);
416
417         return true;
418 }
419
420 void utc_maps_place_set_attribute_p(void)
421 {
422         test_env e;
423
424         maps_item_list_h attributes = NULL;
425         int error = maps_item_list_create(&attributes);
426         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
427         g_assert(attributes);
428
429         maps_place_attribute_h attribute = NULL;
430         error = maps_place_attribute_create(&attribute);
431         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
432         g_assert(attribute);
433
434         error = maps_item_list_append(attributes, attribute,
435                 maps_place_attribute_clone);
436         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
437
438         /* test start --------------------------------- */
439         error = maps_place_set_attributes(e.p, attributes);
440         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
441
442         error = maps_place_foreach_attribute(e.p,
443                 __utc_maps_place_attributes_cb, &e);
444         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
445         g_assert_cmpint(e.iteration, ==, 1);
446         /* test finish --------------------------------- */
447
448         error = maps_place_attribute_destroy(attribute);
449         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
450
451         error = maps_item_list_remove_all(attributes,
452                 maps_place_attribute_destroy);
453         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
454
455         error = maps_item_list_destroy(attributes);
456         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
457 }
458
459 void utc_maps_place_set_attribute_n(void)
460 {
461         test_env e;
462
463         maps_item_list_h attributes = NULL;
464         int error = maps_item_list_create(&attributes);
465         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
466         g_assert(attributes);
467
468         maps_place_attribute_h attribute = NULL;
469         error = maps_place_attribute_create(&attribute);
470         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
471         g_assert(attribute);
472
473         error = maps_item_list_append(attributes, attribute,
474                 maps_place_attribute_clone);
475         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
476
477         /* test start --------------------------------- */
478         error = maps_place_set_attributes(NULL, attributes);
479         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
480
481         error = maps_place_set_attributes(e.p, NULL);
482         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
483
484         error = maps_place_foreach_attribute(NULL,
485                 __utc_maps_place_attributes_cb, &e);
486         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
487         g_assert_cmpint(e.iteration, ==, 0);
488
489         error = maps_place_foreach_attribute(e.p, NULL, &e);
490         g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
491         g_assert_cmpint(e.iteration, ==, 0);
492         /* test finish --------------------------------- */
493
494         error = maps_place_attribute_destroy(attribute);
495         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
496
497         error = maps_item_list_remove_all(attributes,
498                 maps_place_attribute_destroy);
499         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
500
501         error = maps_item_list_destroy(attributes);
502         g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
503 }
504
505 /* int maps_place_set_contact(maps_place_h place, GList* contacts); */
506 /* int maps_place_foreach_contact(maps_place_h place,
507 *  maps_place_contacts_cb callback, void* user_data); */
508 void utc_maps_place_set_contacts_p(void)
509 {
510
511 }
512
513 void utc_maps_place_set_contacts_n(void)
514 {
515
516 }
517
518 /* int maps_place_set_editorials(maps_place_h place, GList* editorials); */
519 /* int maps_place_foreach_editorial(maps_place_h place,
520 *  maps_place_editorials_cb callback, void* user_data); */
521 void utc_maps_place_set_editorial_p(void)
522 {
523
524 }
525
526 void utc_maps_place_set_editorial_n(void)
527 {
528
529 }
530
531 /* int maps_place_set_images(maps_place_h place, GList* images); */
532 /* int maps_place_foreach_image(maps_place_h place,
533 *  maps_place_images_cb callback, void* user_data); */
534 void utc_maps_place_set_image_p(void)
535 {
536
537 }
538
539 void utc_maps_place_set_image_n(void)
540 {
541
542 }
543
544 /* int maps_place_set_reviews(maps_place_h place, GList* reviews); */
545 /* int maps_place_foreach_review(maps_place_h place,
546 *  maps_place_reviews_cb callback, void* user_data); */
547 void utc_maps_place_set_review_p(void)
548 {
549
550 }
551
552 void utc_maps_place_set_review_n(void)
553 {
554
555 }
556
557 /* int maps_place_set_properties(maps_place_h place,
558 *  maps_item_hashtable_h properties) */
559 /* int maps_place_foreach_property(maps_place_h place,
560 *  maps_place_properties_cb callback, void* user_data) { */
561 void utc_maps_place_set_properties_p(void)
562 {
563
564 }
565
566 void utc_maps_place_set_properties_n(void)
567 {
568
569 }
570
571 /* int maps_place_set_rating(maps_place_h place,
572 *  maps_place_rating_h rating); */
573 /* int maps_place_get_rating(maps_place_h place ,
574 *  maps_place_rating_h* rating); */
575 void utc_maps_place_set_rating_p(void)
576 {
577
578 }
579
580 void utc_maps_place_set_rating_n(void)
581 {
582
583 }
584
585 /* int maps_place_set_supplier_link(maps_place_h place,
586 *  maps_place_link_object_h supplier); */
587 /* int maps_place_get_supplier_link(maps_place_image_h place,
588 *  maps_place_link_object_h* supplier); */
589 void utc_maps_place_set_supplier_link_p(void)
590 {
591
592 }
593
594 void utc_maps_place_set_supplier_link_n(void)
595 {
596
597 }
598
599 /* int maps_place_set_related_link(maps_place_h place,
600 *  maps_place_link_object_h related); */
601 /* int maps_place_get_related_link(maps_place_image_h place,
602 *  maps_place_link_object_h* related); */
603 void utc_maps_place_set_related_link_p(void)
604 {
605
606 }
607
608 void utc_maps_place_set_related_link_n(void)
609 {
610
611 }
612
613 /* int maps_place_foreach_property(maps_place_h place,
614 *  maps_place_properties_cb callback, void* user_data); */
615 void utc_maps_place_foreach_property_p(void)
616 {
617
618 }
619
620 void utc_maps_place_foreach_property_n(void)
621 {
622
623 }
624