summaryrefslogtreecommitdiff
path: root/src/components/transport_manager/test/transport_manager_impl_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/transport_manager/test/transport_manager_impl_test.cc')
-rw-r--r--src/components/transport_manager/test/transport_manager_impl_test.cc688
1 files changed, 467 insertions, 221 deletions
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 110b41e08b..eebb247908 100644
--- a/src/components/transport_manager/test/transport_manager_impl_test.cc
+++ b/src/components/transport_manager/test/transport_manager_impl_test.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Ford Motor Company
+ * Copyright (c) 2017, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,24 +35,22 @@
#include "protocol/raw_message.h"
#include "transport_manager/common.h"
#include "transport_manager/transport_manager_impl.h"
-
#include "transport_manager/mock_telemetry_observer.h"
-#include "transport_manager/transport_manager_listener_mock.h"
-#include "transport_manager/mock_transport_adapter_listener.h"
+#include "transport_manager/mock_transport_manager_listener.h"
#include "transport_manager/mock_telemetry_observer.h"
-#include "transport_manager/transport_adapter_mock.h"
+#include "transport_manager/transport_adapter/mock_transport_adapter.h"
#include "transport_manager/mock_transport_manager_impl.h"
#include "transport_manager/mock_transport_manager_settings.h"
-#include "utils/make_shared.h"
+#include "resumption/last_state_impl.h"
#include "utils/shared_ptr.h"
-
-#include "resumption/last_state.h"
#include "utils/make_shared.h"
+#include "utils/test_async_waiter.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::Return;
using ::testing::ReturnRef;
+using ::testing::DoAll;
using ::protocol_handler::RawMessage;
using ::protocol_handler::RawMessagePtr;
@@ -63,23 +61,31 @@ namespace test {
namespace components {
namespace transport_manager_test {
+namespace {
const std::string kAppStorageFolder = "app_storage_folder";
const std::string kAppInfoFolder = "app_info_folder";
-const int kAsyncExpectationsTimeout = 10000;
+const uint32_t kAsyncExpectationsTimeout = 10000u;
+}
class TransportManagerImplTest : public ::testing::Test {
protected:
TransportManagerImplTest()
- : tm_(settings)
- , device_handle_(1)
+ : mock_adapter_(NULL)
+ , tm_(mock_transport_manager_settings_)
, mac_address_("MA:CA:DR:ES:S")
- , dev_info_(device_handle_, mac_address_, "TestDeviceName", "BTMAC") {}
+ , connection_type_("BTMAC")
+ , device_name_("TestDeviceName")
+ , device_handle_(
+ tm_.get_converter().UidToHandle(mac_address_, connection_type_))
+ , dev_info_(
+ device_handle_, mac_address_, device_name_, connection_type_) {}
void SetUp() OVERRIDE {
- resumption::LastState last_state_("app_storage_folder", "app_info_storage");
+ resumption::LastStateImpl last_state_("app_storage_folder",
+ "app_info_storage");
tm_.Init(last_state_);
mock_adapter_ = new MockTransportAdapter();
- tm_listener_ = MakeShared<TransportManagerListenerMock>();
+ tm_listener_ = MakeShared<MockTransportManagerListener>();
#ifdef TELEMETRY_MONITOR
tm_.SetTelemetryObserver(&mock_metric_observer_);
@@ -100,11 +106,46 @@ class TransportManagerImplTest : public ::testing::Test {
MakeShared<RawMessage>(connection_key_, version_protocol_, data, kSize);
}
- void HandleDeviceListUpdated() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_DEVICE_LIST_UPDATED);
+ 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 SetOnDeviceExpectations(const DeviceInfo& device_info) {
+ EXPECT_CALL(*tm_listener_, OnDeviceAdded(device_info));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ }
+
+ void SetDeviceExpectations(MockTransportAdapter* mock_adapter,
+ 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()));
+ }
+
+ void SetAddDeviceExpectations(MockTransportAdapter* mock_adapter,
+ transport_adapter::DeviceType type,
+ const DeviceList& device_list,
+ const DeviceInfo& device_info) {
+ SetDeviceExpectations(mock_adapter, device_list, device_info);
- TransportAdapterEvent test_event(type,
+ EXPECT_CALL(*mock_adapter, GetDeviceType()).WillRepeatedly(Return(type));
+
+ SetOnDeviceExpectations(device_info);
+ }
+
+ void HandleDeviceListUpdated() {
+ TransportAdapterEvent test_event(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
mock_adapter_,
dev_info_.mac_address(),
application_id_,
@@ -124,19 +165,15 @@ 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(vector_dev_info));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
tm_.TestHandle(test_event);
device_list_.pop_back();
}
void HandleConnection() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_DONE);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_CONNECT_DONE,
mock_adapter_,
dev_info_.mac_address(),
application_id_,
@@ -146,7 +183,7 @@ class TransportManagerImplTest : public ::testing::Test {
EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
.WillOnce(Return(dev_info_.name()));
EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
+ .WillRepeatedly(Return(dev_info_.connection_type()));
EXPECT_CALL(*tm_listener_,
OnConnectionEstablished(dev_info_, connection_key_));
@@ -155,10 +192,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleConnectionFailed() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_CONNECT_FAIL,
mock_adapter_,
dev_info_.mac_address(),
application_id_,
@@ -168,7 +202,7 @@ class TransportManagerImplTest : public ::testing::Test {
EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
.WillOnce(Return(dev_info_.name()));
EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
+ .WillRepeatedly(Return(dev_info_.connection_type()));
EXPECT_CALL(*tm_listener_, OnConnectionFailed(dev_info_, _));
@@ -176,9 +210,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleSendDone() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_DONE);
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEND_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -193,9 +225,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleReceiveDone() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_DONE);
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_RECEIVED_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -210,10 +240,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleSendFailed() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEND_FAIL,
mock_adapter_,
mac_address_,
application_id_,
@@ -226,10 +253,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleSearchDone() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -242,10 +266,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleSearchFail() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_FAIL,
mock_adapter_,
mac_address_,
application_id_,
@@ -258,16 +279,13 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleFindNewApplicationsRequest() {
- const int type =
- static_cast<int>(TransportAdapterListenerImpl::EventTypeEnum::
- ON_FIND_NEW_APPLICATIONS_REQUEST);
-
- TransportAdapterEvent test_event(type,
- mock_adapter_,
- mac_address_,
- application_id_,
- test_message_,
- error_);
+ TransportAdapterEvent test_event(
+ EventTypeEnum::ON_FIND_NEW_APPLICATIONS_REQUEST,
+ mock_adapter_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_);
EXPECT_CALL(*tm_listener_, OnFindNewApplicationsRequest());
@@ -275,10 +293,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleConnectionClosed() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_DONE);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_DISCONNECT_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -293,10 +308,7 @@ class TransportManagerImplTest : public ::testing::Test {
}
void HandleDisconnectionFailed() {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_DISCONNECT_FAIL,
mock_adapter_,
mac_address_,
application_id_,
@@ -312,19 +324,22 @@ class TransportManagerImplTest : public ::testing::Test {
EXPECT_CALL(*mock_adapter_, Terminate());
ASSERT_EQ(E_SUCCESS, tm_.Stop());
}
- MockTransportManagerSettings settings;
- MockTransportManagerImpl tm_;
+
+ MockTransportManagerSettings mock_transport_manager_settings_;
#ifdef TELEMETRY_MONITOR
MockTMTelemetryObserver mock_metric_observer_;
#endif // TELEMETRY_MONITOR
MockTransportAdapter* mock_adapter_;
- utils::SharedPtr<TransportManagerListenerMock> tm_listener_;
+ utils::SharedPtr<MockTransportManagerListener> tm_listener_;
+ MockTransportManagerImpl tm_;
const ApplicationHandle application_id_ = 1;
ConnectionUID connection_key_;
RawMessagePtr test_message_;
- DeviceHandle device_handle_;
std::string mac_address_;
+ std::string connection_type_;
+ std::string device_name_;
+ DeviceHandle device_handle_;
const DeviceInfo dev_info_;
DeviceList device_list_;
@@ -491,16 +506,19 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice) {
// Arrange
HandleConnection();
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_))
- .WillOnce(Return(TransportAdapter::OK));
+ .WillOnce(
+ DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK)));
#ifdef TELEMETRY_MONITOR
EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get()));
#endif // TELEMETRY_MONITOR
EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_));
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, SendMessageToDevice_SendingFailed) {
@@ -511,66 +529,81 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice_SendingFailed) {
EXPECT_CALL(mock_metric_observer_, StartRawMsg(_));
#endif // TELEMETRY_MONITOR
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_))
.WillOnce(Return(TransportAdapter::FAIL));
- EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_));
+ EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_))
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_));
#ifdef TELEMETRY_MONITOR
EXPECT_CALL(mock_metric_observer_, StopRawMsg(_)).Times(0);
#endif // TELEMETRY_MONITOR
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, SendMessageToDevice_StartTimeObserver) {
// Arrange
HandleConnection();
+
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_))
- .WillOnce(Return(TransportAdapter::OK));
+ .WillOnce(
+ DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK)));
#ifdef TELEMETRY_MONITOR
EXPECT_CALL(mock_metric_observer_, StartRawMsg(_));
#endif // TELEMETRY_MONITOR
EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_));
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, SendMessageToDevice_SendDone) {
// Arrange
HandleConnection();
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_))
- .WillOnce(Return(TransportAdapter::OK));
+ .WillOnce(
+ DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK)));
+
#ifdef TELEMETRY_MONITOR
EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get()));
#endif // TELEMETRY_MONITOR
+
EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_));
HandleSendDone();
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, SendMessageFailed_GetHandleSendFailed) {
// Arrange
HandleConnection();
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_))
- .WillOnce(Return(TransportAdapter::FAIL));
+ .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter),
+ Return(TransportAdapter::FAIL)));
+
#ifdef TELEMETRY_MONITOR
EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get()));
#endif // TELEMETRY_MONITOR
+
EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_));
EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_));
HandleSendFailed();
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, RemoveDevice_DeviceWasAdded) {
@@ -624,78 +657,72 @@ TEST_F(TransportManagerImplTest, Reinit_InitAdapterFailed) {
TEST_F(TransportManagerImplTest, UpdateDeviceList_AddNewDevice) {
device_list_.push_back(dev_info_.mac_address());
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
- EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
-
- tm_.UpdateDeviceList(mock_adapter_);
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
+ SetOnDeviceExpectations(dev_info_);
+ tm_.OnDeviceListUpdated(mock_adapter_);
device_list_.pop_back();
}
TEST_F(TransportManagerImplTest, UpdateDeviceList_RemoveDevice) {
device_list_.push_back(dev_info_.mac_address());
-
- ::testing::InSequence seq;
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
- EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- tm_.UpdateDeviceList(mock_adapter_);
+ {
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+ ::testing::InSequence s;
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
+ SetOnDeviceExpectations(dev_info_);
+ tm_.OnDeviceListUpdated(mock_adapter_);
+ }
device_list_.pop_back();
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+
// Device list is empty now
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
+ ::testing::InSequence s;
EXPECT_CALL(*tm_listener_, OnDeviceRemoved(dev_info_));
- tm_.UpdateDeviceList(mock_adapter_);
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ tm_.OnDeviceListUpdated(mock_adapter_);
}
/*
* Tests which check correct handling and receiving events
*/
TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceDone) {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE);
-
- TransportAdapterEvent test_event(type,
+ TestAsyncWaiter waiter;
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_DONE,
mock_adapter_,
mac_address_,
application_id_,
test_message_,
error_);
- EXPECT_CALL(*tm_listener_, OnScanDevicesFinished());
+ EXPECT_CALL(*tm_listener_, OnScanDevicesFinished())
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
tm_.ReceiveEventFromDevice(test_event);
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceFail) {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TestAsyncWaiter waiter;
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_FAIL,
mock_adapter_,
mac_address_,
application_id_,
test_message_,
error_);
- EXPECT_CALL(*tm_listener_, OnScanDevicesFailed(_));
+ EXPECT_CALL(*tm_listener_, OnScanDevicesFailed(_))
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
tm_.ReceiveEventFromDevice(test_event);
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) {
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_DEVICE_LIST_UPDATED);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
mock_adapter_,
dev_info_.mac_address(),
application_id_,
@@ -705,6 +732,7 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) {
std::vector<DeviceInfo> vector_dev_info;
vector_dev_info.push_back(dev_info_);
+ TestAsyncWaiter waiter;
EXPECT_CALL(*mock_adapter_, GetDeviceList())
.Times(AtLeast(1))
.WillRepeatedly(Return(device_list_));
@@ -715,13 +743,15 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) {
.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(vector_dev_info));
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_))
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
+ EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_))
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
tm_.ReceiveEventFromDevice(test_event);
device_list_.pop_back();
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(2, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, CheckEvents) {
@@ -745,10 +775,7 @@ TEST_F(TransportManagerImplTest, CheckReceiveEvent) {
TEST_F(TransportManagerImplTest, CheckReceiveFailedEvent) {
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_FAIL);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_RECEIVED_FAIL,
mock_adapter_,
mac_address_,
application_id_,
@@ -763,10 +790,7 @@ TEST_F(TransportManagerImplTest, CheckReceiveFailedEvent) {
TEST_F(TransportManagerImplTest, CheckUnexpectedDisconnect) {
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_UNEXPECTED_DISCONNECT);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_UNEXPECTED_DISCONNECT,
mock_adapter_,
mac_address_,
application_id_,
@@ -848,10 +872,12 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice_ConnectionNotExist) {
TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_TMIsNotInitialized) {
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE);
- TransportAdapterEvent test_event(
- type, NULL, mac_address_, application_id_, test_message_, error_);
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_DONE,
+ NULL,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_);
// Check before Act
UninitializeTM();
// Act and Assert
@@ -879,10 +905,14 @@ TEST_F(TransportManagerImplTest, Visibility_TMIsNotInitialized) {
TEST_F(TransportManagerImplTest, HandleMessage_ConnectionNotExist) {
EXPECT_CALL(*mock_adapter_,
SendData(mac_address_, application_id_, test_message_)).Times(0);
- EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_));
+
+ TestAsyncWaiter waiter;
+ EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_))
+ .WillOnce(NotifyTestAsyncWaiter(&waiter));
tm_.TestHandle(test_message_);
- testing::Mock::AsyncVerifyAndClearExpectations(kAsyncExpectationsTimeout);
+
+ EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout));
}
TEST_F(TransportManagerImplTest, SearchDevices_TMIsNotInitialized) {
@@ -907,84 +937,10 @@ TEST_F(TransportManagerImplTest,
}
TEST_F(TransportManagerImplTest,
- UpdateDeviceList_AddDevices_TwoTransportAdapters) {
- // Arrange
- MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
- device_list_.push_back(dev_info_.mac_address());
- // Check before Act
- EXPECT_CALL(*second_mock_adapter, AddListener(_));
- EXPECT_CALL(*second_mock_adapter, IsInitialised()).WillOnce(Return(true));
- EXPECT_EQ(E_SUCCESS, tm_.AddTransportAdapter(second_mock_adapter));
-
- // Act and Assert
- EXPECT_CALL(*second_mock_adapter, GetDeviceList())
- .WillOnce(Return(device_list_));
- EXPECT_CALL(*second_mock_adapter, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*second_mock_adapter, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- tm_.UpdateDeviceList(second_mock_adapter);
-
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
- EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- tm_.UpdateDeviceList(mock_adapter_);
-
- device_list_.pop_back();
-}
-
-TEST_F(TransportManagerImplTest,
- UpdateDeviceList_RemoveDevices_TwoTransportAdapters) {
- // Arrange
- MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
- device_list_.push_back(dev_info_.mac_address());
- // Check before Act
- EXPECT_CALL(*second_mock_adapter, AddListener(_));
- EXPECT_CALL(*second_mock_adapter, IsInitialised()).WillOnce(Return(true));
- EXPECT_EQ(E_SUCCESS, tm_.AddTransportAdapter(second_mock_adapter));
-
- // Act and Assert
- EXPECT_CALL(*second_mock_adapter, GetDeviceList())
- .WillOnce(Return(device_list_));
- EXPECT_CALL(*second_mock_adapter, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*second_mock_adapter, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- tm_.UpdateDeviceList(second_mock_adapter);
-
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
- EXPECT_CALL(*mock_adapter_, DeviceName(dev_info_.mac_address()))
- .WillOnce(Return(dev_info_.name()));
- EXPECT_CALL(*mock_adapter_, GetConnectionType())
- .WillOnce(Return(dev_info_.connection_type()));
- EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_));
- tm_.UpdateDeviceList(mock_adapter_);
-
- device_list_.pop_back();
-
- EXPECT_CALL(*second_mock_adapter, GetDeviceList())
- .WillOnce(Return(device_list_));
- EXPECT_CALL(*tm_listener_, OnDeviceRemoved(dev_info_));
- tm_.UpdateDeviceList(second_mock_adapter);
-
- EXPECT_CALL(*mock_adapter_, GetDeviceList()).WillOnce(Return(device_list_));
- EXPECT_CALL(*tm_listener_, OnDeviceRemoved(dev_info_));
- tm_.UpdateDeviceList(mock_adapter_);
-}
-
-TEST_F(TransportManagerImplTest,
CheckEventOnDisconnectDone_ConnectionNotExist) {
// SetUp does not add connections
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_DONE);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_DISCONNECT_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -1000,10 +956,7 @@ TEST_F(TransportManagerImplTest,
TEST_F(TransportManagerImplTest, CheckEventOnSendDone_ConnectionNotExist) {
// SetUp does not add connections
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_DONE);
-
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_SEND_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -1021,9 +974,7 @@ TEST_F(TransportManagerImplTest, CheckEventOnSendDone_ConnectionNotExist) {
TEST_F(TransportManagerImplTest, CheckEventOnReceivedDone_ConnectionNotExist) {
// SetUp does not add connections
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_DONE);
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_RECEIVED_DONE,
mock_adapter_,
mac_address_,
application_id_,
@@ -1040,9 +991,7 @@ TEST_F(TransportManagerImplTest, CheckEventOnReceivedDone_ConnectionNotExist) {
TEST_F(TransportManagerImplTest, CheckEventOnReceivedFail_ConnectionNotExist) {
// SetUp does not add connections
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_FAIL);
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_RECEIVED_FAIL,
mock_adapter_,
mac_address_,
application_id_,
@@ -1057,9 +1006,7 @@ TEST_F(TransportManagerImplTest,
CheckEventOnUnexpectedDisconnect_ConnectionNotExist) {
// SetUp does not add connections
// Arrange
- const int type = static_cast<int>(
- TransportAdapterListenerImpl::EventTypeEnum::ON_UNEXPECTED_DISCONNECT);
- TransportAdapterEvent test_event(type,
+ TransportAdapterEvent test_event(EventTypeEnum::ON_UNEXPECTED_DISCONNECT,
mock_adapter_,
mac_address_,
application_id_,
@@ -1077,6 +1024,305 @@ TEST_F(TransportManagerImplTest, RunAppOnDevice_TransportAdapterFound_SUCCESS) {
tm_.RunAppOnDevice(device_handle_, bundle_id);
}
+TEST_F(TransportManagerImplTest,
+ UpdateDeviceList_AddDevices_TwoTransportAdapters_ExpectSuccess) {
+ // Arrange
+ MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
+ device_list_.push_back(dev_info_.mac_address());
+ // Check before Act
+ EXPECT_CALL(*second_mock_adapter, AddListener(_));
+ EXPECT_CALL(*second_mock_adapter, IsInitialised()).WillOnce(Return(true));
+ EXPECT_EQ(E_SUCCESS, tm_.AddTransportAdapter(second_mock_adapter));
+
+ // Act and Assert
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
+ SetOnDeviceExpectations(dev_info_);
+ tm_.OnDeviceListUpdated(mock_adapter_);
+
+ const std::string mac_address("NE:WA:DR:ES:SS");
+ const std::string connection_type("TCP");
+ const std::string device_name("TestName");
+ const transport_manager::DeviceHandle device_handle(
+ tm_.get_converter().UidToHandle(mac_address, connection_type));
+
+ DeviceInfo second_device(
+ device_handle, mac_address, device_name, connection_type);
+ DeviceList device_list_2;
+ device_list_2.push_back(second_device.mac_address());
+
+ SetDeviceExpectations(second_mock_adapter, device_list_2, second_device);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(second_device));
+ SetOnDeviceExpectations(second_device);
+ tm_.OnDeviceListUpdated(second_mock_adapter);
+
+ device_list_.pop_back();
+}
+
+TEST_F(
+ TransportManagerImplTest,
+ UpdateDeviceList_AddSameUUIDNonSwitchableDevices_TwoTransportAdapters_ExpectNoSwitch) {
+ device_list_.push_back(dev_info_.mac_address());
+ 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));
+
+ const auto usb_serial = "USB_serial";
+ DeviceInfo second_device =
+ ConstructDeviceInfo(usb_serial, "USB_IOS", "SecondDeviceName");
+
+ DeviceList second_adapter_device_list;
+ second_adapter_device_list.push_back(usb_serial);
+
+ 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);
+
+ tm_.TestHandle(
+ TransportAdapterEvent(EventTypeEnum::ON_TRANSPORT_SWITCH_REQUESTED,
+ second_mock_adapter,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ device_list_.pop_back();
+}
+
+TEST_F(TransportManagerImplTest, OnlyOneDeviceShouldNotTriggerSwitch) {
+ device_list_.push_back(dev_info_.mac_address());
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+ SetOnDeviceExpectations(dev_info_);
+
+ EXPECT_CALL(*mock_adapter_, StopDevice(_)).Times(0);
+ EXPECT_CALL(*mock_adapter_, DeviceSwitched(_)).Times(0);
+ EXPECT_CALL(*tm_listener_, OnDeviceSwitchingStart(_, _)).Times(0);
+
+ tm_.TestHandle(TransportAdapterEvent(EventTypeEnum::ON_DEVICE_LIST_UPDATED,
+ mock_adapter_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ device_list_.pop_back();
+}
+
+TEST_F(TransportManagerImplTest,
+ TwoTransportAdapterAddSameSwitchableDevice_ExpectSuccess) {
+ device_list_.push_back(dev_info_.mac_address());
+ const uint32_t timeout = 0;
+
+ 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_,
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ 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,
+ second_adapter_devices,
+ second_device);
+
+ 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_, 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(),
+ mac_address_,
+ application_id_,
+ test_message_,
+ error_));
+
+ 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
+ MockTransportAdapter* second_mock_adapter = new MockTransportAdapter();
+ device_list_.push_back(dev_info_.mac_address());
+ // Check before Act
+ EXPECT_CALL(*second_mock_adapter, AddListener(_));
+ EXPECT_CALL(*second_mock_adapter, IsInitialised()).WillOnce(Return(true));
+ EXPECT_EQ(E_SUCCESS, tm_.AddTransportAdapter(second_mock_adapter));
+
+ // Act and Assert
+ SetDeviceExpectations(mock_adapter_, device_list_, dev_info_);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_));
+ SetOnDeviceExpectations(dev_info_);
+ tm_.OnDeviceListUpdated(mock_adapter_);
+
+ const std::string mac_address("NE:WA:DR:ES:SS");
+ const std::string connection_type("TCP");
+ const std::string device_name("TestName");
+ const transport_manager::DeviceHandle device_handle(
+ tm_.get_converter().UidToHandle(mac_address, connection_type));
+
+ DeviceInfo second_device(
+ device_handle, mac_address, device_name, connection_type);
+ DeviceList device_list_2;
+ device_list_2.push_back(second_device.mac_address());
+ SetDeviceExpectations(second_mock_adapter, device_list_2, second_device);
+
+ EXPECT_CALL(*tm_listener_, OnDeviceFound(second_device));
+ SetOnDeviceExpectations(second_device);
+ tm_.OnDeviceListUpdated(second_mock_adapter);
+
+ device_list_.pop_back();
+ device_list_2.pop_back();
+
+ EXPECT_CALL(*second_mock_adapter, GetDeviceList())
+ .WillRepeatedly(Return(device_list_2));
+ EXPECT_CALL(*tm_listener_, OnDeviceRemoved(second_device));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ tm_.OnDeviceListUpdated(second_mock_adapter);
+
+ EXPECT_CALL(*mock_adapter_, GetDeviceList())
+ .WillRepeatedly(Return(device_list_));
+ EXPECT_CALL(*tm_listener_, OnDeviceRemoved(dev_info_));
+ EXPECT_CALL(*tm_listener_, OnDeviceListUpdated(_));
+ tm_.OnDeviceListUpdated(mock_adapter_);
+}
+
} // namespace transport_manager_test
} // namespace components
} // namespace test