Skip to content

Commit 6000724

Browse files
authored
Merge pull request #10703 from AnttiKauppila/optimisation
Cellular: Removed boilerplate code
2 parents 14b77c9 + 1ed338e commit 6000724

28 files changed

+856
-804
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ set(unittest-includes ${unittest-includes}
1616
# Source files
1717
set(unittest-sources
1818
../features/cellular/framework/AT/AT_CellularBase.cpp
19-
../features/cellular/framework/AT/ATHandler_factory.cpp
2019
)
2120

2221
# Test files

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "CellularDevice_stub.h"
2929
#include "equeue_stub.h"
3030
#include "AT_CellularBase_stub.h"
31+
#include "CellularUtil_stub.h"
32+
#include "PinNames.h"
3133

3234
using namespace mbed;
3335
using namespace events;
@@ -62,6 +64,9 @@ class TestAT_CellularContext : public testing::Test {
6264
ATHandler_stub::read_string_table[kRead_string_table_size];
6365
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
6466
CellularDevice_stub::connect_counter = 2;
67+
68+
CellularUtil_stub::char_table[0] = (char *)"\0";
69+
CellularUtil_stub::table_idx = 0;
6570
}
6671

6772
void TearDown()
@@ -131,6 +136,16 @@ class my_AT_CTX : public AT_CellularContext {
131136
AT_CellularContext::cellular_callback(ev, ptr);
132137
}
133138

139+
void activ_non_ip_context()
140+
{
141+
activate_non_ip_context();
142+
}
143+
144+
void deactiv_non_ip_context()
145+
{
146+
deactivate_non_ip_context();
147+
}
148+
134149
my_stack _st;
135150
};
136151

@@ -150,6 +165,19 @@ class my_AT_CTXIPV6 : public AT_CellularContext {
150165
my_stack _st;
151166
};
152167

168+
class def_AT_CTX : public AT_CellularContext {
169+
public:
170+
def_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
171+
AT_CellularContext(at, device, apn) {}
172+
virtual ~def_AT_CTX() {}
173+
174+
uint32_t do_op()
175+
{
176+
return AT_CellularContext::get_timeout_for_operation(mbed::CellularContext::ContextOperation(_op));
177+
}
178+
int _op;
179+
};
180+
153181
static int network_cb_count;
154182
static void network_cb(nsapi_event_t ev, intptr_t intptr)
155183
{
@@ -169,6 +197,9 @@ TEST_F(TestAT_CellularContext, Create)
169197

170198
ctx = new AT_CellularContext(at, &dev);
171199
EXPECT_TRUE(ctx != NULL);
200+
201+
ctx->get_device();
202+
EXPECT_EQ(NSAPI_STATUS_DISCONNECTED, ctx->get_connection_status());
172203
delete ctx;
173204
}
174205

@@ -325,6 +356,20 @@ TEST_F(TestAT_CellularContext, get_pdpcontext_params)
325356
ATHandler_stub::read_string_table[1] = (char *)"25.66.77.88";
326357
ATHandler_stub::read_string_table[0] = (char *)"004.003.002.001";
327358

359+
CellularUtil_stub::table_idx = 12;
360+
CellularUtil_stub::char_table[11] = (char *)"102:304:506:708:90A:B70:D0E:F10\0";
361+
CellularUtil_stub::char_table[10] = (char *)"102:32C:3706:708:90A:B0C:D0E:F10\0";
362+
CellularUtil_stub::char_table[9] = (char *)"1721:2C01:203:377B:E122:B01:000:7BEA\0";
363+
CellularUtil_stub::char_table[8] = (char *)"1.2.3.4\0";
364+
CellularUtil_stub::char_table[7] = (char *)"1.2.3.4\0";
365+
CellularUtil_stub::char_table[6] = (char *)"1.2.3.4\0";
366+
CellularUtil_stub::char_table[5] = (char *)"0.255.0.255\0";
367+
CellularUtil_stub::char_table[4] = (char *)"1.2.3.4\0";
368+
CellularUtil_stub::char_table[3] = (char *)"25.66.77.88\0";
369+
CellularUtil_stub::char_table[2] = (char *)"1.2.3.4\0";
370+
CellularUtil_stub::char_table[1] = (char *)"004.003.002.001\0";
371+
CellularUtil_stub::char_table[0] = (char *)"1.2.3.4\0";
372+
328373
EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list));
329374
CellularContext::pdpcontext_params_t *params = list.get_head();
330375
EXPECT_TRUE(params != NULL);
@@ -457,6 +502,11 @@ TEST_F(TestAT_CellularContext, set_file_handle)
457502
AT_CellularDevice dev(&fh1);
458503
AT_CellularContext ctx(at, &dev);
459504
ctx.set_file_handle(&fh1);
505+
506+
UARTSerial ss(NC, NC);
507+
508+
ctx.set_file_handle(&ss, PTC0, true);
509+
ctx.enable_hup(true);
460510
}
461511

