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");
90 * These tests are incompatible to the specification 2.1
91 * (but compatible to the specification 3.0).
94 //Name: unupdateOfSigned
95 //Description: Tests update that signed web app could be downgraded.
96 //Expected: Widget should not be updated.
98 //RUNNER_TEST(unupdateOfSigned)
100 // std::string tizenId;
101 // std::string wgtPath;
103 // wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
104 // RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
105 // "Failed to install widget");
107 // wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
108 // RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
109 // "Unupdate should be prohibited.");
110 // uninstall(tizenId);
114 //Name: unupdateOfSigned
115 //Description: Tests update that unsigned web app could be downgraded.
116 //Expected: Widget should not be updated.
118 //RUNNER_TEST(unupdateOfUnsigned)
120 // std::string tizenId;
121 // std::string wgtPath;
123 // wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
124 // RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
125 // "Failed to install widget");
127 // wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
128 // RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
129 // "Unupdate should be prohibited.");
130 // uninstall(tizenId);
134 Name: validUpdateOfCrossSigned
135 Description: Tests update the web app where one of widgets are signed and second not.
136 Expected: Widget should not be updated.
138 RUNNER_TEST(updateOfCrossSignedWidgets)
144 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt";
145 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
146 "Failed to install widget");
148 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
149 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
150 "The update unsigned app by the signed app should not be possible");
154 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
155 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
156 "Failed to install widget");
158 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt";
159 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
160 "The update signed app by the unsigned app should not be possible");
167 Name: updateAnotherAuthor
168 Description: Tests update the web app by the widget signed by another author.
169 Expected: Widget should not be updated.
171 RUNNER_TEST(updateAnotherAuthor)
176 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
177 RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId),
178 "Failed to install widget");
180 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220SignedAnotherAuthor.wgt";
181 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId),
182 "The update by another author should not be possible");
188 Name: updateWidgetDataRemember
189 Description: Tests of keeping app data during widget updating.
190 Expected: App data should be kept.
192 RUNNER_TEST(updateWidgetDataRemember)
197 // Installation of the widget
198 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt";
199 RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success,
200 "Failed to install widget");
203 std::string filePath = "/opt/usr/apps/HAdisUJ4Kn/data/test";
204 std::string text = "slonce swieci dzisiaj wyjatkowo wysoko";
205 std::string command = "echo " + text + " > " + filePath;
206 system(command.c_str());
208 // Second installation of the widget
209 wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt";
210 RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId),
211 "Failed update in case both programs are signed");
214 // Checking of the file created before
215 std::stringstream ss;
216 std::ifstream file(filePath);
217 RUNNER_ASSERT_MSG_SAFE(file.good(), "File is gone");
219 for( std::string line; getline( file, line ); ss << line);
221 RUNNER_ASSERT_MSG_SAFE(text == ss.str(), "Content of file is not the same");