mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Added network unit tests.
parent
7efa041fcb
commit
861867e3cc
|
@ -4,7 +4,9 @@ COMPONENT_NAME = AT_CellularNetwork_unit
|
|||
|
||||
#This must be changed manually
|
||||
SRC_FILES = \
|
||||
../../../framework/AT/AT_CellularNetwork.cpp
|
||||
../../../framework/AT/AT_CellularNetwork.cpp \
|
||||
../../../framework/AT/AT_CellularStack.cpp \
|
||||
../../../framework/common/CellularUtil.cpp \
|
||||
|
||||
TEST_SRC_FILES = \
|
||||
main.cpp \
|
||||
|
@ -15,9 +17,10 @@ TEST_SRC_FILES = \
|
|||
../../stubs/EventQueue_stub.cpp \
|
||||
../../stubs/FileHandle_stub.cpp \
|
||||
../../stubs/NetworkInterface_stub.cpp \
|
||||
../../stubs/CellularUtil_stub.cpp \
|
||||
../../stubs/NetworkStack_stub.cpp \
|
||||
../../stubs/us_ticker_stub.cpp \
|
||||
../../stubs/mbed_assert_stub.cpp \
|
||||
../../stubs/SocketAddress_stub.cpp \
|
||||
|
||||
include ../../MakefileWorker.mk
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularnetwork.h"
|
||||
#include "ATHandler_stub.h"
|
||||
|
||||
TEST_GROUP(AT_CellularNetwork)
|
||||
{
|
||||
|
@ -24,6 +25,9 @@ TEST_GROUP(AT_CellularNetwork)
|
|||
void setup()
|
||||
{
|
||||
unit = new Test_AT_CellularNetwork();
|
||||
ATHandler_stub::int_count = kRead_int_table_size;
|
||||
ATHandler_stub::read_string_index = kRead_string_table_size;
|
||||
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
|
||||
}
|
||||
|
||||
void teardown()
|
||||
|
@ -42,11 +46,21 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_constructor)
|
|||
unit->test_AT_CellularNetwork_constructor();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_init)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_init();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_credentials)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_set_credentials();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_activate_context)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_activate_context();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_connect)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_connect();
|
||||
|
@ -72,6 +86,16 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_registration_status)
|
|||
unit->test_AT_CellularNetwork_get_registration_status();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_network_registering_mode)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_get_network_registering_mode();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_registration_urc)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_set_registration_urc();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_attach)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_set_attach();
|
||||
|
@ -107,6 +131,11 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_access_technology)
|
|||
unit->test_AT_CellularNetwork_set_access_technology();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_access_technology)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_get_access_technology();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_scan_plmn)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_scan_plmn();
|
||||
|
@ -166,3 +195,19 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_names)
|
|||
{
|
||||
unit->test_AT_CellularNetwork_get_operator_names();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_AT_CellularNetwork_attach)
|
||||
{
|
||||
unit->test_AT_CellularNetwork_attach();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_get_connection_status)
|
||||
{
|
||||
unit->test_get_connection_status();
|
||||
}
|
||||
|
||||
TEST(AT_CellularNetwork, test_set_blocking)
|
||||
{
|
||||
unit->test_set_blocking();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,8 +26,12 @@ public:
|
|||
|
||||
void test_AT_CellularNetwork_constructor();
|
||||
|
||||
void test_AT_CellularNetwork_init();
|
||||
|
||||
void test_AT_CellularNetwork_set_credentials();
|
||||
|
||||
void test_AT_CellularNetwork_activate_context();
|
||||
|
||||
void test_AT_CellularNetwork_connect();
|
||||
|
||||
void test_AT_CellularNetwork_disconnect();
|
||||
|
@ -38,6 +42,10 @@ public:
|
|||
|
||||
void test_AT_CellularNetwork_get_registration_status();
|
||||
|
||||
void test_AT_CellularNetwork_get_network_registering_mode();
|
||||
|
||||
void test_AT_CellularNetwork_set_registration_urc();
|
||||
|
||||
void test_AT_CellularNetwork_set_attach();
|
||||
|
||||
void test_AT_CellularNetwork_get_attach();
|
||||
|
@ -52,6 +60,8 @@ public:
|
|||
|
||||
void test_AT_CellularNetwork_set_access_technology();
|
||||
|
||||
void test_AT_CellularNetwork_get_access_technology();
|
||||
|
||||
void test_AT_CellularNetwork_scan_plmn();
|
||||
|
||||
void test_AT_CellularNetwork_set_ciot_optimization_config();
|
||||
|
@ -75,6 +85,12 @@ public:
|
|||
void test_AT_CellularNetwork_get_operator_params();
|
||||
|
||||
void test_AT_CellularNetwork_get_operator_names();
|
||||
|
||||
void test_AT_CellularNetwork_attach();
|
||||
|
||||
void test_get_connection_status();
|
||||
|
||||
void test_set_blocking();
|
||||
};
|
||||
|
||||
#endif // TEST_AT_CELLULARNETWORK_H
|
||||
|
|
|
@ -45,6 +45,13 @@ FileHandle_stub *ATHandler_stub::fh_value = NULL;
|
|||
device_err_t ATHandler_stub::device_err_value;
|
||||
Callback<void()> ATHandler_stub::callback = NULL;
|
||||
uint8_t ATHandler_stub::resp_info_true_counter = false;
|
||||
uint8_t ATHandler_stub::info_elem_true_counter = false;
|
||||
int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
|
||||
int ATHandler_stub::int_count = kRead_int_table_size;
|
||||
|
||||
int ATHandler_stub::read_string_index = kRead_string_table_size;
|
||||
char* ATHandler_stub::read_string_table[kRead_string_table_size];
|
||||
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
|
||||
|
||||
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) :
|
||||
_nextATHandler(0),
|
||||
|
@ -91,7 +98,7 @@ void ATHandler::set_file_handle(FileHandle *fh)
|
|||
nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
|
||||
{
|
||||
ATHandler_stub::callback = cb;
|
||||
return NSAPI_ERROR_OK;
|
||||
return ATHandler_stub::nsapi_error_value;
|
||||
}
|
||||
|
||||
void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
|
||||
|
@ -136,6 +143,7 @@ void ATHandler::process_oob()
|
|||
|
||||
void ATHandler::clear_error()
|
||||
{
|
||||
ATHandler_stub::nsapi_error_ok_counter++;
|
||||
}
|
||||
|
||||
void ATHandler::skip_param(uint32_t count) {
|
||||
|
@ -153,15 +161,44 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
|
|||
|
||||
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
||||
{
|
||||
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
|
||||
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value);
|
||||
|
||||
if (ATHandler_stub::read_string_index == kRead_string_table_size) {
|
||||
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
|
||||
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value);
|
||||
}
|
||||
return ATHandler_stub::ssize_value;
|
||||
}
|
||||
return ATHandler_stub::ssize_value;
|
||||
|
||||
ATHandler_stub::read_string_index--;
|
||||
if (ATHandler_stub::read_string_index >= 0) {
|
||||
char* tmp = ATHandler_stub::read_string_table[ATHandler_stub::read_string_index];
|
||||
ssize_t len = strlen(tmp);
|
||||
memcpy(buf, tmp, len+1);
|
||||
return len;
|
||||
}
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ATHandler::read_int()
|
||||
int32_t ATHandler::read_int()
|
||||
{
|
||||
return ATHandler_stub::int_value;
|
||||
if (ATHandler_stub::nsapi_error_value != NSAPI_ERROR_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ATHandler_stub::int_count == kRead_int_table_size) {
|
||||
return ATHandler_stub::int_value;
|
||||
}
|
||||
|
||||
//printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count);
|
||||
ATHandler_stub::int_count--;
|
||||
if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) {
|
||||
return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count];
|
||||
}
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ATHandler::set_delimiter(char delimiter)
|
||||
|
@ -196,6 +233,10 @@ bool ATHandler::info_resp()
|
|||
|
||||
bool ATHandler::info_elem(char start_tag)
|
||||
{
|
||||
if (ATHandler_stub::info_elem_true_counter) {
|
||||
ATHandler_stub::info_elem_true_counter--;
|
||||
return true;
|
||||
}
|
||||
return ATHandler_stub::bool_value;
|
||||
}
|
||||
|
||||
|
@ -206,13 +247,18 @@ bool ATHandler::consume_to_stop_tag()
|
|||
|
||||
void ATHandler::resp_stop()
|
||||
{
|
||||
if (ATHandler_stub::resp_stop_success_count > 0) {
|
||||
ATHandler_stub::resp_stop_success_count--;
|
||||
return;
|
||||
}
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
void ATHandler::cmd_start(const char* cmd)
|
||||
{
|
||||
}
|
||||
|
||||
void ATHandler::write_int(int param)
|
||||
void ATHandler::write_int(int32_t param)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "FileHandle_stub.h"
|
||||
#include "Callback.h"
|
||||
|
||||
static const int kRead_string_table_size = 100;
|
||||
static const int kRead_int_table_size = 100;
|
||||
static const int kResp_stop_count_default = 100;
|
||||
|
||||
namespace ATHandler_stub {
|
||||
extern nsapi_error_t nsapi_error_value;
|
||||
|
@ -33,13 +36,19 @@ namespace ATHandler_stub {
|
|||
extern bool default_timeout;
|
||||
extern bool debug_on;
|
||||
extern ssize_t ssize_value;
|
||||
extern char* read_string_value;
|
||||
extern char *read_string_value;
|
||||
extern size_t size_value;
|
||||
extern size_t return_given_size;
|
||||
extern bool bool_value;
|
||||
extern uint8_t resp_info_true_counter;
|
||||
extern uint8_t info_elem_true_counter;
|
||||
extern uint8_t uint8_value;
|
||||
extern mbed::FileHandle_stub *fh_value;
|
||||
extern mbed::device_err_t device_err_value;
|
||||
extern mbed::Callback<void()> callback;
|
||||
extern char *read_string_table[kRead_string_table_size];
|
||||
extern int read_string_index;
|
||||
extern int int_valid_count_table[kRead_int_table_size];
|
||||
extern int int_count;
|
||||
extern int resp_stop_success_count;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ void AT_CellularNetwork::free_credentials()
|
|||
void AT_CellularNetwork::urc_no_carrier()
|
||||
{
|
||||
tr_error("Data call failed: no carrier");
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED, NSAPI_ERROR_OK);
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
}
|
||||
|
||||
void AT_CellularNetwork::read_reg_params_and_compare(RegistrationType type)
|
||||
|
@ -248,7 +248,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
|
|||
nsapi_error_t err = NSAPI_ERROR_OK;
|
||||
|
||||
// try to find or create context with suitable stack
|
||||
if(get_context()) {
|
||||
if (get_context()) {
|
||||
// try to authenticate user before activating or modifying context
|
||||
err = do_user_authentication();
|
||||
} else {
|
||||
|
@ -258,7 +258,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
|
|||
if (err != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
tr_error("Failed to activate network context! (%d)", err);
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED, NSAPI_ERROR_OK);
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -308,14 +308,14 @@ nsapi_error_t AT_CellularNetwork::activate_context()
|
|||
|
||||
nsapi_error_t AT_CellularNetwork::connect()
|
||||
{
|
||||
call_network_cb(NSAPI_STATUS_CONNECTING, NSAPI_ERROR_OK);
|
||||
call_network_cb(NSAPI_STATUS_CONNECTING);
|
||||
|
||||
nsapi_error_t err = NSAPI_ERROR_OK;
|
||||
if (!_is_context_active) {
|
||||
err = activate_context();
|
||||
}
|
||||
if (err) {
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED, err);
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -325,14 +325,11 @@ nsapi_error_t AT_CellularNetwork::connect()
|
|||
_at.unlock();
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
tr_error("Failed to open data channel!");
|
||||
_connect_status = NSAPI_STATUS_DISCONNECTED;
|
||||
if (_connection_status_cb) {
|
||||
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
|
||||
}
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
call_network_cb(NSAPI_STATUS_GLOBAL_UP, NSAPI_ERROR_OK);
|
||||
call_network_cb(NSAPI_STATUS_GLOBAL_UP);
|
||||
#endif
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
|
@ -389,20 +386,18 @@ nsapi_error_t AT_CellularNetwork::disconnect()
|
|||
_at.resp_stop();
|
||||
_at.restore_at_timeout();
|
||||
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED, _at.get_last_error());
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
|
||||
return _at.unlock_return_error();
|
||||
#endif
|
||||
}
|
||||
|
||||
void AT_CellularNetwork::call_network_cb(nsapi_connection_status_t status, nsapi_error_t err)
|
||||
void AT_CellularNetwork::call_network_cb(nsapi_connection_status_t status)
|
||||
{
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
if (_connect_status != status) {
|
||||
_connect_status = status;
|
||||
if (_connection_status_cb) {
|
||||
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, _connect_status);
|
||||
}
|
||||
if (_connect_status != status) {
|
||||
_connect_status = status;
|
||||
if (_connection_status_cb) {
|
||||
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, _connect_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -572,6 +567,7 @@ bool AT_CellularNetwork::get_context()
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
// requested dual stack or stack is not specified
|
||||
// If dual PDP need to check for IPV4 or IPV6 modem support. Prefer IPv6.
|
||||
if (pdp_stack == IPV4V6_STACK) {
|
||||
if (modem_supports_ipv6) {
|
||||
|
@ -826,7 +822,7 @@ nsapi_error_t AT_CellularNetwork::detach()
|
|||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED, _at.get_last_error());
|
||||
call_network_cb(NSAPI_STATUS_DISCONNECTED);
|
||||
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
|
|
@ -162,7 +162,8 @@ private:
|
|||
|
||||
void read_reg_params_and_compare(RegistrationType type);
|
||||
void read_reg_params(RegistrationType type, RegistrationStatus ®_status, int &lac, int &cell_id, int &act);
|
||||
void call_network_cb(nsapi_connection_status_t status, nsapi_error_t err);
|
||||
// calls network callback only if status was changed, updates local connection status
|
||||
void call_network_cb(nsapi_connection_status_t status);
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
void ppp_status_cb(nsapi_event_t, intptr_t);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue