Skip to content

Commit

Permalink
Update unit tests according to code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AByzhynar committed Sep 20, 2019
1 parent 768a22c commit 107b8ad
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ TEST_F(ConnectionHandlerTest, StartTransportManager) {
AddTestDeviceConnection();
AddTestSession();

EXPECT_CALL(mock_transport_manager_, Visibility(true));
EXPECT_CALL(mock_transport_manager_,
PerformActionOnClients(
transport_manager::TransportAction::kVisibilityOn));
connection_handler_->StartTransportManager();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class MockTransportManager : public ::transport_manager::TransportManager,
MOCK_METHOD1(AddEventListener, int(TransportManagerListener* listener));
MOCK_METHOD0(Stop, int());
MOCK_METHOD1(RemoveDevice, int(const DeviceHandle));
MOCK_CONST_METHOD1(Visibility, int(const bool&));
MOCK_CONST_METHOD1(EnableClientsListening, int(const bool&));
MOCK_CONST_METHOD1(PerformActionOnClients,
int(transport_manager::TransportAction required_action));

MOCK_METHOD1(SetTelemetryObserver,
void(transport_manager::TMTelemetryObserver* observer));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,9 @@ class MockTransportAdapter
const ::transport_manager::DeviceUID& device_handle));
MOCK_METHOD2(RunAppOnDevice, void(const std::string&, const std::string&));
MOCK_CONST_METHOD0(IsClientOriginatedConnectSupported, bool());
MOCK_METHOD0(
StartClientListening,
::transport_manager::transport_adapter::TransportAdapter::Error());
MOCK_METHOD0(
StopClientListening,
::transport_manager::transport_adapter::TransportAdapter::Error());
MOCK_METHOD0(SuspendClientListening,
transport_manager::transport_adapter::TransportAdapter::Error());
MOCK_METHOD0(ResumeClientListening,
transport_manager::transport_adapter::TransportAdapter::Error());
MOCK_METHOD1(ChangeClientListening,
::transport_manager::transport_adapter::TransportAdapter::Error(
::transport_manager::TransportAction required_change));
MOCK_METHOD2(RemoveFinalizedConnection,
void(const ::transport_manager::DeviceUID& device_handle,
const ::transport_manager::ApplicationHandle& app_handle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,8 @@ TEST_F(TransportAdapterTest, StartClientListening_ClientNotInitialized) {
EXPECT_CALL(*clientMock, IsInitialised()).WillOnce(Return(false));
EXPECT_CALL(*clientMock, StartListening()).Times(0);

TransportAdapter::Error res = transport_adapter.StartClientListening();
TransportAdapter::Error res = transport_adapter.ChangeClientListening(
transport_manager::TransportAction::kVisibilityOn);
EXPECT_EQ(TransportAdapter::BAD_STATE, res);

EXPECT_CALL(*dev_mock, Terminate());
Expand All @@ -1058,7 +1059,8 @@ TEST_F(TransportAdapterTest, StartClientListening) {
EXPECT_CALL(*clientMock, StartListening())
.WillOnce(Return(TransportAdapter::OK));

TransportAdapter::Error res = transport_adapter.StartClientListening();
TransportAdapter::Error res = transport_adapter.ChangeClientListening(
transport_manager::TransportAction::kVisibilityOn);
EXPECT_EQ(TransportAdapter::OK, res);

EXPECT_CALL(*dev_mock, Terminate());
Expand Down Expand Up @@ -1092,7 +1094,8 @@ TEST_F(TransportAdapterTest, StopClientListening_Success) {
EXPECT_CALL(*clientMock, StopListening())
.WillOnce(Return(TransportAdapter::OK));

res = transport_adapter.StopClientListening();
res = transport_adapter.ChangeClientListening(
transport_manager::TransportAction::kVisibilityOff);
EXPECT_EQ(TransportAdapter::OK, res);

EXPECT_CALL(*dev_mock, Terminate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ TEST(TestTransportManagerDefault, Init_LastStateNotUsed) {
EXPECT_CALL(transport_manager_settings, bluetooth_uuid())
.WillRepeatedly(Return(kBTUUID.data()));

std::string dummy_parameter;
EXPECT_CALL(transport_manager_settings, aoa_filter_manufacturer())
.WillRepeatedly(ReturnRef(dummy_parameter));
EXPECT_CALL(transport_manager_settings, aoa_filter_model_name())
.WillRepeatedly(ReturnRef(dummy_parameter));
EXPECT_CALL(transport_manager_settings, aoa_filter_description())
.WillRepeatedly(ReturnRef(dummy_parameter));
EXPECT_CALL(transport_manager_settings, aoa_filter_version())
.WillRepeatedly(ReturnRef(dummy_parameter));
EXPECT_CALL(transport_manager_settings, aoa_filter_uri())
.WillRepeatedly(ReturnRef(dummy_parameter));
EXPECT_CALL(transport_manager_settings, aoa_filter_serial_number())
.WillRepeatedly(ReturnRef(dummy_parameter));
transport_manager.Init(mock_last_state);
transport_manager.Stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,23 @@ TEST_F(TransportManagerImplTest, RemoveDevice_DeviceWasAdded) {
}

TEST_F(TransportManagerImplTest, SetVisibilityOn_StartClientListening) {
EXPECT_CALL(*mock_adapter_, StartClientListening())
EXPECT_CALL(
*mock_adapter_,
ChangeClientListening(transport_manager::TransportAction::kVisibilityOn))
.WillOnce(Return(TransportAdapter::OK));
EXPECT_EQ(::transport_manager::E_SUCCESS, tm_.Visibility(true));
EXPECT_EQ(::transport_manager::E_SUCCESS,
tm_.PerformActionOnClients(
transport_manager::TransportAction::kVisibilityOn));
}

TEST_F(TransportManagerImplTest, SetVisibilityOff_StopClientListening) {
EXPECT_CALL(*mock_adapter_, StopClientListening())
EXPECT_CALL(
*mock_adapter_,
ChangeClientListening(transport_manager::TransportAction::kVisibilityOff))
.WillOnce(Return(TransportAdapter::OK));
EXPECT_EQ(::transport_manager::E_SUCCESS, tm_.Visibility(false));
EXPECT_EQ(::transport_manager::E_SUCCESS,
tm_.PerformActionOnClients(
transport_manager::TransportAction::kVisibilityOff));
}

TEST_F(TransportManagerImplTest, StopTransportManager) {
Expand Down Expand Up @@ -942,12 +950,16 @@ TEST_F(TransportManagerImplTest, RemoveDevice_TMIsNotInitialized) {

TEST_F(TransportManagerImplTest, Visibility_TMIsNotInitialized) {
// Arrange
const bool visible = true;
const transport_manager::TransportAction action =
transport_manager::TransportAction::kVisibilityOn;
// Check before Act
UninitializeTM();
// Act and Assert
EXPECT_CALL(*mock_adapter_, StartClientListening()).Times(0);
EXPECT_EQ(E_TM_IS_NOT_INITIALIZED, tm_.Visibility(visible));
EXPECT_CALL(
*mock_adapter_,
ChangeClientListening(transport_manager::TransportAction::kVisibilityOn))
.Times(0);
EXPECT_EQ(E_TM_IS_NOT_INITIALIZED, tm_.PerformActionOnClients(action));
}

TEST_F(TransportManagerImplTest, HandleMessage_ConnectionNotExist) {
Expand All @@ -973,16 +985,24 @@ TEST_F(TransportManagerImplTest, SearchDevices_TMIsNotInitialized) {
}

TEST_F(TransportManagerImplTest, SetVisibilityOn_TransportAdapterNotSupported) {
EXPECT_CALL(*mock_adapter_, StartClientListening())
EXPECT_CALL(
*mock_adapter_,
ChangeClientListening(transport_manager::TransportAction::kVisibilityOn))
.WillOnce(Return(TransportAdapter::NOT_SUPPORTED));
EXPECT_EQ(E_SUCCESS, tm_.Visibility(true));
EXPECT_EQ(E_SUCCESS,
tm_.PerformActionOnClients(
transport_manager::TransportAction::kVisibilityOn));
}

TEST_F(TransportManagerImplTest,
SetVisibilityOff_TransportAdapterNotSupported) {
EXPECT_CALL(*mock_adapter_, StopClientListening())
EXPECT_CALL(
*mock_adapter_,
ChangeClientListening(transport_manager::TransportAction::kVisibilityOff))
.WillOnce(Return(TransportAdapter::NOT_SUPPORTED));
EXPECT_EQ(E_SUCCESS, tm_.Visibility(false));
EXPECT_EQ(E_SUCCESS,
tm_.PerformActionOnClients(
transport_manager::TransportAction::kVisibilityOff));
}

TEST_F(TransportManagerImplTest,
Expand Down

0 comments on commit 107b8ad

Please sign in to comment.