2626#include " ATHandler_stub.h"
2727#include " SocketAddress.h"
2828#include " CellularDevice_stub.h"
29+ #include " AT_CellularDevice_stub.h"
2930#include " myCellularDevice.h"
3031
3132using namespace mbed ;
@@ -34,27 +35,15 @@ using namespace events;
3435class MyStack : public AT_CellularStack {
3536public:
3637 bool bool_value;
37- bool max_sock_value;
3838 nsapi_error_t create_error;
3939 CellularSocket socket;
4040
4141 MyStack (ATHandler &atr, int cid, nsapi_ip_stack_t typ, AT_CellularDevice &device) : AT_CellularStack(atr, cid, typ, device)
4242 {
4343 bool_value = false ;
44- max_sock_value = 0 ;
4544 create_error = NSAPI_ERROR_OK;
4645 }
4746
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-
5847 virtual nsapi_error_t socket_close_impl (int sock_id)
5948 {
6049 return NSAPI_ERROR_OK;
@@ -207,19 +196,22 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
207196 ATHandler at (&fh1, que, 0 , " ," );
208197
209198 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 ;
211201 EXPECT_EQ (st.socket_open (NULL , NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
212202
213- st.bool_value = true ;
214- st.max_sock_value = 0 ;
203+ AT_CellularDevice_stub::supported_bool = 1 ;
215204 nsapi_socket_t sock = &st.socket ;
205+ AT_CellularDevice_stub::max_sock_value = 0 ;
216206 EXPECT_EQ (st.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);
217207
218208 MyStack st2 (at, 0 , IPV6_STACK, *_dev);
219209 st2.bool_value = true ;
220- st2. max_sock_value = 1 ;
210+ AT_CellularDevice_stub:: max_sock_value = 1 ;
221211 sock = &st2.socket ;
222212 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
223215}
224216
225217TEST_F (TestAT_CellularStack, test_AT_CellularStack_socket_close)
@@ -233,13 +225,13 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
233225
234226 nsapi_socket_t sock = &st.socket ;
235227 st.bool_value = true ;
236- st. max_sock_value = 1 ;
228+ AT_CellularDevice_stub:: max_sock_value = 1 ;
237229 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 ;
239231 EXPECT_EQ (st.socket_close (sock), NSAPI_ERROR_DEVICE_ERROR);
240232
241233 MyStack st2 (at, 0 , IPV6_STACK, *_dev);
242- st2. max_sock_value = 1 ;
234+ AT_CellularDevice_stub:: max_sock_value = 1 ;
243235 st2.bool_value = true ;
244236 sock = &st2.socket ;
245237 EXPECT_EQ (st2.socket_open (&sock, NSAPI_TCP), NSAPI_ERROR_OK);
@@ -306,7 +298,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
306298 EXPECT_EQ (st.socket_send (&st.socket , " addr" , 4 ), NSAPI_ERROR_NO_CONNECTION);
307299
308300 SocketAddress addr (" fc00::" , 123 );
309- st. max_sock_value = 1 ;
301+ AT_CellularDevice_stub:: max_sock_value = 1 ;
310302 st.bool_value = true ;
311303 nsapi_socket_t sock = &st.socket ;
312304 st.socket_open (&sock, NSAPI_TCP);
@@ -325,7 +317,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
325317 SocketAddress addr (" fc00::" , 123 );
326318 EXPECT_EQ (st.socket_sendto (NULL , addr, " addr" , 4 ), NSAPI_ERROR_NO_SOCKET);
327319
328- st. max_sock_value = 1 ;
320+ AT_CellularDevice_stub:: max_sock_value = 1 ;
329321 st.bool_value = true ;
330322 nsapi_socket_t sock = &st.socket ;
331323 st.socket_open (&sock, NSAPI_TCP);
@@ -359,7 +351,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
359351 EXPECT_EQ (st.socket_recvfrom (NULL , NULL , table, 4 ), NSAPI_ERROR_NO_SOCKET);
360352
361353 SocketAddress addr;
362- st. max_sock_value = 1 ;
354+ AT_CellularDevice_stub:: max_sock_value = 1 ;
363355 st.bool_value = true ;
364356 nsapi_socket_t sock = &st.socket ;
365357 st.socket_open (&sock, NSAPI_TCP);
@@ -380,7 +372,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
380372 MyStack st (at, 0 , IPV6_STACK, *_dev);
381373
382374 st.socket_attach (NULL , NULL , NULL );
383- st. max_sock_value = 1 ;
375+ AT_CellularDevice_stub:: max_sock_value = 1 ;
384376 st.bool_value = true ;
385377 nsapi_socket_t sock = &st.socket ;
386378 st.socket_open (&sock, NSAPI_TCP);
0 commit comments