summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLitvinenkoIra <ilytvynenko@luxoft.com>2018-11-19 12:36:38 +0200
committerLitvinenkoIra <ilytvynenko@luxoft.com>2018-11-19 16:05:30 +0200
commit0cc571b0e245f830d816fcf775906e86834566a7 (patch)
treef72a3d68f9d5d24fa18b1eaa6df13da91e06bb9e
parentf2f5030cfce35b4af5ab0fe380a55ad2070e8359 (diff)
downloadsdl_core-feature/restructuring_OnResetTimeout.tar.gz
Add MockRequestController and fix UTsfeature/restructuring_OnResetTimeout
-rw-r--r--src/components/application_manager/src/reset_timeout_handler_impl.cc6
-rw-r--r--src/components/application_manager/test/reset_timeout_handler_test.cc16
-rw-r--r--src/components/include/test/application_manager/mock_application_manager.h4
-rw-r--r--src/components/include/test/application_manager/mock_request_controller.h90
4 files changed, 106 insertions, 10 deletions
diff --git a/src/components/application_manager/src/reset_timeout_handler_impl.cc b/src/components/application_manager/src/reset_timeout_handler_impl.cc
index 44cf6cc12a..ce20f5e01a 100644
--- a/src/components/application_manager/src/reset_timeout_handler_impl.cc
+++ b/src/components/application_manager/src/reset_timeout_handler_impl.cc
@@ -69,8 +69,10 @@ bool ResetTimeoutHandlerImpl::CheckConditionsForUpdate(
hmi_apis::FunctionID::eType method_name) {
if (static_cast<hmi_apis::FunctionID::eType>(request.hmi_function_id_) ==
method_name) {
- if (application_manager_.IsUpdateRequestTimeoutRequired(
- request.connection_key_, request.mob_correlation_id_, timeout)) {
+ if (application_manager_.GetRequestController()
+ .IsUpdateRequestTimeoutRequired(request.connection_key_,
+ request.mob_correlation_id_,
+ timeout)) {
return true;
} else {
LOG4CXX_WARN(logger_,
diff --git a/src/components/application_manager/test/reset_timeout_handler_test.cc b/src/components/application_manager/test/reset_timeout_handler_test.cc
index a25f540dc7..fc42f17499 100644
--- a/src/components/application_manager/test/reset_timeout_handler_test.cc
+++ b/src/components/application_manager/test/reset_timeout_handler_test.cc
@@ -38,6 +38,7 @@
#include "application_manager/mock_event_dispatcher.h"
#include "application_manager/commands/command_request_test.h"
#include "application_manager/mock_message_helper.h"
+#include "application_manager/mock_request_controller.h"
namespace test {
namespace components {
@@ -50,6 +51,7 @@ using application_manager::event_engine::Event;
using namespace application_manager::commands;
using namespace application_manager::strings;
using namespace application_manager::request_controller;
+using application_manager_test::MockRequestController;
using sdl_rpc_plugin::commands::hmi::OnResetTimeoutNotification;
using sdl_rpc_plugin::commands::SubscribeWayPointsRequest;
@@ -72,6 +74,8 @@ class ResetTimeoutHandlerTest : public commands_test::CommandRequestTest<
virtual void SetUp() OVERRIDE {
ON_CALL(app_mngr_, event_dispatcher())
.WillByDefault(ReturnRef(event_dispatcher_));
+ ON_CALL(app_mngr_, GetRequestController())
+ .WillByDefault(ReturnRef(mock_request_controller_));
reset_timeout_handler_ =
std::make_shared<ResetTimeoutHandlerImpl>(app_mngr_);
Mock::VerifyAndClearExpectations(&mock_message_helper_);
@@ -82,6 +86,7 @@ class ResetTimeoutHandlerTest : public commands_test::CommandRequestTest<
}
application_manager::MockMessageHelper* mock_message_helper_;
+ MockRequestController mock_request_controller_;
};
TEST_F(ResetTimeoutHandlerTest, on_event_OnResetTimeout_success) {
@@ -113,7 +118,8 @@ TEST_F(ResetTimeoutHandlerTest, on_event_OnResetTimeout_success) {
.WillOnce(Return(hmi_apis::FunctionID::Navigation_SubscribeWayPoints));
EXPECT_CALL(app_mngr_, GetResetTimeoutHandler())
.WillOnce(ReturnRef(*reset_timeout_handler_));
- EXPECT_CALL(app_mngr_,
+
+ EXPECT_CALL(mock_request_controller_,
IsUpdateRequestTimeoutRequired(
mock_app->app_id(), command->correlation_id(), kTimeout))
.WillOnce(Return(true));
@@ -155,7 +161,7 @@ TEST_F(ResetTimeoutHandlerTest, on_event_OnResetTimeout_missed_reset_period) {
EXPECT_CALL(app_mngr_, GetResetTimeoutHandler())
.WillOnce(ReturnRef(*reset_timeout_handler_));
EXPECT_CALL(
- app_mngr_,
+ mock_request_controller_,
IsUpdateRequestTimeoutRequired(
mock_app->app_id(), command->correlation_id(), kDefaultTimeout))
.WillOnce(Return(true));
@@ -198,7 +204,8 @@ TEST_F(ResetTimeoutHandlerTest, on_event_OnResetTimeout_invalid_request_id) {
.WillOnce(Return(hmi_apis::FunctionID::Navigation_SubscribeWayPoints));
EXPECT_CALL(app_mngr_, GetResetTimeoutHandler())
.WillOnce(ReturnRef(*reset_timeout_handler_));
- EXPECT_CALL(app_mngr_, IsUpdateRequestTimeoutRequired(_, _, _)).Times(0);
+ EXPECT_CALL(mock_request_controller_, IsUpdateRequestTimeoutRequired(_, _, _))
+ .Times(0);
EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0);
ASSERT_TRUE(command->Init());
@@ -235,7 +242,8 @@ TEST_F(ResetTimeoutHandlerTest, on_event_OnResetTimeout_invalid_method_name) {
.WillOnce(Return(hmi_apis::FunctionID::INVALID_ENUM));
EXPECT_CALL(app_mngr_, GetResetTimeoutHandler())
.WillOnce(ReturnRef(*reset_timeout_handler_));
- EXPECT_CALL(app_mngr_, IsUpdateRequestTimeoutRequired(_, _, _)).Times(0);
+ EXPECT_CALL(mock_request_controller_, IsUpdateRequestTimeoutRequired(_, _, _))
+ .Times(0);
EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0);
ASSERT_TRUE(command->Init());
diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h
index 0544094c64..4f40f1568b 100644
--- a/src/components/include/test/application_manager/mock_application_manager.h
+++ b/src/components/include/test/application_manager/mock_application_manager.h
@@ -217,10 +217,6 @@ class MockApplicationManager : public application_manager::ApplicationManager {
void(uint32_t connection_key,
uint32_t mobile_correlation_id,
uint32_t new_timeout_value));
- MOCK_METHOD3(IsUpdateRequestTimeoutRequired,
- bool(uint32_t connection_key,
- uint32_t mobile_correlation_id,
- uint32_t new_timeout_value));
MOCK_METHOD0(state_controller, application_manager::StateController&());
MOCK_METHOD1(SetUnregisterAllApplicationsReason,
void(mobile_apis::AppInterfaceUnregisteredReason::eType reason));
diff --git a/src/components/include/test/application_manager/mock_request_controller.h b/src/components/include/test/application_manager/mock_request_controller.h
new file mode 100644
index 0000000000..c52ba56eee
--- /dev/null
+++ b/src/components/include/test/application_manager/mock_request_controller.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_
+#define SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_
+
+#include "application_manager/request_controller.h"
+
+namespace test {
+namespace components {
+namespace application_manager_test {
+
+class MockRequestController
+ : public application_manager::request_controller::RequestController {
+ public:
+ MOCK_METHOD0(InitializeThreadpool, void());
+ MOCK_METHOD0(DestroyThreadpool, void());
+ MOCK_METHOD2(
+ addMobileRequest,
+ TResult(const application_manager::request_controller::RequestPtr request,
+ const mobile_apis::HMILevel::eType& hmi_level));
+ MOCK_METHOD1(addHMIRequest,
+ TResult(const application_manager::request_controller::RequestPtr
+ request));
+ MOCK_METHOD1(
+ addNotification,
+ void(const application_manager::request_controller::RequestPtr request));
+ MOCK_METHOD4(TerminateRequest,
+ void(const uint32_t correlation_id,
+ const uint32_t connection_key,
+ const int32_t function_id,
+ bool force_terminate));
+ MOCK_METHOD3(OnMobileResponse,
+ void(const uint32_t mobile_correlation_id,
+ const uint32_t connection_key,
+ const int32_t function_id));
+ MOCK_METHOD2(OnHMIResponse,
+ void(const uint32_t correlation_id, const int32_t function_id));
+ MOCK_METHOD1(
+ removeNotification,
+ void(const application_manager::commands::Command* notification));
+ MOCK_METHOD1(terminateAppRequests, void(const uint32_t& app_id));
+ MOCK_METHOD0(terminateAllHMIRequests, void());
+ MOCK_METHOD0(terminateAllMobileRequests, void());
+ MOCK_METHOD3(updateRequestTimeout,
+ void(const uint32_t& app_id,
+ const uint32_t& mobile_correlation_id,
+ const uint32_t& new_timeout));
+ MOCK_CONST_METHOD3(IsUpdateRequestTimeoutRequired,
+ bool(const uint32_t app_id,
+ const uint32_t correlation_id,
+ const uint32_t new_timeout));
+ MOCK_METHOD0(OnLowVoltage, void());
+ MOCK_METHOD0(OnWakeUp, void());
+ MOCK_METHOD0(IsLowVoltage, bool());
+};
+}
+}
+}
+
+#endif // SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_