Skip to content

Commit a6b4938

Browse files
author
Antti Kauppila
committed
Small improvements for test cases
1 parent adc4ce4 commit a6b4938

File tree

12 files changed

+123
-27
lines changed

12 files changed

+123
-27
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,10 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
265265
AT_CellularDevice dev(que);
266266
EXPECT_TRUE(0 == dev.get_send_delay());
267267
}
268+
269+
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
270+
{
271+
EventQueue que;
272+
AT_CellularDevice dev(que);
273+
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
274+
}

UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,31 @@ TEST_F(TestAT_CellularSMS, Create)
5656
delete sms;
5757
}
5858

59+
void my_callback()
60+
{
61+
62+
}
63+
5964
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize)
6065
{
6166
EventQueue que;
6267
FileHandle_stub fh1;
6368
ATHandler at(&fh1, que, 0, ",");
6469

70+
ATHandler_stub::call_immediately = true;
71+
6572
AT_CellularSMS sms(at);
6673
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
6774
EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
75+
76+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
77+
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
78+
79+
sms.set_sms_callback(&my_callback);
80+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
81+
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
82+
83+
ATHandler_stub::call_immediately = false;
6884
}
6985

7086
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms)

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ void urc_callback()
3333
{
3434
}
3535

36+
void urc2_callback()
37+
{
38+
}
39+
3640
// AStyle ignored as the definition is not clear due to preprocessor usage
3741
// *INDENT-OFF*
3842
class TestATHandler : public testing::Test {
@@ -119,7 +123,27 @@ TEST_F(TestATHandler, test_ATHandler_set_urc_handler)
119123

120124
ATHandler at(&fh1, que, 0, ",");
121125
const char ch[] = "testtesttesttest";
122-
at.set_urc_handler(ch, &urc_callback);
126+
127+
mbed::Callback<void()> cb(&urc_callback);
128+
at.set_urc_handler(ch, cb);
129+
130+
//THIS IS NOT same callback in find_urc_handler???
131+
EXPECT_TRUE(NSAPI_ERROR_OK == at.set_urc_handler(ch, cb));
132+
}
133+
134+
TEST_F(TestATHandler, test_ATHandler_remove_urc_handler)
135+
{
136+
EventQueue que;
137+
FileHandle_stub fh1;
138+
139+
ATHandler at(&fh1, que, 0, ",");
140+
const char ch[] = "testtesttesttest";
141+
142+
mbed::Callback<void()> cb(&urc_callback);
143+
at.set_urc_handler(ch, cb);
144+
145+
//This does nothing!!!
146+
at.remove_urc_handler(ch, cb);
123147
}
124148

125149
TEST_F(TestATHandler, test_ATHandler_get_last_error)
@@ -214,6 +238,12 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
214238
FileHandle_stub fh1;
215239

216240
ATHandler at(&fh1, que, 0, ",");
241+
at.set_at_timeout(10);
242+
243+
at.set_is_filehandle_usable(false);
244+
at.process_oob();
245+
at.set_is_filehandle_usable(true);
246+
217247
filehandle_stub_short_value_counter = 1;
218248
fh1.short_value = POLLIN;
219249
at.set_urc_handler("s", &urc_callback);
@@ -228,6 +258,8 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
228258
char table[] = "ssssssssssssssssssssssssssssssss\0";
229259
filehandle_stub_table = table;
230260
filehandle_stub_table_pos = 0;
261+
mbed_poll_stub::revents_value = POLLIN;
262+
mbed_poll_stub::int_value = 1;
231263
at.read_bytes(buf, 5);
232264

233265
filehandle_stub_short_value_counter = 2;
@@ -241,25 +273,26 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
241273
filehandle_stub_short_value_counter = 1;
242274
at.process_oob();
243275

244-
char table2[4];
276+
char table2[5];
245277
table2[0] = '\r';
246278
table2[1] = '\r';
247279
table2[2] = '\n';
248-
table2[3] = 0;
280+
table2[3] = '\n';
281+
table2[4] = 0;
249282
filehandle_stub_table = table2;
250283

251284
at.clear_error();
252285
timer_stub_value = 0;
253286
filehandle_stub_table_pos = 0;
287+
mbed_poll_stub::revents_value = POLLIN;
288+
mbed_poll_stub::int_value = 1;
254289
at.read_bytes(buf, 1);
255290

256291
filehandle_stub_short_value_counter = 1;
257292
at.process_oob();
258293

259-
260294
filehandle_stub_table = table;
261295

262-
263296
filehandle_stub_short_value_counter = 0;
264297
filehandle_stub_table_pos = 0;
265298
filehandle_stub_table = NULL;
@@ -412,62 +445,72 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
412445
FileHandle_stub fh1;
413446

414447
ATHandler at(&fh1, que, 0, ",");
448+
at.set_stop_tag("OK\r\n");
415449
at.skip_param();
416450

417451
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
418452
filehandle_stub_table = table;
419-
filehandle_stub_table_pos = 0;
420453

421454
at.flush();
422455
at.clear_error();
456+
filehandle_stub_table_pos = 0;
457+
mbed_poll_stub::revents_value = POLLIN;
458+
mbed_poll_stub::int_value = 1;
459+
filehandle_stub_short_value_counter = 1;
460+
fh1.short_value = POLLIN;
423461
at.resp_start();
424462
at.skip_param();
425463
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
426464

427465
char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0";
428466
filehandle_stub_table = table1;
429-
filehandle_stub_table_pos = 0;
430467

431468
at.flush();
432469
at.clear_error();
470+
filehandle_stub_short_value_counter = 1;
471+
filehandle_stub_table_pos = 0;
433472
at.resp_start();
434473
at.skip_param();
435474

436475
char table2[] = "sssOK\r\n\0";
437476
filehandle_stub_table = table2;
438-
filehandle_stub_table_pos = 0;
439477

440478
at.flush();
441479
at.clear_error();
480+
filehandle_stub_short_value_counter = 1;
481+
filehandle_stub_table_pos = 0;
442482
at.resp_start();
443483
at.skip_param();
444484

445485
char table3[] = "sssssssOK\nssss\0";
446486
filehandle_stub_table = table3;
447-
filehandle_stub_table_pos = 0;
448487

449488
//Need to create a new instance because stop tag already found
450489
ATHandler at2(&fh1, que, 0, ",");
451490
at2.flush();
452491
at2.clear_error();
492+
filehandle_stub_short_value_counter = 1;
493+
filehandle_stub_table_pos = 0;
453494
at2.resp_start();
454495
at2.skip_param();
455496

456497
at2.skip_param(4, 3);
457498

458499
filehandle_stub_table = table3;
459-
filehandle_stub_table_pos = 0;
460500

461501
at2.flush();
462502
at2.clear_error();
503+
filehandle_stub_short_value_counter = 1;
504+
filehandle_stub_table_pos = 0;
463505
at2.resp_start();
464506
at2.skip_param(4, 3);
465507

466508
filehandle_stub_table = table3;
467-
filehandle_stub_table_pos = 0;
468509

469510
at2.flush();
470511
at2.clear_error();
512+
filehandle_stub_short_value_counter = 1;
513+
filehandle_stub_table_pos = 0;
471514
at2.resp_start();
472515
at2.skip_param(24, 17);
473516
}
@@ -834,6 +877,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
834877

835878
at.flush();
836879
at.clear_error();
880+
filehandle_stub_table_pos = 0;
837881
at.resp_start("ssssaaaassssaaaassss"); //too long prefix
838882

839883
char table3[] = "+CME ERROR: 108\0";
@@ -842,20 +886,22 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
842886

843887
at.flush();
844888
at.clear_error();
889+
filehandle_stub_table_pos = 0;
845890
at.resp_start();
846891

847-
filehandle_stub_table_pos = 0;
848892

849893
at.flush();
850894
at.clear_error();
895+
filehandle_stub_table_pos = 0;
851896
at.resp_start();
852897

853898
char table4[] = "+CMS ERROR: 6\0";
854899
filehandle_stub_table = table4;
855-
filehandle_stub_table_pos = 0;
856900

901+
filehandle_stub_table_pos = 0;
857902
at.flush();
858903
at.clear_error();
904+
filehandle_stub_table_pos = 0;
859905
at.resp_start();
860906

861907
char table5[] = "ERROR\r\n\0";
@@ -864,6 +910,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
864910

865911
at.flush();
866912
at.clear_error();
913+
filehandle_stub_table_pos = 0;
867914
at.resp_start();
868915

869916
char table6[] = "OK\r\n\0";
@@ -872,6 +919,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
872919

873920
at.flush();
874921
at.clear_error();
922+
filehandle_stub_table_pos = 0;
875923
at.resp_start();
876924

877925
char table7[] = "ssssss\0";
@@ -881,6 +929,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
881929
at.flush();
882930
at.clear_error();
883931
at.set_urc_handler("ss", NULL);
932+
filehandle_stub_table_pos = 0;
884933
at.resp_start();
885934
}
886935

@@ -905,6 +954,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
905954

