summaryrefslogtreecommitdiff
path: root/src/components/hmi_message_handler
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/hmi_message_handler')
-rw-r--r--src/components/hmi_message_handler/CMakeLists.txt87
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_adapter.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_observer.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_sender.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/messagebroker_adapter.h2
-rw-r--r--src/components/hmi_message_handler/include/hmi_message_handler/mqueue_adapter.h65
-rw-r--r--src/components/hmi_message_handler/src/dbus_message_adapter.cc4
-rw-r--r--src/components/hmi_message_handler/src/hmi_message_adapter.cc2
-rw-r--r--src/components/hmi_message_handler/src/hmi_message_handler_impl.cc2
-rw-r--r--src/components/hmi_message_handler/src/messagebroker_adapter.cc12
-rw-r--r--src/components/hmi_message_handler/src/mqueue_adapter.cc83
-rw-r--r--src/components/hmi_message_handler/test/CMakeLists.txt57
-rw-r--r--src/components/hmi_message_handler/test/Readme.txt11
-rw-r--r--src/components/hmi_message_handler/test/dbus_message_adapter_test.cc67
-rw-r--r--src/components/hmi_message_handler/test/include/hmi_message_handler/mock_dbus_message_controller.h68
-rw-r--r--src/components/hmi_message_handler/test/include/hmi_message_handler/mock_subscriber.h62
-rw-r--r--src/components/hmi_message_handler/test/include/mock_subscriber.h62
-rw-r--r--src/components/hmi_message_handler/test/main.cc41
-rw-r--r--src/components/hmi_message_handler/test/mock_subscriber.cc81
-rw-r--r--src/components/hmi_message_handler/test/mqueue_adapter_test.cc94
22 files changed, 696 insertions, 114 deletions
diff --git a/src/components/hmi_message_handler/CMakeLists.txt b/src/components/hmi_message_handler/CMakeLists.txt
index f280f97664..9559b6b00f 100644
--- a/src/components/hmi_message_handler/CMakeLists.txt
+++ b/src/components/hmi_message_handler/CMakeLists.txt
@@ -1,20 +1,50 @@
+# Copyright (c) 2014, Ford Motor Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided with the
+# distribution.
+#
+# Neither the name of the Ford Motor Company nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
include_directories (
- ./include/
- ../application_manager/include/
- ../utils/include/
- ../smart_objects/include/
- ../formatters/include/
- ../config_profile/include/
- ../media_manager/include/
- ../protocol_handler/include
- ${JSONCPP_INCLUDE_DIRECTORY}
- ${MESSAGE_BROKER_INCLUDE_DIRECTORY}
- ../config_profile/include
- ${CMAKE_SOURCE_DIR}/src/components/
- ${CMAKE_BINARY_DIR}/src/components/
- ${CMAKE_SOURCE_DIR}/src/components/dbus/include/
- ${CMAKE_SOURCE_DIR}/
- ${LOG4CXX_INCLUDE_DIRECTORY}
+ include/
+ ${COMPONENTS_DIR}/application_manager/include/
+ ${COMPONENTS_DIR}/utils/include/
+ ${COMPONENTS_DIR}/smart_objects/include/
+ ${COMPONENTS_DIR}/formatters/include/
+ ${COMPONENTS_DIR}/config_profile/include/
+ ${COMPONENTS_DIR}/media_manager/include/
+ ${COMPONENTS_DIR}/protocol_handler/include
+ ${JSONCPP_INCLUDE_DIRECTORY}
+ ${MESSAGE_BROKER_INCLUDE_DIRECTORY}
+ ${COMPONENTS_DIR}
+ ${CMAKE_BINARY_DIR}/src/components/
+ ${COMPONENTS_DIR}/dbus/include/
+ ${CMAKE_SOURCE_DIR}/
+ ${LOG4CXX_INCLUDE_DIRECTORY}
)
IF (HMIADAPTER STREQUAL "dbus")
@@ -23,22 +53,29 @@ IF (HMIADAPTER STREQUAL "dbus")
ENDIF ()
set (SOURCES
- ./src/hmi_message_handler_impl.cc
- ./src/messagebroker_adapter.cc
- ./src/hmi_message_adapter.cc
- ./src/mqueue_adapter.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/src/hmi_message_handler_impl.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/src/messagebroker_adapter.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/src/hmi_message_adapter.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/src/mqueue_adapter.cc
${DBUS_SOURCE}
)
-set (LIBRARIES
- Utils
- ${DBUS_ADAPTER}
- ${RTLIB}
+set(LIBRARIES
+ Utils
+ ${DBUS_ADAPTER}
+ ${RTLIB}
)
add_library("HMIMessageHandler" ${SOURCES})
target_link_libraries("HMIMessageHandler" ${LIBRARIES})
if(ENABLE_LOG)
- target_link_libraries("HMIMessageHandler" log4cxx -L${LOG4CXX_LIBS_DIRECTORY})
+ target_link_libraries("HMIMessageHandler" log4cxx -L${LOG4CXX_LIBS_DIRECTORY})
endif()
+
+# Tests temporary are inactivated. For details please check
+# Readme.txt in test directory of hmi_message_handler
+
+#if(BUILD_TESTS)
+# add_subdirectory(test)
+#endif()
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_adapter.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_adapter.h
index dc515318a0..5ed37031ea 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_adapter.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_adapter.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h
index 828ae9a00e..3e06c65085 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
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 071ce2c549..d638f370d8 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
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_observer.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_observer.h
index f77a1f6a50..f2f84b13e7 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_observer.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_observer.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_sender.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_sender.h
index 2712857305..d704a4df65 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_sender.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_sender.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/messagebroker_adapter.h b/src/components/hmi_message_handler/include/hmi_message_handler/messagebroker_adapter.h
index df344c80fd..4580b18ee1 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/messagebroker_adapter.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/messagebroker_adapter.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/mqueue_adapter.h b/src/components/hmi_message_handler/include/hmi_message_handler/mqueue_adapter.h
index 9d78fefc69..126ea3a66e 100644
--- a/src/components/hmi_message_handler/include/hmi_message_handler/mqueue_adapter.h
+++ b/src/components/hmi_message_handler/include/hmi_message_handler/mqueue_adapter.h
@@ -1,34 +1,34 @@
/*
-* Copyright (c) 2014, Ford Motor Company
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*
-* Redistributions of source code must retain the above copyright notice, this
-* list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright notice,
-* this list of conditions and the following
-* disclaimer in the documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of the Ford Motor Company nor the names of its contributors
-* may be used to endorse or promote products derived from this software
-* without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-* POSSIBILITY OF SUCH DAMAGE.
-*/
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef SRC_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MQUEUE_ADAPTER_H_
#define SRC_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MQUEUE_ADAPTER_H_
@@ -40,6 +40,8 @@
namespace hmi_message_handler {
+class ReceiverThreadDelegate;
+
/**
* \brief HMI message adapter for mqueue
*/
@@ -55,9 +57,10 @@ class MqueueAdapter : public HMIMessageAdapter {
private:
mqd_t sdl_to_hmi_mqueue_;
mqd_t hmi_to_sdl_mqueue_;
+
+ ReceiverThreadDelegate* receiver_thread_delegate_;
threads::Thread* receiver_thread_;
};
} // namespace hmi_message_handler
-
#endif // SRC_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MQUEUE_ADAPTER_H_
diff --git a/src/components/hmi_message_handler/src/dbus_message_adapter.cc b/src/components/hmi_message_handler/src/dbus_message_adapter.cc
index a79674df67..c08f090f1d 100644
--- a/src/components/hmi_message_handler/src/dbus_message_adapter.cc
+++ b/src/components/hmi_message_handler/src/dbus_message_adapter.cc
@@ -86,7 +86,7 @@ void DBusMessageAdapter::SendMessageToHMI(MessageSharedPointer message) {
break;
case hmi_apis::messageType::INVALID_ENUM:
default:
- LOG4CXX_INFO(logger_, "Message type is invalid");
+ LOG4CXX_WARN(logger_, "Message type is invalid");
}
}
@@ -156,7 +156,7 @@ void DBusMessageAdapter::SubscribeTo() {
}
void DBusMessageAdapter::SendMessageToCore(const smart_objects::SmartObject& obj) {
- LOG4CXX_INFO(logger_, "DBusMessageAdapter::SendMessageToCore");
+ LOG4CXX_AUTO_TRACE(logger_);
if (!handler()) {
LOG4CXX_WARN(logger_, "DBusMessageAdapter hasn't handler");
diff --git a/src/components/hmi_message_handler/src/hmi_message_adapter.cc b/src/components/hmi_message_handler/src/hmi_message_adapter.cc
index 343f13f00a..d8c280bea7 100644
--- a/src/components/hmi_message_handler/src/hmi_message_adapter.cc
+++ b/src/components/hmi_message_handler/src/hmi_message_adapter.cc
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc b/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc
index ed37ee677c..887d145617 100644
--- a/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc
+++ b/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/hmi_message_handler/src/messagebroker_adapter.cc b/src/components/hmi_message_handler/src/messagebroker_adapter.cc
index 8779d2ea6d..d0dd5c09ba 100644
--- a/src/components/hmi_message_handler/src/messagebroker_adapter.cc
+++ b/src/components/hmi_message_handler/src/messagebroker_adapter.cc
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2013, Ford Motor Company
* All rights reserved.
*
@@ -74,17 +74,17 @@ void MessageBrokerAdapter::SendMessageToHMI(
void MessageBrokerAdapter::processResponse(std::string method,
Json::Value& root) {
- LOG4CXX_INFO(logger_, "MessageBrokerAdapter::processResponse");
+ LOG4CXX_AUTO_TRACE(logger_);
ProcessRecievedFromMB(root);
}
void MessageBrokerAdapter::processRequest(Json::Value& root) {
- LOG4CXX_INFO(logger_, "MessageBrokerAdapter::processRequest");
+ LOG4CXX_AUTO_TRACE(logger_);
ProcessRecievedFromMB(root);
}
void MessageBrokerAdapter::processNotification(Json::Value& root) {
- LOG4CXX_INFO(logger_, "MessageBrokerAdapter::processNotification");
+ LOG4CXX_AUTO_TRACE(logger_);
ProcessRecievedFromMB(root);
}
@@ -137,13 +137,15 @@ void MessageBrokerAdapter::SubscribeTo() {
void* MessageBrokerAdapter::SubscribeAndBeginReceiverThread(void* param) {
PassToThread(threads::Thread::CurrentId());
+ // For PASA we don't need to subscribe and register controller
+ // this will prevent from errors on start up
registerController();
SubscribeTo();
return MethodForReceiverThread(param);
}
void MessageBrokerAdapter::ProcessRecievedFromMB(Json::Value& root) {
- LOG4CXX_INFO(logger_, "MessageBrokerAdapter::ProcessRecievedFromMB");
+ LOG4CXX_AUTO_TRACE(logger_);
if (root.isNull()) {
// LOG
return;
diff --git a/src/components/hmi_message_handler/src/mqueue_adapter.cc b/src/components/hmi_message_handler/src/mqueue_adapter.cc
index b1524b5f03..825c27c048 100644
--- a/src/components/hmi_message_handler/src/mqueue_adapter.cc
+++ b/src/components/hmi_message_handler/src/mqueue_adapter.cc
@@ -1,34 +1,34 @@
/*
-* Copyright (c) 2014, Ford Motor Company
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*
-* Redistributions of source code must retain the above copyright notice, this
-* list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright notice,
-* this list of conditions and the following
-* disclaimer in the documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of the Ford Motor Company nor the names of its contributors
-* may be used to endorse or promote products derived from this software
-* without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-* POSSIBILITY OF SUCH DAMAGE.
-*/
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#include "hmi_message_handler/mqueue_adapter.h"
#include "hmi_message_handler/hmi_message_handler.h"
@@ -61,7 +61,7 @@ class ReceiverThreadDelegate : public threads::ThreadDelegate {
continue;
}
const std::string message_string(buffer, buffer + size);
- LOG4CXX_INFO(logger_, "Message: " << message_string);
+ LOG4CXX_DEBUG(logger_, "Message: " << message_string);
MessageSharedPointer message(new application_manager::Message(
protocol_handler::MessagePriority::kDefault));
message->set_json_message(message_string);
@@ -78,7 +78,7 @@ MqueueAdapter::MqueueAdapter(HMIMessageHandler* hmi_message_handler)
: HMIMessageAdapter(hmi_message_handler),
sdl_to_hmi_mqueue_(-1),
hmi_to_sdl_mqueue_(-1),
- receiver_thread_() {
+ receiver_thread_(NULL) {
mq_attr mq_attributes;
mq_attributes.mq_maxmsg = kMqueueSize;
mq_attributes.mq_msgsize = kMqueueMessageSize;
@@ -96,18 +96,17 @@ MqueueAdapter::MqueueAdapter(HMIMessageHandler* hmi_message_handler)
<< kHmiToSdlQueue << ", error " << errno);
return;
}
- ReceiverThreadDelegate* receiver_thread_delegate =
- new ReceiverThreadDelegate(hmi_to_sdl_mqueue_, hmi_message_handler);
- receiver_thread_ =
- threads::CreateThread("MqueueAdapter", receiver_thread_delegate);
+ receiver_thread_delegate_ = new ReceiverThreadDelegate(hmi_to_sdl_mqueue_,
+ hmi_message_handler);
+ receiver_thread_ = threads::CreateThread("MqueueAdapter",
+ receiver_thread_delegate_);
receiver_thread_->start();
}
MqueueAdapter::~MqueueAdapter() {
- if (receiver_thread_) {
- receiver_thread_->stop();
- threads::DeleteThread(receiver_thread_);
- }
+ receiver_thread_->join();
+ delete receiver_thread_delegate_;
+ threads::DeleteThread(receiver_thread_);
if (-1 != hmi_to_sdl_mqueue_) mq_close(hmi_to_sdl_mqueue_);
if (-1 != sdl_to_hmi_mqueue_) mq_close(sdl_to_hmi_mqueue_);
mq_unlink(kHmiToSdlQueue);
@@ -115,7 +114,7 @@ MqueueAdapter::~MqueueAdapter() {
}
void MqueueAdapter::SendMessageToHMI(const MessageSharedPointer message) {
- LOG4CXX_TRACE_ENTER(logger_);
+ LOG4CXX_AUTO_TRACE(logger_);
if (-1 == sdl_to_hmi_mqueue_) {
LOG4CXX_ERROR(logger_, "Message queue is not opened");
@@ -131,8 +130,6 @@ void MqueueAdapter::SendMessageToHMI(const MessageSharedPointer message) {
LOG4CXX_ERROR(logger_, "Could not send message, error " << errno);
return;
}
-
- LOG4CXX_TRACE_EXIT(logger_);
}
void MqueueAdapter::SubscribeTo() {
diff --git a/src/components/hmi_message_handler/test/CMakeLists.txt b/src/components/hmi_message_handler/test/CMakeLists.txt
new file mode 100644
index 0000000000..a8597b51bd
--- /dev/null
+++ b/src/components/hmi_message_handler/test/CMakeLists.txt
@@ -0,0 +1,57 @@
+# Copyright (c) 2014, Ford Motor Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided with the
+# distribution.
+#
+# Neither the name of the Ford Motor Company nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+if(BUILD_TESTS)
+
+include_directories (
+ ${GMOCK_INCLUDE_DIRECTORY}
+ ${COMPONENTS_DIR}/hmi_message_handler/include
+)
+
+set(LIBRARIES
+ gmock
+ ApplicationManager
+ HMIMessageHandler
+)
+
+set(SOURCES
+ ${COMPONENTS_DIR}/hmi_message_handler/test/main.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/test/mqueue_adapter_test.cc
+)
+
+if(${QT_HMI})
+ list (APPEND SOURCES
+ ${COMPONENTS_DIR}/hmi_message_handler/test/mock_subscriber.cc
+ ${COMPONENTS_DIR}/hmi_message_handler/test/dbus_message_adapter_test.cc
+ )
+endif()
+create_test("hmi_message_handler_test" "${SOURCES}" "${LIBRARIES}")
+
+endif() \ No newline at end of file
diff --git a/src/components/hmi_message_handler/test/Readme.txt b/src/components/hmi_message_handler/test/Readme.txt
new file mode 100644
index 0000000000..4dcd565d90
--- /dev/null
+++ b/src/components/hmi_message_handler/test/Readme.txt
@@ -0,0 +1,11 @@
+28.11.2014 Andriy Byzhynar
+
+1) Tests for mqueue_adapter failed as mqueue transport still not used.
+2) Tests are not actual at the moment until PASA moves to use mqueue transport.
+3) To activate tests - just uncomment following lines in CMakeLists.txt of hmi_message_handler :
+
+ - #if(BUILD_TESTS)
+ - # add_subdirectory(test)
+ - #endif()
+
+ They are located at the end of file.
diff --git a/src/components/hmi_message_handler/test/dbus_message_adapter_test.cc b/src/components/hmi_message_handler/test/dbus_message_adapter_test.cc
new file mode 100644
index 0000000000..6699f788dd
--- /dev/null
+++ b/src/components/hmi_message_handler/test/dbus_message_adapter_test.cc
@@ -0,0 +1,67 @@
+/**
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <pthread.h>
+#include "hmi_message_handler/dbus_message_adapter.h"
+#include "dbus/dbus_message_controller.h"
+
+namespace Json {
+class Value;
+}
+
+class MockDBusMessageController :
+ public ::dbus::DBusMessageController {
+ public:
+ MockDBusMessageController(const std::string& serviceName,
+ const std::string& path,
+ const std::string& hmiserviceName,
+ const std::string& hmipath)
+ : DBusMessageController(serviceName, path, hmiserviceName,hmipath),
+ thread_() {}
+
+ virtual void processResponse(std::string method, Json::Value& root) {}
+ virtual void processRequest(Json::Value& root) {}
+ virtual void processNotification(Json::Value& root) {}
+
+ bool Init() {
+ return ::dbus::DBusMessageController::Init() &&
+ pthread_create(&thread_, 0, &Run, this) == 0;
+ }
+ private:
+ pthread_t thread_;
+ static void* Run(void* data) {
+ if (NULL != data) {
+ static_cast<MockDBusMessageController*>(data)->MethodForReceiverThread(nullptr);
+ }
+ return 0;
+ }
+};
diff --git a/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_dbus_message_controller.h b/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_dbus_message_controller.h
new file mode 100644
index 0000000000..7512f2ab19
--- /dev/null
+++ b/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_dbus_message_controller.h
@@ -0,0 +1,68 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_DBUS_MESSAGE_CONTROLLER_H_
+#define TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_DBUS_MESSAGE_CONTROLLER_H_
+
+#include <pthread.h>
+#include "hmi_message_handler/dbus_message_controller.h"
+
+class MockDBusMessageController :
+ public ::hmi_message_handler::DBusMessageController {
+ public:
+ MOCK_METHOD1(Recv, void(std::string&));
+
+ MockDBusMessageController(const std::string& serviceName,
+ const std::string& path)
+ : DBusMessageController(serviceName, path),
+ thread_() {}
+
+ virtual void processResponse(std::string method, Json::Value& root) {}
+ virtual void processRequest(Json::Value& root) {}
+ virtual void processNotification(Json::Value& root) {}
+
+ bool Init() {
+ return ::hmi_message_handler::DBusMessageController::Init() &&
+ pthread_create(&thread_, 0, &Run, this) == 0;
+ }
+ private:
+ pthread_t thread_;
+ static void* Run(void* data) {
+ if (NULL != data) {
+ static_cast<MockDBusMessageController*>(data)->MethodForReceiverThread(nullptr);
+ }
+ return 0;
+ }
+};
+
+
+#endif // TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_DBUS_MESSAGE_CONTROLLER_H_
diff --git a/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_subscriber.h b/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_subscriber.h
new file mode 100644
index 0000000000..62ccafb19a
--- /dev/null
+++ b/src/components/hmi_message_handler/test/include/hmi_message_handler/mock_subscriber.h
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_DBUS_SUBSCRIBER_H_
+#define TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_DBUS_SUBSCRIBER_H_
+
+#include <string>
+
+struct DBusConnection;
+
+namespace test {
+namespace components {
+namespace hmi_message_handler {
+
+class MockSubscriber {
+ public:
+ MockSubscriber(const std::string nameService, const std::string path);
+ virtual ~MockSubscriber();
+ virtual void Receive();
+ bool Start();
+ void Send(const std::string& message);
+
+ private:
+ std::string nameService_;
+ std::string path_;
+ DBusConnection* conn_;
+};
+
+} // namespace hmi_message_handler
+} // namespace components
+} // namespace test
+
+#endif // TEST_COMPONENTS_HMI_MESSAGE_HANDLER_INCLUDE_HMI_MESSAGE_HANDLER_DBUS_SUBSCRIBER_H_
diff --git a/src/components/hmi_message_handler/test/include/mock_subscriber.h b/src/components/hmi_message_handler/test/include/mock_subscriber.h
new file mode 100644
index 0000000000..27e7cad1be
--- /dev/null
+++ b/src/components/hmi_message_handler/test/include/mock_subscriber.h
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef SRC_COMPONENTS_HMI_MESSAGE_HANDLER_TEST_INCLUDE_MOCK_SUBSCRIBER_H_
+#define SRC_COMPONENTS_HMI_MESSAGE_HANDLER_TEST_INCLUDE_MOCK_SUBSCRIBER_H_
+
+#include <string>
+
+struct DBusConnection;
+
+namespace test {
+namespace components {
+namespace hmi_message_handler {
+
+class MockSubscriber {
+ public:
+ MockSubscriber(const std::string &nameService, const std::string & path);
+ virtual ~MockSubscriber();
+ virtual void Receive();
+ bool Start();
+ void Send(const std::string& message);
+
+ private:
+ std::string nameService_;
+ std::string path_;
+ DBusConnection* conn_;
+};
+
+} // namespace hmi_message_handler
+} // namespace components
+} // namespace test
+
+#endif // SRC_COMPONENTS_HMI_MESSAGE_HANDLER_TEST_INCLUDE_MOCK_SUBSCRIBER_H_
diff --git a/src/components/hmi_message_handler/test/main.cc b/src/components/hmi_message_handler/test/main.cc
new file mode 100644
index 0000000000..3a4e919d02
--- /dev/null
+++ b/src/components/hmi_message_handler/test/main.cc
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "gmock/gmock.h"
+
+int main(int argc, char** argv) {
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+
+
+
diff --git a/src/components/hmi_message_handler/test/mock_subscriber.cc b/src/components/hmi_message_handler/test/mock_subscriber.cc
new file mode 100644
index 0000000000..3f1235bea9
--- /dev/null
+++ b/src/components/hmi_message_handler/test/mock_subscriber.cc
@@ -0,0 +1,81 @@
+/**
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <dbus/dbus.h>
+#include "include/mock_subscriber.h"
+
+
+namespace test {
+namespace components {
+namespace hmi_message_handler {
+
+MockSubscriber::MockSubscriber(
+ const std::string & nameService, const std::string & path)
+ : nameService_(nameService),
+ path_(path),
+ conn_(NULL) {
+}
+
+MockSubscriber::~MockSubscriber() {
+}
+
+void MockSubscriber::Receive() {
+}
+
+bool MockSubscriber::Start() {
+ DBusError err;
+ //int ret;
+ dbus_error_init(&err);
+ conn_ = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ dbus_error_free(&err);
+ return false;
+ }
+
+
+ std::string rule = "type='signal',interface='" + nameService_ + "'";
+ dbus_bus_add_match(conn_, rule.c_str(), &err);
+ dbus_connection_flush(conn_);
+ if (dbus_error_is_set(&err)) {
+ dbus_error_free(&err);
+ return false;
+ }
+ return true;
+}
+
+void MockSubscriber::Send(const std::string& message) {
+ // int a = message.length();
+}
+
+} // namespace hmi_message_handler
+} // namespace components
+} // namespace test
diff --git a/src/components/hmi_message_handler/test/mqueue_adapter_test.cc b/src/components/hmi_message_handler/test/mqueue_adapter_test.cc
new file mode 100644
index 0000000000..87fb3a3539
--- /dev/null
+++ b/src/components/hmi_message_handler/test/mqueue_adapter_test.cc
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "hmi_message_handler/hmi_message_handler.h"
+#include "hmi_message_handler/mqueue_adapter.h"
+
+using hmi_message_handler::MessageSharedPointer;
+using hmi_message_handler::HMIMessageHandler;
+using hmi_message_handler::HMIMessageAdapter;
+using hmi_message_handler::MqueueAdapter;
+using application_manager::Message;
+
+class MockHandler : public HMIMessageHandler {
+ public:
+ MOCK_METHOD1(OnMessageReceived, void(MessageSharedPointer message));
+ MOCK_METHOD1(AddHMIMessageAdapter, void(HMIMessageAdapter* adapter));
+ MOCK_METHOD1(RemoveHMIMessageAdapter, void(HMIMessageAdapter* adapter));
+ MOCK_METHOD1(OnErrorSending, void(MessageSharedPointer message));
+ MOCK_METHOD1(SendMessageToHMI, void(MessageSharedPointer message));
+};
+
+//TODO{ALeshin}: APPLINK-10846
+//TEST(MqueueAdapter, Send) {
+// MockHandler handler;
+// HMIMessageAdapter* adapter = new MqueueAdapter(&handler);
+
+// MessageSharedPointer message(
+// new Message(protocol_handler::MessagePriority::kDefault));
+// message->set_json_message("{}");
+// adapter->SendMessageToHMI(message);
+
+// mqd_t mqd = mq_open("/sdl_to_hmi", O_RDONLY);
+// ASSERT_NE(-1, mqd);
+// static char buf[65536];
+// ssize_t sz = mq_receive(mqd, buf, 65536, NULL);
+// ASSERT_EQ(2, sz);
+// EXPECT_STREQ("{}", buf);
+
+// delete adapter;
+//}
+
+//TODO{ALeshin}: APPLINK-10846
+//TEST(MqueueAdapter, Receive) {
+// MockHandler handler;
+// HMIMessageAdapter* adapter = new MqueueAdapter(&handler);
+
+// using ::testing::Property;
+// using ::testing::Pointee;
+// EXPECT_CALL(
+// handler,
+// OnMessageReceived(Property(
+// &MessageSharedPointer::get,
+// Pointee(Property(&Message::json_message, std::string("()"))))));
+
+// mqd_t mqd = mq_open("/hmi_to_sdl", O_WRONLY);
+// ASSERT_NE(-1, mqd);
+// const char buf[] = "()";
+// int rc = mq_send(mqd, buf, sizeof(buf) - 1, 0);
+// ASSERT_EQ(0, rc);
+
+// delete adapter;
+//}