diff --git a/UNITTESTS/target_h/myCellularContext.h b/UNITTESTS/target_h/myCellularContext.h deleted file mode 100644 index c7871c4..0000000 --- a/UNITTESTS/target_h/myCellularContext.h +++ /dev/null @@ -1,225 +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 "CellularContext.h" -#include "ControlPlane_netif_stub.h" - -namespace mbed { - -class myCellularContext : public CellularContext { -public: - std::list return_values; - nsapi_error_t return_value; - ControlPlane_netif_stub *my_cp_netif; - - myCellularContext() - { - return_value = 0; - my_cp_netif = NULL; - } - ~myCellularContext() - { - if (my_cp_netif) { - delete my_cp_netif; - my_cp_netif = NULL; - } - } - - nsapi_error_t configure_hup(PinName dcd_pin, bool active_high) - { - return NSAPI_ERROR_OK; - }; - - void enable_hup(bool enable) - { - }; - - nsapi_error_t connect() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t set_device_ready() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t set_sim_ready() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t register_to_network() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t attach_to_network() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op) - { - return NSAPI_ERROR_OK; - }; - - uint32_t get_timeout_for_operation(ContextOperation op) const - { - uint32_t timeout = 10 * 60 * 1000; // default timeout is 10 minutes as registration and attach may take time - return timeout; - }; - - bool is_connected() - { - return true; - }; - - NetworkStack *get_stack() - { - return NULL; - }; - - nsapi_error_t get_ip_address(SocketAddress *address) - { - return NSAPI_ERROR_UNSUPPORTED; - } - - const char *get_ip_address() - { - return NULL; - }; - - void attach(Callback status_cb) - { - }; - - nsapi_error_t set_blocking(bool blocking) - { - return NSAPI_ERROR_OK; - }; - - void set_plmn(const char *plmn) - { - }; - - void set_sim_pin(const char *sim_pin) - { - }; - - nsapi_error_t connect(const char *sim_pin, const char *apn, const char *uname, - const char *pwd) - { - return NSAPI_ERROR_OK; - }; - - void set_credentials(const char *apn, const char *uname, const char *pwd) - { - - }; - - bool get_context() - { - return true; - }; - - const char* get_nonip_context_type_str() { - return "Non-IP"; - } - - bool set_new_context(int cid) - { - return true; - }; - - nsapi_error_t do_activate_context() - { - return NSAPI_ERROR_OK; - }; - - void do_connect() - { - }; - - nsapi_error_t disconnect() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t get_apn_backoff_timer(int &backoff_timer) - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t get_rate_control( - CellularContext::RateControlExceptionReports &reports, - CellularContext::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate) - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t get_pdpcontext_params(pdpContextList_t ¶ms_list) - { - return NSAPI_ERROR_OK; - }; - - // Called by CellularDevice for network and cellular device changes - void cellular_callback(nsapi_event_t ev, intptr_t ptr) - { - }; - - ControlPlane_netif_stub *get_cp_netif() - { - if (!my_cp_netif) { - my_cp_netif = new ControlPlane_netif_stub(); - } - return my_cp_netif; - }; - - nsapi_error_t activate_non_ip_context() - { - return NSAPI_ERROR_OK; - }; - - nsapi_error_t setup_control_plane_opt() - { - return NSAPI_ERROR_OK; - }; - - void deactivate_ip_context() - { - }; - - void deactivate_non_ip_context() - { - }; - - void set_disconnect() - { - }; - - void set_cid(int cid) - { - }; - - void do_connect_with_retry() - { - }; - -}; - -} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h deleted file mode 100644 index e41aaa2..0000000 --- a/UNITTESTS/target_h/myCellularDevice.h +++ /dev/null @@ -1,193 +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. - */ -#ifndef MY_CELLULARDEVICE_H_ -#define MY_CELLULARDEVICE_H_ - -#include "AT_CellularDevice.h" -#include "AT_CellularNetwork.h" -#include "FileHandle_stub.h" -#include "ATHandler_stub.h" -#include "AT_CellularContext.h" -#include "gtest/gtest.h" -#include "drivers/BufferedSerial.h" - -using namespace events; - -namespace mbed { - -class CellularSMS; -class CellularInformation; -class CellularContext; -class FileHandle; - -class myCellularDevice : public AT_CellularDevice { -public: - myCellularDevice(FileHandle *fh) : AT_CellularDevice(fh), _context_list(0), _network(0) {} - virtual ~myCellularDevice() - { - delete _context_list; - delete _network; - } - - virtual nsapi_error_t set_pin(const char *sim_pin) - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t get_sim_state(SimState &state) - { - return NSAPI_ERROR_OK; - } - - - virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false) - { - if (_context_list) { - return _context_list; - } - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - _context_list = new AT_CellularContext(at, this); - return _context_list; - } - - virtual void delete_context(CellularContext *context) - { - delete _context_list; - } - - virtual CellularNetwork *open_network() - { - if (_network) { - return _network; - } - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - _network = new AT_CellularNetwork(at, *this); - return _network; - } - - virtual CellularSMS *open_sms() - { - return NULL; - } - - virtual CellularInformation *open_information() - { - return NULL; - } - - virtual void close_network() - { - delete _network; - } - - virtual void close_sms() {} - - virtual void close_information() {} - - virtual void set_timeout(int timeout) {} - - virtual void modem_debug_on(bool on) {} - - virtual nsapi_error_t init() - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t is_ready() - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t hard_power_on() - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t hard_power_off() - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t soft_power_on() - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t soft_power_off() - { - return NSAPI_ERROR_OK; - } - - virtual void set_ready_cb(Callback callback) - { - } - - nsapi_error_t set_power_save_mode(int periodic_time, int active_time) - { - return NSAPI_ERROR_OK; - } - - virtual CellularContext *get_context_list() const - { - return _context_list; - } - void cellular_callback(nsapi_event_t ev, intptr_t ptr) - { - CellularDevice::cellular_callback(ev, ptr); - } - virtual ATHandler *get_at_handler() - { - return NULL; - } - virtual nsapi_error_t release_at_handler(ATHandler *at_handler) - { - return NSAPI_ERROR_OK; - } - nsapi_error_t set_baud_rate(int baud_rate) - { - return NSAPI_ERROR_OK; - } - - void verify_timeout_array(const uint16_t timeout[], int array_len) - { - if (array_len > CELLULAR_RETRY_ARRAY_SIZE) { - FAIL(); - } - uint16_t get_timeouts[CELLULAR_RETRY_ARRAY_SIZE]; - int get_timeouts_len = 0; - - get_retry_timeout_array(get_timeouts, get_timeouts_len); - - EXPECT_EQ(array_len, get_timeouts_len); - - for (int i = 0; i < array_len; i++) { - EXPECT_EQ(timeout[i], get_timeouts[i]); - } - } - - - - AT_CellularNetwork *_network; - AT_CellularContext *_context_list; -}; - -} // namespace -#endif /* MY_CELLULARDEVICE_H_ */ diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/myCellularContext.h b/connectivity/cellular/tests/UNITTESTS/doubles/myCellularContext.h new file mode 100644 index 0000000..c7871c4 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/doubles/myCellularContext.h @@ -0,0 +1,225 @@ +/* + * 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 "CellularContext.h" +#include "ControlPlane_netif_stub.h" + +namespace mbed { + +class myCellularContext : public CellularContext { +public: + std::list return_values; + nsapi_error_t return_value; + ControlPlane_netif_stub *my_cp_netif; + + myCellularContext() + { + return_value = 0; + my_cp_netif = NULL; + } + ~myCellularContext() + { + if (my_cp_netif) { + delete my_cp_netif; + my_cp_netif = NULL; + } + } + + nsapi_error_t configure_hup(PinName dcd_pin, bool active_high) + { + return NSAPI_ERROR_OK; + }; + + void enable_hup(bool enable) + { + }; + + nsapi_error_t connect() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t set_device_ready() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t set_sim_ready() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t register_to_network() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t attach_to_network() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op) + { + return NSAPI_ERROR_OK; + }; + + uint32_t get_timeout_for_operation(ContextOperation op) const + { + uint32_t timeout = 10 * 60 * 1000; // default timeout is 10 minutes as registration and attach may take time + return timeout; + }; + + bool is_connected() + { + return true; + }; + + NetworkStack *get_stack() + { + return NULL; + }; + + nsapi_error_t get_ip_address(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } + + const char *get_ip_address() + { + return NULL; + }; + + void attach(Callback status_cb) + { + }; + + nsapi_error_t set_blocking(bool blocking) + { + return NSAPI_ERROR_OK; + }; + + void set_plmn(const char *plmn) + { + }; + + void set_sim_pin(const char *sim_pin) + { + }; + + nsapi_error_t connect(const char *sim_pin, const char *apn, const char *uname, + const char *pwd) + { + return NSAPI_ERROR_OK; + }; + + void set_credentials(const char *apn, const char *uname, const char *pwd) + { + + }; + + bool get_context() + { + return true; + }; + + const char* get_nonip_context_type_str() { + return "Non-IP"; + } + + bool set_new_context(int cid) + { + return true; + }; + + nsapi_error_t do_activate_context() + { + return NSAPI_ERROR_OK; + }; + + void do_connect() + { + }; + + nsapi_error_t disconnect() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_apn_backoff_timer(int &backoff_timer) + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_rate_control( + CellularContext::RateControlExceptionReports &reports, + CellularContext::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate) + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t get_pdpcontext_params(pdpContextList_t ¶ms_list) + { + return NSAPI_ERROR_OK; + }; + + // Called by CellularDevice for network and cellular device changes + void cellular_callback(nsapi_event_t ev, intptr_t ptr) + { + }; + + ControlPlane_netif_stub *get_cp_netif() + { + if (!my_cp_netif) { + my_cp_netif = new ControlPlane_netif_stub(); + } + return my_cp_netif; + }; + + nsapi_error_t activate_non_ip_context() + { + return NSAPI_ERROR_OK; + }; + + nsapi_error_t setup_control_plane_opt() + { + return NSAPI_ERROR_OK; + }; + + void deactivate_ip_context() + { + }; + + void deactivate_non_ip_context() + { + }; + + void set_disconnect() + { + }; + + void set_cid(int cid) + { + }; + + void do_connect_with_retry() + { + }; + +}; + +} diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/myCellularDevice.h b/connectivity/cellular/tests/UNITTESTS/doubles/myCellularDevice.h new file mode 100644 index 0000000..e41aaa2 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/doubles/myCellularDevice.h @@ -0,0 +1,193 @@ +/* + * 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. + */ +#ifndef MY_CELLULARDEVICE_H_ +#define MY_CELLULARDEVICE_H_ + +#include "AT_CellularDevice.h" +#include "AT_CellularNetwork.h" +#include "FileHandle_stub.h" +#include "ATHandler_stub.h" +#include "AT_CellularContext.h" +#include "gtest/gtest.h" +#include "drivers/BufferedSerial.h" + +using namespace events; + +namespace mbed { + +class CellularSMS; +class CellularInformation; +class CellularContext; +class FileHandle; + +class myCellularDevice : public AT_CellularDevice { +public: + myCellularDevice(FileHandle *fh) : AT_CellularDevice(fh), _context_list(0), _network(0) {} + virtual ~myCellularDevice() + { + delete _context_list; + delete _network; + } + + virtual nsapi_error_t set_pin(const char *sim_pin) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t get_sim_state(SimState &state) + { + return NSAPI_ERROR_OK; + } + + + virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false) + { + if (_context_list) { + return _context_list; + } + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + _context_list = new AT_CellularContext(at, this); + return _context_list; + } + + virtual void delete_context(CellularContext *context) + { + delete _context_list; + } + + virtual CellularNetwork *open_network() + { + if (_network) { + return _network; + } + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + _network = new AT_CellularNetwork(at, *this); + return _network; + } + + virtual CellularSMS *open_sms() + { + return NULL; + } + + virtual CellularInformation *open_information() + { + return NULL; + } + + virtual void close_network() + { + delete _network; + } + + virtual void close_sms() {} + + virtual void close_information() {} + + virtual void set_timeout(int timeout) {} + + virtual void modem_debug_on(bool on) {} + + virtual nsapi_error_t init() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t is_ready() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t hard_power_on() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t hard_power_off() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t soft_power_on() + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t soft_power_off() + { + return NSAPI_ERROR_OK; + } + + virtual void set_ready_cb(Callback callback) + { + } + + nsapi_error_t set_power_save_mode(int periodic_time, int active_time) + { + return NSAPI_ERROR_OK; + } + + virtual CellularContext *get_context_list() const + { + return _context_list; + } + void cellular_callback(nsapi_event_t ev, intptr_t ptr) + { + CellularDevice::cellular_callback(ev, ptr); + } + virtual ATHandler *get_at_handler() + { + return NULL; + } + virtual nsapi_error_t release_at_handler(ATHandler *at_handler) + { + return NSAPI_ERROR_OK; + } + nsapi_error_t set_baud_rate(int baud_rate) + { + return NSAPI_ERROR_OK; + } + + void verify_timeout_array(const uint16_t timeout[], int array_len) + { + if (array_len > CELLULAR_RETRY_ARRAY_SIZE) { + FAIL(); + } + uint16_t get_timeouts[CELLULAR_RETRY_ARRAY_SIZE]; + int get_timeouts_len = 0; + + get_retry_timeout_array(get_timeouts, get_timeouts_len); + + EXPECT_EQ(array_len, get_timeouts_len); + + for (int i = 0; i < array_len; i++) { + EXPECT_EQ(timeout[i], get_timeouts[i]); + } + } + + + + AT_CellularNetwork *_network; + AT_CellularContext *_context_list; +}; + +} // namespace +#endif /* MY_CELLULARDEVICE_H_ */