1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
23 #include "maps_place_private.h"
24 #include "maps_util.h"
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)
30 maps_place_h place = NULL;
31 int error = maps_place_create(&place);
32 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
35 error = maps_place_destroy(place);
36 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
39 void utc_maps_place_create_n(void)
41 int error = maps_place_create(NULL);
42 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
44 error = maps_place_destroy(NULL);
45 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
48 /*----------------------------------------------------------------------------*/
49 static int __utc_put_to_hashtable(const char* feature_str,
50 maps_string_hashtable_h t)
52 if (!feature_str || !t)
53 return MAPS_ERROR_INVALID_PARAMETER;
54 return maps_string_hashtable_set(t, feature_str, feature_str);
63 test_env():p(NULL), iteration(0)
65 const int error = maps_place_create(&p);
66 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
69 maps_string_hashtable_h data_supported = NULL;
70 if (maps_string_hashtable_create(&data_supported) !=
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),
78 __utc_put_to_hashtable(_S(MAPS_PLACE_ATTRIBUTES),
80 __utc_put_to_hashtable(_S(MAPS_PLACE_CONTACTS),
82 __utc_put_to_hashtable(_S(MAPS_PLACE_EDITORIALS),
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),
88 __utc_put_to_hashtable(_S(MAPS_PLACE_RELATED), data_supported);
90 _maps_place_set_supported_data(p, data_supported);
91 maps_string_hashtable_destroy(data_supported);
96 const int error = maps_place_destroy(p);
97 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
101 /*----------------------------------------------------------------------------*/
103 /* int maps_place_clone(const maps_place_h origin, maps_place_h* cloned); */
104 void utc_maps_place_clone_p(void)
108 maps_place_h cloned = NULL;
109 int error = maps_place_clone(e.p, &cloned);
110 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
113 /* TODO: it is better to add meaningful values to the origin and check
114 * if they are clonned correctly */
116 error = maps_place_destroy(cloned);
117 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
120 void utc_maps_place_clone_n(void)
124 maps_place_h cloned = NULL;
125 int error = maps_place_clone(e.p, NULL);
126 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
128 error = maps_place_clone(NULL, &cloned);
129 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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)
138 int error = maps_place_set_id(e.p, "place_id_1");
139 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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");
148 void utc_maps_place_set_id_n(void)
152 int error = maps_place_set_id(NULL, "place_id_1");
153 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
155 error = maps_place_set_id(e.p, NULL);
156 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
159 error = maps_place_get_id(NULL, &id);
160 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
162 error = maps_place_get_id(e.p, NULL);
163 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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)
172 int error = maps_place_set_name(e.p, "place_name");
173 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
176 error = maps_place_get_name(e.p, &name);
177 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
178 g_assert_cmpstr(name, ==, "place_name");
182 void utc_maps_place_set_name_n(void)
186 int error = maps_place_set_name(NULL, "place_name");
187 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
189 error = maps_place_set_name(e.p, NULL);
190 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
193 error = maps_place_get_name(NULL, &name);
194 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
196 error = maps_place_get_name(e.p, NULL);
197 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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)
206 int error = maps_place_set_uri(e.p, "place_uri");
207 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
210 error = maps_place_get_uri(e.p, &uri);
211 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
212 g_assert_cmpstr(uri, ==, "place_uri");
216 void utc_maps_place_set_uri_n(void)
220 int error = maps_place_set_uri(NULL, "place_uri");
221 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
223 error = maps_place_set_uri(e.p, NULL);
224 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
227 error = maps_place_get_uri(NULL, &uri);
228 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
230 error = maps_place_get_uri(e.p, NULL);
231 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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)
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);
247 error = maps_place_set_location(e.p, location);
248 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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);
255 double lat = .0, lon = .0;
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);
263 g_assert_cmpfloat(44.4, ==, lat);
264 g_assert_cmpfloat(22.2, ==, lon);
266 error = maps_coordinates_destroy(location);
267 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
269 maps_coordinates_destroy(location_obtained);
272 void utc_maps_place_set_location_n(void)
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);
281 error = maps_place_set_location(NULL, location);
282 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
284 error = maps_place_set_location(e.p, NULL);
285 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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);
291 error = maps_place_get_location(e.p, NULL);
292 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
294 error = maps_coordinates_destroy(location);
295 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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)
308 test_env* e = (test_env*) user_data;
313 maps_place_category_destroy(category);
318 void utc_maps_place_set_category_p(void)
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);
327 maps_place_category_h category = NULL;
328 error = maps_place_category_create(&category);
329 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
332 error = maps_item_list_append(categories, category,
333 maps_place_category_clone);
334 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
336 /* test start --------------------------------- */
337 error = maps_place_set_categories(e.p, categories);
338 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
340 error = maps_place_foreach_category(e.p, __utc_maps_place_categories_cb,
342 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
343 g_assert_cmpint(e.iteration, ==, 1);
344 /* test finish --------------------------------- */
346 error = maps_place_category_destroy(category);
347 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
349 error = maps_item_list_remove_all(categories,
350 maps_place_category_destroy);
351 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
353 error = maps_item_list_destroy(categories);
354 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
357 void utc_maps_place_set_category_n(void)
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);
366 maps_place_category_h category = NULL;
367 error = maps_place_category_create(&category);
368 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
371 error = maps_item_list_append(categories, category,
372 maps_place_category_clone);
373 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
375 /* test start --------------------------------- */
376 error = maps_place_set_categories(NULL, categories);
377 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
379 error = maps_place_set_categories(e.p, NULL);
380 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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);
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 --------------------------------- */
392 error = maps_place_category_destroy(category);
393 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
395 error = maps_item_list_remove_all(categories,
396 maps_place_category_destroy);
397 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
399 error = maps_item_list_destroy(categories);
400 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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)
410 test_env* e = (test_env*) user_data;
415 maps_place_attribute_destroy(attribute);
420 void utc_maps_place_set_attribute_p(void)
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);
429 maps_place_attribute_h attribute = NULL;
430 error = maps_place_attribute_create(&attribute);
431 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
434 error = maps_item_list_append(attributes, attribute,
435 maps_place_attribute_clone);
436 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
438 /* test start --------------------------------- */
439 error = maps_place_set_attributes(e.p, attributes);
440 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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 --------------------------------- */
448 error = maps_place_attribute_destroy(attribute);
449 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
451 error = maps_item_list_remove_all(attributes,
452 maps_place_attribute_destroy);
453 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
455 error = maps_item_list_destroy(attributes);
456 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
459 void utc_maps_place_set_attribute_n(void)
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);
468 maps_place_attribute_h attribute = NULL;
469 error = maps_place_attribute_create(&attribute);
470 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
473 error = maps_item_list_append(attributes, attribute,
474 maps_place_attribute_clone);
475 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
477 /* test start --------------------------------- */
478 error = maps_place_set_attributes(NULL, attributes);
479 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
481 error = maps_place_set_attributes(e.p, NULL);
482 g_assert_cmpint(error, ==, MAPS_ERROR_INVALID_PARAMETER);
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);
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 --------------------------------- */
494 error = maps_place_attribute_destroy(attribute);
495 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
497 error = maps_item_list_remove_all(attributes,
498 maps_place_attribute_destroy);
499 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
501 error = maps_item_list_destroy(attributes);
502 g_assert_cmpint(error, ==, MAPS_ERROR_NONE);
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)
513 void utc_maps_place_set_contacts_n(void)
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)
526 void utc_maps_place_set_editorial_n(void)
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)
539 void utc_maps_place_set_image_n(void)
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)
552 void utc_maps_place_set_review_n(void)
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)
566 void utc_maps_place_set_properties_n(void)
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)
580 void utc_maps_place_set_rating_n(void)
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)
594 void utc_maps_place_set_supplier_link_n(void)
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)
608 void utc_maps_place_set_related_link_n(void)
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)
620 void utc_maps_place_foreach_property_n(void)