906955
at.flush();
907956
at.clear_error();
957+
filehandle_stub_table_pos = 0;
908958
at.resp_start();
909959

910960
at.resp_stop();
@@ -915,6 +965,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop)
915965

916966
at.flush();
917967
at.clear_error();
968+
filehandle_stub_table_pos = 0;
918969
at.resp_start("ss", false);
919970
at.resp_stop();
920971
}
@@ -1020,3 +1071,4 @@ TEST_F(TestATHandler, test_ATHandler_get_3gpp_error)
10201071
ATHandler at(&fh1, que, 0, ",");
10211072
at.get_3gpp_error();
10221073
}
1074+

UNITTESTS/features/cellular/framework/common/util/utiltest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ TEST_F(Testutil, separate_ip_addresses)
127127
char subnet[64] = {0};
128128

129129
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);
130+
separate_ip_addresses(NULL, ip, sizeof(ip), subnet, sizeof(subnet));
131+
130132
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
131133
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
132134
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
@@ -179,3 +181,21 @@ TEST_F(Testutil, separate_ip_addresses)
179181
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
180182
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
181183
}
184+
185+
TEST_F(Testutil, get_dynamic_ip_port)
186+
{
187+
uint16_t port = get_dynamic_ip_port();
188+
uint16_t port2 = get_dynamic_ip_port();
189+
190+
EXPECT_TRUE(port != port2);
191+
}
192+
193+
TEST_F(Testutil, int_to_hex_str)
194+
{
195+
char buf[2];
196+
int_to_hex_str(100, (char*)buf);
197+
198+
EXPECT_TRUE(buf[0] == '6');
199+
EXPECT_TRUE(buf[1] == '4');
200+
}
201+

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ uint8_t ATHandler_stub::uint8_value = 0;
4444
FileHandle_stub *ATHandler_stub::fh_value = NULL;
4545
device_err_t ATHandler_stub::device_err_value;
4646
Callback<void()> ATHandler_stub::callback = NULL;
47+
bool ATHandler_stub::call_immediately = false;
4748
uint8_t ATHandler_stub::resp_info_true_counter = false;
4849
uint8_t ATHandler_stub::info_elem_true_counter = false;
4950
int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
@@ -98,6 +99,9 @@ void ATHandler::set_file_handle(FileHandle *fh)
9899
nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
99100
{
100101
ATHandler_stub::callback = cb;
102+
if (ATHandler_stub::call_immediately) {
103+
cb();
104+
}
101105
return ATHandler_stub::nsapi_error_value;
102106
}
103107

UNITTESTS/stubs/ATHandler_stub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern uint8_t uint8_value;
5151
extern mbed::FileHandle_stub *fh_value;
5252
extern mbed::device_err_t device_err_value;
5353
extern mbed::Callback<void()> callback;
54+
extern bool call_immediately;
5455
extern char *read_string_table[kRead_string_table_size];
5556
extern int read_string_index;
5657
extern int int_valid_count_table[kRead_int_table_size];

UNITTESTS/stubs/Mutex_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ rtos::Mutex::~Mutex()
2727
return;
2828
}
2929

30-
osStatus rtos::Mutex::lock(void)
31-
{
32-
return osOK;
33-
}
34-
3530
osStatus rtos::Mutex::lock(uint32_t millisec)
3631
{
3732
return osOK;

UNITTESTS/unit_test/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def _get_coverage_script(self, coverage_type, excludes):
136136
for path in excludes:
137137
args.extend(["-e", path.replace("\\", "/")])
138138

139+
#Exclude header files from report
140+
args.extend(["-e", ".*\.h"])
141+
139142
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
140143
args.append("-v")
141144

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void ATHandler::set_is_filehandle_usable(bool usable)
159159

160160
nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void()> callback)
161161
{
162-
if (find_urc_handler(prefix, callback)) {
162+
if (find_urc_handler(prefix, &callback)) {
163163
tr_warn("URC already added with prefix: %s", prefix);
164164
return NSAPI_ERROR_OK;
165165
}
@@ -205,11 +205,11 @@ void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> ca
205205
}
206206
}
207207

208-
bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback<void()> callback)
208+
bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback<void()> *callback)
209209
{
210210
struct oob_t *oob = _oobs;
211211
while (oob) {
212-
if (strcmp(prefix, oob->prefix) == 0 && oob->cb == callback) {
212+
if (strcmp(prefix, oob->prefix) == 0 && oob->cb == *callback) {
213213
return true;
214214
}
215215
oob = oob->next;

0 commit comments

Comments
 (0)