summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoratimchenko <atymchenko@luxoft.com>2016-11-17 12:14:21 +0200
committeratimchenko <atymchenko@luxoft.com>2016-12-08 10:58:23 +0200
commit61d7d85c32dbda85e78048dfb17876b7ee2cc566 (patch)
tree62137afd993400e7b1d018f8131a6a9950e8773c /src
parent6609f5d462677254e26611f84d73747cf6d9d02d (diff)
downloadsdl_core-61d7d85c32dbda85e78048dfb17876b7ee2cc566.tar.gz
Cover hmi_message_handler by unit tests
Fully cover hmi_message_handler by unit tests Related task APPLINK-27062
Diffstat (limited to 'src')
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h8
-rw-r--r--src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc62
2 files changed, 65 insertions, 5 deletions
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h
index 3b829b0f27..8b238b4aa8 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h
@@ -106,6 +106,14 @@ class HMIMessageHandlerImpl : public HMIMessageHandler,
HMIMessageObserver* observer() const {
return observer_;
}
+
+ impl::ToHmiQueue* messages_to_hmi() {
+ return &messages_to_hmi_;
+ }
+
+ impl::FromHmiQueue* messages_from_hmi() {
+ return &messages_from_hmi_;
+ }
#endif // BUILD_TESTS
private:
diff --git a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc
index 06cca74ba9..ae864fe053 100644
--- a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc
+++ b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc
@@ -36,13 +36,15 @@
#include "hmi_message_handler/messagebroker_adapter.h"
#include "hmi_message_handler/mock_hmi_message_observer.h"
#include "hmi_message_handler/mock_hmi_message_handler_settings.h"
-#include "utils/make_shared.h"
+#include "hmi_message_handler/mock_hmi_message_adapter_impl.h"
namespace test {
namespace components {
namespace hmi_message_handler_test {
using ::testing::ReturnRef;
+using ::testing::_;
+
class HMIMessageHandlerImplTest : public ::testing::Test {
public:
HMIMessageHandlerImplTest()
@@ -63,10 +65,13 @@ class HMIMessageHandlerImplTest : public ::testing::Test {
.WillByDefault(ReturnRef(stack_size));
hmi_handler_ = new hmi_message_handler::HMIMessageHandlerImpl(
mock_hmi_message_handler_settings);
+ ASSERT_TRUE(NULL != hmi_handler_);
mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter(
hmi_handler_, "localhost", 22);
+ ASSERT_TRUE(NULL != mb_adapter_);
mock_hmi_message_observer_ =
new hmi_message_handler::MockHMIMessageObserver();
+ ASSERT_TRUE(NULL != mock_hmi_message_observer_);
hmi_handler_->set_message_observer(mock_hmi_message_observer_);
EXPECT_TRUE(NULL != hmi_handler_->observer());
}
@@ -77,6 +82,13 @@ class HMIMessageHandlerImplTest : public ::testing::Test {
delete hmi_handler_;
delete mb_adapter_;
}
+
+ hmi_message_handler::MessageSharedPointer CreateMessage() {
+ // The ServiceType doesn't really matter
+ return new application_manager::Message(
+ protocol_handler::MessagePriority::FromServiceType(
+ protocol_handler::ServiceType::kInvalidServiceType));
+ }
};
TEST_F(HMIMessageHandlerImplTest,
@@ -91,16 +103,23 @@ TEST_F(HMIMessageHandlerImplTest,
TEST_F(HMIMessageHandlerImplTest,
OnErrorSending_NotEmptyMessage_ExpectOnErrorSendingProceeded) {
// Arrange
- utils::SharedPtr<application_manager::Message> message(
- utils::MakeShared<application_manager::Message>(
- protocol_handler::MessagePriority::FromServiceType(
- protocol_handler::ServiceType::kControl)));
+ utils::SharedPtr<application_manager::Message> message = CreateMessage();
EXPECT_CALL(*mock_hmi_message_observer_, OnErrorSending(message));
// Act
hmi_handler_->OnErrorSending(message);
}
+TEST_F(HMIMessageHandlerImplTest, OnErrorSending_InvalidObserver_Cancelled) {
+ // Arrange
+ utils::SharedPtr<application_manager::Message> message = CreateMessage();
+
+ hmi_handler_->set_message_observer(NULL);
+ EXPECT_CALL(*mock_hmi_message_observer_, OnErrorSending(_)).Times(0);
+ // Act
+ hmi_handler_->OnErrorSending(message);
+}
+
TEST_F(HMIMessageHandlerImplTest,
AddHMIMessageAdapter_AddExistedAdapter_ExpectAdded) {
// Check before action
@@ -131,6 +150,39 @@ TEST_F(HMIMessageHandlerImplTest, RemoveHMIMessageAdapter_ExpectRemoved) {
EXPECT_TRUE(hmi_handler_->message_adapters().empty());
}
+// TODO(atimchenko) SDLOPEN-44 Wrong message to observer
+TEST_F(HMIMessageHandlerImplTest,
+ DISABLED_OnMessageReceived_ValidObserver_Success) {
+ hmi_message_handler::MessageSharedPointer message = CreateMessage();
+ EXPECT_CALL(*mock_hmi_message_observer_, OnMessageReceived(message));
+
+ hmi_handler_->OnMessageReceived(message);
+ // Wait for the message to be processed
+ hmi_handler_->messages_from_hmi()->WaitDumpQueue();
+}
+
+TEST_F(HMIMessageHandlerImplTest, OnMessageReceived_InvalidObserver_Cancelled) {
+ hmi_message_handler::MessageSharedPointer message = CreateMessage();
+ EXPECT_CALL(*mock_hmi_message_observer_, OnMessageReceived(_)).Times(0);
+ // Make the observer invalid
+ hmi_handler_->set_message_observer(NULL);
+ hmi_handler_->OnMessageReceived(message);
+ hmi_handler_->messages_from_hmi()->WaitDumpQueue();
+}
+
+TEST_F(HMIMessageHandlerImplTest, SendMessageToHMI_Success) {
+ hmi_message_handler::MessageSharedPointer message = CreateMessage();
+
+ MockHMIMessageAdapterImpl message_adapter(hmi_handler_);
+ EXPECT_CALL(message_adapter, SendMessageToHMI(message));
+
+ hmi_handler_->AddHMIMessageAdapter(&message_adapter);
+ hmi_handler_->SendMessageToHMI(message);
+
+ // Wait for the message to be processed
+ hmi_handler_->messages_to_hmi()->WaitDumpQueue();
+}
+
} // namespace hmi_message_handler_test
} // namespace components
} // namespace test