Add BackendInvoker unittest 09/260709/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 1 Jul 2021 09:43:54 +0000 (18:43 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 1 Jul 2021 09:58:00 +0000 (18:58 +0900)
This unittest checks BackendInvoker whether
generates correct backend parameter or not.

Change-Id: Ie205167961bc622f00dc9da9cb56c94490741931
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkg_upgrade/include/backend_invoker.hh
src/pkg_upgrade/src/backend_invoker.cc
tests/unit_tests/src/test_backend_invoker.cc [new file with mode: 0644]

index aca83ac..0f30fd2 100644 (file)
@@ -30,6 +30,8 @@ class BackendInvoker {
       PkgOperation op, bool removable);
   BackendInvoker() {}
 
+  std::list<std::string> GetParameter();
+
   int Run() const;
 
   static int XSystem(const char *argv[]);
index e15a847..5326855 100644 (file)
@@ -69,6 +69,10 @@ BackendInvoker::BackendInvoker(std::string pkgid, PkgType type, PkgLocation loc,
   }
 }
 
+std::list<std::string> 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 (file)
index 0000000..9dcf535
--- /dev/null
@@ -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 <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));
+}