summaryrefslogtreecommitdiff
path: root/src/components/connection_handler
diff options
context:
space:
mode:
authorKozoriz <kozorizandriy@gmail.com>2016-03-28 15:26:18 +0300
committerKozoriz <kozorizandriy@gmail.com>2016-03-28 15:26:18 +0300
commitad1feae56fa4d83e16815d6c42ceb3ef244a2663 (patch)
tree4ac32abed2b2de3b0bdaf1f5191918d2afb3ffa3 /src/components/connection_handler
parente84d3b5048e653c466f9daef301cb77578651d13 (diff)
downloadsdl_core-ad1feae56fa4d83e16815d6c42ceb3ef244a2663.tar.gz
Connection handler tests fix
Corrected impl of Connection class * added initialization of heart_beat_timeout in Constructor Corrected tests of Connection and ConnectionHandler Added additional test case for connection.
Diffstat (limited to 'src/components/connection_handler')
-rw-r--r--src/components/connection_handler/src/connection.cc6
-rw-r--r--src/components/connection_handler/test/connection_handler_impl_test.cc2
-rw-r--r--src/components/connection_handler/test/connection_test.cc35
3 files changed, 38 insertions, 5 deletions
diff --git a/src/components/connection_handler/src/connection.cc b/src/components/connection_handler/src/connection.cc
index bc340e5a7b..6a0f47722e 100644
--- a/src/components/connection_handler/src/connection.cc
+++ b/src/components/connection_handler/src/connection.cc
@@ -79,11 +79,12 @@ Connection::Connection(ConnectionHandle connection_handle,
: connection_handler_(connection_handler),
connection_handle_(connection_handle),
connection_device_handle_(connection_device_handle),
- session_map_lock_(true) {
+ session_map_lock_(true)
+ , heartbeat_timeout_(heartbeat_timeout) {
LOG4CXX_AUTO_TRACE(logger_);
DCHECK(connection_handler_);
- heartbeat_monitor_ = new HeartBeatMonitor(heartbeat_timeout, this);
+ heartbeat_monitor_ = new HeartBeatMonitor(heartbeat_timeout_, this);
heart_beat_monitor_thread_ = threads::CreateThread("HeartBeatMonitor",
heartbeat_monitor_);
heart_beat_monitor_thread_->start();
@@ -343,7 +344,6 @@ bool Connection::SupportHeartBeat(uint8_t session_id) {
return false;
}
Session &session = session_it->second;
-
return ((::protocol_handler::PROTOCOL_VERSION_3 == session.protocol_version ||
::protocol_handler::PROTOCOL_VERSION_4 == session.protocol_version) &&
(0 != heartbeat_timeout_));
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 4ea6f9dcad..388e86811f 100644
--- a/src/components/connection_handler/test/connection_handler_impl_test.cc
+++ b/src/components/connection_handler/test/connection_handler_impl_test.cc
@@ -102,6 +102,8 @@ class ConnectionHandlerTest : public ::testing::Test {
device_name_,
connection_type_);
// Add Device and connection
+ ON_CALL(mock_connection_handler_settings, heart_beat_timeout())
+ .WillByDefault(Return(1000));
connection_handler_->addDeviceConnection(device_info, uid_);
connection_key_ = connection_handler_->KeyFromPair(uid_, 0u);
// Remove all specific services
diff --git a/src/components/connection_handler/test/connection_test.cc b/src/components/connection_handler/test/connection_test.cc
index fac8d8dd8c..5fa36b2e74 100644
--- a/src/components/connection_handler/test/connection_test.cc
+++ b/src/components/connection_handler/test/connection_test.cc
@@ -59,10 +59,11 @@ class ConnectionTest : public ::testing::Test {
mock_connection_handler_settings, transport_manager_mock);
const ConnectionHandle connectionHandle = 0;
const DeviceHandle device_handle = 0;
+ const uint32_t heart_beat = 10000;
connection_ = new Connection(connectionHandle,
device_handle,
connection_handler_,
- 10000);
+ heart_beat);
}
void TearDown() OVERRIDE {
@@ -165,7 +166,7 @@ TEST_F(ConnectionTest, HeartBeat_NotSupported) {
EXPECT_FALSE(connection_->SupportHeartBeat(session_id));
}
-TEST_F(ConnectionTest, HeartBeat_Supported) {
+TEST_F(ConnectionTest, HeartBeat_Protocol3_Supported) {
// Arrange
StartSession();
// Check if protocol version is 3
@@ -175,6 +176,36 @@ TEST_F(ConnectionTest, HeartBeat_Supported) {
EXPECT_TRUE(connection_->SupportHeartBeat(session_id));
}
+TEST_F(ConnectionTest, HeartBeat_Protocol4_PositiveHeartBeat_Supported) {
+ // Arrange
+ StartSession();
+ // Check if protocol version is 4
+ const uint8_t protocol_version = static_cast<uint8_t>(PROTOCOL_VERSION_4);
+ connection_->UpdateProtocolVersionSession(session_id, protocol_version);
+ // Assert
+ EXPECT_TRUE(connection_->SupportHeartBeat(session_id));
+}
+
+TEST_F(ConnectionTest, HeartBeat_Protocol4_ZeroHeartBeat_NotSupported) {
+ // Correctc of connection (need connection with heartbeat=0)
+ delete connection_;
+ connection_ = 0;
+
+ const ConnectionHandle connectionHandle = 0;
+ const DeviceHandle device_handle = 0;
+ const uint32_t heart_beat = 0;
+ connection_ = new Connection(connectionHandle,
+ device_handle,
+ connection_handler_,
+ heart_beat);
+ StartSession();
+ // Check if protocol version is 4
+ const uint8_t protocol_version = static_cast<uint8_t>(PROTOCOL_VERSION_4);
+ connection_->UpdateProtocolVersionSession(session_id, protocol_version);
+ // Assert
+ EXPECT_FALSE(connection_->SupportHeartBeat(session_id));
+}
+
// Try to add service without session
TEST_F(ConnectionTest, Session_AddNewServiceWithoutSession) {
EXPECT_EQ(connection_->AddNewService(session_id, kAudio, true),