@@ -105,6 +105,20 @@ TEST_F(TestTLSSocketWrapper, constructor_hostname)
105
105
delete wrapper2;
106
106
}
107
107
108
+ TEST_F (TestTLSSocketWrapper, no_socket)
109
+ {
110
+ TLSSocketWrapper *wrapperTmp = new TLSSocketWrapper (NULL );
111
+ const SocketAddress a (" 127.0.0.1" , 1024 );
112
+ EXPECT_EQ (wrapperTmp->connect (a), NSAPI_ERROR_NO_SOCKET);
113
+ EXPECT_EQ (wrapperTmp->bind (a), NSAPI_ERROR_NO_SOCKET);
114
+ EXPECT_EQ (wrapperTmp->setsockopt (0 , 0 , 0 , 0 ), NSAPI_ERROR_NO_SOCKET);
115
+ EXPECT_EQ (wrapperTmp->getsockopt (0 , 0 , 0 , 0 ), NSAPI_ERROR_NO_SOCKET);
116
+ EXPECT_EQ (wrapperTmp->send (dataBuf, dataSize), NSAPI_ERROR_NO_SOCKET);
117
+ EXPECT_EQ (wrapperTmp->recv (dataBuf, dataSize), NSAPI_ERROR_NO_SOCKET);
118
+ EXPECT_EQ (wrapperTmp->close (), NSAPI_ERROR_NO_SOCKET);
119
+ delete wrapperTmp;
120
+ }
121
+
108
122
/* connect */
109
123
110
124
TEST_F (TestTLSSocketWrapper, connect)
@@ -194,6 +208,11 @@ TEST_F(TestTLSSocketWrapper, connect_handshake_fail_ssl_handshake_in_progress)
194
208
mbedtls_stub.retArray [2 ] = MBEDTLS_ERR_SSL_WANT_READ; // mbedtls_ssl_handshake error
195
209
const SocketAddress a (" 127.0.0.1" , 1024 );
196
210
EXPECT_EQ (wrapper->connect (a), NSAPI_ERROR_IN_PROGRESS);
211
+
212
+ // Check that send will fail in this situation.
213
+ mbedtls_stub.retArray [3 ] = MBEDTLS_ERR_SSL_WANT_READ; // mbedtls_ssl_handshake error
214
+ eventFlagsStubNextRetval.push_back (osFlagsError); // Break the wait loop
215
+ EXPECT_EQ (wrapper->send (dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK);
197
216
}
198
217
199
218
TEST_F (TestTLSSocketWrapper, connect_handshake_fail_ssl_get_verify_result)
@@ -243,6 +262,17 @@ TEST_F(TestTLSSocketWrapper, send_error_would_block)
243
262
EXPECT_EQ (wrapper->send (dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK);
244
263
}
245
264
265
+ TEST_F (TestTLSSocketWrapper, send_device_error)
266
+ {
267
+ transport->open ((NetworkStack *)&stack);
268
+ mbedtls_stub.useCounter = true ;
269
+ mbedtls_stub.retArray [3 ] = MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE; // mbedtls_ssl_write
270
+ eventFlagsStubNextRetval.push_back (osFlagsError); // Break the wait loop
271
+ const SocketAddress a (" 127.0.0.1" , 1024 );
272
+ EXPECT_EQ (wrapper->connect (a), NSAPI_ERROR_OK);
273
+ EXPECT_EQ (wrapper->send (dataBuf, dataSize), NSAPI_ERROR_DEVICE_ERROR);
274
+ }
275
+
246
276
TEST_F (TestTLSSocketWrapper, send_to)
247
277
{
248
278
transport->open ((NetworkStack *)&stack);
@@ -294,6 +324,17 @@ TEST_F(TestTLSSocketWrapper, recv_would_block)
294
324
EXPECT_EQ (wrapper->recv (dataBuf, dataSize), NSAPI_ERROR_WOULD_BLOCK);
295
325
}
296
326
327
+ TEST_F (TestTLSSocketWrapper, recv_device_error)
328
+ {
329
+ transport->open ((NetworkStack *)&stack);
330
+ mbedtls_stub.useCounter = true ;
331
+ mbedtls_stub.retArray [3 ] = MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE; // mbedtls_ssl_write
332
+ const SocketAddress a (" 127.0.0.1" , 1024 );
333
+ EXPECT_EQ (wrapper->connect (a), NSAPI_ERROR_OK);
334
+ eventFlagsStubNextRetval.push_back (osFlagsError); // Break the wait loop
335
+ EXPECT_EQ (wrapper->recv (dataBuf, dataSize), NSAPI_ERROR_DEVICE_ERROR);
336
+ }
337
+
297
338
TEST_F (TestTLSSocketWrapper, recv_from_no_socket)
298
339
{
299
340
SocketAddress a (" 127.0.0.1" , 1024 );
0 commit comments