summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Byzhynar (GitHub) <AByzhynar@luxoft.com>2016-11-03 11:20:51 +0200
committerGitHub <noreply@github.com>2016-11-03 11:20:51 +0200
commit9bded2eac0f8171a1a00286e107f8a21f6bcc01c (patch)
tree4fd0080a6e5111399cd7a59a8870b41c3048fb41
parent2ee7e2a74bf15564eae1c3fda787fe62b37d0ad5 (diff)
parentb7c341e2672a3dd29bc4101ad0f5b76544339a72 (diff)
downloadsdl_core-feature/pre_5_0_0_modifications.tar.gz
Merge pull request #917 from wolfylambova22/feature/fully_cover_comands_with_UTfeature/pre_5_0_0_modifications
Cover comands with UT
-rw-r--r--src/components/application_manager/include/application_manager/message.h2
-rw-r--r--src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc11
-rw-r--r--src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc14
-rw-r--r--src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc120
-rw-r--r--src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc2
-rw-r--r--src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc2
-rw-r--r--src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc28
-rw-r--r--src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc22
-rw-r--r--src/components/application_manager/test/commands/mobile/delete_file_test.cc56
-rw-r--r--src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc2
-rw-r--r--src/components/application_manager/test/commands/mobile/on_driver_distraction_notification_test.cc112
-rw-r--r--src/components/application_manager/test/commands/mobile/speaker_request_test.cc31
-rw-r--r--src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc100
-rw-r--r--src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc37
-rw-r--r--src/components/application_manager/test/commands/mobile/system_request_test.cc385
-rw-r--r--src/components/include/utils/make_shared.h1
16 files changed, 444 insertions, 481 deletions
diff --git a/src/components/application_manager/include/application_manager/message.h b/src/components/application_manager/include/application_manager/message.h
index fe903393fb..521e0baca5 100644
--- a/src/components/application_manager/include/application_manager/message.h
+++ b/src/components/application_manager/include/application_manager/message.h
@@ -41,6 +41,8 @@
#include "protocol/rpc_type.h"
#include "smart_objects/smart_object.h"
+namespace smart_objects = NsSmartDeviceLink::NsSmartObjects;
+
namespace application_manager {
typedef std::vector<uint8_t> BinaryData;
diff --git a/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc b/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc
index 0ee8f51cd7..832c8ebc37 100644
--- a/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc
+++ b/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc
@@ -31,8 +31,9 @@
*/
#include <set>
+#include "utils/make_shared.h"
#include "application_manager/commands/hmi/on_driver_distraction_notification.h"
-
+#include "smart_objects/smart_object.h"
#include "application_manager/application_impl.h"
#include "interfaces/MOBILE_API.h"
#include "interfaces/HMI_API.h"
@@ -58,12 +59,8 @@ void OnDriverDistractionNotification::Run() {
application_manager_.set_driver_distraction(state);
smart_objects::SmartObjectSPtr on_driver_distraction =
- new smart_objects::SmartObject();
-
- if (!on_driver_distraction) {
- SDL_ERROR("NULL pointer");
- return;
- }
+ utils::MakeShared<smart_objects::SmartObject>(
+ smart_objects::SmartType_Map);
(*on_driver_distraction)[strings::params][strings::function_id] =
mobile_api::FunctionID::OnDriverDistractionID;
diff --git a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc
index 46e71a65ce..71d0d4d7fd 100644
--- a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc
+++ b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc
@@ -1898,14 +1898,14 @@ TEST_F(HMICommandsNotificationsTest,
}
TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) {
- const hmi_apis::Common_DriverDistractionState::eType kState =
+ const hmi_apis::Common_DriverDistractionState::eType state =
hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
- (*message)[am::strings::msg_params][am::hmi_notification::state] = kState;
+ (*message)[am::strings::msg_params][am::hmi_notification::state] = state;
utils::SharedPtr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
- EXPECT_CALL(mock_app_manager_, set_driver_distraction(kState));
+ EXPECT_CALL(mock_app_manager_, set_driver_distraction(state));
EXPECT_CALL(mock_app_manager_, applications())
.WillOnce(Return(applications_));
@@ -1916,10 +1916,10 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) {
TEST_F(HMICommandsNotificationsTest,
OnDriverDistractionNotificationInvalidApp) {
- const hmi_apis::Common_DriverDistractionState::eType kState =
+ const hmi_apis::Common_DriverDistractionState::eType state =
hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
- (*message)[am::strings::msg_params][am::hmi_notification::state] = kState;
+ (*message)[am::strings::msg_params][am::hmi_notification::state] = state;
utils::SharedPtr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
@@ -1934,10 +1934,10 @@ TEST_F(HMICommandsNotificationsTest,
}
TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) {
- const hmi_apis::Common_DriverDistractionState::eType kState =
+ const hmi_apis::Common_DriverDistractionState::eType state =
hmi_apis::Common_DriverDistractionState::DD_ON;
MessageSharedPtr message = CreateMessage();
- (*message)[am::strings::msg_params][am::mobile_notification::state] = kState;
+ (*message)[am::strings::msg_params][am::mobile_notification::state] = state;
utils::SharedPtr<Command> command =
CreateCommand<hmi::OnDriverDistractionNotification>(message);
diff --git a/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc
new file mode 100644
index 0000000000..01b0b717a2
--- /dev/null
+++ b/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#include <stdint.h>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "smart_objects/smart_object.h"
+#include "application_manager/smart_object_keys.h"
+#include "utils/shared_ptr.h"
+#include "utils/lock.h"
+#include "utils/make_shared.h"
+#include "utils/data_accessor.h"
+#include "commands/commands_test.h"
+#include "application_manager/mock_application.h"
+#include "application_manager/mock_application_manager.h"
+#include "hmi/on_driver_distraction_notification.h"
+#include "interfaces/MOBILE_API.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace hmi_commands_test {
+namespace on_driver_distraction_notification {
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::Eq;
+using ::utils::SharedPtr;
+
+namespace am = ::application_manager;
+using am::commands::MessageSharedPtr;
+using am::commands::hmi::OnDriverDistractionNotification;
+using namespace am::commands;
+
+typedef ::utils::SharedPtr<OnDriverDistractionNotification> NotificationPtr;
+
+class HMIOnDriverDistractionNotificationTest
+ : public CommandsTest<CommandsTestMocks::kIsNice> {
+ public:
+ ::sync_primitives::Lock app_set_lock_;
+};
+
+MATCHER_P2(CheckNotificationParams, function_id, state, "") {
+ bool is_function_id_matched =
+ function_id ==
+ static_cast<am::mobile_api::FunctionID::eType>(
+ (*arg)[am::strings::params][am::strings::function_id].asInt());
+ bool is_state_matched =
+ state ==
+ static_cast<hmi_apis::Common_DriverDistractionState::eType>(
+ (*arg)[am::strings::msg_params][am::mobile_notification::state]
+ .asInt());
+ return is_function_id_matched && is_state_matched;
+}
+
+TEST_F(HMIOnDriverDistractionNotificationTest,
+ Run_SendNotificationToMobile_SUCCESS) {
+ MessageSharedPtr msg = CreateMessage();
+ const hmi_apis::Common_DriverDistractionState::eType state =
+ hmi_apis::Common_DriverDistractionState::DD_ON;
+ (*msg)[am::strings::msg_params][am::hmi_notification::state] = state;
+
+ NotificationPtr command(CreateCommand<OnDriverDistractionNotification>(msg));
+
+ EXPECT_CALL(mock_app_manager_, set_driver_distraction(state));
+
+ MockAppPtr mock_app = CreateMockApp();
+ am::ApplicationSet app_set;
+ app_set.insert(mock_app);
+
+ DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_);
+ EXPECT_CALL(mock_app_manager_, applications()).WillOnce(Return(accessor));
+
+ const uint32_t app_id = 1u;
+ EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(app_id));
+
+ EXPECT_CALL(mock_app_manager_,
+ ManageMobileCommand(
+ CheckNotificationParams(
+ am::mobile_api::FunctionID::OnDriverDistractionID, state),
+ Command::CommandOrigin::ORIGIN_SDL));
+
+ command->Run();
+}
+
+} // on_driver_distraction_notification
+} // namespace hmi_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
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 6bbc855499..93334c6cf0 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
@@ -87,7 +87,7 @@ MATCHER_P2(CheckMsgParams, result, corr_id, "") {
const bool is_corr_id_valid =
corr_id ==
- (*arg)[am::strings::params][am::strings::correlation_id].asUInt();
+ ((*arg)[am::strings::params][am::strings::correlation_id].asUInt());
using namespace helpers;
return Compare<bool, EQ, ALL>(true,
diff --git a/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc
index 05e3985ce0..a47da22e91 100644
--- a/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc
+++ b/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc
@@ -35,6 +35,7 @@
#include "gtest/gtest.h"
#include "application_manager/commands/hmi/tts_get_capabilities_response.h"
#include "application_manager/mock_hmi_capabilities.h"
+#include "smart_objects/smart_object.h"
#include "commands/commands_test.h"
namespace test {
@@ -45,7 +46,6 @@ namespace tts_get_capabilities_response {
using application_manager::commands::MessageSharedPtr;
using application_manager::commands::TTSGetCapabilitiesResponse;
-using smart_objects::SmartObject;
using test::components::application_manager_test::MockHMICapabilities;
using utils::SharedPtr;
using testing::_;
diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc
index b145591dfe..1cda09f8c9 100644
--- a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc
+++ b/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc
@@ -53,6 +53,7 @@ namespace am = ::application_manager;
namespace strings = ::application_manager::strings;
namespace hmi_response = am::hmi_response;
using am::commands::VRIsReadyResponse;
+using namespace strings;
typedef SharedPtr<VRIsReadyResponse> VRIsReadyResponsePtr;
typedef NiceMock<
@@ -73,14 +74,13 @@ class VRIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {
};
TEST_F(VRIsReadyResponseTest, RUN_SUCCESS) {
+ using namespace strings;
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[strings::msg_params][strings::number] = kStringNum;
- (*command_msg)[strings::params][strings::connection_key] = kConnectionKey;
- (*command_msg)[strings::params][hmi_response::code] =
- hmi_apis::Common_Result::SUCCESS;
- (*command_msg)[strings::msg_params][hmi_response::capabilities] =
- (capabilities_);
- (*command_msg)[strings::msg_params][strings::available] = kIsAvailable;
+ (*command_msg)[msg_params][number] = kStringNum;
+ (*command_msg)[params][connection_key] = kConnectionKey;
+ (*command_msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS;
+ (*command_msg)[msg_params][hmi_response::capabilities] = (capabilities_);
+ (*command_msg)[msg_params][available] = kIsAvailable;
VRIsReadyResponsePtr command(CreateCommand<VRIsReadyResponse>(command_msg));
@@ -93,13 +93,12 @@ TEST_F(VRIsReadyResponseTest, RUN_SUCCESS) {
}
TEST_F(VRIsReadyResponseTest, RUN_NoKeyAvailable) {
+ using namespace strings;
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
- (*command_msg)[strings::msg_params][strings::number] = kStringNum;
- (*command_msg)[strings::params][strings::connection_key] = kConnectionKey;
- (*command_msg)[strings::params][hmi_response::code] =
- hmi_apis::Common_Result::SUCCESS;
- (*command_msg)[strings::msg_params][hmi_response::capabilities] =
- (capabilities_);
+ (*command_msg)[msg_params][number] = kStringNum;
+ (*command_msg)[params][connection_key] = kConnectionKey;
+ (*command_msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS;
+ (*command_msg)[msg_params][hmi_response::capabilities] = (capabilities_);
VRIsReadyResponsePtr command(CreateCommand<VRIsReadyResponse>(command_msg));
@@ -110,8 +109,7 @@ TEST_F(VRIsReadyResponseTest, RUN_NoKeyAvailable) {
command->Run();
- EXPECT_FALSE(
- (*command_msg)[strings::msg_params].keyExists(strings::available));
+ EXPECT_FALSE((*command_msg)[msg_params].keyExists(available));
}
} // namespace vr_is_ready_response
diff --git a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc b/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc
index 33f598f2d7..41e080c3af 100644
--- a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc
@@ -123,6 +123,28 @@ TEST_F(AddSubMenuRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) {
EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, kReceivedResult);
}
+TEST_F(AddSubMenuRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) {
+ Event event(hmi_apis::FunctionID::UI_AddSubMenu);
+ MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ mobile_apis::Result::SUCCESS;
+ (*event_msg)[am::strings::msg_params] = 0;
+
+ event.set_smart_object(*event_msg);
+
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ AddSubMenuPtr command(CreateCommand<AddSubMenuRequest>(command_msg));
+
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(ApplicationSharedPtr()));
+ EXPECT_CALL(mock_app_manager_, ManageMobileCommand(_, _)).Times(0);
+
+ command->on_event(event);
+}
+
TEST_F(AddSubMenuRequestTest, Run_InvalidSubMenuId_UNSUCCESS) {
MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
(*command_msg)[am::strings::msg_params][am::strings::menu_id] = kMenuId;
diff --git a/src/components/application_manager/test/commands/mobile/delete_file_test.cc b/src/components/application_manager/test/commands/mobile/delete_file_test.cc
index b04a019aec..3165afbdab 100644
--- a/src/components/application_manager/test/commands/mobile/delete_file_test.cc
+++ b/src/components/application_manager/test/commands/mobile/delete_file_test.cc
@@ -95,7 +95,7 @@ MATCHER_P(CheckMessageResultCode, result_code, "") {
}
namespace {
-const uint32_t kConnectionKey = 2u;
+const uint32_t kConnectionKey = 1u;
const uint32_t kCorrelationId = 10u;
const int32_t kMenuId = 5;
} // namespace
@@ -106,11 +106,11 @@ class DeleteFileRequestTest
void SetUp() OVERRIDE {
message_ = CreateMessage();
command_ = CreateCommand<DeleteFileRequest>(message_);
- app_ = CreateMockApp();
+ mock_app_ = CreateMockApp();
}
DeleteFileRequestPtr command_;
MessageSharedPtr message_;
- MockAppPtr app_;
+ MockAppPtr mock_app_;
};
class DeleteFileResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {
@@ -128,16 +128,20 @@ TEST_F(DeleteFileRequestTest, Run_InvalidApp_UNSUCCESS) {
}
TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) {
- EXPECT_CALL(mock_app_manager_, application(_)).WillOnce(Return(app_));
- EXPECT_CALL(*app_, hmi_level())
+ (*message_)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app_));
+ EXPECT_CALL(*mock_app_, hmi_level())
.WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE));
EXPECT_CALL(mock_app_manager_, get_settings())
.WillOnce(ReturnRef(mock_app_manager_settings_));
- const uint32_t kNum = 0;
+ const uint32_t num = 0;
EXPECT_CALL(mock_app_manager_settings_, delete_file_in_none())
- .WillOnce(ReturnRef(kNum));
- EXPECT_CALL(*app_, delete_file_in_none_count()).WillOnce(Return(1));
+ .WillOnce(ReturnRef(num));
+ EXPECT_CALL(*mock_app_, delete_file_in_none_count()).WillOnce(Return(1));
EXPECT_CALL(
mock_app_manager_,
@@ -148,12 +152,15 @@ TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) {
}
TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) {
- const std::string kFileName = "test_file.txt";
- EXPECT_TRUE(file_system::CreateFile(kFileName));
- (*message_)[am::strings::msg_params][am::strings::sync_file_name] = kFileName;
+ const std::string file_name = "test_file.txt";
+ EXPECT_TRUE(file_system::CreateFile(file_name));
+ (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name;
+ (*message_)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
- EXPECT_CALL(mock_app_manager_, application(_)).WillOnce(Return(app_));
- EXPECT_CALL(*app_, hmi_level())
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app_));
+ EXPECT_CALL(*mock_app_, hmi_level())
.WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL));
EXPECT_CALL(mock_app_manager_, get_settings())
@@ -162,13 +169,13 @@ TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) {
EXPECT_CALL(mock_app_manager_settings_, app_storage_folder())
.WillOnce(ReturnRef(kFullFilePath));
- am::AppFile kFile;
- kFile.file_name = kFileName;
- kFile.file_type = mobile_apis::FileType::BINARY;
+ am::AppFile file;
+ file.file_name = file_name;
+ file.file_type = mobile_apis::FileType::BINARY;
- EXPECT_CALL(*app_, GetFile(_)).WillOnce(Return(&kFile));
- EXPECT_CALL(*app_, DeleteFile(_));
- EXPECT_CALL(*app_, increment_delete_file_in_none_count());
+ EXPECT_CALL(*mock_app_, GetFile(_)).WillOnce(Return(&file));
+ EXPECT_CALL(*mock_app_, DeleteFile(_));
+ EXPECT_CALL(*mock_app_, increment_delete_file_in_none_count());
EXPECT_CALL(
mock_app_manager_,
ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::SUCCESS),
@@ -178,11 +185,14 @@ TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) {
}
TEST_F(DeleteFileRequestTest, Run_InvalidFile_UNSUCCESS) {
- const std::string kFileName = "test_file.txt";
- (*message_)[am::strings::msg_params][am::strings::sync_file_name] = kFileName;
+ const std::string file_name = "test_file.txt";
+ (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name;
+ (*message_)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
- EXPECT_CALL(mock_app_manager_, application(_)).WillOnce(Return(app_));
- EXPECT_CALL(*app_, hmi_level())
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(mock_app_));
+ EXPECT_CALL(*mock_app_, hmi_level())
.WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL));
EXPECT_CALL(mock_app_manager_, get_settings())
diff --git a/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc
index dcd9138874..053833e8ba 100644
--- a/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc
@@ -237,6 +237,8 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) {
mobile_result::VEHICLE_DATA_NOT_AVAILABLE;
(*event_msg)[am::strings::params][am::strings::error_msg] = "test_error";
(*event_msg)[am::strings::msg_params][am::hmi_response::method] = 0;
+ (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0]
+ [am::strings::text] = "text";
Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData);
event.set_smart_object(*event_msg);
diff --git a/src/components/application_manager/test/commands/mobile/on_driver_distraction_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_driver_distraction_notification_test.cc
new file mode 100644
index 0000000000..e1619d3265
--- /dev/null
+++ b/src/components/application_manager/test/commands/mobile/on_driver_distraction_notification_test.cc
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#include <stdint.h>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "utils/shared_ptr.h"
+#include "smart_objects/smart_object.h"
+#include "application_manager/smart_object_keys.h"
+#include "application_manager/commands/commands_test.h"
+#include "application_manager/commands/command_impl.h"
+#include "application_manager/mock_message_helper.h"
+#include "mobile/on_driver_distraction_notification.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace mobile_commands_test {
+namespace on_driver_distraction_notification {
+
+namespace am = ::application_manager;
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::Mock;
+using am::commands::CommandImpl;
+using am::MockMessageHelper;
+using am::commands::MessageSharedPtr;
+using am::commands::mobile::OnDriverDistractionNotification;
+
+typedef ::utils::SharedPtr<OnDriverDistractionNotification> CommandPtr;
+
+class MobileOnDriverDistractionNotificationTest
+ : public CommandsTest<CommandsTestMocks::kNotNice> {
+ public:
+ MobileOnDriverDistractionNotificationTest()
+ : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {
+ const uint32_t timeout = kDefaultTimeout_;
+ ON_CALL(mock_app_manager_settings_, default_timeout())
+ .WillByDefault(ReturnRef(timeout));
+ }
+
+ void TearDown() OVERRIDE {
+ Mock::VerifyAndClearExpectations(&mock_message_helper_);
+ }
+
+ void SetSendNotificationExpectations(MessageSharedPtr& msg) {
+ Mock::VerifyAndClearExpectations(&mock_message_helper_);
+ EXPECT_CALL(mock_app_manager_, SendMessageToMobile(msg, _));
+ }
+
+ void VerifySendNotificationData(MessageSharedPtr& msg) {
+ ASSERT_EQ(am::MessageType::kNotification,
+ (*msg)[am::strings::params][am::strings::message_type].asInt());
+ ASSERT_EQ(CommandImpl::mobile_protocol_type_,
+ (*msg)[am::strings::params][am::strings::protocol_type].asInt());
+ ASSERT_EQ(
+ CommandImpl::protocol_version_,
+ (*msg)[am::strings::params][am::strings::protocol_version].asInt());
+ }
+
+ MockMessageHelper& mock_message_helper_;
+};
+
+TEST_F(MobileOnDriverDistractionNotificationTest, Run_SUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+
+ CommandPtr command(
+ CreateCommand<OnDriverDistractionNotification>(command_msg));
+
+ SetSendNotificationExpectations(command_msg);
+
+ command->Run();
+
+ VerifySendNotificationData(command_msg);
+}
+
+} // namespace on_driver_distraction_notification
+} // namespace mobile_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
diff --git a/src/components/application_manager/test/commands/mobile/speaker_request_test.cc b/src/components/application_manager/test/commands/mobile/speaker_request_test.cc
index 3b16db4717..82fa6baef2 100644
--- a/src/components/application_manager/test/commands/mobile/speaker_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/speaker_request_test.cc
@@ -62,7 +62,7 @@ typedef SharedPtr<SpeakRequest> CommandPtr;
namespace {
const uint32_t kAppId = 10u;
-const uint32_t kKey = 5u;
+const uint32_t kConnectionKey = 5u;
}
class SpeakRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> {
@@ -223,7 +223,8 @@ TEST_F(SpeakRequestTest, OnEvent_TTS_Speak_SUCCESS) {
(*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0]
[am::strings::text] = "1234";
(*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result;
- (*event_msg)[am::strings::params][am::strings::connection_key] = kKey;
+ (*event_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
event.set_smart_object(*event_msg);
CommandPtr command(CreateCommand<SpeakRequest>(msg_));
@@ -284,11 +285,33 @@ TEST_F(SpeakRequestTest,
TEST_F(SpeakRequestTest, OnEvent_TTS_OnResetTimeout_UpdateTimeout) {
Event event(Event::EventID::TTS_OnResetTimeout);
- (*msg_)[am::strings::params][am::strings::connection_key] = kKey;
+ (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey;
(*msg_)[am::strings::params][am::strings::correlation_id] = kAppId;
CommandPtr command(CreateCommand<SpeakRequest>(msg_));
- EXPECT_CALL(mock_app_manager_, updateRequestTimeout(kKey, kAppId, _));
+ EXPECT_CALL(mock_app_manager_,
+ updateRequestTimeout(kConnectionKey, kAppId, _));
+
+ command->on_event(event);
+}
+
+TEST_F(SpeakRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) {
+ const hmi_apis::Common_Result::eType hmi_result =
+ hmi_apis::Common_Result::SUCCESS;
+
+ Event event(Event::EventID::TTS_Speak);
+ MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0]
+ [am::strings::text] = "text";
+ (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result;
+ (*event_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ event.set_smart_object(*event_msg);
+ CommandPtr command(CreateCommand<SpeakRequest>(msg_));
+
+ EXPECT_CALL(mock_app_manager_, application(_))
+ .WillOnce(Return(ApplicationSharedPtr()));
command->on_event(event);
}
diff --git a/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc
index 5d34c10b51..27b0260ee0 100644
--- a/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc
@@ -63,6 +63,10 @@ using am::commands::SubscribeButtonRequest;
using am::commands::SubscribeButtonResponse;
using am::commands::MessageSharedPtr;
+namespace {
+const uint32_t kConnectionKey = 1u;
+}
+
typedef SharedPtr<SubscribeButtonRequest> CommandPtr;
typedef SharedPtr<SubscribeButtonResponse> ResponsePtr;
@@ -78,10 +82,36 @@ class SubscribeButtonRequestTest
NiceMock<application_manager_test::MockHMICapabilities>,
application_manager_test::MockHMICapabilities>::Result
MockHMICapabilities;
+ void SetUp() OVERRIDE {
+ command_msg = CreateMessage(smart_objects::SmartType_Map);
+ (*command_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+ mock_app_ = CreateMockApp();
+
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(mock_app_));
+ }
+
+ MessageSharedPtr command_msg;
+ MockAppPtr mock_app_;
};
class SubscribeButtonResponsetTest
- : public CommandsTest<CommandsTestMocks::kIsNice> {};
+ : public CommandsTest<CommandsTestMocks::kIsNice> {
+ protected:
+ void SetUp() OVERRIDE {
+ command_msg = CreateMessage(smart_objects::SmartType_Map);
+ (*command_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+ mock_app_ = CreateMockApp();
+
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(mock_app_));
+ }
+
+ MessageSharedPtr command_msg;
+ MockAppPtr mock_app_;
+};
typedef SubscribeButtonRequestTest::MockHMICapabilities MockHMICapabilities;
@@ -99,14 +129,12 @@ TEST_F(SubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) {
}
TEST_F(SubscribeButtonRequestTest, Run_SubscriptionNotAllowed_UNSUCCESS) {
- MessageSharedPtr msg(CreateMessage());
- (*msg)[am::strings::msg_params][am::strings::button_name] =
+ (*command_msg)[am::strings::msg_params][am::strings::button_name] =
mobile_apis::ButtonName::SEEKLEFT;
- CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg));
- MockAppPtr app(CreateMockApp());
- ON_CALL(mock_app_manager_, application(_)).WillByDefault(Return(app));
- ON_CALL(*app, is_media_application()).WillByDefault(Return(false));
+ CommandPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
+
+ ON_CALL(*mock_app_, is_media_application()).WillByDefault(Return(false));
MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command)));
EXPECT_EQ(mobile_apis::Result::REJECTED,
@@ -116,10 +144,7 @@ TEST_F(SubscribeButtonRequestTest, Run_SubscriptionNotAllowed_UNSUCCESS) {
}
TEST_F(SubscribeButtonRequestTest, Run_UiIsNotSupported_UNSUCCESS) {
- CommandPtr command(CreateCommand<SubscribeButtonRequest>());
-
- MockAppPtr app(CreateMockApp());
- ON_CALL(mock_app_manager_, application(_)).WillByDefault(Return(app));
+ CommandPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
MockHMICapabilities hmi_capabilities;
ON_CALL(mock_app_manager_, hmi_capabilities())
@@ -133,17 +158,35 @@ TEST_F(SubscribeButtonRequestTest, Run_UiIsNotSupported_UNSUCCESS) {
.asInt()));
}
+TEST_F(SubscribeButtonRequestTest, Run_UiIsSupported_UNSUCCESS) {
+ MockHMICapabilities hmi_capabilities;
+ ON_CALL(mock_app_manager_, hmi_capabilities())
+ .WillByDefault(ReturnRef(hmi_capabilities));
+ ON_CALL(hmi_capabilities, is_ui_cooperating()).WillByDefault(Return(true));
+
+ ON_CALL(hmi_capabilities, button_capabilities())
+ .WillByDefault(Return(static_cast<const SmartObject*>(NULL)));
+
+ CommandPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
+
+ MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command)));
+
+ EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE,
+ static_cast<mobile_apis::Result::eType>(
+ (*result_msg)[am::strings::msg_params][am::strings::result_code]
+ .asInt()));
+}
+
TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) {
const mobile_apis::ButtonName::eType kButtonName =
mobile_apis::ButtonName::SEEKLEFT;
- MessageSharedPtr msg(CreateMessage());
- (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName;
- CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg));
+ (*command_msg)[am::strings::msg_params][am::strings::button_name] =
+ kButtonName;
+
+ CommandPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
- MockAppPtr app(CreateMockApp());
- ON_CALL(mock_app_manager_, application(_)).WillByDefault(Return(app));
- ON_CALL(*app, is_media_application()).WillByDefault(Return(true));
+ ON_CALL(*mock_app_, is_media_application()).WillByDefault(Return(true));
MockHMICapabilities hmi_capabilities;
ON_CALL(mock_app_manager_, hmi_capabilities())
@@ -156,7 +199,7 @@ TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) {
ON_CALL(hmi_capabilities, button_capabilities())
.WillByDefault(Return(button_caps_ptr.get()));
- ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(true));
+ ON_CALL(*mock_app_, IsSubscribedToButton(_)).WillByDefault(Return(true));
MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command)));
EXPECT_EQ(mobile_apis::Result::IGNORED,
@@ -168,14 +211,11 @@ TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) {
TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) {
const mobile_apis::ButtonName::eType kButtonName =
mobile_apis::ButtonName::SEEKLEFT;
+ (*command_msg)[am::strings::msg_params][am::strings::button_name] =
+ kButtonName;
+ CommandPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
- MessageSharedPtr msg(CreateMessage());
- (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName;
- CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg));
-
- MockAppPtr app(CreateMockApp());
- ON_CALL(mock_app_manager_, application(_)).WillByDefault(Return(app));
- ON_CALL(*app, is_media_application()).WillByDefault(Return(true));
+ ON_CALL(*mock_app_, is_media_application()).WillByDefault(Return(true));
MockHMICapabilities hmi_capabilities;
ON_CALL(mock_app_manager_, hmi_capabilities())
@@ -188,7 +228,7 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) {
ON_CALL(hmi_capabilities, button_capabilities())
.WillByDefault(Return(button_caps_ptr.get()));
- ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false));
+ ON_CALL(*mock_app_, IsSubscribedToButton(_)).WillByDefault(Return(false));
MessageSharedPtr hmi_result_msg;
EXPECT_CALL(mock_app_manager_, ManageHMICommand(_))
@@ -209,9 +249,8 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) {
}
TEST_F(SubscribeButtonResponsetTest, ResponseFalse_UNSUCCESS) {
- MessageSharedPtr msg(CreateMessage());
- (*msg)[am::strings::msg_params][am::strings::success] = false;
- ResponsePtr command(CreateCommand<SubscribeButtonResponse>(msg));
+ (*command_msg)[am::strings::msg_params][am::strings::success] = false;
+ ResponsePtr command(CreateCommand<SubscribeButtonResponse>(command_msg));
EXPECT_CALL(mock_app_manager_,
SendMessageToMobile(CheckMessageSuccess(false), false));
@@ -219,8 +258,7 @@ TEST_F(SubscribeButtonResponsetTest, ResponseFalse_UNSUCCESS) {
}
TEST_F(SubscribeButtonResponsetTest, ResponseTrue_SUCCESS) {
- MessageSharedPtr msg(CreateMessage());
- ResponsePtr command(CreateCommand<SubscribeButtonResponse>(msg));
+ ResponsePtr command(CreateCommand<SubscribeButtonResponse>(command_msg));
EXPECT_CALL(mock_app_manager_,
SendMessageToMobile(CheckMessageSuccess(true), false));
diff --git a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc
index 9045b32117..67966a4c0b 100644
--- a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc
@@ -62,7 +62,7 @@ typedef SharedPtr<SubscribeWayPointsRequest> CommandPtr;
namespace {
const uint32_t kAppId = 10u;
-const uint32_t kKey = 5u;
+const uint32_t kConnectionKey = 5u;
}
class SubscribeWayPointsRequestTest
@@ -70,7 +70,7 @@ class SubscribeWayPointsRequestTest
protected:
SubscribeWayPointsRequestTest() : app_(CreateMockApp()), info_("") {
msg_ = CreateMessage(smart_objects::SmartType_Map);
- (*msg_)[am::strings::params][am::strings::connection_key] = kKey;
+ (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey;
}
void SetUp() OVERRIDE {
@@ -98,7 +98,8 @@ TEST_F(SubscribeWayPointsRequestTest, Run_ApplicationIsNotRegistered) {
TEST_F(SubscribeWayPointsRequestTest, Run_WayPointsSubscribedBefore_Ignored) {
CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kKey)).WillByDefault(Return(app_));
+ EXPECT_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillOnce(Return(app_));
EXPECT_CALL(mock_app_manager_, IsAppSubscribedForWayPoints(kAppId))
.WillOnce(Return(true));
@@ -111,7 +112,8 @@ TEST_F(SubscribeWayPointsRequestTest, Run_WayPointsSubscribedBefore_Ignored) {
TEST_F(SubscribeWayPointsRequestTest, Run_SomeAppSubscribedBefore_Success) {
CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kKey)).WillByDefault(Return(app_));
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_));
EXPECT_CALL(mock_app_manager_, IsAppSubscribedForWayPoints(kAppId))
.WillOnce(Return(false));
@@ -129,7 +131,8 @@ TEST_F(SubscribeWayPointsRequestTest, Run_SomeAppSubscribedBefore_Success) {
TEST_F(SubscribeWayPointsRequestTest,
Run_AnyAppSubscribedBefore_SuccessSubscribe) {
CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kKey)).WillByDefault(Return(app_));
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_));
EXPECT_CALL(mock_app_manager_, IsAppSubscribedForWayPoints(kAppId))
.WillOnce(Return(false));
@@ -168,7 +171,8 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_SuccessResult_SubscribeApp) {
event.set_smart_object(*event_msg);
CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kKey)).WillByDefault(Return(app_));
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_));
EXPECT_CALL(mock_app_manager_, SubscribeAppForWayPoints(kAppId));
@@ -192,10 +196,13 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_UnsuccessResult_NotSubscribeApp) {
event.set_smart_object(*event_msg);
CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kKey)).WillByDefault(Return(app_));
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_));
EXPECT_CALL(mock_app_manager_, SubscribeAppForWayPoints(kAppId)).Times(0);
+ EXPECT_CALL(*app_, UpdateHash()).Times(0);
+
EXPECT_CALL(
mock_app_manager_,
ManageMobileCommand(
@@ -203,6 +210,22 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_UnsuccessResult_NotSubscribeApp) {
command->on_event(event);
}
+TEST_F(SubscribeWayPointsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[am::strings::params][am::strings::connection_key] =
+ kConnectionKey;
+
+ CommandPtr command(CreateCommand<SubscribeWayPointsRequest>(command_msg));
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_));
+
+ Event event(hmi_apis::FunctionID::INVALID_ENUM);
+
+ EXPECT_CALL(mock_app_manager_, ManageMobileCommand(_, _)).Times(0);
+
+ command->on_event(event);
+}
+
} // namespace subscribe_way_points_request
} // namespace mobile_commands_test
} // namespace commands_test
diff --git a/src/components/application_manager/test/commands/mobile/system_request_test.cc b/src/components/application_manager/test/commands/mobile/system_request_test.cc
deleted file mode 100644
index 16c96de69c..0000000000
--- a/src/components/application_manager/test/commands/mobile/system_request_test.cc
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * Copyright (c) 2016, 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.
- */
-
-#include <stdint.h>
-#include <vector>
-#include <string>
-#include <sstream>
-
-#include "gtest/gtest.h"
-#include "mobile/system_request.h"
-#include "utils/shared_ptr.h"
-#include "commands/commands_test.h"
-#include "commands/command_request_test.h"
-#include "application_manager/application.h"
-#include "application_manager/mock_application_manager.h"
-#include "application_manager/mock_application.h"
-#include "application_manager/smart_object_keys.h"
-#include "interfaces/HMI_API.h"
-#include "interfaces/MOBILE_API.h"
-#include "application_manager/policies/mock_policy_handler_interface.h"
-#include "smart_objects/smart_object.h"
-#include "utils/file_system.h"
-
-namespace test {
-namespace components {
-namespace commands_test {
-namespace mobile_commands_test {
-namespace system_request {
-
-using application_manager::commands::SystemRequest;
-using ::testing::DefaultValue;
-
-namespace mobile_result = mobile_apis::Result;
-namespace am = application_manager;
-
-typedef SharedPtr<SystemRequest> CommandPtr;
-
-namespace {
-const uint32_t kAppId = 10u;
-const std::string kPolicyAppId = "12345";
-const uint32_t kConnectionKey = 5u;
-const std::string kBinaryFolder = "test_binary_folder";
-const std::string kStorageFolder = "test_storage_folder";
-const std::string kStorageFolder2 = "test_storage_folder2";
-const mobile_apis::RequestType::eType kRequestType =
- mobile_apis::RequestType::CLIMATE;
-}
-
-class SystemRequestTest
- : public CommandRequestTest<CommandsTestMocks::kIsNice> {
- protected:
- SystemRequestTest()
- : app_(CreateMockApp()), info_(""), file_name_("file_name") {
- msg_ = CreateMessage(smart_objects::SmartType_Map);
- (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey;
- }
-
- void SetUp() OVERRIDE {
- ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId));
- ON_CALL(*app_, policy_app_id()).WillByDefault(Return(kPolicyAppId));
- ON_CALL(mock_app_manager_, GetPolicyHandler())
- .WillByDefault(ReturnRef(policy_handler_mock));
- }
-
- MockAppPtr app_;
- MessageSharedPtr msg_;
- std::string info_;
- policy_test::MockPolicyHandlerInterface policy_handler_mock;
- const std::string file_name_;
-};
-
-TEST_F(SystemRequestTest, Run_ApplicationIsNotRegistered) {
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
-
- ON_CALL(mock_app_manager_, application(_))
- .WillByDefault(Return(ApplicationSharedPtr()));
-
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(
- MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _));
-
- command->Run();
-}
-
-TEST_F(SystemRequestTest, Run_TypeDisallowed_DisallowedResult) {
- (*msg_)[am::strings::msg_params][am::strings::request_type] = kRequestType;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(policy_handler_mock,
- IsRequestTypeAllowed(kPolicyAppId, kRequestType))
- .WillOnce(Return(false));
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::DISALLOWED, info_, false), _));
-
- command->Run();
-}
-
-TEST_F(SystemRequestTest, Run_FileWithBinaryDataSaveUnsuccessful_GenericError) {
- std::vector<uint8_t> binary_data;
- binary_data.push_back(0x1);
- binary_data.push_back(0x2);
- binary_data.push_back(0x4);
- (*msg_)[am::strings::msg_params][am::strings::request_type] = kRequestType;
- (*msg_)[am::strings::msg_params][am::strings::file_name] = file_name_;
- (*msg_)[am::strings::params][am::strings::binary_data] = binary_data;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(policy_handler_mock,
- IsRequestTypeAllowed(kPolicyAppId, kRequestType))
- .WillOnce(Return(true));
-
- EXPECT_CALL(mock_app_manager_settings_, system_files_path())
- .WillRepeatedly(ReturnRef(kBinaryFolder));
- EXPECT_CALL(mock_app_manager_,
- SaveBinary(binary_data, kBinaryFolder, file_name_, 0))
- .WillOnce(Return(mobile_result::INVALID_DATA));
-
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::GENERIC_ERROR, info_, false), _));
-
- command->Run();
-}
-
-TEST_F(SystemRequestTest,
- Run_FileWithoutBinaryDataNotHTTPTypeNotSystemFile_Rejected) {
- (*msg_)[am::strings::msg_params][am::strings::request_type] = kRequestType;
- (*msg_)[am::strings::msg_params][am::strings::file_name] = file_name_;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(policy_handler_mock,
- IsRequestTypeAllowed(kPolicyAppId, kRequestType))
- .WillOnce(Return(true));
-
- EXPECT_CALL(mock_app_manager_settings_, system_files_path())
- .WillRepeatedly(ReturnRef(kBinaryFolder));
- EXPECT_CALL(mock_app_manager_, SaveBinary(_, _, _, _)).Times(0);
-
- EXPECT_CALL(mock_app_manager_settings_, app_storage_folder())
- .WillRepeatedly(ReturnRef(kStorageFolder));
- am::AppFile ap_file;
- ON_CALL(*app_, folder_name()).WillByDefault(Return(kStorageFolder2));
- ap_file.is_download_complete = false;
- EXPECT_CALL(*app_,
- GetFile(kStorageFolder + file_system::GetPathDelimiter() +
- kStorageFolder2 + file_system::GetPathDelimiter() +
- file_name_)).WillRepeatedly(Return(&ap_file));
- EXPECT_CALL(mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::REJECTED, info_, false), _));
-
- command->Run();
-}
-
-TEST_F(
- SystemRequestTest,
- Run_FileInFileSystemWithoutBinaryDataNotHTTPTypeNotSystemFile_SendRequestToHMI) {
- const std::string file_name = "IVSU";
- mobile_apis::RequestType::eType request_type = mobile_apis::RequestType::HTTP;
- (*msg_)[am::strings::msg_params][am::strings::request_type] = request_type;
- (*msg_)[am::strings::msg_params][am::strings::file_name] = file_name;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(policy_handler_mock,
- IsRequestTypeAllowed(kPolicyAppId, request_type))
- .WillOnce(Return(true));
-
- EXPECT_CALL(mock_app_manager_settings_, system_files_path())
- .WillRepeatedly(ReturnRef(kBinaryFolder));
- EXPECT_CALL(mock_app_manager_, SaveBinary(_, _, _, _)).Times(0);
-
- EXPECT_CALL(mock_app_manager_settings_, app_storage_folder())
- .WillRepeatedly(ReturnRef(kStorageFolder));
- ON_CALL(*app_, folder_name()).WillByDefault(Return("app_storage"));
- am::AppFile ap_file;
-
- // To avoid override of existing file,
- // command append index as a suffix to
- // the file name and increment it, each time
- // when command saves a file.
- std::ostringstream final_file_name;
- final_file_name << SystemRequest::file_index() << file_name;
-
- const std::string app_full_file_path = file_system::ConcatPath(
- kStorageFolder, "app_storage", final_file_name.str());
-
- EXPECT_CALL(*app_, GetFile(app_full_file_path))
- .WillRepeatedly(Return(&ap_file));
-
- EXPECT_CALL(mock_app_manager_, ManageMobileCommand(_, _)).Times(0);
-
- EXPECT_CALL(mock_app_manager_,
- ManageHMICommand(HMIResultCodeIs(
- hmi_apis::FunctionID::BasicCommunication_SystemRequest)))
- .WillOnce(Return(true));
-
- command->Run();
-}
-
-TEST_F(SystemRequestTest, OnEvent_SuccessResult_SuccessfulCommand) {
- Event event(Event::EventID::BasicCommunication_SystemRequest);
-
- MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map));
-
- const hmi_apis::Common_Result::eType hmi_code =
- hmi_apis::Common_Result::SUCCESS;
- (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_code;
- smart_objects::SmartObject& unused = (*event_msg)[am::strings::msg_params];
- // msg_params is unused in this case
- UNUSED(unused)
- event.set_smart_object(*event_msg);
-
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::SUCCESS, info_, true), _));
- command->on_event(event);
-}
-
-TEST_F(SystemRequestTest, OnEvent_WarningResult_SuccessfulCommand) {
- Event event(Event::EventID::BasicCommunication_SystemRequest);
-
- MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map));
-
- const hmi_apis::Common_Result::eType hmi_code =
- hmi_apis::Common_Result::WARNINGS;
- (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_code;
- smart_objects::SmartObject& unused = (*event_msg)[am::strings::msg_params];
- // msg_params is unused in this case
- UNUSED(unused)
- event.set_smart_object(*event_msg);
-
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- EXPECT_CALL(mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::WARNINGS, info_, true), _));
- command->on_event(event);
-}
-
-TEST_F(SystemRequestTest, OnEvent_UnsuccesfulResult_SendUnsuccessfulCommand) {
- Event event(Event::EventID::BasicCommunication_SystemRequest);
-
- MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map));
-
- // Code is neither SUCCESS nor WARNINGS
- const hmi_apis::Common_Result::eType hmi_code =
- hmi_apis::Common_Result::GENERIC_ERROR;
- (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_code;
- smart_objects::SmartObject& unused = (*event_msg)[am::strings::msg_params];
- // msg_params is unused in this case
- UNUSED(unused)
- event.set_smart_object(*event_msg);
-
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
-
- // Result is false
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(
- MobileResponseIs(mobile_result::GENERIC_ERROR, info_, false), _));
- command->on_event(event);
-}
-
-TEST_F(SystemRequestTest, Run_InvalidQueryAppData_GENERIC_ERROR) {
- const mobile_apis::RequestType::eType request_type =
- mobile_apis::RequestType::QUERY_APPS;
- (*msg_)[am::strings::msg_params][am::strings::file_name] = file_name_;
- (*msg_)[am::strings::msg_params][am::strings::request_type] = request_type;
-
- // json_data was not contain required parameter, `json::response`
- const std::string json_data("{\"invalid_json_data\":{}}");
- const std::vector<uint8_t> binary_data(json_data.begin(), json_data.end());
- (*msg_)[am::strings::params][am::strings::binary_data] = binary_data;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
-
- ON_CALL(policy_handler_mock, IsRequestTypeAllowed(kPolicyAppId, request_type))
- .WillByDefault(Return(true));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
- ON_CALL(mock_app_manager_settings_, system_files_path())
- .WillByDefault(ReturnRef(kBinaryFolder));
- ON_CALL(mock_app_manager_settings_, app_storage_folder())
- .WillByDefault(ReturnRef(kStorageFolder));
-
- ON_CALL(mock_app_manager_, SaveBinary(_, kBinaryFolder, file_name_, 0))
- .WillByDefault(Return(mobile_result::SUCCESS));
-
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(MobileResultCodeIs(mobile_result::GENERIC_ERROR), _));
-
- command->Run();
-}
-
-TEST_F(SystemRequestTest, Run_ValidQueryAppData_SUCCESS) {
- const mobile_apis::RequestType::eType request_type =
- mobile_apis::RequestType::QUERY_APPS;
- (*msg_)[am::strings::msg_params][am::strings::file_name] = file_name_;
- (*msg_)[am::strings::msg_params][am::strings::request_type] = request_type;
-
- std::ostringstream json_data_stream;
- json_data_stream << "{\"" << am::json::response << "\":{}}";
-
- // json_data should contain `json::response` parameter, to be valid
- const std::string json_data(json_data_stream.str());
- const std::vector<uint8_t> binary_data(json_data.begin(), json_data.end());
-
- (*msg_)[am::strings::params][am::strings::binary_data] = binary_data;
- CommandPtr command(CreateCommand<SystemRequest>(msg_));
-
- ON_CALL(policy_handler_mock, IsRequestTypeAllowed(kPolicyAppId, request_type))
- .WillByDefault(Return(true));
- ON_CALL(mock_app_manager_, application(kConnectionKey))
- .WillByDefault(Return(app_));
- ON_CALL(mock_app_manager_settings_, system_files_path())
- .WillByDefault(ReturnRef(kBinaryFolder));
- ON_CALL(mock_app_manager_settings_, app_storage_folder())
- .WillByDefault(ReturnRef(kStorageFolder));
-
- ON_CALL(mock_app_manager_, SaveBinary(_, kBinaryFolder, file_name_, 0))
- .WillByDefault(Return(mobile_result::SUCCESS));
-
- EXPECT_CALL(mock_app_manager_, ProcessQueryApp(_, kConnectionKey));
-
- EXPECT_CALL(
- mock_app_manager_,
- ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _));
-
- command->Run();
-}
-
-} // namespace system_request
-} // namespace mobile_commands_test
-} // namespace commands_test
-} // namespace components
-} // namespace test
diff --git a/src/components/include/utils/make_shared.h b/src/components/include/utils/make_shared.h
index 0bfb096f2a..3e00f8ca12 100644
--- a/src/components/include/utils/make_shared.h
+++ b/src/components/include/utils/make_shared.h
@@ -34,6 +34,7 @@
#define SRC_COMPONENTS_INCLUDE_UTILS_MAKE_SHARED_H_
#include <new>
+#include <stddef.h>
/**
* @brief The functions set below allows to create shared pointer in a safe way.
* There are up to 5 parameters could be passed as the constructor parameters.