+/*
+ * 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 TestCases.cpp
+ * @author Karol Pawlowski (k.pawlowski@samsung.com)
+ * @author Tomasz Iwanek (t.iwanek@samsung.com)
+ * @version 1.0
+ * @brief Miscellaneous test's bodies
+ */
+
+#include <string>
+#include <dpl/utils/wrt_utility.h>
+#include <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+#include <InstallerWrapper.h>
+#include <ManifestFile.h>
+
+using namespace InstallerWrapper;
+
+namespace {
+
+const std::string miscWidgetsStuff = "/opt/share/widget/tests/misc/";
+
+struct Result {
+ bool m_exc;
+ bool m_exd;
+ bool m_exs;
+ std::string message;
+ Result(bool exc = false, bool exd = false, bool exs = false)
+ : m_exc(exc), m_exd(exd), m_exs(exs) {}
+};
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+RUNNER_TEST_GROUP_INIT(Manifest)
+
+/*
+Name: creatingManifestFile
+Description: Creation of manifest file by wrt-installer test
+Expected: file should be created and installed by wrt-installer. Content should
+ match expected values
+*/
+RUNNER_TEST(creatingManifestFile)
+{
+ const char * manifestPath = "/opt/share/packages/manifest01.xml";
+ /* This widget removal should stay here in case previous test run failed
+ * (so widget has not been uninstalled) */
+ uninstallByGuid("http://test.samsung.com/widget/manifestTest");
+ std::string tizenId;
+ RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/manifest.wgt", tizenId)
+ == InstallerWrapper::Success);
+ RUNNER_ASSERT(WrtUtilFileExists(manifestPath));
+ ManifestFile mf(manifestPath);
+
+ Try
+ {
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@package")
+ == "manifest01");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@type")
+ == "wgt");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@version")
+ == "1.0");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:label")
+ == "Manifest Example");
+
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@email")
+ == "manifest@misc.test.create.desktop.com");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@href")
+ == "http://misc.test.create.desktop.com");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author")
+ == "Manifest");
+
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@appid")
+ == "manifest01");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@nodisplay")
+ == "false");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@type")
+ == "webapp");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@extraid")
+ == "http://test.samsung.com/widget/manifestTest");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@taskmanage")
+ == "true");
+
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:icon")
+ == "manifest01.png");
+
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[not(@xml:lang)]")
+ == "Manifest Example");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='de_DE']")
+ == "Manifest Beispiel");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='en_US']")
+ == "Manifest Example");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pl']")
+ == "Przykład Manifest");
+ RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pt_PT']")
+ == "Exemplo manifesto");
+ }
+ Catch(ManifestFile::ManifestParseError)
+ {
+ RUNNER_ASSERT_MSG(false,DPL::Exception::KnownExceptionToString(_rethrown_exception));
+ }
+ /* If test finished sucessfully than uninstall test widget */
+ uninstall(tizenId);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+RUNNER_TEST_GROUP_INIT(BackgroundPage)
+
+/*
+Name: widgetWithBackgroundPage
+Description: Tests if widget with background page is installed correctly
+Expected: widget should be installed correctly
+*/
+RUNNER_TEST(widgetWithBackgroundPage)
+{
+ std::string tizenId;
+ RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-00-with_bg.wgt",
+ tizenId) == InstallerWrapper::Success);
+ uninstall(tizenId);
+}
+
+/*
+Name: missingBackgroundFile
+Description: Tests if widget with declared in conifg background page
+ but missing background file will be installed correctly.
+Expected: widget should NOT be installed
+*/
+RUNNER_TEST(missingBackgroundFile)
+{
+ std::string tizenId;
+ if(install(miscWidgetsStuff + "widgets/bg-01-missing_file.wgt",
+ tizenId) == InstallerWrapper::Success) {
+ uninstall(tizenId);
+ RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
+ }
+}
+
+/*
+Name: widgetWithoutBackgroundPage
+Description: Complementary test to check if normal widget\
+ without background page is successfully installed
+Expected: widget should be installed
+*/
+RUNNER_TEST(widgetWithoutBackgroundPage)
+{
+ std::string tizenId;
+ RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/bg-02-without_bg.wgt",
+ tizenId) == InstallerWrapper::Success);
+ uninstall(tizenId);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+RUNNER_TEST_GROUP_INIT(NonRootUser)
+
+/*
+Name: widgetNonRootInstallation
+Description: Check installation from other user than root
+Expected: widget should be installed
+*/
+RUNNER_TEST(widgetNonRootInstallation)
+{
+ std::string tizenId;
+ RUNNER_ASSERT(install(
+ miscWidgetsStuff + "widgets/nonroot.wgt",
+ tizenId,
+ "app") == InstallerWrapper::Success);
+ uninstall(tizenId);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+RUNNER_TEST_GROUP_INIT(NPluginsInstall)
+
+/*
+Name: pluginFilesAdded
+Description: Tests installation of plugins attached to widget
+Expected: widget should be succesfully installed
+*/
+RUNNER_TEST(pluginFilesAdded)
+{
+ std::string tizenId;
+ RUNNER_ASSERT(install(miscWidgetsStuff
+ + "widgets/inst_nplug_1.wgt", tizenId) == InstallerWrapper::Success);
+ uninstall(tizenId);
+}
+
+/*
+Name: emptyPluginsDir
+Description: Tests installation with empty 'plugins' directory
+Expected: widget should be not installed
+*/
+RUNNER_TEST(emptyPluginsDir)
+{
+ std::string tizenId;
+ if(install(miscWidgetsStuff + "widgets/inst_nplug_2.wgt",
+ tizenId) == InstallerWrapper::Success) {
+ uninstall(tizenId);
+ RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
+ }
+}
+
+/*
+Name: pluginFileAndOtherFile
+Description: Tests installation with plugins directory and data files
+Expected: widget should be installed
+*/
+RUNNER_TEST(pluginFileAndOtherFile)
+{
+ std::string tizenId;
+ RUNNER_ASSERT(install(miscWidgetsStuff
+ + "widgets/inst_nplug_3.wgt", tizenId) == InstallerWrapper::Success);
+ uninstall(tizenId);
+}
+
+/*
+Name: pluginFileAndSubdir
+Description: Tests installation with 'plugins' directory and subdirectories
+ inside plugin directory
+Expected: widget should be not installed
+*/
+RUNNER_TEST(pluginFileAndSubdir)
+{
+ std::string tizenId;
+ if(install(miscWidgetsStuff + "widgets/inst_nplug_4.wgt",
+ tizenId) == InstallerWrapper::Success) {
+ uninstall(tizenId);
+ RUNNER_ASSERT_MSG(false, "Invalid widget package installed");
+ }
+}