[Release]wrt-installer_0.1.6
[framework/web/wrt-installer.git] / tests / general / TestCases.cpp
1 /*
2  * Copyright (c) 2013 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    TestCases.cpp
18  * @author  Karol Pawlowski (k.pawlowski@samsung.com)
19  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
20  * @version 1.0
21  * @brief   Miscellaneous test's bodies
22  */
23
24 #include <string>
25 #include <dpl/utils/wrt_utility.h>
26 #include <dpl/test/test_runner.h>
27 #include <dpl/log/log.h>
28 #include <InstallerWrapper.h>
29 #include <ManifestFile.h>
30
31 using namespace InstallerWrapper;
32
33 namespace {
34
35 const std::string miscWidgetsStuff = "/opt/share/widget/tests/misc/";
36
37 struct Result {
38     bool m_exc;
39     bool m_exd;
40     bool m_exs;
41     std::string message;
42     Result(bool exc = false, bool exd = false, bool exs = false)
43         : m_exc(exc), m_exd(exd), m_exs(exs) {}
44 };
45
46 }
47
48 ////////////////////////////////////////////////////////////////////////////////
49
50 RUNNER_TEST_GROUP_INIT(Manifest)
51
52 /*
53 Name: creatingManifestFile
54 Description: Creation of manifest file by wrt-installer test
55 Expected: file should be created and installed by wrt-installer. Content should
56  match expected values
57 */
58 RUNNER_TEST(creatingManifestFile)
59 {
60     const char * manifestPath = "/opt/share/packages/manifest01.xml";
61     /* This widget removal should stay here in case previous test run failed
62      * (so widget has not been uninstalled) */
63     uninstallByGuid("http://test.samsung.com/widget/manifestTest");
64     std::string tizenId;
65     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/manifest.wgt", tizenId)
66             == InstallerWrapper::Success);
67     RUNNER_ASSERT(WrtUtilFileExists(manifestPath));
68     ManifestFile mf(manifestPath);
69
70     Try
71     {
72         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@package")
73                       == "manifest01");
74         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@type")
75                       == "wgt");
76         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@version")
77                       == "1.0");
78         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:label")
79                       == "Manifest Example");
80
81         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@email")
82                       == "manifest@misc.test.create.desktop.com");
83         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@href")
84                       == "http://misc.test.create.desktop.com");
85         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author")
86                       == "Manifest");
87
88         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@appid")
89                       == "manifest01");
90         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@nodisplay")
91                       == "false");
92         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@type")
93                       == "webapp");
94         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@extraid")
95                       == "http://test.samsung.com/widget/manifestTest");
96         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@taskmanage")
97                       == "true");
98
99         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:icon")
100                       == "manifest01.png");
101
102         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[not(@xml:lang)]")
103                       == "Manifest Example");
104         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='de_DE']")
105                       == "Manifest Beispiel");
106         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='en_US']")
107                       == "Manifest Example");
108         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pl']")
109                       == "PrzykĹ‚ad Manifest");
110         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pt_PT']")
111                       == "Exemplo manifesto");
112     }
113     Catch(ManifestFile::ManifestParseError)
114     {
115         RUNNER_ASSERT_MSG(false,DPL::Exception::KnownExceptionToString(_rethrown_exception));
116     }
117     /* If test finished sucessfully than uninstall test widget */
118     uninstall(tizenId);
119 }
120
121 ////////////////////////////////////////////////////////////////////////////////
122
123 RUNNER_TEST_GROUP_INIT(BackgroundPage)
124
125 /*
126 Name: widgetWithBackgroundPage
127 Description: Tests if widget with background page is installed correctly
128 Expected: widget should be installed correctly
129 */
130 RUNNER_TEST(widgetWithBackgroundPage)
131 {
132     std::string tizenId;
133     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-00-with_bg.wgt",
134             tizenId) == InstallerWrapper::Success);
135     uninstall(tizenId);
136 }
137
138 /*
139 Name: missingBackgroundFile
140 Description: Tests if widget with declared in conifg background page
141  but missing background file will be installed correctly.
142 Expected: widget should NOT be installed
143 */
144 RUNNER_TEST(missingBackgroundFile)
145 {
146     std::string tizenId;
147     if(install(miscWidgetsStuff + "widgets/bg-01-missing_file.wgt",
148             tizenId) == InstallerWrapper::Success) {
149         uninstall(tizenId);
150         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
151     }
152 }
153
154 /*
155 Name: widgetWithoutBackgroundPage
156 Description: Complementary test to check if normal widget\
157  without background page is successfully installed
158 Expected: widget should be installed
159 */
160 RUNNER_TEST(widgetWithoutBackgroundPage)
161 {
162     std::string tizenId;
163     RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-02-without_bg.wgt",
164             tizenId) == InstallerWrapper::Success);
165     uninstall(tizenId);
166 }
167
168 ////////////////////////////////////////////////////////////////////////////////
169
170 RUNNER_TEST_GROUP_INIT(NonRootUser)
171
172 /*
173 Name: widgetNonRootInstallation
174 Description: Check installation from other user than root
175 Expected: widget should be installed
176 */
177 RUNNER_TEST(widgetNonRootInstallation)
178 {
179     std::string tizenId;
180     RUNNER_ASSERT(install(
181                 miscWidgetsStuff + "widgets/nonroot.wgt",
182                 tizenId,
183                 "app") == InstallerWrapper::Success);
184     uninstall(tizenId);
185 }
186
187 ////////////////////////////////////////////////////////////////////////////////
188
189 RUNNER_TEST_GROUP_INIT(NPluginsInstall)
190
191 /*
192 Name: pluginFilesAdded
193 Description: Tests installation of plugins attached to widget
194 Expected: widget should be succesfully installed
195 */
196 RUNNER_TEST(pluginFilesAdded)
197 {
198     std::string tizenId;
199     RUNNER_ASSERT(install(miscWidgetsStuff
200             + "widgets/inst_nplug_1.wgt", tizenId) == InstallerWrapper::Success);
201     uninstall(tizenId);
202 }
203
204 /*
205 Name: emptyPluginsDir
206 Description: Tests installation with empty 'plugins' directory
207 Expected: widget should be not installed
208 */
209 RUNNER_TEST(emptyPluginsDir)
210 {
211     std::string tizenId;
212     if(install(miscWidgetsStuff + "widgets/inst_nplug_2.wgt",
213             tizenId) == InstallerWrapper::Success) {
214         uninstall(tizenId);
215         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
216     }
217 }
218
219 /*
220 Name: pluginFileAndOtherFile
221 Description: Tests installation with plugins directory and data files
222 Expected: widget should be installed
223 */
224 RUNNER_TEST(pluginFileAndOtherFile)
225 {
226     std::string tizenId;
227     RUNNER_ASSERT(install(miscWidgetsStuff
228             + "widgets/inst_nplug_3.wgt", tizenId) == InstallerWrapper::Success);
229     uninstall(tizenId);
230 }
231
232 /*
233 Name: pluginFileAndSubdir
234 Description: Tests installation with 'plugins' directory and subdirectories
235  inside plugin directory
236 Expected: widget should be not installed
237 */
238 RUNNER_TEST(pluginFileAndSubdir)
239 {
240     std::string tizenId;
241     if(install(miscWidgetsStuff + "widgets/inst_nplug_4.wgt",
242             tizenId) == InstallerWrapper::Success) {
243         uninstall(tizenId);
244         RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
245     }
246 }