sync
[platform/framework/web/wrt-plugins-common.git] / tests / dao / WidgetDBTest.cpp
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  * @file    WidgetDBTest.cpp
18  * @author  Andrzej Surdej (a.surdej@samsung.com)
19  * @version 1.0
20  * @brief   This file contains tests for widgetDB commons module
21  */
22
23 #include <dpl/test/test_runner.h>
24 #include <dpl/foreach.h>
25 #include <dpl/log/log.h>
26 #include <WidgetDB/IWidgetDB.h>
27 #include <WidgetDB/WidgetDBMgr.h>
28 #include <Commons/Exception.h>
29
30 using namespace WrtDeviceApis::WidgetDB::Api;
31
32 #define RUNNER_ASSERT_WHAT_EQUALS(in, test)                                    \
33     do                                                                         \
34     {                                                                          \
35         std::string temp(in);                                                  \
36         RUNNER_ASSERT_MSG(temp == (test), "Equals: [" << temp << "]");         \
37     }                                                                          \
38     while(0)
39
40 RUNNER_TEST_GROUP_INIT(WidgetDB)
41
42 /*
43 Name: widgetDB_test_get_language1
44 Description: check default widget language
45 Expected: default should be "en"
46 */
47 RUNNER_TEST(widgetDB_test_get_language1)
48 {
49     try
50     {
51         IWidgetDBPtr widget = getWidgetDB(2000);
52         std::string lang = widget->getLanguage();
53
54         LogDebug("language is: " << lang);
55         RUNNER_ASSERT_WHAT_EQUALS(lang, "en");
56
57     }
58     catch(const WrtDeviceApis::Commons::SecurityException &e)
59     {
60         LogError("Exception thrown." << e.DumpToString());
61         RUNNER_ASSERT(false);
62     }
63 }
64
65 /*
66 Name: widgetDB_test_get_language2
67 Description: check language returned by WidgetDB if widget does nto exists
68 Expected: result should be ""
69 */
70 RUNNER_TEST(widgetDB_test_get_language2)
71 {
72     try
73     {
74         IWidgetDBPtr widget = getWidgetDB(1000); //widget not exist
75         std::string lang = widget->getLanguage();
76
77         LogDebug("language is: " << lang);
78         RUNNER_ASSERT_WHAT_EQUALS(lang, "");
79
80     }
81     catch(const WrtDeviceApis::Commons::SecurityException &e)
82     {
83         LogError("Exception thrown." << e.DumpToString());
84         RUNNER_ASSERT(false);
85     }
86 }
87
88 /*
89 Name: widgetDB_test_get_config_value_id
90 Description: check GUID returned by WidgetDB
91 Expected: GUID should match this, which was inserted into widget database
92 */
93 RUNNER_TEST(widgetDB_test_get_config_value_id)
94 {
95     try
96     {
97         IWidgetDBPtr widget = getWidgetDB(2000);
98         std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
99
100         LogDebug("id is: " << tmp);
101         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_id_2000");
102     }
103     catch(const WrtDeviceApis::Commons::SecurityException &e)
104     {
105         LogError("Exception thrown." << e.DumpToString());
106         RUNNER_ASSERT(false);
107     }
108 }
109
110 /*
111 Name: widgetDB_test_get_config_value_version
112 Description: check version returned by WidgetDB
113 Expected: version should match this, which was inserted into widget database
114 */
115 RUNNER_TEST(widgetDB_test_get_config_value_version)
116 {
117     try
118     {
119         IWidgetDBPtr widget = getWidgetDB(2000);
120         std::string tmp = widget->getConfigValue(ConfigAttribute::VERSION);
121
122         LogDebug("version is: " << tmp);
123         RUNNER_ASSERT_WHAT_EQUALS(tmp, "1.0.0");
124     }
125     catch(const WrtDeviceApis::Commons::SecurityException &e)
126     {
127         LogError("Exception thrown." << e.DumpToString());
128         RUNNER_ASSERT(false);
129     }
130 }
131
132 /*
133 Name: widgetDB_test_get_config_value_description
134 Description: check description returned by WidgetDB
135 Expected: description should match this, which was inserted into widget database
136 */
137 RUNNER_TEST(widgetDB_test_get_config_value_description)
138 {
139     try
140     {
141         IWidgetDBPtr widget = getWidgetDB(2000);
142         std::string tmp = widget->getConfigValue(ConfigAttribute::DESCRIPTION);
143
144         LogDebug("description is: " << tmp);
145         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_desc_2000_en");
146     }
147     catch(const WrtDeviceApis::Commons::SecurityException &e)
148     {
149         LogError("Exception thrown." << e.DumpToString());
150         RUNNER_ASSERT(false);
151     }
152 }
153
154 /*
155 Name: widgetDB_test_get_config_value_license
156 Description: check license returned by WidgetDB
157 Expected: license should match this, which was inserted into widget database
158 */
159 RUNNER_TEST(widgetDB_test_get_config_value_license)
160 {
161     try
162     {
163         IWidgetDBPtr widget = getWidgetDB(2000);
164         std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE);
165
166         LogDebug("licence is: " << tmp);
167         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_2000_en");
168     }
169     catch(const WrtDeviceApis::Commons::SecurityException &e)
170     {
171         LogError("Exception thrown." << e.DumpToString());
172         RUNNER_ASSERT(false);
173     }
174 }
175
176 /*
177 Name: widgetDB_test_get_config_value_license_href
178 Description: check license href returned by WidgetDB
179 Expected: license href should match this, which was inserted into widget database
180 */
181 RUNNER_TEST(widgetDB_test_get_config_value_license_href)
182 {
183     try
184     {
185         IWidgetDBPtr widget = getWidgetDB(2000);
186         std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE_HREF);
187
188         LogDebug("license href is: " << tmp);
189         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_href_2000_en");
190     }
191     catch(const WrtDeviceApis::Commons::SecurityException &e)
192     {
193         LogError("Exception thrown." << e.DumpToString());
194         RUNNER_ASSERT(false);
195     }
196 }
197
198 /*
199 Name: widgetDB_test_get_config_value_author_name
200 Description: check author name href returned by WidgetDB
201 Expected: author name should match this, which was inserted into widget database
202 */
203 RUNNER_TEST(widgetDB_test_get_config_value_author_name)
204 {
205     try
206     {
207         IWidgetDBPtr widget = getWidgetDB(2000);
208         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_NAME);
209
210         LogDebug("author name is: " << tmp);
211         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_name_2000");
212     }
213     catch(const WrtDeviceApis::Commons::SecurityException &e)
214     {
215         LogError("Exception thrown." << e.DumpToString());
216         RUNNER_ASSERT(false);
217     }
218 }
219
220 /*
221 Name: widgetDB_test_get_config_value_author_href
222 Description: check author href returned by WidgetDB
223 Expected: author href should match this, which was inserted into widget database
224 */
225 RUNNER_TEST(widgetDB_test_get_config_value_author_href)
226 {
227     try
228     {
229         IWidgetDBPtr widget = getWidgetDB(2000);
230         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_HREF);
231
232         LogDebug("author href is: " << tmp);
233         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_href_2000");
234     }
235     catch(const WrtDeviceApis::Commons::SecurityException &e)
236     {
237         LogError("Exception thrown." << e.DumpToString());
238         RUNNER_ASSERT(false);
239     }
240 }
241
242 /*
243 Name: widgetDB_test_get_config_value_author_email
244 Description: check author email returned by WidgetDB
245 Expected: author email should match this, which was inserted into widget database
246 */
247 RUNNER_TEST(widgetDB_test_get_config_value_author_email)
248 {
249     try
250     {
251         IWidgetDBPtr widget = getWidgetDB(2000);
252         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_EMAIL);
253
254         LogDebug("author email is: " << tmp);
255         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_email_2000");
256     }
257     catch(const WrtDeviceApis::Commons::SecurityException &e)
258     {
259         LogError("Exception thrown." << e.DumpToString());
260         RUNNER_ASSERT(false);
261     }
262 }
263
264 /*
265 Name: widgetDB_test_get_config_value_name
266 Description: check localized widget name returned by WidgetDB
267 Expected: localized widget name should match this, which was inserted into widget database
268 */
269 RUNNER_TEST(widgetDB_test_get_config_value_name)
270 {
271     try
272     {
273         IWidgetDBPtr widget = getWidgetDB(2000);
274         std::string tmp = widget->getConfigValue(ConfigAttribute::NAME);
275
276         LogDebug("name is: " << tmp);
277         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_name_2000_en");
278     }
279     catch(const WrtDeviceApis::Commons::SecurityException &e)
280     {
281         LogError("Exception thrown." << e.DumpToString());
282         RUNNER_ASSERT(false);
283     }
284 }
285
286 /*
287 Name: widgetDB_test_get_config_value_short_name
288 Description: check localized widget short name returned by WidgetDB
289 Expected: localized widget short name should match this, which was inserted into widget database
290 */
291 RUNNER_TEST(widgetDB_test_get_config_value_short_name)
292 {
293     try
294     {
295         IWidgetDBPtr widget = getWidgetDB(2000);
296         std::string tmp = widget->getConfigValue(ConfigAttribute::SHORT_NAME);
297
298         LogDebug("short name is: " << tmp);
299         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_shortname_2000_en");
300     }
301     catch(const WrtDeviceApis::Commons::SecurityException &e)
302     {
303         LogError("Exception thrown." << e.DumpToString());
304         RUNNER_ASSERT(false);
305     }
306 }
307
308 /*
309 Name: widgetDB_test_get_config_value_access_network
310 Description: check network access returned by WidgetDB
311 Expected: network access should be set to "yes"
312 */
313 RUNNER_TEST(widgetDB_test_get_config_value_access_network)
314 {
315     try
316     {
317         IWidgetDBPtr widget = getWidgetDB(2000);
318         std::string tmp = widget->getConfigValue(
319             ConfigAttribute::ACCESS_NETWORK);
320
321         LogDebug("acces network is always true: " << tmp);
322         RUNNER_ASSERT_WHAT_EQUALS(tmp, "yes");
323     }
324     catch(const WrtDeviceApis::Commons::SecurityException &e)
325     {
326         LogError("Exception thrown." << e.DumpToString());
327         RUNNER_ASSERT(false);
328     }
329 }
330
331 /*
332 Name: widgetDB_test_get_config_value_width
333 Description: check widget prefered width returned by WidgetDB
334 Expected: widget prefered width should match this, which was inserted into widget database
335 */
336 RUNNER_TEST(widgetDB_test_get_config_value_width)
337 {
338     try
339     {
340         IWidgetDBPtr widget = getWidgetDB(2000);
341         std::string tmp = widget->getConfigValue(ConfigAttribute::WIDTH);
342
343         LogDebug("width is: " << tmp);
344         RUNNER_ASSERT_WHAT_EQUALS(tmp, "100");
345     }
346     catch(const WrtDeviceApis::Commons::SecurityException &e)
347     {
348         LogError("Exception thrown." << e.DumpToString());
349         RUNNER_ASSERT(false);
350     }
351 }
352
353 /*
354 Name: widgetDB_test_get_config_value_height
355 Description: check widget prefered height returned by WidgetDB
356 Expected: widget prefered height should match this, which was inserted into widget database
357 */
358 RUNNER_TEST(widgetDB_test_get_config_value_height)
359 {
360     try
361     {
362         IWidgetDBPtr widget = getWidgetDB(2000);
363         std::string tmp = widget->getConfigValue(ConfigAttribute::HEIGHT);
364
365         LogDebug("height is: " << tmp);
366         RUNNER_ASSERT_WHAT_EQUALS(tmp, "200");
367     }
368     catch(const WrtDeviceApis::Commons::SecurityException &e)
369     {
370         LogError("Exception thrown." << e.DumpToString());
371         RUNNER_ASSERT(false);
372     }
373 }
374
375 /*
376 Name: widgetDB_test_get_config_value_paths
377 Description: check widget installation path returned by WidgetDB
378 Expected: widget installation path should match this, which was inserted into widget database
379 */
380 RUNNER_TEST(widgetDB_test_get_config_value_paths)
381 {
382     try
383     {
384         IWidgetDBPtr widget = getWidgetDB(2000);
385         std::string tmp = widget->getConfigValue(ConfigAttribute::INSTALL_PATH);
386
387         LogDebug("install path is: " << tmp);
388
389         tmp = widget->getConfigValue(
390             ConfigAttribute::PUBLIC_STORAGE_PATH);
391
392         LogDebug("public storage path is: " << tmp);
393
394     }
395     catch(const WrtDeviceApis::Commons::SecurityException &e)
396     {
397         LogDebug("Exception thrown." << e.DumpToString());
398         RUNNER_ASSERT(false);
399     }
400 }
401
402 /*
403 Name: widgetDB_test_get_config_value_empty
404 Description: check if requesting GUID from WidgetDB throw excpetion if widget does not exists
405 Expected: accessing GUID should throw WrtDeviceApis::Commons::SecurityException
406 */
407 RUNNER_TEST(widgetDB_test_get_config_value_empty)
408 {
409     try
410     {
411         IWidgetDBPtr widget = getWidgetDB(2005);
412         std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
413
414         //exception should be thrown
415         RUNNER_ASSERT(false);
416
417     }
418     catch(const WrtDeviceApis::Commons::SecurityException &e)
419     {
420         LogDebug("OK. Exception thrown." << e.DumpToString());
421     }
422 }
423
424 /*
425 Name: widgetDB_test_check_installation_status_installed
426 Description: check if widget is installed by WidgetDB
427 Expected: plugin should be notified that widget is installed
428 */
429 RUNNER_TEST(widgetDB_test_check_installation_status_installed)
430 {
431     try
432     {
433         IWidgetDBPtr widget = getWidgetDB(2000);
434         InstallationStatus tmp = widget->checkInstallationStatus(
435             "w_id_2000", "w_name_2000_en", "2.0.0");
436
437         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_INSTALLED);
438     }
439     catch(const WrtDeviceApis::Commons::SecurityException &e)
440     {
441         LogError("Exception thrown." << e.DumpToString());
442         RUNNER_ASSERT(false);
443     }
444 }
445
446 /*
447 Name: widgetDB_test_check_installation_status_uninstalled
448 Description: check if widget is not installed by WidgetDB
449 Expected: plugin should be notified that widget is not installed
450 */
451 RUNNER_TEST(widgetDB_test_check_installation_status_uninstalled)
452 {
453     try
454     {
455         IWidgetDBPtr widget = getWidgetDB(2000);
456         InstallationStatus tmp = widget->checkInstallationStatus(
457             "w_id_2011", "w_name_2000_en", "2.0.0");
458
459         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_UNINSTALLED);
460     }
461     catch(const WrtDeviceApis::Commons::SecurityException &e)
462     {
463         LogError("Exception thrown." << e.DumpToString());
464         RUNNER_ASSERT(false);
465     }
466 }
467
468 /*
469 Name: widgetDB_test_check_installation_status_latest
470 Description: check if widget installation information is taken from latest version
471 Expected: plugin installation status should be same is both calls of WidgetDB
472 */
473 RUNNER_TEST(widgetDB_test_check_installation_status_latest)
474 {
475     try
476     {
477         IWidgetDBPtr widget = getWidgetDB(2000);
478         InstallationStatus tmp1 = widget->checkInstallationStatus(
479             "w_id_2000", "w_name_2000_en", "0.1.0");
480         InstallationStatus tmp2 = widget->checkInstallationStatus(
481             "w_id_2000", "w_name_2000_en", "1.0.0");
482
483         RUNNER_ASSERT(tmp1 == InstallationStatus::STATUS_LATEST);
484         RUNNER_ASSERT(tmp2 == InstallationStatus::STATUS_LATEST);
485     }
486     catch(const WrtDeviceApis::Commons::SecurityException &e)
487     {
488         LogError("Exception thrown." << e.DumpToString());
489         RUNNER_ASSERT(false);
490     }
491 }
492
493 /*
494 Name: widgetDB_test_widget_feature
495 Description: check accessiblity of widget features and their values by WidgetDB
496 Expected: feature names and values should match this, which was inserted into widget database
497 */
498 RUNNER_TEST(widgetDB_test_widget_feature)
499 {
500     try
501     {
502         IWidgetDBPtr widget = getWidgetDB(2000);
503         Features features = widget->getWidgetFeatures();
504
505         RUNNER_ASSERT(features.size() == 5);
506
507         FOREACH(it, features)
508         {
509            std::string name = (*it)->getName();
510            if ("first_2000" == name)
511            {
512                RUNNER_ASSERT((*it)->getParams().size() == 4);
513
514                RUNNER_ASSERT((*it)->isRequired());
515            }
516            else if ("second_2000" == name)
517            {
518                RUNNER_ASSERT((*it)->getParams().size() == 1);
519            }
520            else if ("third_2000" == name)
521            {
522                IWidgetFeature::Params params = (*it)->getParams();
523
524                RUNNER_ASSERT(params.size() == 1);
525                RUNNER_ASSERT_WHAT_EQUALS("third_2000", params.begin()->first);
526                RUNNER_ASSERT_WHAT_EQUALS("thirdValue1", params.begin()->second);
527                RUNNER_ASSERT(!(*it)->isRequired());
528            }
529            else if ("fourth_2000" == name)
530            {
531                RUNNER_ASSERT((*it)->getParams().size() == 0);
532            }
533            else if ("fifth_2000" == name)
534            {
535                RUNNER_ASSERT((*it)->getParams().size() == 0);
536            }
537            else
538                RUNNER_ASSERT(false);
539         }
540     }
541     catch(const WrtDeviceApis::Commons::SecurityException &e)
542     {
543         LogError("Exception thrown." << e.DumpToString());
544         RUNNER_ASSERT(false);
545     }
546 }
547
548 /*
549 Name: widgetDB_test_widget_feature2
550 Description: check if requesting features from WidgetDB throw excpetion if widget does not exists
551 Expected: exception should be raise if widget does not exists
552 */
553 RUNNER_TEST(widgetDB_test_widget_feature2)
554 {
555     try
556     {
557         IWidgetDBPtr widget = getWidgetDB(2011); //no such widget
558         Features features = widget->getWidgetFeatures();
559
560         RUNNER_ASSERT(false);
561     }
562     catch(const WrtDeviceApis::Commons::SecurityException &e)
563     {
564         LogDebug("OK. Exception thrown." << e.DumpToString());
565     }
566 }
567
568 #undef RUNNER_ASSERT_WHAT_EQUALS