2 * Copyright (c) 2011 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 * @file WidgetDBTest.cpp
18 * @author Andrzej Surdej (a.surdej@samsung.com)
20 * @brief This file contains tests for widgetDB commons module
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>
30 using namespace WrtDeviceApis::WidgetDB::Api;
32 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
35 std::string temp(in); \
36 RUNNER_ASSERT_MSG(temp == (test), "Equals: [" << temp << "]"); \
40 RUNNER_TEST_GROUP_INIT(WidgetDB)
43 Name: widgetDB_test_get_language1
44 Description: check default widget language
45 Expected: default should be "en"
47 RUNNER_TEST(widgetDB_test_get_language1)
51 IWidgetDBPtr widget = getWidgetDB(2000);
52 std::string lang = widget->getLanguage();
54 LogDebug("language is: " << lang);
55 RUNNER_ASSERT_WHAT_EQUALS(lang, "en");
58 catch(const WrtDeviceApis::Commons::SecurityException &e)
60 LogError("Exception thrown." << e.DumpToString());
66 Name: widgetDB_test_get_language2
67 Description: check language returned by WidgetDB if widget does nto exists
68 Expected: result should be ""
70 RUNNER_TEST(widgetDB_test_get_language2)
74 IWidgetDBPtr widget = getWidgetDB(1000); //widget not exist
75 std::string lang = widget->getLanguage();
77 LogDebug("language is: " << lang);
78 RUNNER_ASSERT_WHAT_EQUALS(lang, "");
81 catch(const WrtDeviceApis::Commons::SecurityException &e)
83 LogError("Exception thrown." << e.DumpToString());
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
93 RUNNER_TEST(widgetDB_test_get_config_value_id)
97 IWidgetDBPtr widget = getWidgetDB(2000);
98 std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
100 LogDebug("id is: " << tmp);
101 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_id_2000");
103 catch(const WrtDeviceApis::Commons::SecurityException &e)
105 LogError("Exception thrown." << e.DumpToString());
106 RUNNER_ASSERT(false);
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
115 RUNNER_TEST(widgetDB_test_get_config_value_version)
119 IWidgetDBPtr widget = getWidgetDB(2000);
120 std::string tmp = widget->getConfigValue(ConfigAttribute::VERSION);
122 LogDebug("version is: " << tmp);
123 RUNNER_ASSERT_WHAT_EQUALS(tmp, "1.0.0");
125 catch(const WrtDeviceApis::Commons::SecurityException &e)
127 LogError("Exception thrown." << e.DumpToString());
128 RUNNER_ASSERT(false);
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
137 RUNNER_TEST(widgetDB_test_get_config_value_description)
141 IWidgetDBPtr widget = getWidgetDB(2000);
142 std::string tmp = widget->getConfigValue(ConfigAttribute::DESCRIPTION);
144 LogDebug("description is: " << tmp);
145 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_desc_2000_en");
147 catch(const WrtDeviceApis::Commons::SecurityException &e)
149 LogError("Exception thrown." << e.DumpToString());
150 RUNNER_ASSERT(false);
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
159 RUNNER_TEST(widgetDB_test_get_config_value_license)
163 IWidgetDBPtr widget = getWidgetDB(2000);
164 std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE);
166 LogDebug("licence is: " << tmp);
167 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_2000_en");
169 catch(const WrtDeviceApis::Commons::SecurityException &e)
171 LogError("Exception thrown." << e.DumpToString());
172 RUNNER_ASSERT(false);
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
181 RUNNER_TEST(widgetDB_test_get_config_value_license_href)
185 IWidgetDBPtr widget = getWidgetDB(2000);
186 std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE_HREF);
188 LogDebug("license href is: " << tmp);
189 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_href_2000_en");
191 catch(const WrtDeviceApis::Commons::SecurityException &e)
193 LogError("Exception thrown." << e.DumpToString());
194 RUNNER_ASSERT(false);
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
203 RUNNER_TEST(widgetDB_test_get_config_value_author_name)
207 IWidgetDBPtr widget = getWidgetDB(2000);
208 std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_NAME);
210 LogDebug("author name is: " << tmp);
211 RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_name_2000");
213 catch(const WrtDeviceApis::Commons::SecurityException &e)
215 LogError("Exception thrown." << e.DumpToString());
216 RUNNER_ASSERT(false);
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
225 RUNNER_TEST(widgetDB_test_get_config_value_author_href)
229 IWidgetDBPtr widget = getWidgetDB(2000);
230 std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_HREF);
232 LogDebug("author href is: " << tmp);
233 RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_href_2000");
235 catch(const WrtDeviceApis::Commons::SecurityException &e)
237 LogError("Exception thrown." << e.DumpToString());
238 RUNNER_ASSERT(false);
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
247 RUNNER_TEST(widgetDB_test_get_config_value_author_email)
251 IWidgetDBPtr widget = getWidgetDB(2000);
252 std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_EMAIL);
254 LogDebug("author email is: " << tmp);
255 RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_email_2000");
257 catch(const WrtDeviceApis::Commons::SecurityException &e)
259 LogError("Exception thrown." << e.DumpToString());
260 RUNNER_ASSERT(false);
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
269 RUNNER_TEST(widgetDB_test_get_config_value_name)
273 IWidgetDBPtr widget = getWidgetDB(2000);
274 std::string tmp = widget->getConfigValue(ConfigAttribute::NAME);
276 LogDebug("name is: " << tmp);
277 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_name_2000_en");
279 catch(const WrtDeviceApis::Commons::SecurityException &e)
281 LogError("Exception thrown." << e.DumpToString());
282 RUNNER_ASSERT(false);
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
291 RUNNER_TEST(widgetDB_test_get_config_value_short_name)
295 IWidgetDBPtr widget = getWidgetDB(2000);
296 std::string tmp = widget->getConfigValue(ConfigAttribute::SHORT_NAME);
298 LogDebug("short name is: " << tmp);
299 RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_shortname_2000_en");
301 catch(const WrtDeviceApis::Commons::SecurityException &e)
303 LogError("Exception thrown." << e.DumpToString());
304 RUNNER_ASSERT(false);
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"
313 RUNNER_TEST(widgetDB_test_get_config_value_access_network)
317 IWidgetDBPtr widget = getWidgetDB(2000);
318 std::string tmp = widget->getConfigValue(
319 ConfigAttribute::ACCESS_NETWORK);
321 LogDebug("acces network is always true: " << tmp);
322 RUNNER_ASSERT_WHAT_EQUALS(tmp, "yes");
324 catch(const WrtDeviceApis::Commons::SecurityException &e)
326 LogError("Exception thrown." << e.DumpToString());
327 RUNNER_ASSERT(false);
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
336 RUNNER_TEST(widgetDB_test_get_config_value_width)
340 IWidgetDBPtr widget = getWidgetDB(2000);
341 std::string tmp = widget->getConfigValue(ConfigAttribute::WIDTH);
343 LogDebug("width is: " << tmp);
344 RUNNER_ASSERT_WHAT_EQUALS(tmp, "100");
346 catch(const WrtDeviceApis::Commons::SecurityException &e)
348 LogError("Exception thrown." << e.DumpToString());
349 RUNNER_ASSERT(false);
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
358 RUNNER_TEST(widgetDB_test_get_config_value_height)
362 IWidgetDBPtr widget = getWidgetDB(2000);
363 std::string tmp = widget->getConfigValue(ConfigAttribute::HEIGHT);
365 LogDebug("height is: " << tmp);
366 RUNNER_ASSERT_WHAT_EQUALS(tmp, "200");
368 catch(const WrtDeviceApis::Commons::SecurityException &e)
370 LogError("Exception thrown." << e.DumpToString());
371 RUNNER_ASSERT(false);
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
380 RUNNER_TEST(widgetDB_test_get_config_value_paths)
384 IWidgetDBPtr widget = getWidgetDB(2000);
385 std::string tmp = widget->getConfigValue(ConfigAttribute::INSTALL_PATH);
387 LogDebug("install path is: " << tmp);
389 tmp = widget->getConfigValue(
390 ConfigAttribute::PUBLIC_STORAGE_PATH);
392 LogDebug("public storage path is: " << tmp);
395 catch(const WrtDeviceApis::Commons::SecurityException &e)
397 LogDebug("Exception thrown." << e.DumpToString());
398 RUNNER_ASSERT(false);
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
407 RUNNER_TEST(widgetDB_test_get_config_value_empty)
411 IWidgetDBPtr widget = getWidgetDB(2005);
412 std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
414 //exception should be thrown
415 RUNNER_ASSERT(false);
418 catch(const WrtDeviceApis::Commons::SecurityException &e)
420 LogDebug("OK. Exception thrown." << e.DumpToString());
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
429 RUNNER_TEST(widgetDB_test_check_installation_status_installed)
433 IWidgetDBPtr widget = getWidgetDB(2000);
434 InstallationStatus tmp = widget->checkInstallationStatus(
435 "w_id_2000", "w_name_2000_en", "2.0.0");
437 RUNNER_ASSERT(tmp == InstallationStatus::STATUS_INSTALLED);
439 catch(const WrtDeviceApis::Commons::SecurityException &e)
441 LogError("Exception thrown." << e.DumpToString());
442 RUNNER_ASSERT(false);
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
451 RUNNER_TEST(widgetDB_test_check_installation_status_uninstalled)
455 IWidgetDBPtr widget = getWidgetDB(2000);
456 InstallationStatus tmp = widget->checkInstallationStatus(
457 "w_id_2011", "w_name_2000_en", "2.0.0");
459 RUNNER_ASSERT(tmp == InstallationStatus::STATUS_UNINSTALLED);
461 catch(const WrtDeviceApis::Commons::SecurityException &e)
463 LogError("Exception thrown." << e.DumpToString());
464 RUNNER_ASSERT(false);
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
473 RUNNER_TEST(widgetDB_test_check_installation_status_latest)
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");
483 RUNNER_ASSERT(tmp1 == InstallationStatus::STATUS_LATEST);
484 RUNNER_ASSERT(tmp2 == InstallationStatus::STATUS_LATEST);
486 catch(const WrtDeviceApis::Commons::SecurityException &e)
488 LogError("Exception thrown." << e.DumpToString());
489 RUNNER_ASSERT(false);
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
498 RUNNER_TEST(widgetDB_test_widget_feature)
502 IWidgetDBPtr widget = getWidgetDB(2000);
503 Features features = widget->getWidgetFeatures();
505 RUNNER_ASSERT(features.size() == 5);
507 FOREACH(it, features)
509 std::string name = (*it)->getName();
510 if ("first_2000" == name)
512 RUNNER_ASSERT((*it)->getParams().size() == 4);
514 RUNNER_ASSERT((*it)->isRequired());
516 else if ("second_2000" == name)
518 RUNNER_ASSERT((*it)->getParams().size() == 1);
520 else if ("third_2000" == name)
522 IWidgetFeature::Params params = (*it)->getParams();
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());
529 else if ("fourth_2000" == name)
531 RUNNER_ASSERT((*it)->getParams().size() == 0);
533 else if ("fifth_2000" == name)
535 RUNNER_ASSERT((*it)->getParams().size() == 0);
538 RUNNER_ASSERT(false);
541 catch(const WrtDeviceApis::Commons::SecurityException &e)
543 LogError("Exception thrown." << e.DumpToString());
544 RUNNER_ASSERT(false);
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
553 RUNNER_TEST(widgetDB_test_widget_feature2)
557 IWidgetDBPtr widget = getWidgetDB(2011); //no such widget
558 Features features = widget->getWidgetFeatures();
560 RUNNER_ASSERT(false);
562 catch(const WrtDeviceApis::Commons::SecurityException &e)
564 LogDebug("OK. Exception thrown." << e.DumpToString());
568 #undef RUNNER_ASSERT_WHAT_EQUALS