diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 4f76140..a81923a 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -33,7 +33,6 @@ INTERFACE ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/mbed-client-libservice - ${mbed-os_SOURCE_DIR}/connectivity/netsocket/include ${mbed-os_SOURCE_DIR}/connectivity ${mbed-os_SOURCE_DIR}/connectivity/mbedtls ${mbed-os_SOURCE_DIR}/connectivity/mbedtls/include diff --git a/UNITTESTS/stubs/ControlPlane_netif_stub.h b/UNITTESTS/stubs/ControlPlane_netif_stub.h deleted file mode 100644 index be220f4..0000000 --- a/UNITTESTS/stubs/ControlPlane_netif_stub.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/ControlPlane_netif.h" -#include - -namespace mbed { - -class ControlPlane_netif_stub : public ControlPlane_netif { -public: - std::list return_values; - nsapi_error_t return_value; - bool cp_data_received_called; - - ControlPlane_netif_stub() - { - return_value = 0; - cp_data_received_called = false; - } - -protected: - virtual nsapi_error_t send(const void *cpdata, nsapi_size_t cpdata_length) - { - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - - virtual nsapi_error_t recv(void *cpdata, nsapi_size_t cpdata_length) - { - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - - virtual void data_received() - { - cp_data_received_called = true; - }; - - virtual void attach(void (*callback)(void *), void *data) {}; -}; - -} diff --git a/UNITTESTS/stubs/EMAC_mock.h b/UNITTESTS/stubs/EMAC_mock.h deleted file mode 100644 index 2e33bcc..0000000 --- a/UNITTESTS/stubs/EMAC_mock.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EMACMOCK_H -#define EMACMOCK_H - -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include "netsocket/EMAC.h" - -class MockEMAC : public EMAC { -public: - MOCK_METHOD0(power_up, bool()); - MOCK_METHOD0(power_down, void()); - MOCK_CONST_METHOD0(get_mtu_size, uint32_t()); - MOCK_CONST_METHOD0(get_align_preference, uint32_t()); - MOCK_CONST_METHOD2(get_ifname, void(char *name, uint8_t size)); - MOCK_CONST_METHOD0(get_hwaddr_size, uint8_t()); - MOCK_CONST_METHOD1(get_hwaddr, bool(uint8_t *addr)); - MOCK_METHOD1(set_hwaddr, void(const uint8_t *)); - MOCK_METHOD1(link_out, bool(emac_mem_buf_t *buf)); - MOCK_METHOD1(set_link_input_cb, void(emac_link_input_cb_t input_cb)); - MOCK_METHOD1(set_link_state_cb, void(emac_link_state_change_cb_t state_cb)); - MOCK_METHOD1(add_multicast_group, void(const uint8_t *address)); - MOCK_METHOD1(remove_multicast_group, void(const uint8_t *address)); - MOCK_METHOD1(set_all_multicast, void(bool all)); - MOCK_METHOD1(set_memory_manager, void(EMACMemoryManager &mem_mngr)); - - static MockEMAC &get_instance() - { - static MockEMAC emacMock1; - return emacMock1; - } -}; - -MBED_WEAK EMAC &EMAC::get_default_instance() -{ - return MockEMAC::get_instance(); -} - -#endif // EMACMOCK_H diff --git a/UNITTESTS/stubs/NetworkStack_stub.h b/UNITTESTS/stubs/NetworkStack_stub.h deleted file mode 100644 index 916937e..0000000 --- a/UNITTESTS/stubs/NetworkStack_stub.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETWORKSTACKSTUB_H -#define NETWORKSTACKSTUB_H - -#include "netsocket/NetworkStack.h" -#include - -/* - * Note: If you want to: - * - control and/or set expectations for the data returned/sent from/to the stack - * - set expectations on the calls to NetworkStack - * See OnboardNetworkStack_mock.h and its OnboardNetworkStackMock class. - */ - -class NetworkStackstub : public NetworkStack { -public: - std::list return_values; - nsapi_error_t return_value; - SocketAddress return_socketAddress; - - NetworkStackstub() : - return_value(0), - return_socketAddress() - { - } - - virtual nsapi_error_t get_ip_address(SocketAddress* address) - { - address->set_ip_address("127.0.0.1"); - return NSAPI_ERROR_OK; - } - virtual nsapi_error_t gethostbyname(const char *host, - SocketAddress *address, nsapi_version_t version, const char *interface_name) - { - return return_value; - } - virtual nsapi_value_or_error_t getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) - { - return return_value; - } - virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version, - const char *interface_name) - { - return return_value; - } - virtual nsapi_value_or_error_t getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) - { - return return_value; - } - virtual nsapi_error_t gethostbyname_async_cancel(int id) - { - return return_value; - } - -protected: - virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) - { - if (return_value == NSAPI_ERROR_OK && return_values.front() == NSAPI_ERROR_OK) { - // Make sure a non-NULL value is returned if error is not expected - *handle = reinterpret_cast(1234); - } else { - *handle = NULL; - } - return return_value; - }; - virtual nsapi_error_t socket_close(nsapi_socket_t handle) - { - return return_value; - }; - virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) - { - return return_value; - }; - virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) - { - return return_value; - }; - virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) - { - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - virtual nsapi_error_t socket_accept(nsapi_socket_t server, - nsapi_socket_t *handle, SocketAddress *address = 0) - { - if (return_value == NSAPI_ERROR_OK && return_values.front() == NSAPI_ERROR_OK) { - // Make sure a non-NULL value is returned if error is not expected - *handle = reinterpret_cast(1234); - } else { - *handle = NULL; - } - return return_value; - }; - virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, - const void *data, nsapi_size_t size) - { - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, - void *data, nsapi_size_t size) - { - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, - const void *data, nsapi_size_t size) - { - return return_value; - }; - virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, - void *buffer, nsapi_size_t size) - { - if (return_socketAddress != SocketAddress()) { - *address = return_socketAddress; - } - if (!return_values.empty()) { - nsapi_error_t ret = return_values.front(); - return_values.pop_front(); - return ret; - } - return return_value; - }; - virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) {}; - -private: - virtual nsapi_error_t call_in(int delay, mbed::Callback func) - { - return return_value; - } -}; - -#endif // NETWORKSTACKSTUB_H diff --git a/UNITTESTS/stubs/OnboardNetworkStack_mock.h b/UNITTESTS/stubs/OnboardNetworkStack_mock.h deleted file mode 100644 index 24d15f5..0000000 --- a/UNITTESTS/stubs/OnboardNetworkStack_mock.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2019, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ -#define UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "netsocket/OnboardNetworkStack.h" - -/* - * Note: If all you need is a simple stub with basic return value control - * consider using NetworkStack_stub.h and its NetworkStackstub class. - */ - -class OnboardNetworkStackMock : public OnboardNetworkStack { -public: - MOCK_METHOD3(gethostbyname, nsapi_error_t(const char *host, SocketAddress *address, nsapi_version_t version)); - MOCK_METHOD1(add_dns_server, nsapi_error_t(const SocketAddress &address)); - MOCK_METHOD3(get_dns_server, nsapi_error_t(int index, SocketAddress *address, const char *interface_name)); - MOCK_METHOD2(call_in, nsapi_error_t(int delay, mbed::Callback func)); - MOCK_METHOD2(socket_open, nsapi_error_t(nsapi_socket_t *handle, nsapi_protocol_t proto)); - MOCK_METHOD1(socket_close, nsapi_error_t(nsapi_socket_t handle)); - MOCK_METHOD2(socket_bind, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address)); - MOCK_METHOD2(socket_listen, nsapi_error_t(nsapi_socket_t handle, int backlog)); - MOCK_METHOD2(socket_connect, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address)); - MOCK_METHOD3(socket_accept, nsapi_error_t(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address)); - MOCK_METHOD3(socket_send, nsapi_error_t(nsapi_socket_t handle, const void *data, nsapi_size_t size)); - MOCK_METHOD3(socket_recv, nsapi_error_t(nsapi_socket_t handle, void *data, nsapi_size_t size)); - MOCK_METHOD4(socket_sendto, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)); - MOCK_METHOD4(socket_recvfrom, nsapi_error_t(nsapi_socket_t handle, SocketAddress *address, void *data, nsapi_size_t size)); - MOCK_METHOD5(setsockopt, nsapi_error_t(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)); - MOCK_METHOD5(getsockopt, nsapi_error_t(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned *optlen)); -// MOCK_METHOD3(socket_attach, void(nsapi_socket_t handle, void (*callback)(void *), void *data)); - MOCK_METHOD3(add_ethernet_interface, nsapi_error_t(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)); - MOCK_METHOD3(add_ppp_interface, nsapi_error_t(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out)); - MOCK_METHOD1(set_default_interface, void (OnboardNetworkStack::Interface *interface)); - void *socket_cb; - // No need to mock socket_attach really. - void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) - { - socket_cb = data; - }; - - - static OnboardNetworkStackMock &get_instance() - { - static OnboardNetworkStackMock stackMock1; - return stackMock1; - } - - class InterfaceMock : public OnboardNetworkStack::Interface { - public: - - static InterfaceMock &get_instance() - { - static InterfaceMock test_interface; - return test_interface; - } - MOCK_METHOD6(bringup, nsapi_error_t(bool dhcp, const char *ip, - const char *netmask, const char *gw, - nsapi_ip_stack_t stack, - bool blocking - )); - MOCK_METHOD0(bringdown, nsapi_error_t()); - MOCK_METHOD1(attach, void(mbed::Callback status_cb)); - MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t()); - MOCK_METHOD1(get_interface_name, char *(char *buf)); - MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen)); - MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address)); - MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address)); - MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen)); - MOCK_METHOD1(get_netmask, nsapi_error_t (SocketAddress *address)); - MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen)); - MOCK_METHOD1(get_gateway, nsapi_error_t (SocketAddress *address)); - }; -}; - - -#endif /* UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ */ diff --git a/UNITTESTS/stubs/connectivity/CMakeLists.txt b/UNITTESTS/stubs/connectivity/CMakeLists.txt index 72e79c5..2e70a42 100644 --- a/UNITTESTS/stubs/connectivity/CMakeLists.txt +++ b/UNITTESTS/stubs/connectivity/CMakeLists.txt @@ -19,17 +19,9 @@ target_sources(mbed-stubs-connectivity PRIVATE aes_stub.c - CellularInterface_stub.cpp cipher_stub.c cmac_stub.c ip4tos_stub.c - MeshInterface_stub.cpp - NetworkInterfaceDefaults_stub.cpp - NetworkInterface_stub.cpp - NetworkStack_stub.cpp - nsapi_dns_stub.cpp - SocketAddress_stub.cpp - SocketStats_Stub.cpp stoip4_stub.c ${mbed-os_SOURCE_DIR}/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c ) diff --git a/UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp b/UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp deleted file mode 100644 index 154dece..0000000 --- a/UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Socket - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/CellularInterface.h" - -MBED_WEAK CellularInterface *CellularInterface::get_target_default_instance() -{ - return NULL; -} - - diff --git a/UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp b/UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp deleted file mode 100644 index f6346ab..0000000 --- a/UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Socket - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/MeshInterface.h" - -MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() -{ - return NULL; -} - - diff --git a/UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp deleted file mode 100644 index dd3a562..0000000 --- a/UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "netsocket/NetworkInterface.h" -#include "netsocket/WiFiInterface.h" -#include "netsocket/CellularInterface.h" -#include "netsocket/MeshInterface.h" - -MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance() -{ - return NULL; -} - -MBED_WEAK MeshInterface *MeshInterface::get_default_instance() -{ - return NULL; -} - -MBED_WEAK CellularInterface *CellularInterface::get_default_instance() -{ - return NULL; -} - -MBED_WEAK WiFiInterface *WiFiInterface::get_target_default_instance() -{ - return NULL; -} - -MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance() -{ - return NULL; -} - -void NetworkInterface::set_default_parameters() -{ -} - -void WiFiInterface::set_default_parameters() -{ -} - -void CellularInterface::set_default_parameters() -{ -} - -MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() -{ - return NULL; -} diff --git a/UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp deleted file mode 100644 index 020a551..0000000 --- a/UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/NetworkInterface.h" -#include "netsocket/NetworkStack.h" -#include - - -// Default network-interface state -const char *NetworkInterface::get_mac_address() -{ - return 0; -} - -nsapi_error_t NetworkInterface::set_mac_address(uint8_t *mac_addr, nsapi_size_t addr_len) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::get_netmask(SocketAddress *) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::get_gateway(SocketAddress *) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::set_dhcp(bool dhcp) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -// DNS operations go through the underlying stack by default -nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_value_or_error_t NetworkInterface::getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::get_dns_server(int index, SocketAddress *address, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -void NetworkInterface::attach(mbed::Callback status_cb) -{ - -} - -nsapi_connection_status_t NetworkInterface::get_connection_status() const -{ - return NSAPI_STATUS_LOCAL_UP; -} - -nsapi_error_t NetworkInterface::set_blocking(bool blocking) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const *, mbed::Callback, nsapi_version, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_value_or_error_t NetworkInterface::getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -void NetworkInterface::set_as_default() -{ -} - -char *NetworkInterface::get_interface_name(char *interface_name) -{ - return NULL; -} - -NetworkInterface::~NetworkInterface() -{ -} diff --git a/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp deleted file mode 100644 index dd68b3e..0000000 --- a/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/NetworkStack.h" -#include "netsocket/nsapi_dns.h" -#include "mbed.h" -#include "stddef.h" -#include - -// Default NetworkStack operations -nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) -{ - return NSAPI_ERROR_OK; -} - -nsapi_value_or_error_t NetworkStack::getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address, const char *interface_name) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -// Conversion function for network stacks -NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) -{ - return nullptr; -} - -nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version, - const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_value_or_error_t NetworkStack::getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -call_in_callback_cb_t NetworkStack::get_call_in_callback() -{ - return NULL; -} - -nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::get_ip_address(SocketAddress* address) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress* address, const char *interface_name) -{ - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp b/UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp deleted file mode 100644 index 4d1dd34..0000000 --- a/UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/SocketAddress.h" - - -SocketAddress::SocketAddress(const nsapi_addr_t &addr, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const char *addr, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const SocketAddress &addr) -{ -} - -bool SocketAddress::set_ip_address(const char *addr) -{ - return false; -} - -void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version) -{ -} - -void SocketAddress::set_addr(const nsapi_addr_t &addr) -{ -} - -const char *SocketAddress::get_ip_address() const -{ - return NULL; -} - -SocketAddress::operator bool() const -{ - return false; -} - -SocketAddress &SocketAddress::operator=(const SocketAddress &addr) -{ - set_addr(addr.get_addr()); - set_port(addr.get_port()); - return *this; -} - -bool operator==(const SocketAddress &a, const SocketAddress &b) -{ - return false; -} - -bool operator!=(const SocketAddress &a, const SocketAddress &b) -{ - return false; -} diff --git a/UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp b/UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp deleted file mode 100644 index 4da9602..0000000 --- a/UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/SocketStats.h" - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED -int SocketStats::get_entry_position(const Socket *const reference_id) -{ - return 0; -} - -size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_t count) -{ - return 0; -} - -SocketStats::SocketStats() -{ -} - -void SocketStats::stats_new_socket_entry(const Socket *const reference_id) -{ - return; -} - -void SocketStats::stats_update_socket_state(const Socket *const reference_id, socket_state state) -{ - return; -} - -void SocketStats::stats_update_peer(const Socket *const reference_id, const SocketAddress &peer) -{ - return; -} - -void SocketStats::stats_update_proto(const Socket *const reference_id, nsapi_protocol_t proto) -{ - return; -} - -void SocketStats::stats_update_sent_bytes(const Socket *const reference_id, size_t sent_bytes) -{ - return; -} - -void SocketStats::stats_update_recv_bytes(const Socket *const reference_id, size_t recv_bytes) -{ - return; -} -#endif diff --git a/UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp b/UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp deleted file mode 100644 index 9b7af9a..0000000 --- a/UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "netsocket/nsapi_dns.h" - - -nsapi_error_t nsapi_stub_return_value = NSAPI_ERROR_DNS_FAILURE; -NetworkStack::hostbyname_cb_t query_callback; -call_in_callback_cb_t callin_callback; - -nsapi_error_t nsapi_dns_query(NetworkStack *stack, const char *host, - SocketAddress *addr, const char *interface_name, nsapi_version_t version) -{ - return nsapi_stub_return_value; -} - -nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const char *host, - SocketAddress *addresses, nsapi_size_t addr_count, const char *interface_name, nsapi_version_t version) -{ - return nsapi_stub_return_value; -} - -nsapi_error_t nsapi_dns_query_async(NetworkStack *stack, const char *host, - NetworkStack::hostbyname_cb_t callback, call_in_callback_cb_t call_in_cb, const char *interface_name, - nsapi_version_t version) -{ - query_callback = callback; - callin_callback = call_in_cb; - return nsapi_stub_return_value; -} - -nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const char *host, - NetworkStack::hostbyname_cb_t callback, nsapi_size_t addr_count, - call_in_callback_cb_t call_in_cb, const char *interface_name, nsapi_version_t version) -{ - query_callback = callback; - callin_callback = call_in_cb; - return nsapi_stub_return_value; -} - -nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id) -{ - return nsapi_stub_return_value; -} - -extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr, const char *interface_name) -{ - return NSAPI_ERROR_OK; -} - -void nsapi_dns_cache_reset() -{ - -} diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt index 7934053..8e310cc 100644 --- a/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt @@ -56,7 +56,9 @@ mbed-headers-drivers mbed-headers-hal mbed-headers-events + mbed-headers-netsocket mbed-headers-cellular + mbed-stubs-netsocket mbed-stubs-headers gtest ) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt index 17c73c0..b2ce284 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt @@ -24,9 +24,11 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-headers-filesystem mbed-stubs + mbed-stubs-netsocket mbed-stubs-cellular mbed-stubs-headers mbed-stubs-rtos-headers diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt index 228f89d..4fd647c 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt @@ -30,8 +30,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs + mbed-stubs-netsocket mbed-stubs-cellular mbed-stubs-headers mbed-stubs-rtos diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt index b497c81..3379dec 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt @@ -22,8 +22,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs + mbed-stubs-netsocket mbed-stubs-cellular mbed-stubs-headers gmock_main diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt index cec6b8f..45488bf 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt @@ -23,8 +23,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs + mbed-stubs-netsocket mbed-stubs-cellular mbed-stubs-headers gmock_main diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt index f8f34eb..d40d85e 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt @@ -23,8 +23,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs + mbed-stubs-netsocket mbed-stubs-cellular mbed-stubs-headers gmock_main diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt index a2c2fb8..2361dff 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs mbed-stubs-cellular diff --git a/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt index cd77650..21cbc64 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs-platform gmock_main diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt index 76f3c8a..1d801ef 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs mbed-stubs-cellular diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt index ddd9181..9d8c2aa 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt @@ -36,9 +36,11 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs mbed-stubs-cellular + mbed-stubs-netsocket mbed-stubs-headers gmock_main ) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt index 54c9dc7..272e30a 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(${TEST_NAME} PRIVATE + mbed-headers-netsocket mbed-headers mbed-headers-cellular mbed-stubs diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt index a5c1b55..ab3529d 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt @@ -29,6 +29,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs mbed-stubs-cellular diff --git a/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt index e23c5d4..b54cb6b 100644 --- a/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +add_subdirectory(doubles) add_subdirectory(netsocket) diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt new file mode 100644 index 0000000..634caa0 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-headers-netsocket INTERFACE) + +target_include_directories(mbed-headers-netsocket + INTERFACE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/include +) + +add_library(mbed-stubs-netsocket) + +target_include_directories(mbed-stubs-netsocket + PUBLIC + . +) + +target_sources(mbed-stubs-netsocket + PRIVATE + CellularInterface_stub.cpp + MeshInterface_stub.cpp + NetworkInterfaceDefaults_stub.cpp + NetworkInterface_stub.cpp + NetworkStack_stub.cpp + nsapi_dns_stub.cpp + SocketAddress_stub.cpp + SocketStats_Stub.cpp +) + +target_link_libraries(mbed-stubs-netsocket + PRIVATE + mbed-headers-netsocket + mbed-stubs-rtos-headers + mbed-headers + mbed-stubs-headers + mbed-stubs-rtos + gtest +) diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/CellularInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/CellularInterface_stub.cpp new file mode 100644 index 0000000..154dece --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/CellularInterface_stub.cpp @@ -0,0 +1,25 @@ +/* Socket + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/CellularInterface.h" + +MBED_WEAK CellularInterface *CellularInterface::get_target_default_instance() +{ + return NULL; +} + + diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/ControlPlane_netif_stub.h b/connectivity/netsocket/tests/UNITTESTS/doubles/ControlPlane_netif_stub.h new file mode 100644 index 0000000..be220f4 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/ControlPlane_netif_stub.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/ControlPlane_netif.h" +#include + +namespace mbed { + +class ControlPlane_netif_stub : public ControlPlane_netif { +public: + std::list return_values; + nsapi_error_t return_value; + bool cp_data_received_called; + + ControlPlane_netif_stub() + { + return_value = 0; + cp_data_received_called = false; + } + +protected: + virtual nsapi_error_t send(const void *cpdata, nsapi_size_t cpdata_length) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + + virtual nsapi_error_t recv(void *cpdata, nsapi_size_t cpdata_length) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + + virtual void data_received() + { + cp_data_received_called = true; + }; + + virtual void attach(void (*callback)(void *), void *data) {}; +}; + +} diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/EMAC_mock.h b/connectivity/netsocket/tests/UNITTESTS/doubles/EMAC_mock.h new file mode 100644 index 0000000..2e33bcc --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/EMAC_mock.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EMACMOCK_H +#define EMACMOCK_H + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "netsocket/EMAC.h" + +class MockEMAC : public EMAC { +public: + MOCK_METHOD0(power_up, bool()); + MOCK_METHOD0(power_down, void()); + MOCK_CONST_METHOD0(get_mtu_size, uint32_t()); + MOCK_CONST_METHOD0(get_align_preference, uint32_t()); + MOCK_CONST_METHOD2(get_ifname, void(char *name, uint8_t size)); + MOCK_CONST_METHOD0(get_hwaddr_size, uint8_t()); + MOCK_CONST_METHOD1(get_hwaddr, bool(uint8_t *addr)); + MOCK_METHOD1(set_hwaddr, void(const uint8_t *)); + MOCK_METHOD1(link_out, bool(emac_mem_buf_t *buf)); + MOCK_METHOD1(set_link_input_cb, void(emac_link_input_cb_t input_cb)); + MOCK_METHOD1(set_link_state_cb, void(emac_link_state_change_cb_t state_cb)); + MOCK_METHOD1(add_multicast_group, void(const uint8_t *address)); + MOCK_METHOD1(remove_multicast_group, void(const uint8_t *address)); + MOCK_METHOD1(set_all_multicast, void(bool all)); + MOCK_METHOD1(set_memory_manager, void(EMACMemoryManager &mem_mngr)); + + static MockEMAC &get_instance() + { + static MockEMAC emacMock1; + return emacMock1; + } +}; + +MBED_WEAK EMAC &EMAC::get_default_instance() +{ + return MockEMAC::get_instance(); +} + +#endif // EMACMOCK_H diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/MeshInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/MeshInterface_stub.cpp new file mode 100644 index 0000000..f6346ab --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/MeshInterface_stub.cpp @@ -0,0 +1,25 @@ +/* Socket + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/MeshInterface.h" + +MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() +{ + return NULL; +} + + diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp new file mode 100644 index 0000000..dd3a562 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "netsocket/NetworkInterface.h" +#include "netsocket/WiFiInterface.h" +#include "netsocket/CellularInterface.h" +#include "netsocket/MeshInterface.h" + +MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance() +{ + return NULL; +} + +MBED_WEAK MeshInterface *MeshInterface::get_default_instance() +{ + return NULL; +} + +MBED_WEAK CellularInterface *CellularInterface::get_default_instance() +{ + return NULL; +} + +MBED_WEAK WiFiInterface *WiFiInterface::get_target_default_instance() +{ + return NULL; +} + +MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance() +{ + return NULL; +} + +void NetworkInterface::set_default_parameters() +{ +} + +void WiFiInterface::set_default_parameters() +{ +} + +void CellularInterface::set_default_parameters() +{ +} + +MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() +{ + return NULL; +} diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterface_stub.cpp new file mode 100644 index 0000000..020a551 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterface_stub.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/NetworkInterface.h" +#include "netsocket/NetworkStack.h" +#include + + +// Default network-interface state +const char *NetworkInterface::get_mac_address() +{ + return 0; +} + +nsapi_error_t NetworkInterface::set_mac_address(uint8_t *mac_addr, nsapi_size_t addr_len) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::get_netmask(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::get_gateway(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::set_dhcp(bool dhcp) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +// DNS operations go through the underlying stack by default +nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_value_or_error_t NetworkInterface::getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::get_dns_server(int index, SocketAddress *address, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +void NetworkInterface::attach(mbed::Callback status_cb) +{ + +} + +nsapi_connection_status_t NetworkInterface::get_connection_status() const +{ + return NSAPI_STATUS_LOCAL_UP; +} + +nsapi_error_t NetworkInterface::set_blocking(bool blocking) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const *, mbed::Callback, nsapi_version, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_value_or_error_t NetworkInterface::getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +void NetworkInterface::set_as_default() +{ +} + +char *NetworkInterface::get_interface_name(char *interface_name) +{ + return NULL; +} + +NetworkInterface::~NetworkInterface() +{ +} diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp new file mode 100644 index 0000000..7d6331a --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/NetworkStack.h" +#include "netsocket/nsapi_dns.h" +#include "mbed.h" +#include "stddef.h" +#include + +// Default NetworkStack operations +nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) +{ + return NSAPI_ERROR_OK; +} + +nsapi_value_or_error_t NetworkStack::getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address, const char *interface_name) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +// Conversion function for network stacks +NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) +{ + return nullptr; +} + +nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version, + const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_value_or_error_t NetworkStack::getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +call_in_callback_cb_t NetworkStack::get_call_in_callback() +{ + return NULL; +} + +nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::get_ip_address(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress *address, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.h b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.h new file mode 100644 index 0000000..d6b630a --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NETWORKSTACKSTUB_H +#define NETWORKSTACKSTUB_H + +#include "netsocket/NetworkStack.h" +#include + +/* + * Note: If you want to: + * - control and/or set expectations for the data returned/sent from/to the stack + * - set expectations on the calls to NetworkStack + * See OnboardNetworkStack_mock.h and its OnboardNetworkStackMock class. + */ + +class NetworkStackstub : public NetworkStack { +public: + std::list return_values; + nsapi_error_t return_value; + SocketAddress return_socketAddress; + + NetworkStackstub() : + return_value(0), + return_socketAddress() + { + } + + virtual nsapi_error_t get_ip_address(SocketAddress *address) + { + address->set_ip_address("127.0.0.1"); + return NSAPI_ERROR_OK; + } + virtual nsapi_error_t gethostbyname(const char *host, + SocketAddress *address, nsapi_version_t version, const char *interface_name) + { + return return_value; + } + virtual nsapi_value_or_error_t getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name) + { + return return_value; + } + virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version, + const char *interface_name) + { + return return_value; + } + virtual nsapi_value_or_error_t getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name) + { + return return_value; + } + virtual nsapi_error_t gethostbyname_async_cancel(int id) + { + return return_value; + } + +protected: + virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) + { + if (return_value == NSAPI_ERROR_OK && return_values.front() == NSAPI_ERROR_OK) { + // Make sure a non-NULL value is returned if error is not expected + *handle = reinterpret_cast(1234); + } else { + *handle = NULL; + } + return return_value; + }; + virtual nsapi_error_t socket_close(nsapi_socket_t handle) + { + return return_value; + }; + virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) + { + return return_value; + }; + virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) + { + return return_value; + }; + virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + virtual nsapi_error_t socket_accept(nsapi_socket_t server, + nsapi_socket_t *handle, SocketAddress *address = 0) + { + if (return_value == NSAPI_ERROR_OK && return_values.front() == NSAPI_ERROR_OK) { + // Make sure a non-NULL value is returned if error is not expected + *handle = reinterpret_cast(1234); + } else { + *handle = NULL; + } + return return_value; + }; + virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, + const void *data, nsapi_size_t size) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, + void *data, nsapi_size_t size) + { + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, + const void *data, nsapi_size_t size) + { + return return_value; + }; + virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, + void *buffer, nsapi_size_t size) + { + if (return_socketAddress != SocketAddress()) { + *address = return_socketAddress; + } + if (!return_values.empty()) { + nsapi_error_t ret = return_values.front(); + return_values.pop_front(); + return ret; + } + return return_value; + }; + virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) {}; + +private: + virtual nsapi_error_t call_in(int delay, mbed::Callback func) + { + return return_value; + } +}; + +#endif // NETWORKSTACKSTUB_H diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/OnboardNetworkStack_mock.h b/connectivity/netsocket/tests/UNITTESTS/doubles/OnboardNetworkStack_mock.h new file mode 100644 index 0000000..24d15f5 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/OnboardNetworkStack_mock.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ +#define UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "netsocket/OnboardNetworkStack.h" + +/* + * Note: If all you need is a simple stub with basic return value control + * consider using NetworkStack_stub.h and its NetworkStackstub class. + */ + +class OnboardNetworkStackMock : public OnboardNetworkStack { +public: + MOCK_METHOD3(gethostbyname, nsapi_error_t(const char *host, SocketAddress *address, nsapi_version_t version)); + MOCK_METHOD1(add_dns_server, nsapi_error_t(const SocketAddress &address)); + MOCK_METHOD3(get_dns_server, nsapi_error_t(int index, SocketAddress *address, const char *interface_name)); + MOCK_METHOD2(call_in, nsapi_error_t(int delay, mbed::Callback func)); + MOCK_METHOD2(socket_open, nsapi_error_t(nsapi_socket_t *handle, nsapi_protocol_t proto)); + MOCK_METHOD1(socket_close, nsapi_error_t(nsapi_socket_t handle)); + MOCK_METHOD2(socket_bind, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address)); + MOCK_METHOD2(socket_listen, nsapi_error_t(nsapi_socket_t handle, int backlog)); + MOCK_METHOD2(socket_connect, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address)); + MOCK_METHOD3(socket_accept, nsapi_error_t(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address)); + MOCK_METHOD3(socket_send, nsapi_error_t(nsapi_socket_t handle, const void *data, nsapi_size_t size)); + MOCK_METHOD3(socket_recv, nsapi_error_t(nsapi_socket_t handle, void *data, nsapi_size_t size)); + MOCK_METHOD4(socket_sendto, nsapi_error_t(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)); + MOCK_METHOD4(socket_recvfrom, nsapi_error_t(nsapi_socket_t handle, SocketAddress *address, void *data, nsapi_size_t size)); + MOCK_METHOD5(setsockopt, nsapi_error_t(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)); + MOCK_METHOD5(getsockopt, nsapi_error_t(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned *optlen)); +// MOCK_METHOD3(socket_attach, void(nsapi_socket_t handle, void (*callback)(void *), void *data)); + MOCK_METHOD3(add_ethernet_interface, nsapi_error_t(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)); + MOCK_METHOD3(add_ppp_interface, nsapi_error_t(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out)); + MOCK_METHOD1(set_default_interface, void (OnboardNetworkStack::Interface *interface)); + void *socket_cb; + // No need to mock socket_attach really. + void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) + { + socket_cb = data; + }; + + + static OnboardNetworkStackMock &get_instance() + { + static OnboardNetworkStackMock stackMock1; + return stackMock1; + } + + class InterfaceMock : public OnboardNetworkStack::Interface { + public: + + static InterfaceMock &get_instance() + { + static InterfaceMock test_interface; + return test_interface; + } + MOCK_METHOD6(bringup, nsapi_error_t(bool dhcp, const char *ip, + const char *netmask, const char *gw, + nsapi_ip_stack_t stack, + bool blocking + )); + MOCK_METHOD0(bringdown, nsapi_error_t()); + MOCK_METHOD1(attach, void(mbed::Callback status_cb)); + MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t()); + MOCK_METHOD1(get_interface_name, char *(char *buf)); + MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address)); + MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address)); + MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_netmask, nsapi_error_t (SocketAddress *address)); + MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_gateway, nsapi_error_t (SocketAddress *address)); + }; +}; + + +#endif /* UNITTESTS_STUBS_ONBOARDNETWORKSTACK_MOCK_H_ */ diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/SocketAddress_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketAddress_stub.cpp new file mode 100644 index 0000000..4d1dd34 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketAddress_stub.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) , Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/SocketAddress.h" + + +SocketAddress::SocketAddress(const nsapi_addr_t &addr, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const char *addr, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const SocketAddress &addr) +{ +} + +bool SocketAddress::set_ip_address(const char *addr) +{ + return false; +} + +void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version) +{ +} + +void SocketAddress::set_addr(const nsapi_addr_t &addr) +{ +} + +const char *SocketAddress::get_ip_address() const +{ + return NULL; +} + +SocketAddress::operator bool() const +{ + return false; +} + +SocketAddress &SocketAddress::operator=(const SocketAddress &addr) +{ + set_addr(addr.get_addr()); + set_port(addr.get_port()); + return *this; +} + +bool operator==(const SocketAddress &a, const SocketAddress &b) +{ + return false; +} + +bool operator!=(const SocketAddress &a, const SocketAddress &b) +{ + return false; +} diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/SocketStats_Stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketStats_Stub.cpp new file mode 100644 index 0000000..4da9602 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketStats_Stub.cpp @@ -0,0 +1,64 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/SocketStats.h" + +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED +int SocketStats::get_entry_position(const Socket *const reference_id) +{ + return 0; +} + +size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_t count) +{ + return 0; +} + +SocketStats::SocketStats() +{ +} + +void SocketStats::stats_new_socket_entry(const Socket *const reference_id) +{ + return; +} + +void SocketStats::stats_update_socket_state(const Socket *const reference_id, socket_state state) +{ + return; +} + +void SocketStats::stats_update_peer(const Socket *const reference_id, const SocketAddress &peer) +{ + return; +} + +void SocketStats::stats_update_proto(const Socket *const reference_id, nsapi_protocol_t proto) +{ + return; +} + +void SocketStats::stats_update_sent_bytes(const Socket *const reference_id, size_t sent_bytes) +{ + return; +} + +void SocketStats::stats_update_recv_bytes(const Socket *const reference_id, size_t recv_bytes) +{ + return; +} +#endif diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/nsapi_dns_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/nsapi_dns_stub.cpp new file mode 100644 index 0000000..9b7af9a --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/nsapi_dns_stub.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "netsocket/nsapi_dns.h" + + +nsapi_error_t nsapi_stub_return_value = NSAPI_ERROR_DNS_FAILURE; +NetworkStack::hostbyname_cb_t query_callback; +call_in_callback_cb_t callin_callback; + +nsapi_error_t nsapi_dns_query(NetworkStack *stack, const char *host, + SocketAddress *addr, const char *interface_name, nsapi_version_t version) +{ + return nsapi_stub_return_value; +} + +nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const char *host, + SocketAddress *addresses, nsapi_size_t addr_count, const char *interface_name, nsapi_version_t version) +{ + return nsapi_stub_return_value; +} + +nsapi_error_t nsapi_dns_query_async(NetworkStack *stack, const char *host, + NetworkStack::hostbyname_cb_t callback, call_in_callback_cb_t call_in_cb, const char *interface_name, + nsapi_version_t version) +{ + query_callback = callback; + callin_callback = call_in_cb; + return nsapi_stub_return_value; +} + +nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const char *host, + NetworkStack::hostbyname_cb_t callback, nsapi_size_t addr_count, + call_in_callback_cb_t call_in_cb, const char *interface_name, nsapi_version_t version) +{ + query_callback = callback; + callin_callback = call_in_cb; + return nsapi_stub_return_value; +} + +nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id) +{ + return nsapi_stub_return_value; +} + +extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr, const char *interface_name) +{ + return NSAPI_ERROR_OK; +} + +void nsapi_dns_cache_reset() +{ + +} diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt index 2acaddb..98da637 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt @@ -23,9 +23,11 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-headers-cellular mbed-stubs mbed-stubs-cellular + mbed-stubs-netsocket mbed-stubs-headers gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt index 9f24188..9564055 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt @@ -31,8 +31,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt index 20a0e4c..bfc358b 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt @@ -30,8 +30,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt index 2081cf2..6f6478b 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt @@ -28,9 +28,11 @@ target_link_libraries(${TEST_NAME} PRIVATE + mbed-headers-netsocket mbed-headers mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt index 68ee8fb..cfaf6ae 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt @@ -43,8 +43,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt index 981790d..efed786 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt @@ -26,8 +26,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt index f92e9ed..80862ec 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt @@ -29,8 +29,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt index f320819..77a21b3 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt @@ -25,8 +25,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt index f78c6cc..ebb0ee4 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt @@ -29,8 +29,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt index 5ac15b6..0e36bc7 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt @@ -19,6 +19,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers gmock_main diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt index ca51a12..b4d6d16 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt @@ -27,8 +27,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt index b9242f9..8d1fc33 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt @@ -29,8 +29,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt index 459d5c6..56248a3 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt @@ -28,8 +28,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt index e62438c..e4ffc7e 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt @@ -28,8 +28,10 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers + mbed-stubs-netsocket gmock_main ) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt index d51f755..f6a5ef1 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-netsocket mbed-stubs mbed-stubs-headers gmock_main