mirror of https://github.com/ARMmbed/mbed-os.git
Small improvements for test cases
parent
adc4ce4385
commit
a6b4938844
|
@ -265,3 +265,10 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
|
|||
AT_CellularDevice dev(que);
|
||||
EXPECT_TRUE(0 == dev.get_send_delay());
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
|
||||
}
|
||||
|
|
|
@ -56,15 +56,31 @@ TEST_F(TestAT_CellularSMS, Create)
|
|||
delete sms;
|
||||
}
|
||||
|
||||
void my_callback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
ATHandler_stub::call_immediately = true;
|
||||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
sms.set_sms_callback(&my_callback);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
ATHandler_stub::call_immediately = false;
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms)
|
||||
|
|
|
@ -33,6 +33,10 @@ void urc_callback()
|
|||
{
|
||||
}
|
||||
|
||||
void urc2_callback()
|
||||
{
|
||||
}
|
||||
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestATHandler : public testing::Test {
|
||||
|
@ -119,7 +123,27 @@ TEST_F(TestATHandler, test_ATHandler_set_urc_handler)
|
|||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
const char ch[] = "testtesttesttest";
|
||||
at.set_urc_handler(ch, &urc_callback);
|
||||
|
||||
mbed::Callback<void()> cb(&urc_callback);
|
||||
at.set_urc_handler(ch, cb);
|
||||
|
||||
//THIS IS NOT same callback in find_urc_handler???
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.set_urc_handler(ch, cb));
|
||||
}
|
||||
|
||||
TEST_F(TestATHandler, test_ATHandler_remove_urc_handler)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
const char ch[] = "testtesttesttest";
|
||||
|
||||
mbed::Callback<void()> cb(&urc_callback);
|
||||
at.set_urc_handler(ch, cb);
|
||||
|
||||
//This does nothing!!!
|
||||
at.remove_urc_handler(ch, cb);
|
||||
}
|
||||
|
||||
TEST_F(TestATHandler, test_ATHandler_get_last_error)
|
||||
|
@ -214,6 +238,12 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
|
|||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
at.set_at_timeout(10);
|
||||
|
||||
at.set_is_filehandle_usable(false);
|
||||
at.process_oob();
|
||||
at.set_is_filehandle_usable(true);
|
||||
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
fh1.short_value = POLLIN;
|
||||
at.set_urc_handler("s", &urc_callback);
|
||||
|
@ -228,6 +258,8 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
|
|||
char table[] = "ssssssssssssssssssssssssssssssss\0";
|
||||
filehandle_stub_table = table;
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
at.read_bytes(buf, 5);
|
||||
|
||||
filehandle_stub_short_value_counter = 2;
|
||||
|
@ -241,25 +273,26 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
|
|||
filehandle_stub_short_value_counter = 1;
|
||||
at.process_oob();
|
||||
|
||||
char table2[4];
|
||||
char table2[5];
|
||||
table2[0] = '\r';
|
||||
table2[1] = '\r';
|
||||
table2[2] = '\n';
|
||||
table2[3] = 0;
|
||||
table2[3] = '\n';
|
||||
table2[4] = 0;
|
||||
filehandle_stub_table = table2;
|
||||
|
||||
at.clear_error();
|
||||
timer_stub_value = 0;
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
at.read_bytes(buf, 1);
|
||||
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
at.process_oob();
|
||||
|
||||
|
||||
filehandle_stub_table = table;
|
||||
|
||||
|
||||
filehandle_stub_short_value_counter = 0;
|
||||
filehandle_stub_table_pos = 0;
|
||||
filehandle_stub_table = NULL;
|
||||
|
@ -412,62 +445,72 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
|
|||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
at.set_stop_tag("OK\r\n");
|
||||
at.skip_param();
|
||||
|
||||
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
|
||||
filehandle_stub_table = table;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
fh1.short_value = POLLIN;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
|
||||
|
||||
char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0";
|
||||
filehandle_stub_table = table1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
|
||||
char table2[] = "sssOK\r\n\0";
|
||||
filehandle_stub_table = table2;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
|
||||
char table3[] = "sssssssOK\nssss\0";
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
//Need to create a new instance because stop tag already found
|
||||
ATHandler at2(&fh1, que, 0, ",");
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param();
|
||||
|
||||
at2.skip_param(4, 3);
|
||||
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param(4, 3);
|
||||
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param(24, 17);
|
||||
}
|
||||
|
@ -834,6 +877,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start("ssssaaaassssaaaassss"); //too long prefix
|
||||
|
||||
char table3[] = "+CME ERROR: 108\0";
|
||||
|
@ -842,20 +886,22 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table4[] = "+CMS ERROR: 6\0";
|
||||
filehandle_stub_table = table4;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table5[] = "ERROR\r\n\0";
|
||||
|
@ -864,6 +910,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table6[] = "OK\r\n\0";
|
||||
|
@ -872,6 +919,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table7[] = "ssssss\0";
|
||||
|
@ -881,6 +929,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
|
|||
at.flush();
|
||||
at.clear_error();
|
||||
at.set_urc_handler("ss", NULL);
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
}
|
||||
|
||||
|
@ -905,6 +954,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
at.resp_stop();
|
||||
|
@ -915,6 +965,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start("ss", false);
|
||||
at.resp_stop();
|
||||
}
|
||||
|
@ -1020,3 +1071,4 @@ TEST_F(TestATHandler, test_ATHandler_get_3gpp_error)
|
|||
ATHandler at(&fh1, que, 0, ",");
|
||||
at.get_3gpp_error();
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,8 @@ TEST_F(Testutil, separate_ip_addresses)
|
|||
char subnet[64] = {0};
|
||||
|
||||
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94);
|
||||
separate_ip_addresses(NULL, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
|
||||
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
|
||||
|
@ -179,3 +181,21 @@ TEST_F(Testutil, separate_ip_addresses)
|
|||
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
|
||||
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
|
||||
}
|
||||
|
||||
TEST_F(Testutil, get_dynamic_ip_port)
|
||||
{
|
||||
uint16_t port = get_dynamic_ip_port();
|
||||
uint16_t port2 = get_dynamic_ip_port();
|
||||
|
||||
EXPECT_TRUE(port != port2);
|
||||
}
|
||||
|
||||
TEST_F(Testutil, int_to_hex_str)
|
||||
{
|
||||
char buf[2];
|
||||
int_to_hex_str(100, (char*)buf);
|
||||
|
||||
EXPECT_TRUE(buf[0] == '6');
|
||||
EXPECT_TRUE(buf[1] == '4');
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ uint8_t ATHandler_stub::uint8_value = 0;
|
|||
FileHandle_stub *ATHandler_stub::fh_value = NULL;
|
||||
device_err_t ATHandler_stub::device_err_value;
|
||||
Callback<void()> ATHandler_stub::callback = NULL;
|
||||
bool ATHandler_stub::call_immediately = false;
|
||||
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];
|
||||
|
@ -98,6 +99,9 @@ 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;
|
||||
if (ATHandler_stub::call_immediately) {
|
||||
cb();
|
||||
}
|
||||
return ATHandler_stub::nsapi_error_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ 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 bool call_immediately;
|
||||
extern char *read_string_table[kRead_string_table_size];
|
||||
extern int read_string_index;
|
||||
extern int int_valid_count_table[kRead_int_table_size];
|
||||
|
|
|
@ -27,11 +27,6 @@ rtos::Mutex::~Mutex()
|
|||
return;
|
||||
}
|
||||
|
||||
osStatus rtos::Mutex::lock(void)
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
|
||||
osStatus rtos::Mutex::lock(uint32_t millisec)
|
||||
{
|
||||
return osOK;
|
||||
|
|
|
@ -136,6 +136,9 @@ class UnitTestTool(object):
|
|||
for path in excludes:
|
||||
args.extend(["-e", path.replace("\\", "/")])
|
||||
|
||||
#Exclude header files from report
|
||||
args.extend(["-e", ".*\.h"])
|
||||
|
||||
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
|
||||
args.append("-v")
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ void ATHandler::set_is_filehandle_usable(bool usable)
|
|||
|
||||
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void()> callback)
|
||||
{
|
||||
if (find_urc_handler(prefix, callback)) {
|
||||
if (find_urc_handler(prefix, &callback)) {
|
||||
tr_warn("URC already added with prefix: %s", prefix);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
@ -205,11 +205,11 @@ void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> ca
|
|||
}
|
||||
}
|
||||
|
||||
bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback<void()> callback)
|
||||
bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback<void()> *callback)
|
||||
{
|
||||
struct oob_t *oob = _oobs;
|
||||
while (oob) {
|
||||
if (strcmp(prefix, oob->prefix) == 0 && oob->cb == callback) {
|
||||
if (strcmp(prefix, oob->prefix) == 0 && oob->cb == *callback) {
|
||||
return true;
|
||||
}
|
||||
oob = oob->next;
|
||||
|
|
|
@ -510,7 +510,7 @@ private:
|
|||
const char *mem_str(const char *dest, size_t dest_len, const char *src, size_t src_len);
|
||||
|
||||
// check is urc is already added
|
||||
bool find_urc_handler(const char *prefix, mbed::Callback<void()> callback);
|
||||
bool find_urc_handler(const char *prefix, mbed::Callback<void()> *callback);
|
||||
|
||||
// print contents of a buffer to trace log
|
||||
void debug_print(char *p, int len);
|
||||
|
|
|
@ -256,8 +256,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
|
|||
|
||||
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
|
||||
{
|
||||
if (_at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) ||
|
||||
_at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) {
|
||||
if (NSAPI_ERROR_OK != _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) ||
|
||||
NSAPI_ERROR_OK != _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
|
|
|
@ -330,9 +330,7 @@ uint16_t get_dynamic_ip_port()
|
|||
}
|
||||
|
||||
port_counter += randLIB_get_random_in_range(1, RANDOM_PORT_NUMBER_MAX_STEP);
|
||||
if (port_counter >= RANDOM_PORT_NUMBER_COUNT) {
|
||||
port_counter -= RANDOM_PORT_NUMBER_COUNT;
|
||||
}
|
||||
port_counter %= RANDOM_PORT_NUMBER_COUNT;
|
||||
|
||||
return (RANDOM_PORT_NUMBER_START + port_counter);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue