2 * Copyright (c) 2014 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 TaskConfigurationTests.cpp
18 * @author Dominik Duda (d.duda@samsung.com)
20 * @brief Tests functions from
21 * wrt-installer/src/jobs/widget_install/task_configuration.cpp
24 #include <installer_log.h>
25 #include <InstallerWrapper.h>
26 #include <dpl/utils/wrt_utility.h>
27 #include <dpl/test/test_runner.h>
28 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
29 #include <widget_install/widget_install_errors.h>
30 #include <widget_install/widget_installer_struct.h>
31 #include <widget_install/task_configuration.h>
32 #include <widget_install/job_widget_install.h>
33 #include <installer_callbacks_translate.h>
34 #include <pkg-manager/pkgmgr_signal_dummy.h>
38 using namespace WidgetInstall;
40 RUNNER_TEST_GROUP_INIT(TaskConfiguration)
43 const std::string wgtTmpPath = "/tmp/J7ZwBudste";
44 const std::string wgtPath = InstallerWrapper::miscWidgetsStuff +
45 "widgets/widgetUpdateVer100Signed.wgt";
46 const std::string tarCMD = "tar -xf " + InstallerWrapper::miscWidgetsStuff +
47 "widgets/widgetInDir.tar -C /tmp";
51 void staticWrtInitPreloadStatusCallback(std::string tizenId, WrtErrStatus status,
59 Name: task_configuration_test_01
60 Description: Installs widget which is needed for further tests.
61 This installation will test standard use of the TaskConfiguration class.
62 Expected: The widget should be successfully installed.
64 RUNNER_TEST(task_configuration_test_01)
66 //Install the widget to get a tizenID
67 InstallerWrapper::install(wgtPath, tizenId);
69 //Uninstall the widget in order to be sure that a next installation
71 RUNNER_ASSERT_MSG(InstallerWrapper::uninstall(tizenId),
72 "Failed to uninstall a widget");
74 //That will be the first installation of the widget.
76 InstallerWrapper::install(wgtPath, tizenId) == InstallerWrapper::Success,
77 "Failed to install a widget");
81 Name: task_configuration_test_02
82 Description: Tests recognizing an update installation.
83 Expected: All task configration steps should be completed without errors.
85 RUNNER_TEST(task_configuration_test_02)
87 const WidgetInstallationStruct installerStruct(
88 InstallerCallbacksTranslate::installFinishedCallback,
89 InstallerCallbacksTranslate::installProgressCallback,
90 new InstallerCallbacksTranslate::StatusCallbackStruct(
91 NULL, &staticWrtInitPreloadStatusCallback, NULL),
93 std::make_shared<PackageManager::PkgmgrSignalDummy>());
95 InstallerContext i_context;
97 i_context.mode = InstallMode();
98 i_context.requestedPath = wgtPath;
99 i_context.job = new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
102 TaskConfiguration taskConf(i_context);
103 size_t stepsCnt = taskConf.GetStepCount();
108 while(i < stepsCnt && result)
111 result = taskConf.NextStep();
114 RUNNER_ASSERT(i == stepsCnt);
118 Name: task_configuration_test_03
119 Description: Tests widget installation with incorrect config.xml file.
120 Expected: Task configuration process should throw an exception when parsing
123 RUNNER_TEST(task_configuration_test_03)
125 const WidgetInstallationStruct installerStruct(
126 InstallerCallbacksTranslate::installFinishedCallback,
127 InstallerCallbacksTranslate::installProgressCallback,
128 new InstallerCallbacksTranslate::StatusCallbackStruct(
129 NULL, &staticWrtInitPreloadStatusCallback, NULL),
131 std::make_shared<PackageManager::PkgmgrSignalDummy>());
133 InstallerContext i_context;
135 i_context.mode = InstallMode();
136 i_context.requestedPath = InstallerWrapper::miscWidgetsStuff + "widgets/widgetFakeConfig.wgt";
139 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
142 TaskConfiguration taskConf(i_context);
143 size_t stepsCnt = taskConf.GetStepCount();
149 while(i < stepsCnt && result)
152 result = taskConf.NextStep();
155 Catch(WidgetInstall::Exceptions::WidgetConfigFileInvalid){
156 RUNNER_ASSERT(i == 4);
160 RUNNER_ASSERT_MSG(false,
161 "An Exception should be thrown if config.xml file is incorrect.");
165 Name: task_configuration_test_04
166 Description: Tests task configuration for widget installation directly from
168 Expected: Widget should be successfully installed.
170 RUNNER_TEST(task_configuration_test_04)
172 int ret = system(tarCMD.c_str());
174 RUNNER_ASSERT_MSG(!WIFEXITED(ret) || !WIFSIGNALED(ret),
175 "Cannot untar a widget to check direct installation from the directory!");
177 const WidgetInstallationStruct installerStruct(
178 InstallerCallbacksTranslate::installFinishedCallback,
179 InstallerCallbacksTranslate::installProgressCallback,
180 new InstallerCallbacksTranslate::StatusCallbackStruct(
181 NULL, &staticWrtInitPreloadStatusCallback, NULL),
183 std::make_shared<PackageManager::PkgmgrSignalDummy>());
185 InstallerContext i_context;
187 i_context.mode = InstallMode();
188 i_context.mode.extension = InstallMode::ExtensionType::DIR;
189 i_context.requestedPath = wgtTmpPath;
192 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
195 TaskConfiguration taskConf(i_context);
196 size_t stepsCnt = taskConf.GetStepCount();
201 while(i < stepsCnt && result)
204 result = taskConf.NextStep();
207 RUNNER_ASSERT(i == stepsCnt);
211 Name: task_configuration_test_05
212 Description: Tests if an exception will ocure when there is no config.xml file
213 in the widget directory.
214 Expected: An exception should be thrown.
216 RUNNER_TEST(task_configuration_test_05)
218 int ret = system(tarCMD.c_str());
220 RUNNER_ASSERT_MSG(!WIFEXITED(ret) || !WIFSIGNALED(ret),
221 "Cannot untar widget to check direct installation from directory!");
223 const WidgetInstallationStruct installerStruct(
224 InstallerCallbacksTranslate::installFinishedCallback,
225 InstallerCallbacksTranslate::installProgressCallback,
226 new InstallerCallbacksTranslate::StatusCallbackStruct(
227 NULL, &staticWrtInitPreloadStatusCallback, NULL),
229 std::make_shared<PackageManager::PkgmgrSignalDummy>());
231 InstallerContext i_context;
233 i_context.mode = InstallMode();
234 i_context.mode.extension = InstallMode::ExtensionType::DIR;
235 i_context.requestedPath = wgtTmpPath + "/TestWgt.wgt";
238 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
241 TaskConfiguration taskConf(i_context);
242 size_t stepsCnt = taskConf.GetStepCount();
248 while(i < stepsCnt && result)
255 RUNNER_ASSERT(WrtUtilRemove(wgtTmpPath + "/config.xml"));
258 result = taskConf.NextStep();
261 Catch(WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist){
262 RUNNER_ASSERT(i == 3);
266 RUNNER_ASSERT_MSG(false,
267 "An Exception should be thrown after deletion of config.xml file.");
271 Name: task_configuration_test_06
272 Description: Tests if missing config file will be detected during parsing step.
273 Expected: An exception should be thrown if there is no config file.
275 RUNNER_TEST(task_configuration_test_06)
277 int ret = system(tarCMD.c_str());
279 RUNNER_ASSERT_MSG(!WIFEXITED(ret) || !WIFSIGNALED(ret),
280 "Cannot untar widget to check direct installation from directory!");
282 const WidgetInstallationStruct installerStruct(
283 InstallerCallbacksTranslate::installFinishedCallback,
284 InstallerCallbacksTranslate::installProgressCallback,
285 new InstallerCallbacksTranslate::StatusCallbackStruct(
286 NULL, &staticWrtInitPreloadStatusCallback, NULL),
288 std::make_shared<PackageManager::PkgmgrSignalDummy>());
290 InstallerContext i_context;
292 i_context.mode = InstallMode();
293 i_context.mode.extension = InstallMode::ExtensionType::DIR;
294 i_context.requestedPath = wgtTmpPath;
297 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
300 TaskConfiguration taskConf(i_context);
301 size_t stepsCnt = taskConf.GetStepCount();
307 while(i < stepsCnt && result)
314 RUNNER_ASSERT(WrtUtilRemove(wgtTmpPath + "/config.xml"));
317 result = taskConf.NextStep();
320 Catch(WidgetInstall::Exceptions::MissingConfig){
321 RUNNER_ASSERT(i == 4);
325 RUNNER_ASSERT_MSG(false,
326 "An Exception should be thrown in parsing step if there is no "
327 "config.xml file in the directory.");
331 Name: task_configuration_test_07
332 Description: Tests reinstallation of a widget from the directory.
333 Expected: A widget should be successfully installed.
335 RUNNER_TEST(task_configuration_test_07)
337 int ret = system(tarCMD.c_str());
339 RUNNER_ASSERT_MSG(!WIFEXITED(ret) || !WIFSIGNALED(ret),
340 "Cannot untar widget to check direct installation from directory!");
342 //This widget is needed to be installed to find the tizen PkgId in the database
343 //during reinstallation step.
345 InstallerWrapper::install(wgtTmpPath + "/TestWgt.wgt", tizenId) == InstallerWrapper::Success,
346 "Failed to install a widget");
348 const WidgetInstallationStruct installerStruct(
349 InstallerCallbacksTranslate::installFinishedCallback,
350 InstallerCallbacksTranslate::installProgressCallback,
351 new InstallerCallbacksTranslate::StatusCallbackStruct(
352 NULL, &staticWrtInitPreloadStatusCallback, NULL),
354 std::make_shared<PackageManager::PkgmgrSignalDummy>());
356 InstallerContext i_context;
358 i_context.mode = InstallMode();
359 i_context.mode.command = InstallMode::Command::REINSTALL;
360 i_context.mode.extension = InstallMode::ExtensionType::DIR;
361 i_context.requestedPath = wgtTmpPath;
364 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
367 TaskConfiguration taskConf(i_context);
368 size_t stepsCnt = taskConf.GetStepCount();
373 while(i < stepsCnt && result)
376 result = taskConf.NextStep();
379 RUNNER_ASSERT(i == stepsCnt);
383 Name: task_configuration_test_08
384 Description: Tests recovery installation of the widget from the directory.
385 Expected: A widget should be successfully installed.
387 RUNNER_TEST(task_configuration_test_08)
389 int ret = system(tarCMD.c_str());
391 RUNNER_ASSERT_MSG(!WIFEXITED(ret) || !WIFSIGNALED(ret),
392 "Cannot untar widget to check direct installation from directory!");
394 //This widget is needed to be installed to find the tizen PkgId in the database
395 //during reinstallation step.
397 InstallerWrapper::install(wgtTmpPath + "/TestWgt.wgt", tizenId) == InstallerWrapper::Success,
398 "Failed to install a widget");
400 const WidgetInstallationStruct installerStruct(
401 InstallerCallbacksTranslate::installFinishedCallback,
402 InstallerCallbacksTranslate::installProgressCallback,
403 new InstallerCallbacksTranslate::StatusCallbackStruct(
404 NULL, &staticWrtInitPreloadStatusCallback, NULL),
406 std::make_shared<PackageManager::PkgmgrSignalDummy>());
408 InstallerContext i_context;
410 i_context.mode = InstallMode();
411 i_context.mode.command = InstallMode::Command::RECOVERY;
412 i_context.mode.extension = InstallMode::ExtensionType::DIR;
413 i_context.requestedPath = wgtTmpPath;
416 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
419 TaskConfiguration taskConf(i_context);
420 size_t stepsCnt = taskConf.GetStepCount();
425 while(i < stepsCnt && result)
428 result = taskConf.NextStep();
431 RUNNER_ASSERT(i == stepsCnt);
435 Name: task_configuration_test_09
436 Description: Tests if a tizenAppID and tizenPkgID will be generated if were not
438 Expected: IDs should be properly generated.
440 RUNNER_TEST(task_configuration_test_09)
442 const WidgetInstallationStruct installerStruct(
443 InstallerCallbacksTranslate::installFinishedCallback,
444 InstallerCallbacksTranslate::installProgressCallback,
445 new InstallerCallbacksTranslate::StatusCallbackStruct(
446 NULL, &staticWrtInitPreloadStatusCallback, NULL),
448 std::make_shared<PackageManager::PkgmgrSignalDummy>());
450 InstallerContext i_context;
452 i_context.mode = InstallMode();
453 i_context.requestedPath = wgtPath;
456 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
459 TaskConfiguration taskConf(i_context);
460 size_t stepsCnt = taskConf.GetStepCount();
465 while(i < stepsCnt && result)
470 i_context.widgetConfig.tzAppid = L"";
471 i_context.widgetConfig.tzPkgid = L"";
472 i_context.widgetConfig.configInfo.tizenAppId = boost::none;
473 i_context.widgetConfig.configInfo.tizenPkgId = boost::none;
476 result = taskConf.NextStep();
479 RUNNER_ASSERT(i == stepsCnt &&
480 i_context.widgetConfig.tzAppid != L"" &&
481 i_context.widgetConfig.tzPkgid != L"");
485 Name: task_configuration_test_10
486 Description: Tests if a tizenPkgID will be generated if was not set earlier.
487 Expected: ID should be properly generated.
489 RUNNER_TEST(task_configuration_test_10)
491 const WidgetInstallationStruct installerStruct(
492 InstallerCallbacksTranslate::installFinishedCallback,
493 InstallerCallbacksTranslate::installProgressCallback,
494 new InstallerCallbacksTranslate::StatusCallbackStruct(
495 NULL, &staticWrtInitPreloadStatusCallback, NULL),
497 std::make_shared<PackageManager::PkgmgrSignalDummy>());
499 InstallerContext i_context;
501 i_context.mode = InstallMode();
502 i_context.requestedPath = wgtPath;
505 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
508 TaskConfiguration taskConf(i_context);
509 size_t stepsCnt = taskConf.GetStepCount();
514 while(i < stepsCnt && result)
519 i_context.widgetConfig.tzPkgid = L"";
520 i_context.widgetConfig.configInfo.tizenPkgId = boost::none;
523 result = taskConf.NextStep();
526 RUNNER_ASSERT(i == stepsCnt &&
527 i_context.widgetConfig.tzPkgid != L"");
531 Name: task_configuration_test_11
532 Description: Tests if a tizenAppId and tizenPkgID will be generated if
533 tizenApp ID is too short and tizenPkgID is not set.
534 Expected: IDs should be properly generated. An exception should be thrown
535 in step 9 beacuse this widget is already installed.
537 RUNNER_TEST(task_configuration_test_11)
539 const WidgetInstallationStruct installerStruct(
540 InstallerCallbacksTranslate::installFinishedCallback,
541 InstallerCallbacksTranslate::installProgressCallback,
542 new InstallerCallbacksTranslate::StatusCallbackStruct(
543 NULL, &staticWrtInitPreloadStatusCallback, NULL),
545 std::make_shared<PackageManager::PkgmgrSignalDummy>());
547 InstallerContext i_context;
549 i_context.mode = InstallMode();
550 i_context.requestedPath = wgtPath;
553 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
556 TaskConfiguration taskConf(i_context);
557 size_t stepsCnt = taskConf.GetStepCount();
563 while(i < stepsCnt && result)
568 i_context.widgetConfig.tzPkgid = L"";
569 i_context.widgetConfig.configInfo.tizenAppId = L"abcd";
570 i_context.widgetConfig.configInfo.tizenPkgId = boost::none;
573 result = taskConf.NextStep();
576 Catch(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid){
577 RUNNER_ASSERT(i == 9 &&
578 i_context.widgetConfig.tzPkgid != L"");
582 RUNNER_ASSERT_MSG(false, "An exception should be thrown because this widget"
583 " is already installed!");
587 Name: task_configuration_test_12
588 Description: Tests if a tizenAppId and tizenPkgID will be generated if
589 tizenApp ID has incorrect characters and tizenPkgID is not set.
590 Expected: IDs should be properly generated. An exception should be thrown
591 in step 9 beacuse this widget is already installed.
593 RUNNER_TEST(task_configuration_test_12)
595 const WidgetInstallationStruct installerStruct(
596 InstallerCallbacksTranslate::installFinishedCallback,
597 InstallerCallbacksTranslate::installProgressCallback,
598 new InstallerCallbacksTranslate::StatusCallbackStruct(
599 NULL, &staticWrtInitPreloadStatusCallback, NULL),
601 std::make_shared<PackageManager::PkgmgrSignalDummy>());
603 InstallerContext i_context;
605 i_context.mode = InstallMode();
606 i_context.requestedPath = wgtPath;
609 new Jobs::WidgetInstall::JobWidgetInstall(wgtPath, "",
612 TaskConfiguration taskConf(i_context);
613 size_t stepsCnt = taskConf.GetStepCount();
619 while(i < stepsCnt && result)
624 i_context.widgetConfig.tzPkgid = L"";
625 i_context.widgetConfig.configInfo.tizenAppId = L"1234!@#$qw";
626 i_context.widgetConfig.configInfo.tizenPkgId = boost::none;
628 FOREACH(localizedData, i_context.widgetConfig.configInfo.localizedDataSet)
630 localizedData->second.name = L"1234!@#$qw";
634 result = taskConf.NextStep();
637 Catch(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid){
638 RUNNER_ASSERT(i == 9 &&
639 i_context.widgetConfig.tzPkgid != L"");
643 RUNNER_ASSERT_MSG(false, "An exception should be thrown because this widget"
644 " is already installed!");