From e2126b58a861d5a1c726a34036100fcaa5eb1e7c Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 10 Aug 2021 16:45:12 +0900 Subject: [PATCH] Implement RequestHandlerInvoker, ConditionValidator Change-Id: I2d70a0c78dd2c9a6ebf0cbcbf4246c6dfe12de95 Signed-off-by: Junghyun Yeon --- src/rsc-copy/CMakeLists.txt | 1 + .../include/abstract_request_handler.hh | 2 +- src/rsc-copy/include/condition_validator.hh | 16 ++- src/rsc-copy/include/copy_request_handler.hh | 2 +- src/rsc-copy/include/error_type.hh | 1 + .../include/remove_request_handler.hh | 2 +- .../include/request_handler_invoker.hh | 11 +- .../include/uninstall_request_handler.hh | 2 +- src/rsc-copy/src/condition_validator.cc | 115 ++++++++++++++- src/rsc-copy/src/copy_request_handler.cc | 2 +- src/rsc-copy/src/remove_request_handler.cc | 2 +- src/rsc-copy/src/request_handler_invoker.cc | 64 ++++++++- src/rsc-copy/src/uninstall_request_handler.cc | 2 +- .../rsc-copy/src/test_condition_validator.cc | 135 ++++++++++++++++++ .../src/test_request_handler_invoker.cc | 94 ++++++++++++ 15 files changed, 429 insertions(+), 22 deletions(-) create mode 100644 tests/unit_tests/rsc-copy/src/test_condition_validator.cc create mode 100644 tests/unit_tests/rsc-copy/src/test_request_handler_invoker.cc diff --git a/src/rsc-copy/CMakeLists.txt b/src/rsc-copy/CMakeLists.txt index d6d1cdf..56bc952 100644 --- a/src/rsc-copy/CMakeLists.txt +++ b/src/rsc-copy/CMakeLists.txt @@ -12,6 +12,7 @@ APPLY_PKG_CONFIG(${TARGET_RSC_COPY} PUBLIC BUNDLE_DEPS Boost PKGMGR_INFO_DEPS + TZPLATFORM_DEPS ) # Install diff --git a/src/rsc-copy/include/abstract_request_handler.hh b/src/rsc-copy/include/abstract_request_handler.hh index 99ebaa3..55d4a20 100644 --- a/src/rsc-copy/include/abstract_request_handler.hh +++ b/src/rsc-copy/include/abstract_request_handler.hh @@ -31,7 +31,7 @@ class AbstractRequestHandler { pkgid_(pkgid), path_list_(path_list) {}; virtual ErrorType Execute() = 0; - virtual std::string GetRequestHandlerType() = 0; + virtual const std::string GetRequestHandlerType() const = 0; protected: std::string GetRootPath(); diff --git a/src/rsc-copy/include/condition_validator.hh b/src/rsc-copy/include/condition_validator.hh index 1c681f9..6a1d451 100644 --- a/src/rsc-copy/include/condition_validator.hh +++ b/src/rsc-copy/include/condition_validator.hh @@ -20,19 +20,27 @@ #include #include +#include "include/error_type.hh" #include "include/rsc_path_info.hh" +#include "include/request_type.hh" namespace rsc_handler { class ConditionValidator { public: - ConditionValidator(std::list list); - bool ValidateCondition(); + ConditionValidator(std::string pkgid, uid_t uid); + ErrorType ValidateCondition(ReqType req_type, + std::list path_list); private: - std::list path_info_list_; + std::string pkgid_; + std::string root_path_; + uid_t uid_; + + ErrorType CheckCopyRequest(std::list path_list); + ErrorType CheckRemoveRequest(std::list path_list); }; -} // rsc_handler +} // namespace rsc_handler #endif // CONDITION_VALIDATOR_HH_ diff --git a/src/rsc-copy/include/copy_request_handler.hh b/src/rsc-copy/include/copy_request_handler.hh index adbeba6..5e7cda0 100644 --- a/src/rsc-copy/include/copy_request_handler.hh +++ b/src/rsc-copy/include/copy_request_handler.hh @@ -31,7 +31,7 @@ class CopyRequestHandler : public AbstractRequestHandler { CopyRequestHandler(std::string pkgid, std::list path_list); ErrorType Execute() override; - std::string GetRequestHandlerType() override; + const std::string GetRequestHandlerType() const override; }; } // namespace rsc_handler diff --git a/src/rsc-copy/include/error_type.hh b/src/rsc-copy/include/error_type.hh index c6684c4..df9701d 100644 --- a/src/rsc-copy/include/error_type.hh +++ b/src/rsc-copy/include/error_type.hh @@ -25,6 +25,7 @@ enum ErrorType { ERROR_PKG_NOT_FOUND, ERROR_PERMISSION_DENIED, ERROR_SYSTEM_ERROR, + ERROR_RES_NOT_FOUND, ERROR_OUT_OF_SPACE, ERROR_OUT_OF_MEMORY }; diff --git a/src/rsc-copy/include/remove_request_handler.hh b/src/rsc-copy/include/remove_request_handler.hh index bd316e2..a4432e2 100644 --- a/src/rsc-copy/include/remove_request_handler.hh +++ b/src/rsc-copy/include/remove_request_handler.hh @@ -31,7 +31,7 @@ class RemoveRequestHandler : public AbstractRequestHandler { RemoveRequestHandler(std::string pkgid, std::list path_list); ErrorType Execute() override; - std::string GetRequestHandlerType() override; + const std::string GetRequestHandlerType() const override; }; } // namespace rsc_handler diff --git a/src/rsc-copy/include/request_handler_invoker.hh b/src/rsc-copy/include/request_handler_invoker.hh index 187e4b3..0098aea 100644 --- a/src/rsc-copy/include/request_handler_invoker.hh +++ b/src/rsc-copy/include/request_handler_invoker.hh @@ -17,22 +17,29 @@ #ifndef REQUEST_HANDLER_INVOKER_HH_ #define REQUEST_HANDLER_INVOKER_HH_ -#include "include/param_checker.hh" +#include +#include + +#include "include/abstract_request_handler.hh" #include "include/event_signal_sender.hh" +#include "include/param_checker.hh" namespace rsc_handler { class RequestHandlerInvoker { public: - RequestHandlerInvoker(ParamChecker option, EventSignalSender signal); bool Validate(); bool Execute(); + const std::string GetHandlerType() const; private: + std::unique_ptr handler_; ParamChecker option_; EventSignalSender signal_; + + void SetReqHandler(); }; } // rsc_handler diff --git a/src/rsc-copy/include/uninstall_request_handler.hh b/src/rsc-copy/include/uninstall_request_handler.hh index 0f742c4..e8a6a51 100644 --- a/src/rsc-copy/include/uninstall_request_handler.hh +++ b/src/rsc-copy/include/uninstall_request_handler.hh @@ -31,7 +31,7 @@ class UninstallRequestHandler : public AbstractRequestHandler { UninstallRequestHandler(std::string pkgid, std::list path_list); ErrorType Execute() override; - std::string GetRequestHandlerType() override; + const std::string GetRequestHandlerType() const override; }; } // namespace rsc_handler diff --git a/src/rsc-copy/src/condition_validator.cc b/src/rsc-copy/src/condition_validator.cc index 82ac9cd..8cc575b 100644 --- a/src/rsc-copy/src/condition_validator.cc +++ b/src/rsc-copy/src/condition_validator.cc @@ -17,20 +17,125 @@ #include "include/condition_validator.hh" +#include +#include +#include +#include + #include +#include +#include +#include "include/logging.hh" #include "include/request_type.hh" #include "include/rsc_path_info.hh" -namespace rsc_handler { +#include -ConditionValidator::ConditionValidator(std::list list) : - path_info_list_(list) {} +namespace { + +std::string GetRootPath(uid_t uid) { + tzplatform_set_user(uid); + const char* rootpath = tzplatform_getenv(TZ_USER_HOME); + tzplatform_reset_user(); + return rootpath; +} -bool ConditionValidator::ValidateCondition() { - std::cout << "ConditionValidator::ValidateCondition" << std::endl; +bool IsPackageExists(std::string pkgid, uid_t uid) { + pkgmgrinfo_pkginfo_h handle; + if (pkgmgrinfo_pkginfo_get_usr_pkginfo( + pkgid.c_str(), uid, &handle) != PMINFO_R_OK) { + LOG(ERROR) << "package not exists : " << pkgid; + return false; + } + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); return true; } +bool CheckFreeSpaceAtPath(int64_t required_size, + const boost::filesystem::path& target_location) { + boost::system::error_code error; + boost::filesystem::path root = target_location; + + while (!boost::filesystem::exists(root) && root != root.root_path()) + root = root.parent_path(); + + if (!boost::filesystem::exists(root)) { + LOG(ERROR) << "No mount point for path: " << target_location; + return false; + } + + boost::filesystem::space_info space_info = + boost::filesystem::space(root, error); + if (error) { + LOG(ERROR) << "Failed to get space_info: " << error.message(); + return false; + } + + return (space_info.free >= static_cast(required_size)); +} + +} // namespace + +namespace rsc_handler { + +ConditionValidator::ConditionValidator(std::string pkgid, uid_t uid) : + pkgid_(pkgid), uid_(uid) { + root_path_ = GetRootPath(uid_); +} + +ErrorType ConditionValidator::ValidateCondition(ReqType req_type, + std::list path_list) { + if (!IsPackageExists(pkgid_, uid_)) + return ErrorType::ERROR_PKG_NOT_FOUND; + + if (req_type == ReqType::REQ_TYPE_NEW) + return CheckCopyRequest(path_list); + else if (req_type == ReqType::REQ_TYPE_REMOVE) + return CheckRemoveRequest(path_list); + + return ErrorType::ERROR_NONE; +} + +ErrorType ConditionValidator::CheckCopyRequest( + std::list path_list) { + boost::filesystem::path src_root_path(root_path_); + uintmax_t rsc_size = 0; + + src_root_path = src_root_path / "apps_rw" / pkgid_; + for (auto& path_info : path_list) { + boost::filesystem::path rsc_path(src_root_path); + rsc_path = rsc_path / path_info.GetSrcPath(); + if (!boost::filesystem::exists(rsc_path)) { + LOG(ERROR) << "Resource not exists : " << rsc_path; + return ErrorType::ERROR_RES_NOT_FOUND; + } + + rsc_size += boost::filesystem::file_size(rsc_path); + } + LOG(INFO) << "Required size for resource: " << rsc_size; + + if (!CheckFreeSpaceAtPath(static_cast(rsc_size), root_path_)) { + LOG(ERROR) << "Not enough space for resource"; + return ErrorType::ERROR_OUT_OF_SPACE; + } + + return ErrorType::ERROR_NONE; +} + +ErrorType ConditionValidator::CheckRemoveRequest( + std::list path_list) { + for (auto& path_info : path_list) { + boost::filesystem::path dst_path(root_path_); + dst_path = dst_path / "shared_res"/ pkgid_ / path_info.GetDstPath(); + if (!boost::filesystem::exists(dst_path)) { + LOG(ERROR) << "Resource not exists : " << dst_path; + return ErrorType::ERROR_RES_NOT_FOUND; + } + } + + return ErrorType::ERROR_NONE; +} + } // namespace rsc_handler diff --git a/src/rsc-copy/src/copy_request_handler.cc b/src/rsc-copy/src/copy_request_handler.cc index d26995b..f810b90 100644 --- a/src/rsc-copy/src/copy_request_handler.cc +++ b/src/rsc-copy/src/copy_request_handler.cc @@ -42,7 +42,7 @@ ErrorType CopyRequestHandler::Execute() { return ErrorType::ERROR_NONE; } -std::string CopyRequestHandler::GetRequestHandlerType() { +const std::string CopyRequestHandler::GetRequestHandlerType() const { return kCopyReqHandlerType; } diff --git a/src/rsc-copy/src/remove_request_handler.cc b/src/rsc-copy/src/remove_request_handler.cc index ca16f30..3232965 100644 --- a/src/rsc-copy/src/remove_request_handler.cc +++ b/src/rsc-copy/src/remove_request_handler.cc @@ -42,7 +42,7 @@ ErrorType RemoveRequestHandler::Execute() { return ErrorType::ERROR_NONE; } -std::string RemoveRequestHandler::GetRequestHandlerType() { +const std::string RemoveRequestHandler::GetRequestHandlerType() const { return kRemoveReqHandlerType; } diff --git a/src/rsc-copy/src/request_handler_invoker.cc b/src/rsc-copy/src/request_handler_invoker.cc index 5335434..d9d0ad4 100644 --- a/src/rsc-copy/src/request_handler_invoker.cc +++ b/src/rsc-copy/src/request_handler_invoker.cc @@ -19,26 +19,82 @@ #include +#include "include/abstract_request_handler.hh" +#include "include/condition_validator.hh" +#include "include/copy_request_handler.hh" #include "include/event_signal_sender.hh" +#include "include/logging.hh" #include "include/param_checker.hh" +#include "include/remove_request_handler.hh" #include "include/request_type.hh" +#include "include/uninstall_request_handler.hh" namespace rsc_handler { RequestHandlerInvoker::RequestHandlerInvoker( ParamChecker option, EventSignalSender signal) : - option_(option), signal_(signal) {} + option_(option), signal_(signal) { + SetReqHandler(); +} bool RequestHandlerInvoker::Validate() { - std::cout << "RequestHandlerInvoker::Validate" << std::endl; + if (!option_.Validate()) { + LOG(ERROR) << "Parameter validation failed"; + return false; + } + + if (handler_ == nullptr) { + LOG(ERROR) << "Failed to initialize handler"; + return false; + } + + ConditionValidator validator(option_.GetPkgID(), option_.GetUID()); + if (validator.ValidateCondition( + option_.GetRequestType(), option_.GetPathList()) + != ErrorType::ERROR_NONE) { + LOG(ERROR) << "Validation failed"; + return false; + } return true; } bool RequestHandlerInvoker::Execute() { - std::cout << "RequestHandlerInvoker::Execute" << std::endl; + if (handler_ == nullptr) + return false; - return true; + return handler_->Execute(); +} + +const std::string RequestHandlerInvoker::GetHandlerType() const { + if (handler_ == nullptr) { + LOG(ERROR) << "handler has not initialized"; + return {}; + } + + return handler_->GetRequestHandlerType(); +} + +void RequestHandlerInvoker::SetReqHandler() { + switch (option_.GetRequestType()) { + case ReqType::REQ_TYPE_NEW: + handler_.reset( + new CopyRequestHandler(option_.GetPkgID(), option_.GetPathList())); + break; + case ReqType::REQ_TYPE_REMOVE: + + handler_.reset( + new RemoveRequestHandler(option_.GetPkgID(), option_.GetPathList())); + break; + case ReqType::REQ_TYPE_UNINSTALL: + handler_.reset( + new UninstallRequestHandler( + option_.GetPkgID(), option_.GetPathList())); + break; + default: + LOG(ERROR) << "Invalid request type"; + break; + } } } // namespace rsc_handler diff --git a/src/rsc-copy/src/uninstall_request_handler.cc b/src/rsc-copy/src/uninstall_request_handler.cc index 5d93d81..7b787db 100644 --- a/src/rsc-copy/src/uninstall_request_handler.cc +++ b/src/rsc-copy/src/uninstall_request_handler.cc @@ -42,7 +42,7 @@ ErrorType UninstallRequestHandler::Execute() { return ErrorType::ERROR_NONE; } -std::string UninstallRequestHandler::GetRequestHandlerType() { +const std::string UninstallRequestHandler::GetRequestHandlerType() const { return kUninstallReqHandlerType; } diff --git a/tests/unit_tests/rsc-copy/src/test_condition_validator.cc b/tests/unit_tests/rsc-copy/src/test_condition_validator.cc new file mode 100644 index 0000000..fd13222 --- /dev/null +++ b/tests/unit_tests/rsc-copy/src/test_condition_validator.cc @@ -0,0 +1,135 @@ +/* + * 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 "mock/os_mock.h" +#include "mock/pkgmgr_info_mock.h" +#include "mock/test_fixture.h" + +#include "include/condition_validator.hh" +#include "include/param_checker.hh" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::SetArgPointee; +using ::testing::InvokeArgument; +using ::testing::SaveArg; + +using rsc_handler::ConditionValidator; +using rsc_handler::ParamChecker; + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +class ConditionValidatorTest : public TestFixture { + public: + ConditionValidatorTest() : TestFixture(std::make_unique()) {} + virtual ~ConditionValidatorTest() {} + + virtual void SetUp() { + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, _, _)) + .WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_destroy_pkginfo(_)) + .WillRepeatedly(Return(0)) ; + } + virtual void TearDown() {} +}; + +TEST_F(ConditionValidatorTest, PkgNotExist) { + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, _, _)) + .WillRepeatedly(Return(-1)); + + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--copy", + "org.test.targetpkgid", "-p", "srcpath", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_PKG_NOT_FOUND); +} + +TEST_F(ConditionValidatorTest, CopyPkgNotExist) { + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, _, _)) + .WillRepeatedly(Return(-1)); + + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--copy", + "org.test.targetpkgid", "-p", "srcpath", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_PKG_NOT_FOUND); +} + +TEST_F(ConditionValidatorTest, CopySrcNotExist) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--copy", + "org.test.targetpkgid", "-p", "srcpath", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_RES_NOT_FOUND); +} + +TEST_F(ConditionValidatorTest, RemovePkgNotExist) { + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, _, _)) + .WillRepeatedly(Return(-1)); + + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--remove", + "org.test.targetpkgid", "-p", "", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_PKG_NOT_FOUND); +} + +TEST_F(ConditionValidatorTest, RemoveSrcNotExist) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--remove", + "org.test.targetpkgid", "-p", "", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_RES_NOT_FOUND); +} + +TEST_F(ConditionValidatorTest, DeletePkgNotExist) { + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, _, _)) + .WillRepeatedly(Return(-1)); + + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--delete", + "org.test.targetpkgid", nullptr}; + ParamChecker checker(5, (char**)argv); + ConditionValidator validator(checker.GetPkgID(), checker.GetUID()); + rsc_handler::ErrorType ret = validator.ValidateCondition( + checker.GetRequestType(), checker.GetPathList()); + + EXPECT_EQ(ret, rsc_handler::ErrorType::ERROR_PKG_NOT_FOUND); +} + diff --git a/tests/unit_tests/rsc-copy/src/test_request_handler_invoker.cc b/tests/unit_tests/rsc-copy/src/test_request_handler_invoker.cc new file mode 100644 index 0000000..24316c7 --- /dev/null +++ b/tests/unit_tests/rsc-copy/src/test_request_handler_invoker.cc @@ -0,0 +1,94 @@ +/* + * 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 "mock/os_mock.h" +#include "mock/pkgmgr_info_mock.h" +#include "mock/test_fixture.h" +#include "include/event_signal_sender.hh" +#include "include/param_checker.hh" +#include "include/request_handler_invoker.hh" +#include "include/request_type.hh" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::SetArgPointee; +using ::testing::InvokeArgument; +using ::testing::SaveArg; + +using rsc_handler::ParamChecker; +using rsc_handler::RequestHandlerInvoker; + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +class RequestHandlerInvokerTest : public TestFixture { + public: + RequestHandlerInvokerTest() : TestFixture(std::make_unique()) { + signal_sender_.SetPkgID("org.tizen.targepkgid"); + signal_sender_.SetReqType(rsc_handler::ReqType::REQ_TYPE_UNKNOWN); + } + virtual ~RequestHandlerInvokerTest() {} + + virtual void SetUp() {} + virtual void TearDown() {} + + rsc_handler::EventSignalSender signal_sender_; +}; + +TEST_F(RequestHandlerInvokerTest, CopyType) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--copy", + "org.test.targetpkgid", "-p", "srcpath", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + + RequestHandlerInvoker request_handler_invoker(checker, signal_sender_); + EXPECT_EQ(request_handler_invoker.GetHandlerType(), "copy"); + +} + +TEST_F(RequestHandlerInvokerTest, RemoveType) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--remove", + "org.test.targetpkgid", "-p", "", "dstpath", nullptr}; + ParamChecker checker(8, (char**)argv); + + RequestHandlerInvoker request_handler_invoker(checker, signal_sender_); + EXPECT_EQ(request_handler_invoker.GetHandlerType(), "remove"); +} + +TEST_F(RequestHandlerInvokerTest, UninstallType) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", "--delete", + "org.test.targetpkgid", nullptr}; + ParamChecker checker(5, (char**)argv); + + RequestHandlerInvoker request_handler_invoker(checker, signal_sender_); + EXPECT_EQ(request_handler_invoker.GetHandlerType(), "delete"); +} + +TEST_F(RequestHandlerInvokerTest, InvalidType) { + const char *argv[] = { "/bin/rsc-copy", "--uid", "5001", nullptr}; + ParamChecker checker(3, (char**)argv); + + RequestHandlerInvoker request_handler_invoker(checker, signal_sender_); + EXPECT_EQ(request_handler_invoker.GetHandlerType(), ""); + EXPECT_EQ(request_handler_invoker.Execute(), false); +} -- 2.34.1