From: Grzegorz Rynkowski Date: Tue, 11 Jun 2013 13:37:20 +0000 (+0200) Subject: Add WidgetUpdate tests X-Git-Tag: submit/tizen_2.2/20130713.111652^2~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55e5c827e13f066477ba3fc3acdbe2d2f0db626b;p=platform%2Fframework%2Fweb%2Fwrt-installer.git Add WidgetUpdate tests [Issue#] LINUXWRT-403 [Problem] A lot of paths used in wrt are constructedmanually [Cause] N/A [Solution] Add WidgetUpdate test group. [Verification] 1. Build wrt-installer repo with --define "WITH_TESTS ON" 2. Run tests wrt-installer-tests-general --output=text. It should be test group named "WidgetUpdate" who contains 7 tesets. Five of them passed, and two failed. Change-Id: I7ade49f50cfbf6ef2e476357e8ad39f0315889cd --- diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt index 8e67a1a..0eca7ea 100644 --- a/tests/general/CMakeLists.txt +++ b/tests/general/CMakeLists.txt @@ -66,6 +66,7 @@ SET(INSTALLER_TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/NonRootUserTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/NPluginsInstallTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ParsingTizenAppcontrolTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/WidgetUpdateTests.cpp ) SET(INSTALLER_TESTS_TARGET "wrt-installer-tests-general") @@ -129,13 +130,6 @@ target_link_libraries(${INSTALLER_TESTS_TARGET} ) #widgets -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/manifest.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/bg-00-with_bg.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/bg-01-missing_file.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/bg-02-without_bg.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/nonroot.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/inst_nplug_1.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/inst_nplug_2.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/inst_nplug_3.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/inst_nplug_4.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/widgets/app-control.wgt DESTINATION /opt/share/widget/tests/installer/widgets/) +FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/widgets/*.wgt") +INSTALL(FILES ${files} DESTINATION /opt/share/widget/tests/installer/widgets/) + diff --git a/tests/general/WidgetUpdateTests.cpp b/tests/general/WidgetUpdateTests.cpp new file mode 100644 index 0000000..cbcc24f --- /dev/null +++ b/tests/general/WidgetUpdateTests.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file WidgetUpdateTests.cpp + * @author Grzegorz Rynkowski (g.rynkowski@samsung.com) + * @version 1.0 + * @brief Test a process of updating web applications. + */ + +#include +#include +#include +#include + +using namespace InstallerWrapper; + +#define RUNNER_ASSERT_MSG_SAFE(test, message) \ + { \ + DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \ + \ + if (!(test)) \ + { \ + uninstall(tizenId); \ + std::ostringstream assertMsg; \ + assertMsg << message; \ + throw DPL::Test::TestRunner::TestFailed(#test, \ + __FILE__, \ + __LINE__, \ + assertMsg.str()); \ + } \ + } + +RUNNER_TEST_GROUP_INIT(WidgetUpdate) + +/* +Name: validUpdateOfSigned +Description: Tests update the web app where origin and a new one are signed. +Expected: Widget should be successfully installed. +*/ +RUNNER_TEST(validUpdateOfSigned) +{ + std::string tizenId; + std::string wgtPath; + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt"; + RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success, + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt"; + RUNNER_ASSERT_MSG_SAFE(install(wgtPath, tizenId) == InstallerWrapper::Success, + "Failed update in case both programs are signed"); + uninstall(tizenId); +} + +/* +Name: validUpdateOfUnsigned +Description: Tests update the web app where origin and a new one are unsigned. +Expected: Widget should be successfully updated. +*/ +RUNNER_TEST(validUpdateOfUnsigned) +{ + std::string tizenId; + std::string wgtPath; + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed update in case both programs are signed"); + uninstall(tizenId); +} + +/* +Name: unupdateOfSigned +Description: Tests update that signed web app could be downgraded. +Expected: Widget should not be updated. +*/ +RUNNER_TEST(unupdateOfSigned) +{ + std::string tizenId; + std::string wgtPath; + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId), + "Unupdate should be prohibited."); + uninstall(tizenId); +} + +/* +Name: unupdateOfSigned +Description: Tests update that unsigned web app could be downgraded. +Expected: Widget should not be updated. +*/ +RUNNER_TEST(unupdateOfUnsigned) +{ + std::string tizenId; + std::string wgtPath; + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId), + "Unupdate should be prohibited."); + uninstall(tizenId); +} + +/* +Name: validUpdateOfCrossSigned +Description: Tests update the web app where one of widgets are signed and second not. +Expected: Widget should not be updated. +*/ +RUNNER_TEST(updateOfCrossSignedWidgets) +{ + std::string tizenId; + std::string wgtPath; + + { + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Unsigned.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId), + "The update unsigned app by the signed app should not be possible"); + uninstall(tizenId); + } + { + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Unsigned.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId), + "The update signed app by the unsigned app should not be possible"); + uninstall(tizenId); + } +} + + +/* +Name: updateAnotherAuthor +Description: Tests update the web app by the widget signed by another author. +Expected: Widget should not be updated. +*/ +RUNNER_TEST(updateAnotherAuthor) +{ + std::string tizenId; + std::string wgtPath; + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt"; + RUNNER_ASSERT_MSG(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed to install widget"); + + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220SignedAnotherAuthor.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success != install(wgtPath, tizenId), + "The update by another author should not be possible"); + uninstall(tizenId); +} + + +/* +Name: updateWidgetDataRemember +Description: Tests of keeping app data during widget updating. +Expected: App data should be kept. +*/ +RUNNER_TEST(updateWidgetDataRemember) +{ + std::string tizenId; + std::string wgtPath; + + // Installation of the widget + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer100Signed.wgt"; + RUNNER_ASSERT_MSG(install(wgtPath, tizenId) == InstallerWrapper::Success, + "Failed to install widget"); + + // Creating a file + std::string filePath = "/opt/usr/apps/HAdisUJ4Kn/data/test"; + std::string text = "slonce swieci dzisiaj wyjatkowo wysoko"; + std::string command = "echo " + text + " > " + filePath; + system(command.c_str()); + + // Second installation of the widget + wgtPath = miscWidgetsStuff + "widgets/widgetUpdateVer220Signed.wgt"; + RUNNER_ASSERT_MSG_SAFE(InstallerWrapper::Success == install(wgtPath, tizenId), + "Failed update in case both programs are signed"); + + + // Checking of the file created before + std::stringstream ss; + std::ifstream file(filePath); + RUNNER_ASSERT_MSG_SAFE(file.good(), "File is gone"); + + for( std::string line; getline( file, line ); ss << line); + file.close(); + RUNNER_ASSERT_MSG_SAFE(text == ss.str(), "Content of file is not the same"); + uninstall(tizenId); +} diff --git a/tests/general/widgets/widgetUpdateVer100Signed.wgt b/tests/general/widgets/widgetUpdateVer100Signed.wgt new file mode 100644 index 0000000..b3ff8bf Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer100Signed.wgt differ diff --git a/tests/general/widgets/widgetUpdateVer100Unsigned.wgt b/tests/general/widgets/widgetUpdateVer100Unsigned.wgt new file mode 100644 index 0000000..751aed0 Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer100Unsigned.wgt differ diff --git a/tests/general/widgets/widgetUpdateVer220Signed.wgt b/tests/general/widgets/widgetUpdateVer220Signed.wgt new file mode 100644 index 0000000..5ef42af Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer220Signed.wgt differ diff --git a/tests/general/widgets/widgetUpdateVer220SignedAnotherAuthor.wgt b/tests/general/widgets/widgetUpdateVer220SignedAnotherAuthor.wgt new file mode 100644 index 0000000..c1aeaa3 Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer220SignedAnotherAuthor.wgt differ diff --git a/tests/general/widgets/widgetUpdateVer220Unsigned.wgt b/tests/general/widgets/widgetUpdateVer220Unsigned.wgt new file mode 100644 index 0000000..181447d Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer220Unsigned.wgt differ diff --git a/tests/general/widgets/widgetUpdateVer220UnsignedDifferentId.wgt b/tests/general/widgets/widgetUpdateVer220UnsignedDifferentId.wgt new file mode 100644 index 0000000..8fb6c19 Binary files /dev/null and b/tests/general/widgets/widgetUpdateVer220UnsignedDifferentId.wgt differ