462512
TEST_F(TestAT_CellularContext, connect_disconnect_sync)
@@ -481,10 +531,44 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
481531
data.error = NSAPI_ERROR_OK;
482532
ctx1.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
483533

534+
ATHandler_stub::resp_info_true_counter = 1;
535+
ATHandler_stub::read_string_table[0] = (char *)"APN";
536+
ATHandler_stub::read_string_table[1] = (char *)"IP";
537+
ATHandler_stub::read_string_index = 2;
484538
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
485539

486540
ASSERT_EQ(network_cb_count, 5);
487541

542+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
543+
ATHandler_stub::resp_info_true_counter = 1;
544+
ATHandler_stub::read_string_table[1] = (char *)"Non-IP";
545+
ATHandler_stub::read_string_index = 2;
546+
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
547+
548+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
549+
ATHandler_stub::resp_info_true_counter = 1;
550+
ATHandler_stub::read_string_table[1] = (char *)"IPV6";
551+
ATHandler_stub::read_string_index = 2;
552+
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
553+
554+
AT_CellularBase_stub::supported_bool = true;
555+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
556+
ATHandler_stub::resp_info_true_counter = 1;
557+
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
558+
ATHandler_stub::read_string_index = 2;
559+
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
560+
AT_CellularBase_stub::supported_bool = false;
561+
562+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
563+
ATHandler_stub::resp_info_true_counter = 1;
564+
ATHandler_stub::read_string_table[0] = (char *)"APN2";
565+
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
566+
ATHandler_stub::read_string_index = 2;
567+
ATHandler_stub::int_value = 10;
568+
ctx1.set_credentials("APN");
569+
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
570+
ATHandler_stub::int_value = -1;
571+
488572
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_IS_CONNECTED);
489573

490574
EXPECT_TRUE(ctx1.is_connected() == true);
@@ -519,6 +603,26 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
519603
// More connect test after we are re-writted getting of PDP context...
520604
}
521605

606+
TEST_F(TestAT_CellularContext, de_and_activate_non_ip_context)
607+
{
608+
EventQueue que;
609+
FileHandle_stub fh1;
610+
ATHandler at(&fh1, que, 0, ",");
611+
AT_CellularDevice dev(&fh1);
612+
my_AT_CTX ctx(at, &dev);
613+
ctx.attach(&network_cb);
614+
Semaphore_stub::acquire_return_value = true;
615+
616+
// call callback so that network is opened which is needed in disconnect
617+
cell_callback_data_t data;
618+
data.error = NSAPI_ERROR_OK;
619+
ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
620+
621+
ctx.activ_non_ip_context();
622+
623+
ctx.deactiv_non_ip_context();
624+
}
625+
522626
TEST_F(TestAT_CellularContext, set_device_ready_sync)
523627
{
524628
EventQueue que;
@@ -625,3 +729,22 @@ TEST_F(TestAT_CellularContext, connect_disconnect_async)
625729

626730
// More connect test after we are re-writted getting of PDP context...
627731
}
732+
733+
TEST_F(TestAT_CellularContext, get_timeout_for_operation)
734+
{
735+
EventQueue que;
736+
FileHandle_stub fh1;
737+
ATHandler at(&fh1, que, 0, ",");
738+
739+
AT_CellularDevice dev(&fh1);
740+
def_AT_CTX ctx1(at, &dev);
741+
ctx1._op = 1;
742+
EXPECT_EQ(300 * 1000, ctx1.do_op());
743+
744+
ctx1._op = 0;
745+
EXPECT_EQ(300 * 1000, ctx1.do_op());
746+
747+
ctx1._op = -1;
748+
EXPECT_EQ(1800 * 1000, ctx1.do_op());
749+
750+
}

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ set(unittest-includes ${unittest-includes}
1515
# Source files
1616
set(unittest-sources
1717
../features/cellular/framework/AT/AT_CellularContext.cpp
18-
../features/cellular/framework/AT/ATHandler_factory.cpp
19-
../features/cellular/framework/common/CellularUtil.cpp
2018
)
2119

2220
# Test files
@@ -42,4 +40,5 @@ set(unittest-test-sources
4240
stubs/UARTSerial_stub.cpp
4341
stubs/SerialBase_stub.cpp
4442
stubs/CellularContext_stub.cpp
43+
stubs/CellularUtil_stub.cpp
4544
)

0 commit comments

Comments
 (0)