diff options
Diffstat (limited to 'src/components/transport_manager/test/include')
10 files changed, 796 insertions, 0 deletions
diff --git a/src/components/transport_manager/test/include/mock_application.h b/src/components/transport_manager/test/include/mock_application.h new file mode 100644 index 0000000000..7ec71ebb1e --- /dev/null +++ b/src/components/transport_manager/test/include/mock_application.h @@ -0,0 +1,80 @@ +/* + * mock_application.h + * + * Copyright (c) 2013, 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 MOCK_APPLICATION_H_ +#define MOCK_APPLICATION_H_ + +#include <pthread.h> + +#include <sstream> +#include <string> + +#include <transport_manager/common.h> +#include <transport_manager/transport_manager.h> +#include <transport_manager/transport_adapter/transport_adapter_impl.h> +#include <transport_manager/transport_manager_impl.h> +#include "mock_device_scanner.h" + +namespace test { +namespace components { +namespace transport_manager { + +class MockDevice; +using ::transport_manager::ApplicationHandle; + +class MockApplication { + public: + const MockDevice *device; + ApplicationHandle handle; + pthread_t workerThread; + pthread_cond_t ready_cond; + pthread_mutex_t ready_mutex; + int sockfd; + bool active; + private: + std::string socket_name_; + public: + MockApplication(const MockDevice* device, ApplicationHandle id); + void Start(); + void Stop(); + const std::string &socket_name() const { + return socket_name_; + } +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* MOCK_APPLICATION_H_ */ diff --git a/src/components/transport_manager/test/include/mock_connection.h b/src/components/transport_manager/test/include/mock_connection.h new file mode 100644 index 0000000000..8f67107065 --- /dev/null +++ b/src/components/transport_manager/test/include/mock_connection.h @@ -0,0 +1,69 @@ +/* + * \file mock_connection.h + * \brief + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTION_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTION_H_ + +#include "transport_manager/common.h" +#include "transport_manager/error.h" +#include "transport_manager/transport_adapter/transport_adapter_impl.h" +#include "transport_manager/transport_adapter/threaded_socket_connection.h" + +using ::transport_manager::ApplicationHandle; +using ::transport_manager::DeviceHandle; +using ::transport_manager::transport_adapter::Connection; +using ::transport_manager::transport_adapter::TransportAdapterController; +using ::transport_manager::ConnectError; +using ::transport_manager::transport_adapter::ThreadedSocketConnection; +using ::transport_manager::transport_adapter::TransportAdapter; +namespace test { +namespace components { +namespace transport_manager { + +class MockTransportAdapter; + +class MockConnection : public ThreadedSocketConnection{ + public: + MockConnection(const ::transport_manager::DeviceUID& device_handle, + const ApplicationHandle& app_handle, + TransportAdapterController* adapter); + bool Establish(ConnectError **error); +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTION_H_ */ diff --git a/src/components/transport_manager/test/include/mock_connection_factory.h b/src/components/transport_manager/test/include/mock_connection_factory.h new file mode 100644 index 0000000000..afead19cb6 --- /dev/null +++ b/src/components/transport_manager/test/include/mock_connection_factory.h @@ -0,0 +1,69 @@ +/* + * \file mock_connection_factory.h + * \brief + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTIONFACTORY_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTIONFACTORY_H_ + +#include "transport_manager/transport_adapter/server_connection_factory.h" + +using ::transport_manager::ApplicationHandle; +using ::transport_manager::DeviceHandle; +using ::transport_manager::transport_adapter::TransportAdapter; +using ::transport_manager::transport_adapter::ServerConnectionFactory; + +namespace test { +namespace components { +namespace transport_manager { + +class MockTransportAdapter; + +class MockConnectionFactory : public ServerConnectionFactory { + public: + MockConnectionFactory(MockTransportAdapter *adapter); + TransportAdapter::Error Init() { return TransportAdapter::OK; } + TransportAdapter::Error CreateConnection(const ::transport_manager::DeviceUID& device_handle, + const ApplicationHandle& app_handle); + void Terminate() {} + bool IsInitialised() const { return true; } + + private: + MockTransportAdapter *controller_; +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKCONNECTIONFACTORY_H_ */ diff --git a/src/components/transport_manager/test/include/mock_device.h b/src/components/transport_manager/test/include/mock_device.h new file mode 100644 index 0000000000..1225f851d7 --- /dev/null +++ b/src/components/transport_manager/test/include/mock_device.h @@ -0,0 +1,82 @@ +/* + * \file mock_device.h + * \brief + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICE_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICE_H_ + +#include "transport_manager/common.h" +#include "transport_manager/transport_adapter/transport_adapter_impl.h" + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <transport_manager/transport_adapter/transport_adapter_impl.h> +#include <transport_manager/transport_manager_impl.h> +#include "mock_device_scanner.h" +#include "mock_application.h" + +using ::transport_manager::ApplicationList; +using ::transport_manager::transport_adapter::Device; +using ::transport_manager::transport_adapter::TransportAdapterController; + +namespace test { +namespace components { +namespace transport_manager { + +class MockDevice : public ::transport_manager::transport_adapter::Device { + + pthread_mutex_t device_started_mutex; + std::vector<MockApplication> applications_; + int applications_cnt_; + TransportAdapterController *controller_; + public: + MockDevice(const std::string& name, const std::string& id, + TransportAdapterController * controller) + : Device(name, id), + applications_cnt_(0), + controller_(controller) { + } + const ApplicationHandle addApplication(); + void Start(); + void Stop(); + bool IsSameAs(const Device* other) const; + ApplicationList GetApplicationList() const; + bool operator == (const MockDevice &other); +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICE_H_ */ diff --git a/src/components/transport_manager/test/include/mock_device_scanner.h b/src/components/transport_manager/test/include/mock_device_scanner.h new file mode 100644 index 0000000000..6ebae39a7c --- /dev/null +++ b/src/components/transport_manager/test/include/mock_device_scanner.h @@ -0,0 +1,76 @@ +/* + * \file mock_device_scanner.h + * \brief + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICESCANNER_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICESCANNER_H_ + +#include "transport_manager/transport_adapter/device_scanner.h" + +using ::transport_manager::transport_adapter::TransportAdapter; +using ::transport_manager::transport_adapter::DeviceScanner; +using ::transport_manager::transport_adapter::DeviceVector; + +namespace test { +namespace components { +namespace transport_manager { + +class MockTransportAdapter; + +class MockDeviceScanner : public DeviceScanner { + public: + MockDeviceScanner(MockTransportAdapter *adapter); + void reset(); + void AddDevice(const std::string& name, const std::string& unique_id, bool start = true); + void RemoveDevice(const std::string& name); + void fail_further_search() { is_search_failed_ = true; } + + protected: + TransportAdapter::Error Init(); + TransportAdapter::Error Scan(); + void Terminate(); + bool IsInitialised() const; + + private: + MockTransportAdapter *controller_; + DeviceVector devices_; + bool is_initialized_; + bool is_search_failed_; +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICESCANNER_H_ */ diff --git a/src/components/transport_manager/test/include/mock_transport_adapter.h b/src/components/transport_manager/test/include/mock_transport_adapter.h new file mode 100644 index 0000000000..fef37f9b83 --- /dev/null +++ b/src/components/transport_manager/test/include/mock_transport_adapter.h @@ -0,0 +1,62 @@ +/* + * \file mock_transport_adapter.h + * \brief + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICEADAPTER_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICEADAPTER_H_ + +#include "transport_manager/transport_adapter/transport_adapter_impl.h" + +using ::transport_manager::transport_adapter::TransportAdapterImpl; +using ::transport_manager::transport_adapter::DeviceType; + +namespace test { +namespace components { +namespace transport_manager { + +class MockDeviceScanner; + +class MockTransportAdapter : public TransportAdapterImpl { + public: + MockTransportAdapter(); + MockDeviceScanner* get_device_scanner() const; + DeviceType GetDeviceType() const { return "mock-adapter"; } + void reset(); +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORTMANAGER_INCLUDE_MOCKDEVICEADAPTER_H_ */ diff --git a/src/components/transport_manager/test/include/mock_transport_adapter_listener.h b/src/components/transport_manager/test/include/mock_transport_adapter_listener.h new file mode 100644 index 0000000000..e45564d275 --- /dev/null +++ b/src/components/transport_manager/test/include/mock_transport_adapter_listener.h @@ -0,0 +1,93 @@ +/* + * \file mock_transport_adapter_listener.h + * \brief + * + * Copyright (c) 2013, 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 MOCK_transport_adapter_LISTENER_H_ +#define MOCK_transport_adapter_LISTENER_H_ + +#include <gmock/gmock.h> + +#include "transport_manager/transport_adapter/transport_adapter_listener.h" + +using namespace transport_manager; +using transport_manager::transport_adapter::TransportAdapter; +using transport_manager::transport_adapter::TransportAdapterListener; + +namespace test { +namespace components { +namespace transport_manager { +using namespace ::protocol_handler; + +class MockTransportAdapterListener : public TransportAdapterListener { + public: + MOCK_METHOD1(OnSearchDeviceDone, + void(const TransportAdapter* transport_adapter)); + MOCK_METHOD2(OnSearchDeviceFailed, + void(const TransportAdapter* transport_adapter, const SearchDeviceError& error)); + MOCK_METHOD1(OnFindNewApplicationsRequest, + void(const TransportAdapter* adapter)); + MOCK_METHOD1(OnDeviceListUpdated, + void(const TransportAdapter* transport_adapter)); + MOCK_METHOD3(OnConnectDone, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle)); + MOCK_METHOD4(OnConnectFailed, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const ConnectError& error)); + MOCK_METHOD4(OnUnexpectedDisconnect, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const CommunicationError& error)); + MOCK_METHOD3(OnDisconnectDone, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle)); + MOCK_METHOD4(OnDisconnectFailed, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const DisconnectError& error)); + MOCK_METHOD2(OnDisconnectDeviceDone, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle)); + MOCK_METHOD3(OnDisconnectDeviceFailed, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const DisconnectDeviceError& error)); + MOCK_METHOD4(OnDataSendDone, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const RawMessagePtr data_container)); + MOCK_METHOD5(OnDataSendFailed, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const RawMessagePtr data_container, const DataSendError& error)); + MOCK_METHOD4(OnDataReceiveDone, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const RawMessagePtr data_container)); + MOCK_METHOD4(OnDataReceiveFailed, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle, const DataReceiveError& error)); + MOCK_METHOD3(OnCommunicationError, + void(const TransportAdapter* transport_adapter, const DeviceUID& device_handle, const ApplicationHandle& app_handle)); + MOCK_METHOD3(OnConnectRequested, void(const TransportAdapter*, const DeviceUID&, const ApplicationHandle&)); +}; + +} +} +} + +#endif /* MOCK_transport_adapter_LISTENER_H_ */ diff --git a/src/components/transport_manager/test/include/mock_transport_manager_listener.h b/src/components/transport_manager/test/include/mock_transport_manager_listener.h new file mode 100644 index 0000000000..9518e1a92a --- /dev/null +++ b/src/components/transport_manager/test/include/mock_transport_manager_listener.h @@ -0,0 +1,103 @@ +/* + * \file mock_transport_adapter_listener.h + * \brief + * + * Copyright (c) 2013, 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 MOCK_TRANSPORT_MANAGER_LISTENER_H +#define MOCK_TRANSPORT_MANAGER_LISTENER_H + +#include <gmock/gmock.h> + +#include "transport_manager/common.h" +#include "transport_manager/info.h" +#include "transport_manager/transport_adapter/transport_adapter.h" +#include "transport_manager/transport_manager_listener.h" + +using ::transport_manager::ApplicationList; +using ::transport_manager::ApplicationHandle; +using ::transport_manager::transport_adapter::TransportAdapter; +using ::transport_manager::SearchDeviceError; +using ::transport_manager::ConnectionUID; +using ::transport_manager::ConnectError; +using ::transport_manager::DisconnectError; +using ::transport_manager::DisconnectDeviceError; +using ::transport_manager::DataSendError; +using ::transport_manager::DataReceiveError; +using ::transport_manager::CommunicationError; +using ::transport_manager::DeviceInfo; +using ::transport_manager::DeviceHandle; + +namespace test { +namespace components { +namespace transport_manager { + +class MockTransportManagerListener : + public ::transport_manager::TransportManagerListener { + public: + MOCK_METHOD1(OnDeviceListUpdated, void(const std::vector<DeviceInfo>&)); + MOCK_METHOD0(OnFindNewApplicationsRequest, void()); + MOCK_METHOD1(OnDeviceFound, void(const DeviceInfo &device_info)); + MOCK_METHOD1(OnDeviceAdded, void(const DeviceInfo &device_info)); + MOCK_METHOD1(OnDeviceRemoved, void(const DeviceInfo &device_info)); + MOCK_METHOD0(OnNoDeviceFound, void()); + MOCK_METHOD0(OnScanDevicesFinished, void()); + MOCK_METHOD1(OnScanDevicesFailed, void(const SearchDeviceError& error)); + + MOCK_METHOD2(OnConnectionEstablished, void(const DeviceInfo& device_info, + const ConnectionUID &connection_id)); + MOCK_METHOD2(OnConnectionFailed, void(const DeviceInfo& device_info, + const ConnectError& error)); + + MOCK_METHOD1(OnConnectionClosed, void(ConnectionUID connection_id)); + MOCK_METHOD2(OnConnectionClosedFailure, void (ConnectionUID connection_id, + const DisconnectError& error)); + MOCK_METHOD2(OnUnexpectedDisconnect, void (ConnectionUID connection_id, + const CommunicationError& error)); + MOCK_METHOD2(OnDeviceConnectionLost, void (const DeviceHandle& device, + const DisconnectDeviceError& error)); + MOCK_METHOD2(OnDisconnectFailed, void (const DeviceHandle& device, + const DisconnectDeviceError& error)); + + MOCK_METHOD1(OnTMMessageReceived, void(const RawMessagePtr data_container)); + MOCK_METHOD2(OnTMMessageReceiveFailed, void(ConnectionUID connection_id, + const DataReceiveError& error)); + MOCK_METHOD1(OnTMMessageSend, void(const RawMessagePtr message)); + MOCK_METHOD2(OnTMMessageSendFailed, void(const DataSendError& error, + const RawMessagePtr message)); +}; + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* MOCK_TRANSPORT_MANAGER_LISTENER_H */ diff --git a/src/components/transport_manager/test/include/raw_message_matcher.h b/src/components/transport_manager/test/include/raw_message_matcher.h new file mode 100644 index 0000000000..89f1cdd182 --- /dev/null +++ b/src/components/transport_manager/test/include/raw_message_matcher.h @@ -0,0 +1,75 @@ +/* + * \file raw_message_matcher.h + * \brief matcher RawMessagePtr + * + * Copyright (c) 2013, 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 APPLINK_TEST_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_RAW_MESSAGE_MATCHER_H_ +#define APPLINK_TEST_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_RAW_MESSAGE_MATCHER_H_ + +#include <gmock/gmock.h> + +#include "transport_manager/common.h" +#include "protocol/common.h" + +using ::testing::Matcher; +using ::testing::MatcherInterface; +using ::testing::MatchResultListener; + +namespace test { +namespace components { +namespace transport_manager { + +using namespace ::protocol_handler; + +class RawMessageMatcher : public MatcherInterface<RawMessagePtr> { + public: + explicit RawMessageMatcher(RawMessagePtr ptr); + + virtual bool MatchAndExplain(const RawMessagePtr ptr, + MatchResultListener* listener) const; + virtual void DescribeTo(::std::ostream* os) const; + virtual void DescribeNegationTo(::std::ostream* os) const; + + private: + const RawMessagePtr ptr_; +}; + +inline const Matcher<RawMessagePtr> RawMessageEq(RawMessagePtr msg) { + return MakeMatcher(new RawMessageMatcher(msg)); +} + +} // namespace transport_manager +} // namespace components +} // namespace test + +#endif /* APPLINK_TEST_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_RAW_MESSAGE_MATCHER_H_ */ diff --git a/src/components/transport_manager/test/include/transport_manager_mock.h b/src/components/transport_manager/test/include/transport_manager_mock.h new file mode 100644 index 0000000000..6593f992de --- /dev/null +++ b/src/components/transport_manager/test/include/transport_manager_mock.h @@ -0,0 +1,87 @@ +/* + * 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_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_MOCK_H_ +#define TEST_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_MOCK_H_ + +#include <gmock/gmock.h> +#include <string> +#include "transport_manager/transport_manager.h" +#include "transport_manager/transport_adapter/transport_adapter_event.h" + +namespace test { +namespace components { +namespace transport_manager_test { + +using ::transport_manager::DeviceHandle; +using ::transport_manager::ConnectionUID; +using ::transport_manager::transport_adapter::TransportAdapter; +using ::transport_manager::TransportAdapterEvent; +using ::transport_manager::TransportManagerListener; +/* + * MOCK implementation of ::transport_manager::TransportManager interface + */ +class TransportManagerMock: public ::transport_manager::TransportManager { + public: + MOCK_METHOD0(Init, + int()); + MOCK_METHOD0(Reinit, + int()); + MOCK_METHOD0(SearchDevices, + int()); + MOCK_METHOD1(ConnectDevice, + int(const DeviceHandle &)); + MOCK_METHOD1(DisconnectDevice, + int(const DeviceHandle &)); + MOCK_METHOD1(Disconnect, + int(const ConnectionUID &)); + MOCK_METHOD1(DisconnectForce, + int(const ConnectionUID &)); + MOCK_METHOD1(SendMessageToDevice, + int(const ::protocol_handler::RawMessagePtr)); + MOCK_METHOD1(ReceiveEventFromDevice, + int(const TransportAdapterEvent&)); + MOCK_METHOD1(AddTransportAdapter, + int(TransportAdapter *)); + MOCK_METHOD1(AddEventListener, + int(TransportManagerListener *)); + MOCK_METHOD0(Stop, + int()); + MOCK_METHOD1(RemoveDevice, + int(const DeviceHandle &)); + MOCK_CONST_METHOD1(Visibility, + int(const bool &)); +}; +} // namespace transport_manager_test +} // namespace components +} // namespace test +#endif // TEST_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_MOCK_H_ |