summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Byzhynar (GitHub) <AByzhynar@luxoft.com>2016-10-06 09:20:30 +0300
committerGitHub <noreply@github.com>2016-10-06 09:20:30 +0300
commit91c67e98eb3513adc14bd410f20550c225494bc8 (patch)
tree68c2a83e706c6a23df0d9d0124cb405b991baa96
parent0501609732e38f441a238dad390a09d7bee52614 (diff)
parent93f6f52263c3bd8c9100cea72b3ad66ad57e573b (diff)
downloadsdl_core-91c67e98eb3513adc14bd410f20550c225494bc8.tar.gz
Merge pull request #864 from okozlovlux/feature/Fully_cover_commands_with_UT_5
Cover commands with unit tests
-rw-r--r--src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc2
-rw-r--r--src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc170
-rw-r--r--src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc53
-rw-r--r--src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc70
-rw-r--r--src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc221
5 files changed, 438 insertions, 78 deletions
diff --git a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc
index 7240b3bde3..6057ce80a4 100644
--- a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc
+++ b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc
@@ -149,7 +149,7 @@ uint32_t SDLActivateAppRequest::app_id() const {
uint32_t SDLActivateAppRequest::hmi_app_id(
const smart_objects::SmartObject& so) const {
- if (so.keyExists(strings::params)) {
+ if (so.keyExists(strings::msg_params)) {
if (so[strings::msg_params].keyExists(strings::application)) {
if (so[strings::msg_params][strings::application].keyExists(
strings::app_id)) {
diff --git a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc
index 85aadf2442..26e1f79626 100644
--- a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc
+++ b/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc
@@ -34,12 +34,15 @@
#include "gtest/gtest.h"
#include "utils/lock.h"
+#include "utils/helpers.h"
#include "application_manager/commands/hmi/sdl_activate_app_request.h"
#include "application_manager/mock_application.h"
#include "application_manager/application_manager.h"
#include "application_manager/policies/mock_policy_handler_interface.h"
#include "commands/command_request_test.h"
#include "application_manager/mock_message_helper.h"
+#include "application_manager/event_engine/event.h"
+#include "application_manager/mock_event_dispatcher.h"
namespace test {
namespace components {
@@ -53,11 +56,13 @@ namespace hmi_response = am::hmi_response;
using am::commands::MessageSharedPtr;
using am::commands::SDLActivateAppRequest;
using am::ApplicationSet;
+using testing::Mock;
using testing::Return;
using testing::ReturnRef;
using testing::Mock;
using am::MockMessageHelper;
using policy_test::MockPolicyHandlerInterface;
+using am::event_engine::Event;
namespace {
const uint32_t kCorrelationID = 1u;
@@ -66,6 +71,33 @@ const uint32_t kAppIDFirst = 1u;
const connection_handler::DeviceHandle kHandle = 2u;
} // namespace
+MATCHER_P2(CheckMsgParams, result, corr_id, "") {
+ const bool is_func_id_valid =
+ hmi_apis::FunctionID::SDL_ActivateApp ==
+ static_cast<int32_t>(
+ (*arg)[am::strings::params][am::strings::function_id].asInt());
+
+ const bool is_result_code_valid =
+ hmi_apis::Common_Result::APPLICATION_NOT_REGISTERED ==
+ static_cast<int32_t>(
+ (*arg)[am::strings::msg_params][am::strings::result_code].asInt());
+
+ const bool is_result_valid =
+ result == (*arg)[am::strings::msg_params][am::strings::success].asBool();
+
+ const bool is_corr_id_valid =
+ corr_id ==
+ static_cast<int32_t>(
+ (*arg)[am::strings::params][am::strings::correlation_id].asInt());
+
+ using namespace helpers;
+ return Compare<bool, EQ, ALL>(true,
+ is_func_id_valid,
+ is_result_code_valid,
+ is_result_valid,
+ is_corr_id_valid);
+}
+
class SDLActivateAppRequestTest
: public CommandRequestTest<CommandsTestMocks::kIsNice> {
protected:
@@ -84,8 +116,12 @@ class SDLActivateAppRequestTest
MockAppPtr mock_app = CreateMockApp();
CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout);
ON_CALL((*mock_app), app_id()).WillByDefault(Return(kAppID));
- EXPECT_CALL(mock_app_manager_, application_by_hmi_app(kAppID))
- .WillOnce(Return(mock_app));
+ ON_CALL(mock_app_manager_, application_by_hmi_app(kAppID))
+ .WillByDefault(Return(mock_app));
+ }
+ void SetCorrelationAndAppID(MessageSharedPtr msg) {
+ (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
+ (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
}
ApplicationSet app_list_;
@@ -96,8 +132,7 @@ class SDLActivateAppRequestTest
TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -127,8 +162,7 @@ TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) {
TEST_F(SDLActivateAppRequestTest, AppIdNotFound_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -143,8 +177,7 @@ TEST_F(SDLActivateAppRequestTest, AppIdNotFound_SUCCESS) {
TEST_F(SDLActivateAppRequestTest, DevicesAppsEmpty_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -162,8 +195,7 @@ TEST_F(SDLActivateAppRequestTest, DevicesAppsEmpty_SUCCESS) {
TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -195,8 +227,7 @@ TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) {
TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -226,10 +257,47 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) {
command->Run();
}
+TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) {
+ Mock::VerifyAndClearExpectations(&message_helper_mock_);
+ MessageSharedPtr msg = CreateMessage();
+ SetCorrelationAndAppID(msg);
+
+ SharedPtr<SDLActivateAppRequest> command(
+ CreateCommand<SDLActivateAppRequest>(msg));
+
+ MockAppPtr mock_app(CreateMockApp());
+
+ const std::string schema("schema");
+ mock_app->SetShemaUrl(schema);
+ const std::string package_name("package_name");
+ mock_app->SetPackageName(package_name);
+
+ ON_CALL(mock_app_manager_, application(kAppID))
+ .WillByDefault(Return(mock_app));
+
+ EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle));
+
+ MockAppPtr mock_app_first(CreateMockApp());
+ ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle));
+ ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false));
+
+ app_list_.insert(mock_app_first);
+ DataAccessor<ApplicationSet> accessor(app_list_, lock_);
+ EXPECT_CALL(mock_app_manager_, applications()).WillOnce(Return(accessor));
+
+ EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(true));
+ EXPECT_CALL(*mock_app_first, device()).WillOnce(Return(kHandle));
+ EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(true));
+
+ EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, schema, package_name, _));
+
+ command->Run();
+ Mock::VerifyAndClearExpectations(&message_helper_mock_);
+}
+
TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -257,8 +325,7 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) {
TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) {
MessageSharedPtr msg = CreateMessage();
- (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
- (*msg)[am::strings::msg_params][strings::app_id] = kAppID;
+ SetCorrelationAndAppID(msg);
SharedPtr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
@@ -287,6 +354,77 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) {
command->Run();
}
+TEST_F(SDLActivateAppRequestTest, OnTimeout_SUCCESS) {
+ MessageSharedPtr msg = CreateMessage();
+ SetCorrelationAndAppID(msg);
+
+ SharedPtr<SDLActivateAppRequest> command(
+ CreateCommand<SDLActivateAppRequest>(msg));
+
+ EXPECT_CALL(mock_app_manager_,
+ ManageHMICommand(CheckMsgParams(false, kCorrelationID)))
+ .WillOnce(Return(true));
+
+ command->onTimeOut();
+}
+
+TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidEventId_UNSUCCESS) {
+ MessageSharedPtr event_msg = CreateMessage();
+ (*event_msg)[am::strings::params][strings::correlation_id] = kCorrelationID;
+
+ SharedPtr<SDLActivateAppRequest> command(
+ CreateCommand<SDLActivateAppRequest>());
+
+ Event event(hmi_apis::FunctionID::INVALID_ENUM);
+ event.set_smart_object(*event_msg);
+ EXPECT_CALL(mock_app_manager_, application_by_hmi_app(_)).Times(0);
+
+ command->on_event(event);
+}
+
+TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidAppId_UNSUCCESS) {
+ MessageSharedPtr event_msg = CreateMessage();
+ (*event_msg)[strings::msg_params][strings::application][strings::app_id] =
+ kAppID;
+
+ SharedPtr<SDLActivateAppRequest> command(
+ CreateCommand<SDLActivateAppRequest>());
+
+ Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered);
+ event.set_smart_object(*event_msg);
+
+ MockAppPtr invalid_mock_app;
+ EXPECT_CALL(mock_app_manager_, application_by_hmi_app(kAppID))
+ .WillOnce(Return(invalid_mock_app));
+ EXPECT_CALL(mock_app_manager_, GetPolicyHandler()).Times(0);
+
+ command->on_event(event);
+}
+
+TEST_F(SDLActivateAppRequestTest, OnEvent_SUCCESS) {
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::correlation_id] = kCorrelationID;
+ SharedPtr<SDLActivateAppRequest> command(
+ CreateCommand<SDLActivateAppRequest>(msg));
+
+ MessageSharedPtr event_msg = CreateMessage();
+ (*event_msg)[strings::msg_params][strings::application][strings::app_id] =
+ kAppID;
+
+ Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered);
+ event.set_smart_object(*event_msg);
+
+ MockAppPtr mock_app(CreateMockApp());
+ EXPECT_CALL(mock_app_manager_, application_by_hmi_app(kAppID))
+ .WillOnce(Return(mock_app));
+ EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppID));
+ EXPECT_CALL(mock_app_manager_, GetPolicyHandler())
+ .WillOnce(ReturnRef(policy_handler_));
+ EXPECT_CALL(policy_handler_, OnActivateApp(kAppID, kCorrelationID));
+
+ command->on_event(event);
+}
+
} // namespace sdl_activate_app_request
} // namespace hmi_commands_test
} // namespace commands_test
diff --git a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc
index 15ed92085a..a7c37d9b7f 100644
--- a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc
+++ b/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc
@@ -101,6 +101,7 @@
#include "hmi/sdl_policy_update_response.h"
#include "hmi/update_app_list_response.h"
#include "hmi/update_device_list_response.h"
+#include "hmi/notification_from_hmi.h"
namespace test {
namespace components {
@@ -109,6 +110,7 @@ namespace hmi_commands_test {
namespace simple_response_from_hmi_test {
using ::testing::_;
+using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::Types;
using ::testing::Eq;
@@ -318,6 +320,57 @@ TEST_F(OtherResponseFromHMICommandsTest, VIIsReadyResponse_Run_SUCCESS) {
command->Run();
}
+MATCHER_P(CheckMsgType, msg_type, "") {
+ return msg_type ==
+ static_cast<int32_t>(
+ (*arg)[am::strings::params][am::strings::message_type].asInt());
+}
+
+class NotificationFromHMITest
+ : public CommandsTest<CommandsTestMocks::kIsNice> {};
+
+TEST_F(NotificationFromHMITest, BasicMethodsOverloads_SUCCESS) {
+ SharedPtr<commands::NotificationFromHMI> command(
+ CreateCommand<commands::NotificationFromHMI>());
+ // Current implementation always return `true`
+ EXPECT_TRUE(command->Init());
+ EXPECT_TRUE(command->CleanUp());
+ EXPECT_NO_THROW(command->Run());
+}
+
+TEST_F(NotificationFromHMITest, SendNotificationToMobile_SUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[am::strings::params][am::strings::message_type] =
+ static_cast<int32_t>(am::MessageType::kNotification);
+
+ SharedPtr<commands::NotificationFromHMI> command(
+ CreateCommand<commands::NotificationFromHMI>());
+
+ EXPECT_CALL(
+ mock_app_manager_,
+ ManageMobileCommand(CheckMsgType(am::MessageType::kNotification),
+ am::commands::Command::CommandOrigin::ORIGIN_SDL));
+
+ command->SendNotificationToMobile(command_msg);
+}
+
+TEST_F(NotificationFromHMITest, CreateHMIRequest_UNSUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[am::strings::msg_params] = 0;
+ SharedPtr<commands::NotificationFromHMI> command(
+ CreateCommand<commands::NotificationFromHMI>(command_msg));
+
+ const uint32_t correlation_id = 1u;
+ EXPECT_CALL(mock_app_manager_, GetNextHMICorrelationID())
+ .WillOnce(Return(correlation_id));
+ EXPECT_CALL(mock_app_manager_,
+ ManageHMICommand(CheckMsgType(am::MessageType::kRequest)))
+ .WillOnce(Return(false));
+
+ command->CreateHMIRequest(hmi_apis::FunctionID::INVALID_ENUM,
+ (*command_msg)[am::strings::msg_params]);
+}
+
} // namespace simple_response_from_hmi_test
} // namespace hmi_commands_test
} // namespace commands_test
diff --git a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc
index a0fe05d47e..ace1e3afec 100644
--- a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc
+++ b/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc
@@ -75,12 +75,15 @@ class OnSystemRequestNotificationTest
void SetUp() OVERRIDE {
Mock::VerifyAndClearExpectations(&message_helper_);
+ ON_CALL(mock_app_manager_, GetPolicyHandler())
+ .WillByDefault(ReturnRef(mock_policy_handler_));
}
void TearDown() OVERRIDE {
Mock::VerifyAndClearExpectations(&message_helper_);
}
MockMessageHelper& message_helper_;
+ MockPolicyHandlerInterface mock_policy_handler_;
};
#ifdef EXTENDED_POLICY
@@ -122,7 +125,7 @@ bool CheckHeader(MessageSharedPtr msg) {
required_members.insert("ContentType");
required_members.insert("ConnectTimeout");
required_members.insert("DoOutput");
- required_members.insert("Content-Length");
+ required_members.insert("Content_Length");
required_members.insert("DoInput");
required_members.insert("UseCaches");
required_members.insert("RequestMethod");
@@ -138,7 +141,7 @@ bool CheckHeader(MessageSharedPtr msg) {
// TODO(SLevchenko): Enable test after fixes from PR #642 merged in current
// branch. APPLINK-27274
-TEST_F(OnSystemRequestNotificationTest, DISABLED_Run_ProprietaryType_SUCCESS) {
+TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) {
const RequestType::eType kRequestType = RequestType::PROPRIETARY;
MessageSharedPtr msg = CreateMessage();
@@ -151,19 +154,53 @@ TEST_F(OnSystemRequestNotificationTest, DISABLED_Run_ProprietaryType_SUCCESS) {
MockAppPtr mock_app = CreateMockApp();
EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
.WillOnce(Return(mock_app));
- MockPolicyHandlerInterface mock_policy_handler;
- EXPECT_CALL(mock_app_manager_, GetPolicyHandler())
- .WillRepeatedly(ReturnRef(mock_policy_handler));
std::string policy_app_id;
EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id));
- EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _))
+ EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _))
.WillOnce(Return(true));
#ifdef EXTENDED_POLICY
- EXPECT_CALL(mock_app_manager_, GetPolicyHandler())
- .Times(2)
- .WillRepeatedly(ReturnRef(mock_policy_handler));
- EXPECT_CALL(mock_policy_handler, TimeoutExchange()).WillOnce(Return(5u));
+ EXPECT_CALL(mock_policy_handler_, TimeoutExchange()).WillOnce(Return(5u));
+#endif // EXTENDED_POLICY
+
+ EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false));
+ EXPECT_CALL(mock_app_manager_, SendMessageToMobile(msg, _));
+
+ command->Run();
+
+ EXPECT_EQ(FileType::JSON,
+ (*msg)[strings::msg_params][strings::file_type].asInt());
+ EXPECT_EQ(application_manager::MessageType::kNotification,
+ (*msg)[strings::params][strings::message_type].asInt());
+ EXPECT_EQ(CommandImpl::mobile_protocol_type_,
+ (*msg)[strings::params][strings::protocol_type].asInt());
+ EXPECT_EQ(CommandImpl::protocol_version_,
+ (*msg)[strings::params][strings::protocol_version].asInt());
+#ifdef EXTENDED_POLICY
+ EXPECT_TRUE(CheckHeader(msg));
+#endif // EXTENDED_POLICY
+}
+
+TEST_F(OnSystemRequestNotificationTest, Run_EmptyMessage_UNSUCCESS) {
+ const RequestType::eType kRequestType = RequestType::PROPRIETARY;
+
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::connection_key] = kConnectionKey;
+ (*msg)[strings::msg_params][strings::request_type] = kRequestType;
+
+ SharedPtr<OnSystemRequestNotification> command =
+ CreateCommand<OnSystemRequestNotification>(msg);
+
+ MockAppPtr mock_app = CreateMockApp();
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app));
+ std::string policy_app_id;
+ EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id));
+ EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _))
+ .WillOnce(Return(true));
+
+#ifdef EXTENDED_POLICY
+ EXPECT_CALL(mock_policy_handler_, TimeoutExchange()).WillOnce(Return(NULL));
#endif // EXTENDED_POLICY
EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false));
@@ -197,12 +234,9 @@ TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) {
MockAppPtr mock_app = CreateMockApp();
EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
.WillOnce(Return(mock_app));
- MockPolicyHandlerInterface mock_policy_handler;
- EXPECT_CALL(mock_app_manager_, GetPolicyHandler())
- .WillOnce(ReturnRef(mock_policy_handler));
std::string policy_app_id;
EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id));
- EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _))
+ EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _))
.WillOnce(Return(true));
EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false));
@@ -235,8 +269,7 @@ TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) {
.WillOnce(Return(MockAppPtr()));
EXPECT_CALL(mock_app_manager_, GetPolicyHandler()).Times(0);
EXPECT_CALL(*mock_app, policy_app_id()).Times(0);
- MockPolicyHandlerInterface mock_policy_handler;
- EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)).Times(0);
+ EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)).Times(0);
EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0);
EXPECT_CALL(mock_app_manager_, SendMessageToMobile(msg, _)).Times(0);
@@ -257,12 +290,9 @@ TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) {
MockAppPtr mock_app = CreateMockApp();
EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
.WillOnce(Return(mock_app));
- MockPolicyHandlerInterface mock_policy_handler;
- EXPECT_CALL(mock_app_manager_, GetPolicyHandler())
- .WillOnce(ReturnRef(mock_policy_handler));
std::string policy_app_id;
EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id));
- EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _))
+ EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _))
.WillOnce(Return(false));
EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0);
diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc
index e0345d8297..c267de0b05 100644
--- a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc
@@ -51,18 +51,26 @@ namespace mobile_result = mobile_apis::Result;
using ::testing::Mock;
using ::testing::_;
+using ::testing::Mock;
using am::commands::UnsubscribeVehicleDataRequest;
using am::commands::MessageSharedPtr;
-
+using am::MockMessageHelper;
typedef ::utils::SharedPtr<UnsubscribeVehicleDataRequest> CommandPtr;
namespace {
const uint32_t kConnectionKey = 1u;
+const uint32_t kCorrelationKey = 2u;
const std::string kMsgParamKey = "test_key";
const am::VehicleDataType kVehicleType = am::VehicleDataType::SPEED;
} // namespace
+MATCHER_P(CheckMsgCorrelationKey, correlation_key, "") {
+ return correlation_key ==
+ static_cast<uint32_t>(
+ (*arg)[am::strings::params][am::strings::correlation_id].asUInt());
+}
+
class UnsubscribeVehicleRequestTest
: public CommandRequestTest<CommandsTestMocks::kIsNice> {
public:
@@ -72,8 +80,24 @@ class UnsubscribeVehicleRequestTest
}
protected:
+ UnsubscribeVehicleRequestTest()
+ : message_helper_mock_(am::MockMessageHelper::message_helper_mock()) {}
+
void UnsubscribeSuccessfully();
+ void SetMsgParamsAndVehicleData(MessageSharedPtr msg) {
+ (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey;
+ (*msg)[am::strings::msg_params][kMsgParamKey] = kVehicleType;
+
+ vehicle_data_.insert(
+ am::VehicleData::value_type(kMsgParamKey, kVehicleType));
+ }
+ void TearDown() OVERRIDE {
+ Mock::VerifyAndClearExpectations(&message_helper_mock_);
+ }
+
sync_primitives::Lock app_set_lock_;
+ am::VehicleData vehicle_data_;
+ am::MockMessageHelper* message_helper_mock_;
};
TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) {
@@ -96,10 +120,9 @@ TEST_F(UnsubscribeVehicleRequestTest,
kConnectionKey;
(*command_msg)[am::strings::msg_params][am::strings::button_name] =
kVehicleType;
-
- am::VehicleData data;
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
- .WillOnce(ReturnRef(data));
+ am::VehicleData empty_vehicle_data;
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(empty_vehicle_data));
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
MockAppPtr mock_app(CreateMockApp());
@@ -116,14 +139,10 @@ TEST_F(UnsubscribeVehicleRequestTest,
TEST_F(UnsubscribeVehicleRequestTest,
Run_UnsubscribeNotSubscribedBeforeData_IGNORED) {
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[am::strings::params][am::strings::connection_key] =
- kConnectionKey;
- (*command_msg)[am::strings::msg_params][kMsgParamKey] = kVehicleType;
- am::VehicleData vehicle_data;
- vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType));
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
- .WillOnce(ReturnRef(vehicle_data));
+ SetMsgParamsAndVehicleData(command_msg);
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
MockAppPtr mock_app(CreateMockApp());
@@ -140,14 +159,11 @@ TEST_F(UnsubscribeVehicleRequestTest,
TEST_F(UnsubscribeVehicleRequestTest,
Run_UnsubscribeNotSubscribedBeforeData_UNSUCCESS) {
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[am::strings::params][am::strings::connection_key] =
- kConnectionKey;
- (*command_msg)[am::strings::msg_params][kMsgParamKey] = true;
- am::VehicleData vehicle_data;
- vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType));
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
- .WillOnce(ReturnRef(vehicle_data));
+ SetMsgParamsAndVehicleData(command_msg);
+
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
MockAppPtr mock_app(CreateMockApp());
@@ -168,7 +184,7 @@ TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) {
am::VehicleData vehicle_data;
vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType));
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
.WillOnce(ReturnRef(vehicle_data));
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
@@ -185,13 +201,10 @@ TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) {
void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() {
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[am::strings::params][am::strings::connection_key] =
- kConnectionKey;
- (*command_msg)[am::strings::msg_params][kMsgParamKey] = true;
- am::VehicleData vehicle_data;
- vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType));
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
- .WillOnce(ReturnRef(vehicle_data));
+
+ SetMsgParamsAndVehicleData(command_msg);
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
am::ApplicationSet application_set_;
@@ -214,24 +227,151 @@ void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() {
command->Run();
}
+TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribedKeyType_UNSUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+
+ SetMsgParamsAndVehicleData(command_msg);
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
+ CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
+
+ MockAppPtr mock_app(CreateMockApp());
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app));
+
+ EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*mock_app, UnsubscribeFromIVI(kVehicleType))
+ .WillOnce(Return(false));
+
+ EXPECT_CALL(
+ mock_app_manager_,
+ ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _));
+
+ command->Run();
+}
+
+TEST_F(UnsubscribeVehicleRequestTest, Run_SubscribedKeyType_SUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+
+ SetMsgParamsAndVehicleData(command_msg);
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
+ CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
+
+ am::ApplicationSet application_set_;
+ MockAppPtr mock_app(CreateMockApp());
+ application_set_.insert(mock_app);
+ DataAccessor<am::ApplicationSet> accessor(application_set_, app_set_lock_);
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app));
+ EXPECT_CALL(mock_app_manager_, applications()).WillOnce(Return(accessor));
+
+ EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType))
+ .WillOnce(Return(true))
+ .WillOnce(Return(false));
+ EXPECT_CALL(*mock_app, UnsubscribeFromIVI(kVehicleType))
+ .WillOnce(Return(true));
+
+ EXPECT_CALL(mock_app_manager_, GetNextHMICorrelationID())
+ .WillOnce(Return(kCorrelationKey));
+
+ EXPECT_CALL(mock_app_manager_,
+ ManageHMICommand(CheckMsgCorrelationKey(kCorrelationKey)))
+ .WillOnce(Return(false));
+
+ EXPECT_CALL(
+ mock_app_manager_,
+ ManageMobileCommand(MobileResultCodeIs(mobile_result::OUT_OF_MEMORY), _));
+
+ command->Run();
+}
+
TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeData_SUCCESS) {
UnsubscribeSuccessfully();
}
+TEST_F(UnsubscribeVehicleRequestTest, OnEvent_UnknownEvent_UNSUCCESS) {
+ CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>());
+ am::event_engine::Event test_event(hmi_apis::FunctionID::INVALID_ENUM);
+ SmartObject message(smart_objects::SmartType_Map);
+ const hmi_apis::Common_Result::eType hmi_result =
+ hmi_apis::Common_Result::SUCCESS;
+ message[am::strings::params][am::hmi_response::code] = hmi_result;
+ message[am::strings::msg_params][kMsgParamKey] = true;
+ test_event.set_smart_object(message);
+ EXPECT_CALL(*message_helper_mock_, HMIToMobileResult(hmi_result)).Times(0);
+
+ EXPECT_CALL(mock_app_manager_, ManageMobileCommand(_, _)).Times(0);
+
+ command->on_event(test_event);
+}
+
+TEST_F(UnsubscribeVehicleRequestTest,
+ OnEvent_AddAlreadyUnsubscribedVI_SUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+
+ SetMsgParamsAndVehicleData(command_msg);
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
+ CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
+
+ am::ApplicationSet application_set_;
+ MockAppPtr mock_app(CreateMockApp());
+ application_set_.insert(mock_app);
+ DataAccessor<am::ApplicationSet> accessor(application_set_, app_set_lock_);
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app));
+ EXPECT_CALL(mock_app_manager_, applications()).WillOnce(Return(accessor));
+
+ EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType))
+ .WillOnce(Return(true))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*mock_app, UnsubscribeFromIVI(kVehicleType))
+ .WillOnce(Return(true));
+
+ EXPECT_CALL(
+ mock_app_manager_,
+ ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _));
+
+ command->Run();
+
+ am::event_engine::Event test_event(
+ hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData);
+ SmartObject message(smart_objects::SmartType_Map);
+ const hmi_apis::Common_Result::eType hmi_result =
+ hmi_apis::Common_Result::SUCCESS;
+ const mobile_apis::Result::eType mob_result = mobile_apis::Result::SUCCESS;
+ message[am::strings::params][am::hmi_response::code] = hmi_result;
+ message[am::strings::msg_params][kMsgParamKey] = true;
+ test_event.set_smart_object(message);
+
+ EXPECT_CALL(*message_helper_mock_, HMIToMobileResult(hmi_result))
+ .WillOnce(Return(mob_result));
+
+ EXPECT_CALL(
+ mock_app_manager_,
+ ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _));
+ MockAppPtr invalid_app;
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(invalid_app));
+ EXPECT_CALL(*mock_app, UpdateHash()).Times(0);
+
+ command->on_event(test_event);
+}
+
TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) {
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[am::strings::params][am::strings::connection_key] =
- kConnectionKey;
- (*command_msg)[am::strings::msg_params][kMsgParamKey] = true;
+
+ SetMsgParamsAndVehicleData(command_msg);
+
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
- am::VehicleData vehicle_data;
MockAppPtr mock_app(CreateMockApp());
EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
.WillRepeatedly(Return(mock_app));
- vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType));
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data())
- .WillOnce(ReturnRef(vehicle_data));
+ EXPECT_CALL(*message_helper_mock_, vehicle_data())
+ .WillOnce(ReturnRef(vehicle_data_));
EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType))
.WillRepeatedly(Return(false));
EXPECT_CALL(
@@ -248,8 +388,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) {
message[am::strings::params][am::hmi_response::code] = hmi_result;
message[am::strings::msg_params][kMsgParamKey] = true;
test_event.set_smart_object(message);
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()),
- HMIToMobileResult(hmi_result)).WillOnce(Return(mob_result));
+ EXPECT_CALL(*message_helper_mock_, HMIToMobileResult(hmi_result))
+ .WillOnce(Return(mob_result));
EXPECT_CALL(
mock_app_manager_,
@@ -262,9 +402,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) {
TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) {
UnsubscribeSuccessfully();
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[am::strings::params][am::strings::connection_key] =
- kConnectionKey;
- (*command_msg)[am::strings::msg_params][kMsgParamKey] = true;
+
+ SetMsgParamsAndVehicleData(command_msg);
CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg));
MockAppPtr mock_app(CreateMockApp());
@@ -278,8 +417,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) {
message[am::strings::msg_params][kMsgParamKey] = true;
test_event.set_smart_object(message);
- EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()),
- HMIToMobileResult(hmi_result)).WillOnce(Return(mob_result));
+ EXPECT_CALL(*message_helper_mock_, HMIToMobileResult(hmi_result))
+ .WillOnce(Return(mob_result));
EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
.WillOnce(Return(mock_app));