28
28
#include " CellularDevice_stub.h"
29
29
#include " equeue_stub.h"
30
30
#include " AT_CellularBase_stub.h"
31
+ #include " CellularUtil_stub.h"
32
+ #include " PinNames.h"
31
33
32
34
using namespace mbed ;
33
35
using namespace events ;
@@ -62,6 +64,9 @@ class TestAT_CellularContext : public testing::Test {
62
64
ATHandler_stub::read_string_table[kRead_string_table_size ];
63
65
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default ;
64
66
CellularDevice_stub::connect_counter = 2 ;
67
+
68
+ CellularUtil_stub::char_table[0 ] = (char *)" \0 " ;
69
+ CellularUtil_stub::table_idx = 0 ;
65
70
}
66
71
67
72
void TearDown ()
@@ -131,6 +136,16 @@ class my_AT_CTX : public AT_CellularContext {
131
136
AT_CellularContext::cellular_callback (ev, ptr);
132
137
}
133
138
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
+
134
149
my_stack _st;
135
150
};
136
151
@@ -150,6 +165,19 @@ class my_AT_CTXIPV6 : public AT_CellularContext {
150
165
my_stack _st;
151
166
};
152
167
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
+
153
181
static int network_cb_count;
154
182
static void network_cb (nsapi_event_t ev, intptr_t intptr)
155
183
{
@@ -169,6 +197,9 @@ TEST_F(TestAT_CellularContext, Create)
169
197
170
198
ctx = new AT_CellularContext (at, &dev);
171
199
EXPECT_TRUE (ctx != NULL );
200
+
201
+ ctx->get_device ();
202
+ EXPECT_EQ (NSAPI_STATUS_DISCONNECTED, ctx->get_connection_status ());
172
203
delete ctx;
173
204
}
174
205
@@ -325,6 +356,20 @@ TEST_F(TestAT_CellularContext, get_pdpcontext_params)
325
356
ATHandler_stub::read_string_table[1 ] = (char *)" 25.66.77.88" ;
326
357
ATHandler_stub::read_string_table[0 ] = (char *)" 004.003.002.001" ;
327
358
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
+
328
373
EXPECT_TRUE (NSAPI_ERROR_OK == cn.get_pdpcontext_params (list));
329
374
CellularContext::pdpcontext_params_t *params = list.get_head ();
330
375
EXPECT_TRUE (params != NULL );
@@ -457,6 +502,11 @@ TEST_F(TestAT_CellularContext, set_file_handle)
457
502
AT_CellularDevice dev (&fh1);
458
503
AT_CellularContext ctx (at, &dev);
459
504
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 );
460
510
}
461
511
462
512
TEST_F (TestAT_CellularContext, connect_disconnect_sync)
@@ -481,10 +531,44 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
481
531
data.error = NSAPI_ERROR_OK;
482
532
ctx1.cellular_callback ((nsapi_event_t )CellularDeviceReady, (intptr_t )&data);
483
533
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 ;
484
538
ASSERT_EQ (ctx1.connect (), NSAPI_ERROR_OK);
485
539
486
540
ASSERT_EQ (network_cb_count, 5 );
487
541
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
+
488
572
ASSERT_EQ (ctx1.connect (), NSAPI_ERROR_IS_CONNECTED);
489
573
490
574
EXPECT_TRUE (ctx1.is_connected () == true );
@@ -519,6 +603,26 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
519
603
// More connect test after we are re-writted getting of PDP context...
520
604
}
521
605
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
+
522
626
TEST_F (TestAT_CellularContext, set_device_ready_sync)
523
627
{
524
628
EventQueue que;
@@ -618,3 +722,22 @@ TEST_F(TestAT_CellularContext, connect_disconnect_async)
618
722
619
723
// More connect test after we are re-writted getting of PDP context...
620
724
}
725
+
726
+ TEST_F (TestAT_CellularContext, get_timeout_for_operation)
727
+ {
728
+ EventQueue que;
729
+ FileHandle_stub fh1;
730
+ ATHandler at (&fh1, que, 0 , " ," );
731
+
732
+ AT_CellularDevice dev (&fh1);
733
+ def_AT_CTX ctx1 (at, &dev);
734
+ ctx1._op = 1 ;
735
+ EXPECT_EQ (300 * 1000 , ctx1.do_op ());
736
+
737
+ ctx1._op = 0 ;
738
+ EXPECT_EQ (300 * 1000 , ctx1.do_op ());
739
+
740
+ ctx1._op = -1 ;
741
+ EXPECT_EQ (1800 * 1000 , ctx1.do_op ());
742
+
743
+ }
0 commit comments