From 908b473c971e98581dbc7fd026361406766b81c0 Mon Sep 17 00:00:00 2001 From: "Pavel Zhdanov (GitHub)" <39907184+ZhdanovP@users.noreply.github.com> Date: Mon, 8 Jun 2020 18:03:06 +0300 Subject: Sdl must store onWayPointChange internally (#2490) * Add saving way points during notification - When OnWayPointNotification appeared the wayPoint is saving - When new app subscribing on wayPointNotification stored way points are sending to app * Add unit tests * fix style, update to remove (uint32_t) overload of SubscribeAppForWayPoints Co-authored-by: collin --- .../mobile/on_way_point_change_notification.cc | 1 + .../on_way_point_change_notification_test.cc | 66 +++++++++++++++++++--- 2 files changed, 60 insertions(+), 7 deletions(-) (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin') diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc index e89ede53b9..39e0735013 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc @@ -65,6 +65,7 @@ void OnWayPointChangeNotification::Run() { (*message_)[strings::params][strings::connection_key] = *app_id; SendNotification(); } + application_manager_.SaveWayPointsMessage(message_); } } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc index 83958954cd..ec401ae2a8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -59,19 +59,40 @@ using sdl_rpc_plugin::commands::OnWayPointChangeNotification; typedef std::shared_ptr NotificationPtr; namespace { -const uint32_t kAppId = 1u; +const uint32_t kApp1Id = 1u; +const uint32_t kApp2Id = 2u; } // namespace class OnWayPointChangeNotificationTest : public CommandsTest { public: - OnWayPointChangeNotificationTest() - : command_(CreateCommand()) {} + OnWayPointChangeNotificationTest() {} + + void SetUp() OVERRIDE { + command_ = CreateCommand(); + } + + std::shared_ptr CreateCommand() { + InitCommand(CommandsTest::kDefaultTimeout_); + message_ = CreateMessage(); + return std::make_shared( + message_, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); + } + + MessageSharedPtr CreateMessage( + const smart_objects::SmartType type = smart_objects::SmartType_Null) { + return std::make_shared(type); + } NotificationPtr command_; + MessageSharedPtr message_; }; -MATCHER(CheckMessageData, "") { +MATCHER_P(CheckMessageData, appID, "") { const bool kIsMobileProtocolTypeCorrect = (*arg)[am::strings::params][am::strings::protocol_type].asInt() == am::commands::CommandImpl::mobile_protocol_type_; @@ -86,7 +107,7 @@ MATCHER(CheckMessageData, "") { const bool kIsConnectionKeyCorrect = (*arg)[am::strings::params][am::strings::connection_key].asUInt() == - kAppId; + appID; using namespace helpers; return Compare(true, @@ -99,11 +120,42 @@ MATCHER(CheckMessageData, "") { TEST_F(OnWayPointChangeNotificationTest, Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { std::set apps_subscribed_for_way_points; - apps_subscribed_for_way_points.insert(kAppId); + apps_subscribed_for_way_points.insert(kApp1Id); EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) .WillOnce(Return(apps_subscribed_for_way_points)); - EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_StoreWayPointsDuringNotification_SUCCESS) { + std::set apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(app_mngr_, SaveWayPointsMessage(message_)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_BroadcastingWayPointsToAllApps_SUCCESS) { + std::set apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + apps_subscribed_for_way_points.insert(kApp2Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp2Id), _)); command_->Run(); } -- cgit v1.2.1