--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+
+#include <list>
+#include <memory>
+
+#include "backend_invoker.hh"
+#include "mock/test_fixture.h"
+
+using namespace common_fota;
+
+class BackendInvokerTest : public ::testing::Test {
+ protected:
+ void SetUp() override {}
+ void TearDown() override {}
+};
+
+bool CompareArgumentList(std::list<std::string> l_arglist,
+ std::list<std::string> r_arglist) {
+ if (l_arglist.size() != r_arglist.size() ||
+ l_arglist.size() == 0 || r_arglist.size() == 0)
+ return false;
+
+ for (auto arg : l_arglist) {
+ if (!(std::find(r_arglist.begin(), r_arglist.end(), arg) !=
+ r_arglist.end()))
+ return false;
+ }
+
+ return true;
+}
+
+TEST_F(BackendInvokerTest, TPKPreloadRWUpdateRemovable) {
+ BackendInvoker update_backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RW, PkgOperation::UPDATE, true);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-y",
+ "tpk_pkgid", "--preload-rw", "--skip-check-reference"};
+
+ EXPECT_TRUE(CompareArgumentList(update_backend.GetParameter(),
+ expected_argument));
+
+ BackendInvoker install_backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RW, PkgOperation::INSTALL, true);
+ EXPECT_TRUE(CompareArgumentList(install_backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTPreloadRWUpdateRemovable) {
+ BackendInvoker update_backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RW, PkgOperation::UPDATE, true);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-y",
+ "wgt_pkgid", "--preload-rw", "--skip-check-reference"};
+
+ EXPECT_TRUE(CompareArgumentList(update_backend.GetParameter(),
+ expected_argument));
+
+ BackendInvoker install_backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RW, PkgOperation::INSTALL, true);
+ EXPECT_TRUE(CompareArgumentList(install_backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, TPKPreloadROUpdate) {
+ BackendInvoker update_backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RO, PkgOperation::UPDATE, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-y",
+ "tpk_pkgid", "--preload", "--partial-rw", "--skip-check-reference"};
+
+ EXPECT_TRUE(CompareArgumentList(update_backend.GetParameter(),
+ expected_argument));
+
+ BackendInvoker install_backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RO, PkgOperation::INSTALL, false);
+ EXPECT_TRUE(CompareArgumentList(install_backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTPreloadROUpdate) {
+ BackendInvoker update_backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RO, PkgOperation::UPDATE, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-y",
+ "wgt_pkgid", "--preload", "--partial-rw", "--skip-check-reference"};
+ EXPECT_TRUE(CompareArgumentList(update_backend.GetParameter(),
+ expected_argument));
+
+ BackendInvoker install_backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RO, PkgOperation::INSTALL, false);
+ EXPECT_TRUE(CompareArgumentList(install_backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, TPKPreloadROUninstall) {
+ BackendInvoker backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RO, PkgOperation::UNINSTALL, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-d",
+ "tpk_pkgid", "--preload", "--force-remove", "--partial-rw"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTPreloadROUninstall) {
+ BackendInvoker backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RO, PkgOperation::UNINSTALL, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-d",
+ "wgt_pkgid", "--preload", "--force-remove", "--partial-rw"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, TPKRWUninstall) {
+ BackendInvoker backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RW, PkgOperation::UNINSTALL, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-d",
+ "tpk_pkgid", "--force-remove", "--partial-rw"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTRWUninstall) {
+ BackendInvoker backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RW, PkgOperation::UNINSTALL, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-d",
+ "wgt_pkgid", "--force-remove", "--partial-rw"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, TPKPreloadROUninstallKeepRWData) {
+ BackendInvoker backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RO, PkgOperation::UNINSTALL_KEEP_RW_DATA, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-d",
+ "tpk_pkgid", "--preload", "--force-remove", "--keep-rwdata"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTPreloadROUninstallKeepRWData) {
+ BackendInvoker backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RO, PkgOperation::UNINSTALL_KEEP_RW_DATA, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-d",
+ "wgt_pkgid", "--preload", "--force-remove", "--keep-rwdata"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, TPKRWUninstallKeepRWData) {
+ BackendInvoker backend("tpk_pkgid", PkgType::TPK,
+ PkgLocation::RW, PkgOperation::UNINSTALL_KEEP_RW_DATA, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/tpk-backend", "-d",
+ "tpk_pkgid", "--force-remove", "--keep-rwdata"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}
+
+TEST_F(BackendInvokerTest, WGTRWUninstallKeepRWData) {
+ BackendInvoker backend("wgt_pkgid", PkgType::WGT,
+ PkgLocation::RW, PkgOperation::UNINSTALL_KEEP_RW_DATA, false);
+
+ std::list<std::string> expected_argument { "/usr/bin/wgt-backend", "-d",
+ "wgt_pkgid", "--force-remove", "--keep-rwdata"};
+ EXPECT_TRUE(CompareArgumentList(backend.GetParameter(),
+ expected_argument));
+}