@@ -85,6 +85,89 @@ TEST_F(TestAT_CellularNetwork, Create)
85
85
delete cn;
86
86
}
87
87
88
+ int expected_rat = 0 ;
89
+ int expected_status = 0 ;
90
+ int expected_cellid = 0 ;
91
+
92
+ void status_cb_urc (nsapi_event_t ev, intptr_t ptr)
93
+ {
94
+ const cell_callback_data_t *data = (const cell_callback_data_t *)ptr;
95
+ switch (ev) {
96
+ case CellularRadioAccessTechnologyChanged:
97
+ EXPECT_EQ (NSAPI_ERROR_OK, data->error );
98
+ EXPECT_EQ (expected_rat, data->status_data );
99
+ break ;
100
+ case CellularRegistrationStatusChanged:
101
+ EXPECT_EQ (NSAPI_ERROR_OK, data->error );
102
+ EXPECT_EQ (expected_status, data->status_data );
103
+ break ;
104
+ case CellularCellIDChanged:
105
+ EXPECT_EQ (NSAPI_ERROR_OK, data->error );
106
+ EXPECT_EQ (expected_cellid, data->status_data );
107
+ break ;
108
+ default :
109
+ if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
110
+ EXPECT_EQ (NSAPI_STATUS_DISCONNECTED, (int )ptr);
111
+ } else {
112
+ FAIL ();
113
+ }
114
+ }
115
+ }
116
+
117
+ TEST_F (TestAT_CellularNetwork, test_urc_creg)
118
+ {
119
+ EventQueue que;
120
+ FileHandle_stub fh1;
121
+ ATHandler at (&fh1, que, 0 , " ," );
122
+
123
+ AT_CellularNetwork cn (at);
124
+ cn.attach (status_cb_urc);
125
+
126
+ EXPECT_STREQ (" +CEREG:" , ATHandler_stub::urc_handlers[0 ].urc );
127
+ EXPECT_STREQ (" +CREG:" , ATHandler_stub::urc_handlers[1 ].urc );
128
+
129
+ // Connected to home network
130
+ expected_rat = CellularNetwork::RAT_NB1;
131
+ expected_status = CellularNetwork::RegisteredHomeNetwork;
132
+ expected_cellid = 305463233 ;
133
+
134
+ ATHandler_stub::int_count = 4 ;
135
+ ATHandler_stub::int_valid_count_table[3 ] = 1 ; // [1] STAT, Registered to home network
136
+ ATHandler_stub::int_valid_count_table[2 ] = 9 ; // [4] ACT, NB-IoT
137
+ ATHandler_stub::int_valid_count_table[1 ] = 1 ; // [5] cause_type, skipped
138
+ ATHandler_stub::int_valid_count_table[0 ] = 1 ; // [6] reject_cause, skipped
139
+
140
+ ATHandler_stub::read_string_index = 4 ;
141
+ ATHandler_stub::read_string_table[3 ] = " 00C3" ; // [2] LAC, 195
142
+ ATHandler_stub::read_string_table[2 ] = " 1234FFC1" ; // [3] ci, 305463233
143
+ ATHandler_stub::read_string_table[1 ] = " 00100100" ; // [7] active time
144
+ ATHandler_stub::read_string_table[0 ] = " 01000111" ; // [8] periodic-tau
145
+
146
+ ATHandler_stub::urc_handlers[0 ].cb ();
147
+
148
+ // Disconnected
149
+ expected_rat = CellularNetwork::RAT_NB1;
150
+ expected_status = CellularNetwork::NotRegistered;
151
+ expected_cellid = 0 ;
152
+
153
+ ATHandler_stub::int_count = 4 ;
154
+ ATHandler_stub::int_valid_count_table[3 ] = 0 ; // [1] STAT, Not reqistered
155
+ ATHandler_stub::int_valid_count_table[2 ] = 9 ; // [4] ACT, NB-IoT
156
+ ATHandler_stub::int_valid_count_table[1 ] = 1 ; // [5] cause_type, skipped
157
+ ATHandler_stub::int_valid_count_table[0 ] = 1 ; // [6] reject_cause, skipped
158
+
159
+ ATHandler_stub::read_string_index = 4 ;
160
+ ATHandler_stub::read_string_table[3 ] = " 0000" ; // [2] LAC, 0000
161
+ ATHandler_stub::read_string_table[2 ] = " 00000000" ; // [3] ci, 000000000
162
+ ATHandler_stub::read_string_table[1 ] = " 00100100" ; // [7] active time
163
+ ATHandler_stub::read_string_table[0 ] = " 01000111" ; // [8] periodic-tau
164
+
165
+ ATHandler_stub::urc_handlers[0 ].cb ();
166
+ ATHandler_stub::read_string_index = kRead_string_table_size ;
167
+ ATHandler_stub::read_string_value = NULL ;
168
+ ATHandler_stub::ssize_value = 0 ;
169
+ }
170
+
88
171
TEST_F (TestAT_CellularNetwork, test_AT_CellularNetwork_set_registration)
89
172
{
90
173
EventQueue que;
0 commit comments