diff options
author | AKalinich-Luxoft <AKalinich@luxoft.com> | 2017-09-20 13:44:48 +0300 |
---|---|---|
committer | Valerii <vmalkov@luxoft.com> | 2018-01-26 15:17:35 +0200 |
commit | 8b8d734487c6bd825db9a8f5d388d7e4e70eb228 (patch) | |
tree | c57d60ebd3d04cf76a99d90bea8ae476d5f2bdd2 | |
parent | 2c3fb437109db06bc91a9277cc011145b3735ca3 (diff) | |
download | sdl_core-8b8d734487c6bd825db9a8f5d388d7e4e70eb228.tar.gz |
Fix affected unit tests and add new unit tests after updates
Also updated mocks
5 files changed, 123 insertions, 13 deletions
diff --git a/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc index 979fb0cc83..8c4ef550b1 100644 --- a/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc @@ -44,6 +44,7 @@ #include "interfaces/MOBILE_API.h" #include "application_manager/mock_hmi_interface.h" #include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" namespace test { namespace components { @@ -57,6 +58,7 @@ using ::testing::_; using application_manager::commands::GetWayPointsRequest; using application_manager::MockMessageHelper; using application_manager::MockHmiInterfaces; +using application_manager_test::MockHMICapabilities; typedef SharedPtr<GetWayPointsRequest> CommandPtr; typedef mobile_apis::Result::eType MobileResult; @@ -86,6 +88,7 @@ class GetWayPointsRequestTest } MockAppPtr mock_app_; + MockHMICapabilities mock_hmi_capabilities_; MessageSharedPtr message_; utils::SharedPtr<application_manager::commands::GetWayPointsRequest> command_sptr_; @@ -112,12 +115,11 @@ class GetWayPointsRequestOnEventTest event.set_smart_object(*event_msg); - const MobileResult mobile_result = static_cast<MobileResult>(ResultCode); - MessageSharedPtr result_msg( CatchMobileCommandResult(CallOnEvent(*command, event))); + EXPECT_EQ( - mobile_result, + static_cast<MobileResult>(ResultCode), static_cast<MobileResult>( (*result_msg)[am::strings::msg_params][am::strings::result_code] .asInt())); @@ -152,6 +154,58 @@ TEST_F(GetWayPointsRequestTest, EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, result); } +TEST_F(GetWayPointsRequestTest, Run_NaviInterfaceIsNotAvailable_Unsupported) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + MockAppPtr application_sptr = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillOnce(Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast<mobile_apis::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE, result); +} + +TEST_F(GetWayPointsRequestTest, Run_RequestDisallowedByCaps_Unsupported) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + MockAppPtr application_sptr = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + + smart_objects::SmartObject navi_caps_so(smart_objects::SmartType_Map); + navi_caps_so["getWayPointsEnabled"] = false; + EXPECT_CALL(mock_hmi_capabilities_, navigation_capability()) + .WillOnce(Return(&navi_caps_so)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast<mobile_apis::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE, result); +} + TEST_F(GetWayPointsRequestTest, Run_ApplicationRegistered_Success) { (*message_)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -165,6 +219,14 @@ TEST_F(GetWayPointsRequestTest, Run_ApplicationRegistered_Success) { EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) .WillOnce(Return(kCorrelationId)); + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + + smart_objects::SmartObject navi_caps_so(smart_objects::SmartType_Map); + navi_caps_so["getWayPointsEnabled"] = true; + EXPECT_CALL(mock_hmi_capabilities_, navigation_capability()) + .WillOnce(Return(&navi_caps_so)); + CallRun caller(*command_sptr_); MessageSharedPtr result_message = CatchHMICommandResult(caller); diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc index 5615b0cabd..a75609ed50 100644 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc @@ -64,7 +64,8 @@ using am::commands::MessageSharedPtr; namespace { const uint32_t kConnectionKey = 3u; -const uint32_t kAppId = 5u; +const uint32_t kAppId1 = 5u; +const uint32_t kAppId2 = 6u; } // namespace class UnSubscribeWayPointsRequestTest @@ -100,9 +101,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(app_mngr_, - IsAppSubscribedForWayPoints( - ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId1)); + + EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId1)) .WillOnce(Return(false)); EXPECT_CALL( @@ -112,20 +113,51 @@ TEST_F(UnSubscribeWayPointsRequestTest, command_->Run(); } +TEST_F(UnSubscribeWayPointsRequestTest, + Run_AnotherAppSubscribedForWayPoints_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId1)); + + EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId1)) + .WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, UnsubscribeAppFromWayPoints(kAppId1)); + + std::set<int32_t> subscribed_apps; + subscribed_apps.insert(kAppId1); + subscribed_apps.insert(kAppId2); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(subscribed_apps)); + + EXPECT_CALL( + app_mngr_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command_->Run(); +} + TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(app_mngr_, - IsAppSubscribedForWayPoints( - ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId1)); + + EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId1)) .WillOnce(Return(true)); EXPECT_CALL(app_mngr_, ManageHMICommand(HMIResultCodeIs( hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints))); + std::set<int32_t> subscribed_apps; + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(subscribed_apps)); + command_->Run(); } @@ -154,9 +186,14 @@ TEST_F(UnSubscribeWayPointsRequestTest, Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); event.set_smart_object(*event_msg); - EXPECT_CALL(app_mngr_, - UnsubscribeAppFromWayPoints( - ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId1)); + + EXPECT_CALL(app_mngr_, UnsubscribeAppFromWayPoints(kAppId1)); + + std::set<int32_t> subscribed_apps; + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(subscribed_apps)); + EXPECT_CALL(app_mngr_, SetWaypointsInfo(_)); EXPECT_CALL( app_mngr_, diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 7598e33e19..456b55d434 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -90,6 +90,9 @@ class MockMessageHelper { void(protocol_handler::ServiceType service, bool available, ApplicationManager& app_mngr)); + MOCK_METHOD2(SendOnWaypointChangeNotification, + void(const uint32_t connection_key, + ApplicationManager& app_mngr)); MOCK_METHOD3(CreateGetVehicleDataRequest, void(uint32_t correlation_id, const std::vector<std::string>& params, diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 2a74f5b3b1..0df9a7bee2 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -77,6 +77,12 @@ void MessageHelper::SendOnDataStreaming(protocol_handler::ServiceType service, service, available, app_mngr); } +void MessageHelper::SendOnWaypointChangeNotification( + const uint32_t connection_key, ApplicationManager& app_mngr) { + MockMessageHelper::message_helper_mock()->SendOnWaypointChangeNotification( + connection_key, app_mngr); +} + void MessageHelper::SendDecryptCertificateToHMI(const std::string& file_name, ApplicationManager& app_mngr) { MockMessageHelper::message_helper_mock()->SendDecryptCertificateToHMI( 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 4f2d964488..1e0c7b38e6 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -281,6 +281,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(application_manager::ApplicationSharedPtr)); MOCK_CONST_METHOD0(IsAnyAppSubscribedForWayPoints, bool()); MOCK_CONST_METHOD0(GetAppsSubscribedForWayPoints, const std::set<int32_t>()); + MOCK_CONST_METHOD0(GetWaypointsInfo, smart_objects::SmartObjectSPtr()); + MOCK_METHOD1(SetWaypointsInfo, void(const smart_objects::SmartObject& obj)); MOCK_CONST_METHOD1( WaitingApplicationByID, application_manager::ApplicationConstSharedPtr(const uint32_t)); |