[Release] wrt-plugins-common_0.3.79
[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         IWidgetDBPtr widget = getWidgetDB(2000);
51         std::string lang = widget->getLanguage();
52
53         LogDebug("language is: " << lang);
54         RUNNER_ASSERT_WHAT_EQUALS(lang, "en");
55     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
56         LogError("Exception thrown." << e.DumpToString());
57         RUNNER_ASSERT(false);
58     }
59 }
60
61 /*
62  * Name: widgetDB_test_get_language2
63  * Description: check language returned by WidgetDB if widget does nto exists
64  * Expected: result should be ""
65  */
66 RUNNER_TEST(widgetDB_test_get_language2)
67 {
68     try {
69         IWidgetDBPtr widget = getWidgetDB(1000); //widget not exist
70         std::string lang = widget->getLanguage();
71
72         LogDebug("language is: " << lang);
73         RUNNER_ASSERT_WHAT_EQUALS(lang, "");
74     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
75         LogError("Exception thrown." << e.DumpToString());
76         RUNNER_ASSERT(false);
77     }
78 }
79
80 /*
81  * Name: widgetDB_test_get_config_value_id
82  * Description: check GUID returned by WidgetDB
83  * Expected: GUID should match this, which was inserted into widget database
84  */
85 RUNNER_TEST(widgetDB_test_get_config_value_id)
86 {
87     try {
88         IWidgetDBPtr widget = getWidgetDB(2000);
89         std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
90
91         LogDebug("id is: " << tmp);
92         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_id_2000");
93     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
94         LogError("Exception thrown." << e.DumpToString());
95         RUNNER_ASSERT(false);
96     }
97 }
98
99 /*
100  * Name: widgetDB_test_get_config_value_version
101  * Description: check version returned by WidgetDB
102  * Expected: version should match this, which was inserted into widget database
103  */
104 RUNNER_TEST(widgetDB_test_get_config_value_version)
105 {
106     try {
107         IWidgetDBPtr widget = getWidgetDB(2000);
108         std::string tmp = widget->getConfigValue(ConfigAttribute::VERSION);
109
110         LogDebug("version is: " << tmp);
111         RUNNER_ASSERT_WHAT_EQUALS(tmp, "1.0.0");
112     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
113         LogError("Exception thrown." << e.DumpToString());
114         RUNNER_ASSERT(false);
115     }
116 }
117
118 /*
119  * Name: widgetDB_test_get_config_value_description
120  * Description: check description returned by WidgetDB
121  * Expected: description should match this, which was inserted into widget
122  * database
123  */
124 RUNNER_TEST(widgetDB_test_get_config_value_description)
125 {
126     try {
127         IWidgetDBPtr widget = getWidgetDB(2000);
128         std::string tmp = widget->getConfigValue(ConfigAttribute::DESCRIPTION);
129
130         LogDebug("description is: " << tmp);
131         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_desc_2000_en");
132     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
133         LogError("Exception thrown." << e.DumpToString());
134         RUNNER_ASSERT(false);
135     }
136 }
137
138 /*
139  * Name: widgetDB_test_get_config_value_license
140  * Description: check license returned by WidgetDB
141  * Expected: license should match this, which was inserted into widget database
142  */
143 RUNNER_TEST(widgetDB_test_get_config_value_license)
144 {
145     try {
146         IWidgetDBPtr widget = getWidgetDB(2000);
147         std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE);
148
149         LogDebug("licence is: " << tmp);
150         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_2000_en");
151     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
152         LogError("Exception thrown." << e.DumpToString());
153         RUNNER_ASSERT(false);
154     }
155 }
156
157 /*
158  * Name: widgetDB_test_get_config_value_license_href
159  * Description: check license href returned by WidgetDB
160  * Expected: license href should match this, which was inserted into widget
161  * database
162  */
163 RUNNER_TEST(widgetDB_test_get_config_value_license_href)
164 {
165     try {
166         IWidgetDBPtr widget = getWidgetDB(2000);
167         std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE_HREF);
168
169         LogDebug("license href is: " << tmp);
170         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_href_2000_en");
171     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
172         LogError("Exception thrown." << e.DumpToString());
173         RUNNER_ASSERT(false);
174     }
175 }
176
177 /*
178  * Name: widgetDB_test_get_config_value_author_name
179  * Description: check author name href returned by WidgetDB
180  * Expected: author name should match this, which was inserted into widget
181  * database
182  */
183 RUNNER_TEST(widgetDB_test_get_config_value_author_name)
184 {
185     try {
186         IWidgetDBPtr widget = getWidgetDB(2000);
187         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_NAME);
188
189         LogDebug("author name is: " << tmp);
190         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_name_2000");
191     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
192         LogError("Exception thrown." << e.DumpToString());
193         RUNNER_ASSERT(false);
194     }
195 }
196
197 /*
198  * Name: widgetDB_test_get_config_value_author_href
199  * Description: check author href returned by WidgetDB
200  * Expected: author href should match this, which was inserted into widget
201  * database
202  */
203 RUNNER_TEST(widgetDB_test_get_config_value_author_href)
204 {
205     try {
206         IWidgetDBPtr widget = getWidgetDB(2000);
207         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_HREF);
208
209         LogDebug("author href is: " << tmp);
210         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_href_2000");
211     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
212         LogError("Exception thrown." << e.DumpToString());
213         RUNNER_ASSERT(false);
214     }
215 }
216
217 /*
218  * Name: widgetDB_test_get_config_value_author_email
219  * Description: check author email returned by WidgetDB
220  * Expected: author email should match this, which was inserted into widget
221  * database
222  */
223 RUNNER_TEST(widgetDB_test_get_config_value_author_email)
224 {
225     try {
226         IWidgetDBPtr widget = getWidgetDB(2000);
227         std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_EMAIL);
228
229         LogDebug("author email is: " << tmp);
230         RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_email_2000");
231     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
232         LogError("Exception thrown." << e.DumpToString());
233         RUNNER_ASSERT(false);
234     }
235 }
236
237 /*
238  * Name: widgetDB_test_get_config_value_name
239  * Description: check localized widget name returned by WidgetDB
240  * Expected: localized widget name should match this, which was inserted into
241  * widget database
242  */
243 RUNNER_TEST(widgetDB_test_get_config_value_name)
244 {
245     try {
246         IWidgetDBPtr widget = getWidgetDB(2000);
247         std::string tmp = widget->getConfigValue(ConfigAttribute::NAME);
248
249         LogDebug("name is: " << tmp);
250         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_name_2000_en");
251     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
252         LogError("Exception thrown." << e.DumpToString());
253         RUNNER_ASSERT(false);
254     }
255 }
256
257 /*
258  * Name: widgetDB_test_get_config_value_short_name
259  * Description: check localized widget short name returned by WidgetDB
260  * Expected: localized widget short name should match this, which was inserted
261  * into widget database
262  */
263 RUNNER_TEST(widgetDB_test_get_config_value_short_name)
264 {
265     try {
266         IWidgetDBPtr widget = getWidgetDB(2000);
267         std::string tmp = widget->getConfigValue(ConfigAttribute::SHORT_NAME);
268
269         LogDebug("short name is: " << tmp);
270         RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_shortname_2000_en");
271     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
272         LogError("Exception thrown." << e.DumpToString());
273         RUNNER_ASSERT(false);
274     }
275 }
276
277 /*
278  * Name: widgetDB_test_get_config_value_access_network
279  * Description: check network access returned by WidgetDB
280  * Expected: network access should be set to "yes"
281  */
282 RUNNER_TEST(widgetDB_test_get_config_value_access_network)
283 {
284     try {
285         IWidgetDBPtr widget = getWidgetDB(2000);
286         std::string tmp = widget->getConfigValue(
287                 ConfigAttribute::ACCESS_NETWORK);
288
289         LogDebug("acces network is always true: " << tmp);
290         RUNNER_ASSERT_WHAT_EQUALS(tmp, "yes");
291     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
292         LogError("Exception thrown." << e.DumpToString());
293         RUNNER_ASSERT(false);
294     }
295 }
296
297 /*
298  * Name: widgetDB_test_get_config_value_width
299  * Description: check widget prefered width returned by WidgetDB
300  * Expected: widget prefered width should match this, which was inserted into
301  * widget database
302  */
303 RUNNER_TEST(widgetDB_test_get_config_value_width)
304 {
305     try {
306         IWidgetDBPtr widget = getWidgetDB(2000);
307         std::string tmp = widget->getConfigValue(ConfigAttribute::WIDTH);
308
309         LogDebug("width is: " << tmp);
310         RUNNER_ASSERT_WHAT_EQUALS(tmp, "100");
311     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
312         LogError("Exception thrown." << e.DumpToString());
313         RUNNER_ASSERT(false);
314     }
315 }
316
317 /*
318  * Name: widgetDB_test_get_config_value_height
319  * Description: check widget prefered height returned by WidgetDB
320  * Expected: widget prefered height should match this, which was inserted into
321  * widget database
322  */
323 RUNNER_TEST(widgetDB_test_get_config_value_height)
324 {
325     try {
326         IWidgetDBPtr widget = getWidgetDB(2000);
327         std::string tmp = widget->getConfigValue(ConfigAttribute::HEIGHT);
328
329         LogDebug("height is: " << tmp);
330         RUNNER_ASSERT_WHAT_EQUALS(tmp, "200");
331     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
332         LogError("Exception thrown." << e.DumpToString());
333         RUNNER_ASSERT(false);
334     }
335 }
336
337 /*
338  * Name: widgetDB_test_get_config_value_paths
339  * Description: check widget installation path returned by WidgetDB
340  * Expected: widget installation path should match this, which was inserted into
341  * widget database
342  */
343 RUNNER_TEST(widgetDB_test_get_config_value_paths)
344 {
345     try {
346         IWidgetDBPtr widget = getWidgetDB(2000);
347         std::string tmp = widget->getConfigValue(ConfigAttribute::INSTALL_PATH);
348
349         LogDebug("install path is: " << tmp);
350
351         tmp = widget->getConfigValue(
352                 ConfigAttribute::PUBLIC_STORAGE_PATH);
353
354         LogDebug("public storage path is: " << tmp);
355     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
356         LogDebug("Exception thrown." << e.DumpToString());
357         RUNNER_ASSERT(false);
358     }
359 }
360
361 /*
362  * Name: widgetDB_test_get_config_value_empty
363  * Description: check if requesting GUID from WidgetDB throw excpetion if widget
364  * does not exists
365  * Expected: accessing GUID should throw
366  * WrtDeviceApis::Commons::SecurityException
367  */
368 RUNNER_TEST(widgetDB_test_get_config_value_empty)
369 {
370     try {
371         IWidgetDBPtr widget = getWidgetDB(2005);
372         widget->getConfigValue(ConfigAttribute::ID);
373
374         //exception should be thrown
375         RUNNER_ASSERT(false);
376     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
377         LogDebug("OK. Exception thrown." << e.DumpToString());
378     }
379 }
380
381 /*
382  * Name: widgetDB_test_check_installation_status_installed
383  * Description: check if widget is installed by WidgetDB
384  * Expected: plugin should be notified that widget is installed
385  */
386 RUNNER_TEST(widgetDB_test_check_installation_status_installed)
387 {
388     try {
389         IWidgetDBPtr widget = getWidgetDB(2000);
390         InstallationStatus tmp = widget->checkInstallationStatus(
391                 "w_id_2000", "w_name_2000_en", "2.0.0");
392
393         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_INSTALLED);
394     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
395         LogError("Exception thrown." << e.DumpToString());
396         RUNNER_ASSERT(false);
397     }
398 }
399
400 /*
401  * Name: widgetDB_test_check_installation_status_uninstalled
402  * Description: check if widget is not installed by WidgetDB
403  * Expected: plugin should be notified that widget is not installed
404  */
405 RUNNER_TEST(widgetDB_test_check_installation_status_uninstalled)
406 {
407     try {
408         IWidgetDBPtr widget = getWidgetDB(2000);
409         InstallationStatus tmp = widget->checkInstallationStatus(
410                 "w_id_2011", "w_name_2000_en", "2.0.0");
411
412         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_UNINSTALLED);
413     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
414         LogError("Exception thrown." << e.DumpToString());
415         RUNNER_ASSERT(false);
416     }
417 }
418
419 /*
420  * Name: widgetDB_test_check_installation_status_latest
421  * Description: check if widget installation information is taken from latest
422  * version
423  * Expected: plugin installation status should be same is both calls of WidgetDB
424  */
425 RUNNER_TEST(widgetDB_test_check_installation_status_latest)
426 {
427     try {
428         IWidgetDBPtr widget = getWidgetDB(2000);
429         InstallationStatus tmp1 = widget->checkInstallationStatus(
430                 "w_id_2000", "w_name_2000_en", "0.1.0");
431         InstallationStatus tmp2 = widget->checkInstallationStatus(
432                 "w_id_2000", "w_name_2000_en", "1.0.0");
433
434         RUNNER_ASSERT(tmp1 == InstallationStatus::STATUS_LATEST);
435         RUNNER_ASSERT(tmp2 == InstallationStatus::STATUS_LATEST);
436     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
437         LogError("Exception thrown." << e.DumpToString());
438         RUNNER_ASSERT(false);
439     }
440 }
441
442 #undef RUNNER_ASSERT_WHAT_EQUALS