26
26
#include " ATHandler_stub.h"
27
27
#include " SocketAddress.h"
28
28
#include " CellularDevice_stub.h"
29
+ #include " AT_CellularDevice_stub.h"
29
30
#include " myCellularDevice.h"
30
31
31
32
using namespace mbed ;
@@ -34,27 +35,15 @@ using namespace events;
34
35
class MyStack : public AT_CellularStack {
35
36
public:
36
37
bool bool_value;
37
- bool max_sock_value;
38
38
nsapi_error_t create_error;
39
39
CellularSocket socket;
40
40
41
41
MyStack (ATHandler &atr, int cid, nsapi_ip_stack_t typ, AT_CellularDevice &device) : AT_CellularStack(atr, cid, typ, device)
42
42
{
43
43
bool_value = false ;
44
- max_sock_value = 0 ;
45
44
create_error = NSAPI_ERROR_OK;
46
45
}
47
46
48
- virtual int get_max_socket_count ()
49
- {
50
- return max_sock_value;
51
- }
52
-
53
- virtual bool is_protocol_supported (nsapi_protocol_t protocol)
54
- {
55
- return bool_value;
56
- }
57
-
58
47
virtual nsapi_error_t socket_close_impl (int sock_id)
59
48
{
60
49
return NSAPI_ERROR_OK;
@@ -207,19 +196,22 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
207
196
ATHandler at (&fh1, que, 0 , " ," );
208
197
209
198
MyStack st (at, 0 , IPV6_STACK, *_dev);
210
- st.bool_value = false ;
199
+ AT_CellularDevice_stub::supported_bool = 0 ;
200
+ AT_CellularDevice_stub::max_sock_value = 1 ;
211
201
EXPECT_EQ (st.socket_open (NULL , NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
212
202
213
- st.bool_value = true ;
214
- st.max_sock_value = 0 ;
203
+ AT_CellularDevice_stub::supported_bool = 1 ;
215
204
nsapi_socket_t sock = &st.socket ;
205
+ AT_CellularDevice_stub::max_sock_value = 0 ;
216
206
EXPECT_EQ (st.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);
217
207
218
208
MyStack st2 (at, 0 , IPV6_STACK, *_dev);
219
209
st2.bool_value = true ;
220
- st2. max_sock_value = 1 ;
210
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
221
211
sock = &st2.socket ;
222
212
EXPECT_EQ (st2.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_OK);
213
+
214
+ AT_CellularDevice_stub::max_sock_value = 1 ; // value must be the same as before the first open
223
215
}
224
216
225
217
TEST_F (TestAT_CellularStack, test_AT_CellularStack_socket_close)
@@ -233,13 +225,13 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
233
225
234
226
nsapi_socket_t sock = &st.socket ;
235
227
st.bool_value = true ;
236
- st. max_sock_value = 1 ;
228
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
237
229
EXPECT_EQ (st.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_OK);
238
- st. max_sock_value = 0 ;
230
+ AT_CellularDevice_stub:: max_sock_value = 0 ;
239
231
EXPECT_EQ (st.socket_close (sock), NSAPI_ERROR_DEVICE_ERROR);
240
232
241
233
MyStack st2 (at, 0 , IPV6_STACK, *_dev);
242
- st2. max_sock_value = 1 ;
234
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
243
235
st2.bool_value = true ;
244
236
sock = &st2.socket ;
245
237
EXPECT_EQ (st2.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_OK);
@@ -306,7 +298,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
306
298
EXPECT_EQ (st.socket_send (&st.socket , " addr" , 4 ), NSAPI_ERROR_NO_CONNECTION);
307
299
308
300
SocketAddress addr (" fc00::" , 123 );
309
- st. max_sock_value = 1 ;
301
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
310
302
st.bool_value = true ;
311
303
nsapi_socket_t sock = &st.socket ;
312
304
st.socket_open (&sock, NSAPI_TCP);
@@ -325,7 +317,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
325
317
SocketAddress addr (" fc00::" , 123 );
326
318
EXPECT_EQ (st.socket_sendto (NULL , addr, " addr" , 4 ), NSAPI_ERROR_NO_SOCKET);
327
319
328
- st. max_sock_value = 1 ;
320
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
329
321
st.bool_value = true ;
330
322
nsapi_socket_t sock = &st.socket ;
331
323
st.socket_open (&sock, NSAPI_TCP);
@@ -359,7 +351,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
359
351
EXPECT_EQ (st.socket_recvfrom (NULL , NULL , table, 4 ), NSAPI_ERROR_NO_SOCKET);
360
352
361
353
SocketAddress addr;
362
- st. max_sock_value = 1 ;
354
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
363
355
st.bool_value = true ;
364
356
nsapi_socket_t sock = &st.socket ;
365
357
st.socket_open (&sock, NSAPI_TCP);
@@ -380,7 +372,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
380
372
MyStack st (at, 0 , IPV6_STACK, *_dev);
381
373
382
374
st.socket_attach (NULL , NULL , NULL );
383
- st. max_sock_value = 1 ;
375
+ AT_CellularDevice_stub:: max_sock_value = 1 ;
384
376
st.bool_value = true ;
385
377
nsapi_socket_t sock = &st.socket ;
386
378
st.socket_open (&sock, NSAPI_TCP);
0 commit comments