From 7b6b9e986fff5e7712dcdc70735c8b7b0e23e6ea Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 1 Jul 2021 18:43:54 +0900 Subject: [PATCH] Add BackendInvoker unittest This unittest checks BackendInvoker whether generates correct backend parameter or not. Change-Id: Ie205167961bc622f00dc9da9cb56c94490741931 Signed-off-by: Junghyun Yeon --- src/pkg_upgrade/include/backend_invoker.hh | 2 + src/pkg_upgrade/src/backend_invoker.cc | 4 + tests/unit_tests/src/test_backend_invoker.cc | 191 +++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 tests/unit_tests/src/test_backend_invoker.cc diff --git a/src/pkg_upgrade/include/backend_invoker.hh b/src/pkg_upgrade/include/backend_invoker.hh index aca83ac..0f30fd2 100644 --- a/src/pkg_upgrade/include/backend_invoker.hh +++ b/src/pkg_upgrade/include/backend_invoker.hh @@ -30,6 +30,8 @@ class BackendInvoker { PkgOperation op, bool removable); BackendInvoker() {} + std::list GetParameter(); + int Run() const; static int XSystem(const char *argv[]); diff --git a/src/pkg_upgrade/src/backend_invoker.cc b/src/pkg_upgrade/src/backend_invoker.cc index e15a847..5326855 100644 --- a/src/pkg_upgrade/src/backend_invoker.cc +++ b/src/pkg_upgrade/src/backend_invoker.cc @@ -69,6 +69,10 @@ BackendInvoker::BackendInvoker(std::string pkgid, PkgType type, PkgLocation loc, } } +std::list BackendInvoker::GetParameter() { + return parameters_; +} + int BackendInvoker::Run() const { const char* param[parameters_.size() + 1] = { nullptr, }; diff --git a/tests/unit_tests/src/test_backend_invoker.cc b/tests/unit_tests/src/test_backend_invoker.cc new file mode 100644 index 0000000..9dcf535 --- /dev/null +++ b/tests/unit_tests/src/test_backend_invoker.cc @@ -0,0 +1,191 @@ +/* + * 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 +#include +#include + +#include +#include + +#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 l_arglist, + std::list 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 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 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 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 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 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 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 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 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 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 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 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 expected_argument { "/usr/bin/wgt-backend", "-d", + "wgt_pkgid", "--force-remove", "--keep-rwdata"}; + EXPECT_TRUE(CompareArgumentList(backend.GetParameter(), + expected_argument)); +} -- 2.34.1