2 * Copyright (c) 2013 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 WidgetUpdateTests.cpp
18 * @author Grzegorz Rynkowski (g.rynkowski@samsung.com)
20 * @brief Test a process of updating web applications.
24 #include <dpl/test/test_runner.h>
25 #include <InstallerWrapper.h>
28 using namespace InstallerWrapper;
30 #define RUNNER_ASSERT_MSG_SAFE(test, message) \
32 DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
37 std::ostringstream assertMsg; \
38 assertMsg << message; \
39 throw DPL::Test::TestRunner::TestFailed(#test, \
46 RUNNER_TEST_GROUP_INIT(WidgetUpdate)
49 Name: validUpdateOfSigned
50 Description: Tests update the web app where origin and a new one are signed.
51 Expected: Widget should be successfully installed.
53 RUNNER_TEST(validUpdateOfSigned)
58 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
59 RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
60 "Failed to install widget");
62 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
63 RUNNER_ASSERT_MSG_SAFE(install(wgtPath, tizenId) == InstallerWrapper::Success,
64 "Failed update in case both programs are signed");
69 Name: validUpdateOfUnsigned
70 Description: Tests update the web app where origin and a new one are unsigned.
71 Expected: Widget should be successfully updated.
73 RUNNER_TEST(validUpdateOfUnsigned)
78 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
79 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
80 "Failed to install widget");
82 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
83 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
84 "Failed update in case both programs are signed");
89 Name: unupdateOfSigned
90 Description: Tests update that signed web app could be downgraded.
91 Expected: Widget should not be updated.
93 RUNNER_TEST(unupdateOfSigned)
98 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
99 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
100 "Failed to install widget");
102 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
103 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
104 "Unupdate should be prohibited.");
109 Name: unupdateOfSigned
110 Description: Tests update that unsigned web app could be downgraded.
111 Expected: Widget should not be updated.
113 RUNNER_TEST(unupdateOfUnsigned)
118 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
119 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
120 "Failed to install widget");
122 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
123 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
124 "Unupdate should be prohibited.");
129 Name: validUpdateOfCrossSigned
130 Description: Tests update the web app where one of widgets are signed and second not.
131 Expected: Widget should not be updated.
133 RUNNER_TEST(updateOfCrossSignedWidgets)
139 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
140 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
141 "Failed to install widget");
143 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
144 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
145 "The update unsigned app by the signed app should not be possible");
149 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
150 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
151 "Failed to install widget");
153 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
154 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
155 "The update signed app by the unsigned app should not be possible");
162 Name: updateAnotherAuthor
163 Description: Tests update the web app by the widget signed by another author.
164 Expected: Widget should not be updated.
166 RUNNER_TEST(updateAnotherAuthor)
171 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
172 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
173 "Failed to install widget");
175 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220SignedAnotherAuthor.wgt";
176 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
177 "The update by another author should not be possible");
183 Name: updateWidgetDataRemember
184 Description: Tests of keeping app data during widget updating.
185 Expected: App data should be kept.
187 RUNNER_TEST(updateWidgetDataRemember)
192 // Installation of the widget
193 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
194 RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
195 "Failed to install widget");
198 std::string filePath = "/opt/usr/apps/HAdisUJ4Kn/data/test";
199 std::string text = "slonce swieci dzisiaj wyjatkowo wysoko";
200 std::string command = "echo " + text + " > " + filePath;
201 system(command.c_str());
203 // Second installation of the widget
204 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
205 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
206 "Failed update in case both programs are signed");
209 // Checking of the file created before
210 std::stringstream ss;
211 std::ifstream file(filePath);
212 RUNNER_ASSERT_MSG_SAFE(file.good(), "File is gone");
214 for( std::string line; getline( file, line ); ss << line);
216 RUNNER_ASSERT_MSG_SAFE(text == ss.str(), "Content of file is not the same");