summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Oleynik (GitHub) <aoleynik@luxoft.com>2017-11-30 09:43:44 +0200
committerAndrey Oleynik (GitHub) <aoleynik@luxoft.com>2017-11-30 09:50:55 +0200
commit9f49324aeb546193e959390af9f5e841aec25bf8 (patch)
tree1dbdef76e2588c5cfc8a63d6963b357a8d8c24fd
parenteeb949d3cfc8f05fab59ac2b959795fa88bff182 (diff)
downloadsdl_core-feature/External_triggering_iAP_over_BT.tar.gz
Updates mocks and unit tests after prior commitfeature/External_triggering_iAP_over_BT
Fixes mock classes interfaces, unit tests and build after changes related to making iAP2 switching triggered externally and using of Bluetooth MAC/USB serial instead of UUID for internal device management.
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc27
-rw-r--r--src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc19
-rw-r--r--src/components/application_manager/test/application_manager_impl_test.cc107
-rw-r--r--src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc18
-rw-r--r--src/components/connection_handler/test/connection_handler_impl_test.cc46
-rw-r--r--src/components/include/test/application_manager/policies/mock_policy_handler_interface.h2
-rw-r--r--src/components/include/test/connection_handler/mock_connection_handler_observer.h4
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_cache_manager.h2
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_manager.h2
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h2
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h3
-rw-r--r--src/components/include/test/transport_manager/mock_transport_manager_listener.h3
-rw-r--r--src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h5
-rw-r--r--src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h2
-rw-r--r--src/components/transport_manager/test/transport_manager_impl_test.cc221
15 files changed, 322 insertions, 141 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 0561c733a3..016799eaa0 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -1076,29 +1076,28 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart(
const connection_handler::Device& device_from,
const connection_handler::Device& device_to) {
LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock lock(reregister_wait_list_lock_);
{
auto apps_data_accessor = applications();
std::copy_if(
- apps_data_accessor.GetData().begin(),
- apps_data_accessor.GetData().end(),
- std::back_inserter(reregister_wait_list_),
- std::bind1st(std::ptr_fun(&device_id_comparator),
- device_from.mac_address()));
+ apps_data_accessor.GetData().begin(),
+ apps_data_accessor.GetData().end(),
+ std::back_inserter(reregister_wait_list_),
+ std::bind1st(std::ptr_fun(&device_id_comparator),
+ device_from.mac_address()));
}
{
// During sending of UpdateDeviceList this lock is acquired also so making
// it scoped
sync_primitives::AutoLock lock(reregister_wait_list_lock_);
- for (auto i = reregister_wait_list_.begin(); reregister_wait_list_.end() != i;
- ++i) {
- auto app = *i;
- request_ctrl_.terminateAppRequests(app->app_id());
- resume_ctrl_->SaveApplication(app);
+ for (auto i = reregister_wait_list_.begin(); reregister_wait_list_.end() != i;
+ ++i) {
+ auto app = *i;
+ request_ctrl_.terminateAppRequests(app->app_id());
+ resume_ctrl_->SaveApplication(app);
+ }
}
-}
policy_handler_->OnDeviceSwitching(device_from.mac_address(),
device_to.mac_address());
@@ -1108,6 +1107,10 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart(
smart_objects::SmartObjectSPtr msg_params =
MessageHelper::CreateDeviceListSO(device_list, GetPolicyHandler(), *this);
+ if (!msg_params) {
+ LOG4CXX_ERROR(logger_, "Can't create UpdateDeviceList notification");
+ return;
+ }
auto update_list = utils::MakeShared<smart_objects::SmartObject>();
smart_objects::SmartObject& so_to_send = *update_list;
diff --git a/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc b/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc
index 4de7be7c4c..471270f9b8 100644
--- a/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc
@@ -39,6 +39,7 @@
#include "application_manager/application_manager_impl.h"
#include "utils/custom_string.h"
#include "utils/make_shared.h"
+#include "encryption/hashing.h"
#include "application_manager/mock_application_manager_settings.h"
#include "application_manager/mock_resumption_data.h"
@@ -162,7 +163,7 @@ TEST_F(ApplicationManagerImplMockHmiTest,
utils::SharedPtr<ApplicationImpl> app_impl = new ApplicationImpl(
application_id,
policy_app_id,
- mac_address,
+ encryption::MakeHash(mac_address),
device_id,
app_name,
utils::SharedPtr<usage_statistics::StatisticsManager>(
@@ -171,11 +172,25 @@ TEST_F(ApplicationManagerImplMockHmiTest,
app_manager_impl_->AddMockApplication(app_impl);
- app_manager_impl_->OnDeviceSwitchingStart(mac_address);
+ const connection_handler::Device bt(device_id,
+ "BT_device",
+ mac_address,
+ "BLUETOOTH");
+
+ const connection_handler::Device usb(device_id + 1,
+ "USB_device",
+ "USB_serial",
+ "USB_IOS");
MockHMICommandFactory* mock_hmi_factory =
MockHMICommandFactory::mock_hmi_command_factory();
+ // Skip sending notification on device switching as it is not the goal here
+ EXPECT_CALL(*mock_hmi_factory, CreateCommand(_, _))
+ .WillOnce(Return(utils::SharedPtr<commands::Command>()));
+
+ app_manager_impl_->OnDeviceSwitchingStart(bt, usb);
+
const uint32_t connection_key = 1u;
const uint32_t correlation_id_1 = 1u;
const uint32_t correlation_id_2 = 2u;
diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc
index f2af615025..4398952237 100644
--- a/src/components/application_manager/test/application_manager_impl_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_test.cc
@@ -56,6 +56,7 @@
#include "utils/lock.h"
#include "utils/make_shared.h"
#include "utils/push_log.h"
+#include "encryption/hashing.h"
namespace test {
namespace components {
@@ -131,7 +132,7 @@ class ApplicationManagerImplTest : public ::testing::Test {
ON_CALL(mock_application_manager_settings_, app_storage_folder())
.WillByDefault(ReturnRef(kDirectoryName));
ON_CALL(mock_application_manager_settings_, launch_hmi())
- .WillByDefault(Return(true));
+ .WillByDefault(Return(false));
ON_CALL(mock_application_manager_settings_, stop_streaming_timeout())
.WillByDefault(Return(stop_streaming_timeout));
ON_CALL(mock_application_manager_settings_, default_timeout())
@@ -679,29 +680,56 @@ TEST_F(ApplicationManagerImplTest,
utils::SharedPtr<MockApplication> switching_app_ptr =
utils::MakeShared<MockApplication>();
- const std::string switching_mac_address = "switching";
+ const std::string switching_device_id = "switching";
+ const std::string switching_device_id_hash =
+ encryption::MakeHash(switching_device_id);
app_manager_impl_->AddMockApplication(switching_app_ptr);
EXPECT_CALL(*switching_app_ptr, mac_address())
- .WillRepeatedly(ReturnRef(switching_mac_address));
+ .WillRepeatedly(ReturnRef(switching_device_id_hash));
const std::string policy_app_id_switch = "abc";
EXPECT_CALL(*switching_app_ptr, policy_app_id())
.WillRepeatedly(Return(policy_app_id_switch));
+ const auto hmi_level_switching_app = mobile_apis::HMILevel::HMI_FULL;
+ EXPECT_CALL(*switching_app_ptr, hmi_level())
+ .WillRepeatedly(Return(hmi_level_switching_app));
+
utils::SharedPtr<MockApplication> nonswitching_app_ptr =
utils::MakeShared<MockApplication>();
- const std::string nonswitching_mac_address = "nonswitching";
+ const std::string nonswitching_device_id = "nonswitching";
+ const std::string nonswitching_device_id_hash =
+ encryption::MakeHash(nonswitching_device_id);
app_manager_impl_->AddMockApplication(nonswitching_app_ptr);
EXPECT_CALL(*nonswitching_app_ptr, mac_address())
- .WillRepeatedly(ReturnRef(nonswitching_mac_address));
+ .WillRepeatedly(ReturnRef(nonswitching_device_id_hash));
const std::string policy_app_id_nonswitch = "efg";
EXPECT_CALL(*nonswitching_app_ptr, policy_app_id())
.WillRepeatedly(Return(policy_app_id_nonswitch));
+ const auto hmi_level_nonswitching_app = mobile_apis::HMILevel::HMI_LIMITED;
+ EXPECT_CALL(*nonswitching_app_ptr, hmi_level())
+ .WillRepeatedly(Return(hmi_level_nonswitching_app));
+
// Act
- app_manager_impl_->OnDeviceSwitchingStart(switching_mac_address);
+ const connection_handler::DeviceHandle switching_handle = 1;
+ const connection_handler::Device switching_device(switching_handle,
+ "switching_device",
+ switching_device_id,
+ "BLUETOOTH");
+
+ const connection_handler::DeviceHandle non_switching_handle = 2;
+ const connection_handler::Device non_switching_device(non_switching_handle,
+ "non_switching_device",
+ nonswitching_device_id,
+ "USB");
+
+ EXPECT_CALL(*mock_message_helper_, CreateDeviceListSO(_, _, _))
+ .WillOnce(Return(smart_objects::SmartObjectSPtr()));
+ app_manager_impl_->OnDeviceSwitchingStart(switching_device,
+ non_switching_device);
EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch));
EXPECT_FALSE(
app_manager_impl_->IsAppInReconnectMode(policy_app_id_nonswitch));
@@ -712,62 +740,63 @@ TEST_F(ApplicationManagerImplTest,
utils::SharedPtr<MockApplication> switching_app_ptr =
utils::MakeShared<MockApplication>();
- const uint32_t switching_app_id = 1u;
- EXPECT_CALL(*switching_app_ptr, app_id())
- .WillRepeatedly(Return(switching_app_id));
-
- const uint32_t switching_device_id = 1u;
- EXPECT_CALL(*switching_app_ptr, device())
- .WillRepeatedly(Return(switching_device_id));
-
- const std::string switching_mac_address = "switching";
+ const std::string switching_device_id = "switching";
+ const std::string switching_device_id_hash =
+ encryption::MakeHash(switching_device_id);
app_manager_impl_->AddMockApplication(switching_app_ptr);
EXPECT_CALL(*switching_app_ptr, mac_address())
- .WillRepeatedly(ReturnRef(switching_mac_address));
+ .WillRepeatedly(ReturnRef(switching_device_id_hash));
const std::string policy_app_id_switch = "abc";
EXPECT_CALL(*switching_app_ptr, policy_app_id())
.WillRepeatedly(Return(policy_app_id_switch));
+ const auto hmi_level_switching_app = mobile_apis::HMILevel::HMI_FULL;
+ EXPECT_CALL(*switching_app_ptr, hmi_level())
+ .WillRepeatedly(Return(hmi_level_switching_app));
+
utils::SharedPtr<MockApplication> nonswitching_app_ptr =
utils::MakeShared<MockApplication>();
- const uint32_t nonswitching_app_id = 2u;
- EXPECT_CALL(*nonswitching_app_ptr, app_id())
- .WillRepeatedly(Return(nonswitching_app_id));
-
- const uint32_t nonswitching_device_id = 2u;
- EXPECT_CALL(*nonswitching_app_ptr, device())
- .WillRepeatedly(Return(nonswitching_device_id));
-
- const std::string nonswitching_mac_address = "nonswitching";
+ const std::string nonswitching_device_id = "nonswitching";
+ const std::string nonswitching_device_id_hash =
+ encryption::MakeHash(nonswitching_device_id);
app_manager_impl_->AddMockApplication(nonswitching_app_ptr);
EXPECT_CALL(*nonswitching_app_ptr, mac_address())
- .WillRepeatedly(ReturnRef(nonswitching_mac_address));
+ .WillRepeatedly(ReturnRef(nonswitching_device_id_hash));
const std::string policy_app_id_nonswitch = "efg";
EXPECT_CALL(*nonswitching_app_ptr, policy_app_id())
.WillRepeatedly(Return(policy_app_id_nonswitch));
+ const auto hmi_level_nonswitching_app = mobile_apis::HMILevel::HMI_LIMITED;
+ EXPECT_CALL(*nonswitching_app_ptr, hmi_level())
+ .WillRepeatedly(Return(hmi_level_nonswitching_app));
+
// Act
- app_manager_impl_->OnDeviceSwitchingStart(switching_mac_address);
- EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch));
- EXPECT_FALSE(
- app_manager_impl_->IsAppInReconnectMode(policy_app_id_nonswitch));
+ const connection_handler::DeviceHandle switching_handle = 1;
+ const connection_handler::Device switching_device(switching_handle,
+ "switching_device",
+ switching_device_id,
+ "BLUETOOTH");
- smart_objects::SmartObjectSPtr sptr =
- MakeShared<smart_objects::SmartObject>();
+ const connection_handler::DeviceHandle non_switching_handle = 2;
+ const connection_handler::Device non_switching_device(non_switching_handle,
+ "non_switching_device",
+ nonswitching_device_id,
+ "USB");
- ON_CALL(*mock_message_helper_, CreateModuleInfoSO(_, _))
- .WillByDefault(Return(sptr));
- ON_CALL(*mock_message_helper_, CreateNegativeResponse(_, _, _, _))
- .WillByDefault(Return(sptr));
+ EXPECT_CALL(*mock_message_helper_, CreateDeviceListSO(_, _, _))
+ .WillOnce(Return(smart_objects::SmartObjectSPtr()));
+
+ app_manager_impl_->OnDeviceSwitchingStart(switching_device,
+ non_switching_device);
+
+ EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch));
- app_manager_impl_->OnDeviceSwitchingFinish(switching_mac_address);
+ app_manager_impl_->OnDeviceSwitchingFinish(switching_device_id);
EXPECT_FALSE(
app_manager_impl_->application_by_policy_id(policy_app_id_switch));
- EXPECT_TRUE(
- app_manager_impl_->application_by_policy_id(policy_app_id_nonswitch));
}
TEST_F(ApplicationManagerImplTest,
diff --git a/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc
index b0928044fc..bf619e5229 100644
--- a/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc
+++ b/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc
@@ -432,13 +432,7 @@ TEST_F(RegisterAppInterfaceRequestTest,
mock_app),
request_hash_id)).WillOnce(Return(true));
- EXPECT_CALL(
- mock_resume_crt_,
- CheckPersistenceFilesForResumption(
- MockAppPtr::static_pointer_cast<application_manager::Application>(
- mock_app))).WillOnce(Return(true));
-
- EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0);
+ EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0);
EXPECT_CALL(mock_application_helper_, RecallApplicationData(_, _)).Times(0);
@@ -473,11 +467,7 @@ TEST_F(RegisterAppInterfaceRequestTest,
mock_app),
request_hash_id)).WillOnce(Return(false));
- EXPECT_CALL(mock_resume_crt_,
- RemoveApplicationFromSaved(MockAppPtr::static_pointer_cast<
- const application_manager::Application>(mock_app)));
-
- EXPECT_CALL(
+ EXPECT_CALL(
mock_application_helper_,
RecallApplicationData(
MockAppPtr::static_pointer_cast<application_manager::Application>(
@@ -507,10 +497,6 @@ TEST_F(RegisterAppInterfaceRequestTest,
EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey));
- EXPECT_CALL(mock_resume_crt_,
- RemoveApplicationFromSaved(MockAppPtr::static_pointer_cast<
- const application_manager::Application>(mock_app)));
-
EXPECT_CALL(
mock_application_helper_,
RecallApplicationData(
diff --git a/src/components/connection_handler/test/connection_handler_impl_test.cc b/src/components/connection_handler/test/connection_handler_impl_test.cc
index 87561b339f..362f779142 100644
--- a/src/components/connection_handler/test/connection_handler_impl_test.cc
+++ b/src/components/connection_handler/test/connection_handler_impl_test.cc
@@ -471,6 +471,14 @@ TEST_F(ConnectionHandlerTest, IsHeartBeatSupported) {
connection_handler_->IsHeartBeatSupported(uid_, start_session_id_));
}
+MATCHER_P(SameDevice, device, "") {
+ return
+ arg.device_handle() == device.device_handle() &&
+ arg.user_friendly_name() == device.user_friendly_name() &&
+ arg.mac_address() == device.mac_address() &&
+ arg.connection_type() == device.connection_type();
+}
+
TEST_F(ConnectionHandlerTest, SendEndServiceWithoutSetProtocolHandler) {
AddTestDeviceConnection();
AddTestSession();
@@ -1900,23 +1908,35 @@ TEST_F(ConnectionHandlerTest, OnDeviceConnectionSwitching) {
connection_handler_->set_connection_handler_observer(
&mock_connection_handler_observer);
- const std::string fake_device_id = "fake_device_id";
- EXPECT_CALL(mock_connection_handler_observer,
- OnDeviceSwitchingStart(encryption::MakeHash(fake_device_id)));
- connection_handler_->OnDeviceSwitchingStart(fake_device_id);
-}
+ const transport_manager::DeviceInfo device_info_1(device_handle_,
+ mac_address_,
+ device_name_,
+ connection_type_);
-TEST_F(ConnectionHandlerTest, OnDeviceSwitchingFinish) {
- connection_handler_test::MockConnectionHandlerObserver
- mock_connection_handler_observer;
- connection_handler_->set_connection_handler_observer(
- &mock_connection_handler_observer);
+ connection_handler_->OnDeviceAdded(device_info_1);
+
+ const auto second_mac_address = "second_mac_address";
+ const transport_manager::DeviceInfo device_info_2(device_handle_ + 1,
+ second_mac_address,
+ "second_device_name",
+ "second_connection_type");
+
+ connection_handler_->OnDeviceAdded(device_info_2);
+
+ connection_handler::Device d1(device_info_1.device_handle(),
+ device_info_1.name(),
+ device_info_1.mac_address(),
+ device_info_1.connection_type());
+
+ connection_handler::Device d2(device_info_2.device_handle(),
+ device_info_2.name(),
+ device_info_2.mac_address(),
+ device_info_2.connection_type());
- const std::string fake_device_id = "fake_device_id";
EXPECT_CALL(mock_connection_handler_observer,
- OnDeviceSwitchingFinish(encryption::MakeHash(fake_device_id)));
+ OnDeviceSwitchingStart(SameDevice(d1), SameDevice(d2)));
- connection_handler_->OnDeviceSwitchingFinish(fake_device_id);
+ connection_handler_->OnDeviceSwitchingStart(mac_address_, second_mac_address);
}
} // namespace connection_handler_test
diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
index 812df19ccd..bb4e5d3e21 100644
--- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
+++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
@@ -255,6 +255,8 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
MOCK_METHOD2(SetDefaultHmiTypes,
void(const std::string& application_id,
const smart_objects::SmartObject* app_types));
+ MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from,
+ const std::string& device_id_to));
#endif // SDL_REMOTE_CONTROL
private:
diff --git a/src/components/include/test/connection_handler/mock_connection_handler_observer.h b/src/components/include/test/connection_handler/mock_connection_handler_observer.h
index 3bcd8d5214..0d0d362adb 100644
--- a/src/components/include/test/connection_handler/mock_connection_handler_observer.h
+++ b/src/components/include/test/connection_handler/mock_connection_handler_observer.h
@@ -67,7 +67,9 @@ class MockConnectionHandlerObserver
GetHandshakeContext,
security_manager::SSLContext::HandshakeContext(uint32_t key));
- MOCK_METHOD1(OnDeviceSwitchingStart, void(const std::string& device_uid));
+ MOCK_METHOD2(OnDeviceSwitchingStart, void(
+ const connection_handler::Device& device_from,
+ const connection_handler::Device& device_to));
MOCK_METHOD1(OnDeviceSwitchingFinish, void(const std::string& device_uid));
};
diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
index e90fa63075..2f3c785865 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
@@ -247,6 +247,8 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
GroupsByExternalConsentStatus(const ExternalConsentStatus&));
MOCK_METHOD0(GetKnownLinksFromPT, std::map<std::string, std::string>());
MOCK_METHOD1(SetExternalConsentForApp, void(const PermissionConsent&));
+ MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from,
+ const std::string& device_id_to));
};
} // namespace policy_test
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
index 6227e7e85c..3b835be422 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
@@ -215,6 +215,8 @@ class MockPolicyManager : public PolicyManager {
MOCK_METHOD0(GetExternalConsentStatus, ExternalConsentStatus());
MOCK_CONST_METHOD1(IsNeedToUpdateExternalConsentStatus,
bool(const ExternalConsentStatus&));
+ MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from,
+ const std::string& device_id_to));
};
} // namespace policy_manager_test
} // namespace components
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
index 39876cf713..9a254417ec 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
@@ -211,6 +211,8 @@ class MockCacheManagerInterface : public CacheManagerInterface {
MOCK_CONST_METHOD2(AppHasHMIType,
bool(const std::string& application_id,
policy_table::AppHMIType hmi_type));
+ MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from,
+ const std::string& device_id_to));
};
} // namespace policy_test
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
index cfe41ee64c..66fc9bcf8d 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
@@ -222,6 +222,9 @@ class MockPolicyManager : public PolicyManager {
CheckPendingPermissionsChanges,
void(const std::string& policy_app_id,
const std::vector<FunctionalGroupPermission>& current_permissions));
+
+ MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from,
+ const std::string& device_id_to));
};
} // namespace policy_manager_test
diff --git a/src/components/include/test/transport_manager/mock_transport_manager_listener.h b/src/components/include/test/transport_manager/mock_transport_manager_listener.h
index a57ae69bbb..2099c2c56b 100644
--- a/src/components/include/test/transport_manager/mock_transport_manager_listener.h
+++ b/src/components/include/test/transport_manager/mock_transport_manager_listener.h
@@ -81,7 +81,8 @@ class MockTransportManagerListener : public TransportManagerListener {
MOCK_METHOD2(OnTMMessageSendFailed,
void(const DataSendError& error,
const ::protocol_handler::RawMessagePtr message));
- MOCK_METHOD1(OnDeviceSwitchingStart, void(const DeviceUID& device_uid));
+ MOCK_METHOD2(OnDeviceSwitchingStart, void(const DeviceUID& device_uid_from,
+ const DeviceUID& device_uid_to));
MOCK_METHOD1(OnDeviceSwitchingFinish, void(const DeviceUID& device_uid));
};
diff --git a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h
index 3f915a75f4..c37c41d4f8 100644
--- a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h
+++ b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h
@@ -98,10 +98,11 @@ class MockTransportAdapter
MOCK_CONST_METHOD1(StopDevice,
void(const ::transport_manager::DeviceUID& device_id));
-
+ MOCK_CONST_METHOD0(DoTransportSwitch, void());
MOCK_METHOD1(DeviceSwitched,
void(const ::transport_manager::DeviceUID& device_handle));
-
+ MOCK_CONST_METHOD0(GetSwitchableDevices,
+ transport_manager::SwitchableDevices());
#ifdef TELEMETRY_MONITOR
MOCK_METHOD0(GetTelemetryObserver,
::transport_manager::TMTelemetryObserver*());
diff --git a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h
index 8302a63beb..29bf7c8e83 100644
--- a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h
+++ b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h
@@ -120,6 +120,8 @@ class MockTransportAdapterListener : public TransportAdapterListener {
void(const TransportAdapter*,
const DeviceUID&,
const ApplicationHandle&));
+ MOCK_METHOD1(OnTransportSwitchRequested,
+ void(const TransportAdapter* transport_adapter));
};
} // namespace transport_manager_test
diff --git a/src/components/transport_manager/test/transport_manager_impl_test.cc b/src/components/transport_manager/test/transport_manager_impl_test.cc
index 65884d8e94..7380d68bbc 100644
--- a/src/components/transport_manager/test/transport_manager_impl_test.cc
+++ b/src/components/transport_manager/test/transport_manager_impl_test.cc
@@ -106,6 +106,34 @@ class TransportManagerImplTest : public ::testing::Test {
MakeShared<RawMessage>(connection_key_, version_protocol_, data, kSize);
}
+ DeviceInfo ConstructDeviceInfo(const std::string& mac_address,
+ const std::string& connection_type,
+ const std::string& device_name) {
+ const auto device_handle(
+ tm_.get_converter().UidToHandle(mac_address, connection_type));
+
+ return DeviceInfo(device_handle, mac_address, device_name, connection_type);
+ }
+
+ void SetAddDeviceExpectations(MockTransportAdapter* mock_adapter,
+ transport_adapter::DeviceType type,
+ const DeviceList& device_list,
+ const DeviceInfo& device_info) {
+ EXPECT_CALL(*mock_adapter, GetDeviceList())
+ .WillRepeatedly(Return(device_list));
+
+ EXPECT_CALL(*mock_adapter, DeviceName(device_info.mac_address()))
+ .WillRepeatedly(Return(device_info.name()));
+
+ EXPECT_CALL(*mock_adapter, GetConnectionType())
+ .WillRepeatedly(Return(device_info.connection_type()));
+
+ EXPECT_CALL(*mock_adapter, GetDeviceType()).WillRepeatedly(Return(type));
+
+ EXPECT_CALL(*tm_listener_, OnDeviceAdded(device_info));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ }
+
void HandleDeviceListUpdated() {
TransportAdapterEvent test_event(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
mock_adapter_,
@@ -127,8 +155,8 @@ class TransportManagerImplTest : public ::testing::Test {
.Times(AtLeast(1))
.WillRepeatedly(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
tm_.TestHandle(test_event);
device_list_.pop_back();
@@ -287,24 +315,6 @@ class TransportManagerImplTest : public ::testing::Test {
ASSERT_EQ(E_SUCCESS, tm_.Stop());
}
- void SetAddDeviceExpectations(MockTransportAdapter* mock_adapter,
- transport_adapter::DeviceType type) {
- EXPECT_CALL(*mock_adapter, GetDeviceList())
- .WillRepeatedly(Return(device_list_));
-
- EXPECT_CALL(*mock_adapter, DeviceName(dev_info_.mac_address()))
- .WillRepeatedly(Return(dev_info_.name()));
-
- EXPECT_CALL(*mock_adapter, GetConnectionType())
- .WillRepeatedly(Return(dev_info_.connection_type()));
-
- EXPECT_CALL(*mock_adapter, GetDeviceType()).WillRepeatedly(Return(type));
-
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
- EXPECT_CALL(*tm_listener_, OnDeviceFound(_));
- }
-
MockTransportManagerSettings mock_transport_manager_settings_;
#ifdef TELEMETRY_MONITOR
MockTMTelemetryObserver mock_metric_observer_;
@@ -1073,44 +1083,44 @@ TEST_F(TransportManagerImplTest,
TEST_F(
TransportManagerImplTest,
- UpdateDeviceList_AddSameUUIDNonSwitchableDevices_TwoTransportAdapters_ExpectSecondFailed) {
- // Arrange
- MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
+ UpdateDeviceList_AddSameUUIDNonSwitchableDevices_TwoTransportAdapters_ExpectNoSwitch) {
device_list_.push_back(dev_info_.mac_address());
- // Check before Act
+ SetAddDeviceExpectations(
+ mock_adapter_, transport_adapter::DeviceType::TCP, device_list_, dev_info_);
+
+ tm_.OnDeviceListUpdated(mock_adapter_);
+
+ // Adapter will be removed by TM on destruction
+ MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
EXPECT_CALL(*second_mock_adapter, AddListener(_));
EXPECT_CALL(*second_mock_adapter, IsInitialised()).WillOnce(Return(true));
EXPECT_EQ(E_SUCCESS, tm_.AddTransportAdapter(second_mock_adapter));
- EXPECT_CALL(*mock_adapter_, GetDeviceType())
- .WillRepeatedly(Return(transport_adapter::DeviceType::TCP));
- EXPECT_CALL(*mock_adapter_, GetDeviceList())
- .WillRepeatedly(Return(device_list_));
- EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
- .WillRepeatedly(Return(dev_info_.name()));
- EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillRepeatedly(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ const auto usb_serial = "USB_serial";
+ DeviceInfo second_device =
+ ConstructDeviceInfo(usb_serial, "USB_IOS", "SecondDeviceName");
- // Act
- tm_.OnDeviceListUpdated(mock_adapter_);
+ DeviceList second_adapter_device_list;
+ second_adapter_device_list.push_back(usb_serial);
- EXPECT_CALL(*second_mock_adapter, GetDeviceList())
- .WillRepeatedly(Return(device_list_));
- EXPECT_CALL(*second_mock_adapter, DeviceName(dev_info_.mac_address()))
- .WillRepeatedly(Return(dev_info_.name()));
- EXPECT_CALL(*second_mock_adapter, GetConnectionType())
- .WillRepeatedly(Return(dev_info_.connection_type()));
- EXPECT_CALL(*second_mock_adapter, GetDeviceType())
- .WillRepeatedly(Return(transport_adapter::DeviceType::IOS_USB));
+ SetAddDeviceExpectations(second_mock_adapter,
+ transport_adapter::DeviceType::IOS_USB,
+ second_adapter_device_list,
+ second_device);
+
+ tm_.OnDeviceListUpdated(second_mock_adapter);
+
+ // Act
EXPECT_CALL(*second_mock_adapter, StopDevice(_)).Times(0);
EXPECT_CALL(*second_mock_adapter, DeviceSwitched(_)).Times(0);
- EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_)).Times(0);
- // Act
- tm_.OnDeviceListUpdated(second_mock_adapter);
+ tm_.TestHandle(
+ TransportAdapterEvent(EventTypeEnum::ON_TRANSPORT_SWITCH_REQUESTED,
+ second_mock_adapter,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
device_list_.pop_back();
}
@@ -1129,7 +1139,7 @@ TEST_F(TransportManagerImplTest, OnlyOneDeviceShouldNotTriggerSwitch) {
EXPECT_CALL(*mock_adapter_, StopDevice(_)).Times(0);
EXPECT_CALL(*mock_adapter_, DeviceSwitched(_)).Times(0);
- EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(_)).Times(0);
+ EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(_, _)).Times(0);
tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
mock_adapter_,
@@ -1146,8 +1156,10 @@ TEST_F(TransportManagerImplTest,
device_list_.push_back(dev_info_.mac_address());
const uint32_t timeout = 0;
- SetAddDeviceExpectations(mock_adapter_,
- transport_adapter::DeviceType::IOS_BT);
+ SetAddDeviceExpectations(
+ mock_adapter_, transport_adapter::DeviceType::IOS_BT, device_list_, dev_info_);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
mock_adapter_,
@@ -1158,19 +1170,89 @@ TEST_F(TransportManagerImplTest,
auto second_mock_adapter = utils::MakeShared<MockTransportAdapter>();
+ const auto usb_serial = "USB_serial";
+ DeviceInfo second_device =
+ ConstructDeviceInfo(usb_serial, "USB_IOS", "SecondDeviceName");
+
+ DeviceList second_adapter_devices;
+ second_adapter_devices.push_back(second_device.mac_address());
+
SetAddDeviceExpectations(second_mock_adapter.get(),
- transport_adapter::DeviceType::IOS_USB);
+ transport_adapter::DeviceType::IOS_USB,
+ second_adapter_devices,
+ second_device);
- EXPECT_CALL(*mock_adapter_, StopDevice(mac_address_));
- EXPECT_CALL(*second_mock_adapter, DeviceSwitched(mac_address_));
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(second_device));
+ EXPECT_CALL(*second_mock_adapter, DeviceSwitched(_)).Times(0);
+
+ tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
+ second_mock_adapter.get(),
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ // Act
+ const auto uuid = "ABC-DEF-GHJ-KLM";
+ SwitchableDevices bt_switchables;
+ bt_switchables.insert(std::make_pair(dev_info_.mac_address(), uuid));
+ EXPECT_CALL(*mock_adapter_, GetSwitchableDevices())
+ .WillOnce(Return(bt_switchables));
+
+ SwitchableDevices usb_switchables;
+ usb_switchables.insert(std::make_pair(second_device.mac_address(), uuid));
+ EXPECT_CALL(*second_mock_adapter, GetSwitchableDevices())
+ .WillOnce(Return(usb_switchables));
+ EXPECT_CALL(*mock_adapter_, StopDevice(mac_address_));
+ EXPECT_CALL(*second_mock_adapter, DeviceSwitched(usb_serial));
EXPECT_CALL(mock_transport_manager_settings_, app_transport_change_timer())
.WillOnce(Return(timeout));
EXPECT_CALL(mock_transport_manager_settings_,
app_transport_change_timer_addition()).WillOnce(Return(0));
- EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(mac_address_));
- EXPECT_CALL(*tm_listener_, OnDeviceSwitchingFinish(mac_address_));
+ EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(mac_address_, usb_serial));
+
+ tm_.TestHandle(
+ TransportAdapterEvent(EventTypeEnum::ON_TRANSPORT_SWITCH_REQUESTED,
+ second_mock_adapter.get(),
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ // There is internal timer started on switching. Need to wait for timeout.
+ sleep(1);
+ device_list_.pop_back();
+}
+
+TEST_F(TransportManagerImplTest,
+ TwoTransportAdapterAddSameDeviceSecondSkipped) {
+ device_list_.push_back(dev_info_.mac_address());
+
+ SetAddDeviceExpectations(
+ mock_adapter_, transport_adapter::DeviceType::IOS_BT, device_list_, dev_info_);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(_));
+
+ tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
+ mock_adapter_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ auto second_mock_adapter = utils::MakeShared<MockTransportAdapter>();
+
+ DeviceInfo second_device =
+ ConstructDeviceInfo("MA:CA:DR:ES:S", "USB_IOS", "SecondDeviceName");
+
+ SetAddDeviceExpectations(second_mock_adapter.get(),
+ transport_adapter::DeviceType::IOS_USB,
+ device_list_,
+ second_device);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(_)).Times(0);
tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
second_mock_adapter.get(),
@@ -1182,6 +1264,35 @@ TEST_F(TransportManagerImplTest,
device_list_.pop_back();
}
+TEST_F(TransportManagerImplTest, NoDeviceTransportSwitchRequest_Fail) {
+ device_list_.push_back(dev_info_.mac_address());
+ SetAddDeviceExpectations(
+ mock_adapter_, transport_adapter::DeviceType::IOS_USB, device_list_, dev_info_);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(_));
+
+ tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
+ mock_adapter_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ EXPECT_CALL(*mock_adapter_, StopDevice(mac_address_)).Times(0);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(mac_address_, mac_address_)).Times(0);
+
+ tm_.TestHandle(
+ TransportAdapterEvent(EventTypeEnum::ON_TRANSPORT_SWITCH_REQUESTED,
+ mock_adapter_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ device_list_.pop_back();
+}
+
TEST_F(TransportManagerImplTest,
UpdateDeviceList_RemoveDevices_TwoTransportAdapters_ExpectSuccess) {
// Arrange