Initialize Tizen 2.3
[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_width
279  * Description: check widget prefered width returned by WidgetDB
280  * Expected: widget prefered width should match this, which was inserted into
281  * widget database
282  */
283 RUNNER_TEST(widgetDB_test_get_config_value_width)
284 {
285     try {
286         IWidgetDBPtr widget = getWidgetDB(2000);
287         std::string tmp = widget->getConfigValue(ConfigAttribute::WIDTH);
288
289         LogDebug("width is: " << tmp);
290         RUNNER_ASSERT_WHAT_EQUALS(tmp, "100");
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_height
299  * Description: check widget prefered height returned by WidgetDB
300  * Expected: widget prefered height should match this, which was inserted into
301  * widget database
302  */
303 RUNNER_TEST(widgetDB_test_get_config_value_height)
304 {
305     try {
306         IWidgetDBPtr widget = getWidgetDB(2000);
307         std::string tmp = widget->getConfigValue(ConfigAttribute::HEIGHT);
308
309         LogDebug("height is: " << tmp);
310         RUNNER_ASSERT_WHAT_EQUALS(tmp, "200");
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_paths
319  * Description: check widget installation path returned by WidgetDB
320  * Expected: widget installation path should match this, which was inserted into
321  * widget database
322  */
323 RUNNER_TEST(widgetDB_test_get_config_value_paths)
324 {
325     try {
326         IWidgetDBPtr widget = getWidgetDB(2000);
327         std::string tmp = widget->getConfigValue(ConfigAttribute::INSTALL_PATH);
328
329         LogDebug("install path is: " << tmp);
330
331         tmp = widget->getConfigValue(
332                 ConfigAttribute::PUBLIC_STORAGE_PATH);
333
334         LogDebug("public storage path is: " << tmp);
335     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
336         LogDebug("Exception thrown." << e.DumpToString());
337         RUNNER_ASSERT(false);
338     }
339 }
340
341 /*
342  * Name: widgetDB_test_get_config_value_empty
343  * Description: check if requesting GUID from WidgetDB throw excpetion if widget
344  * does not exists
345  * Expected: accessing GUID should throw
346  * WrtDeviceApis::Commons::SecurityException
347  */
348 RUNNER_TEST(widgetDB_test_get_config_value_empty)
349 {
350     try {
351         IWidgetDBPtr widget = getWidgetDB(2005);
352         widget->getConfigValue(ConfigAttribute::ID);
353
354         //exception should be thrown
355         RUNNER_ASSERT(false);
356     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
357         LogDebug("OK. Exception thrown." << e.DumpToString());
358     }
359 }
360
361 /*
362  * Name: widgetDB_test_check_installation_status_installed
363  * Description: check if widget is installed by WidgetDB
364  * Expected: plugin should be notified that widget is installed
365  */
366 RUNNER_TEST(widgetDB_test_check_installation_status_installed)
367 {
368     try {
369         IWidgetDBPtr widget = getWidgetDB(2000);
370         InstallationStatus tmp = widget->checkInstallationStatus(
371                 "w_id_2000", "w_name_2000_en", "2.0.0");
372
373         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_INSTALLED);
374     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
375         LogError("Exception thrown." << e.DumpToString());
376         RUNNER_ASSERT(false);
377     }
378 }
379
380 /*
381  * Name: widgetDB_test_check_installation_status_uninstalled
382  * Description: check if widget is not installed by WidgetDB
383  * Expected: plugin should be notified that widget is not installed
384  */
385 RUNNER_TEST(widgetDB_test_check_installation_status_uninstalled)
386 {
387     try {
388         IWidgetDBPtr widget = getWidgetDB(2000);
389         InstallationStatus tmp = widget->checkInstallationStatus(
390                 "w_id_2011", "w_name_2000_en", "2.0.0");
391
392         RUNNER_ASSERT(tmp == InstallationStatus::STATUS_UNINSTALLED);
393     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
394         LogError("Exception thrown." << e.DumpToString());
395         RUNNER_ASSERT(false);
396     }
397 }
398
399 /*
400  * Name: widgetDB_test_check_installation_status_latest
401  * Description: check if widget installation information is taken from latest
402  * version
403  * Expected: plugin installation status should be same is both calls of WidgetDB
404  */
405 RUNNER_TEST(widgetDB_test_check_installation_status_latest)
406 {
407     try {
408         IWidgetDBPtr widget = getWidgetDB(2000);
409         InstallationStatus tmp1 = widget->checkInstallationStatus(
410                 "w_id_2000", "w_name_2000_en", "0.1.0");
411         InstallationStatus tmp2 = widget->checkInstallationStatus(
412                 "w_id_2000", "w_name_2000_en", "1.0.0");
413
414         RUNNER_ASSERT(tmp1 == InstallationStatus::STATUS_LATEST);
415         RUNNER_ASSERT(tmp2 == InstallationStatus::STATUS_LATEST);
416     } catch (const WrtDeviceApis::Commons::SecurityException &e) {
417         LogError("Exception thrown." << e.DumpToString());
418         RUNNER_ASSERT(false);
419     }
420 }
421
422 #undef RUNNER_ASSERT_WHAT_EQUALS