Skip to content

Commit f7148c7

Browse files
author
Tero Heinonen
committed
unittests fixed
1 parent 1620eb4 commit f7148c7

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ bool test_coap_connection_handler_send_data()
122122

123123
connection_handler_destroy(handler);
124124

125-
coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t));
126-
memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t));
125+
coap_security_handler_stub.sec_obj = (coap_security_t *)malloc(sizeof(coap_security_t));
126+
memset(coap_security_handler_stub.sec_obj, 0, sizeof(coap_security_t));
127127
coap_security_handler_stub.sec_obj->_remote_port = 22;
128128
memset(coap_security_handler_stub.sec_obj->_remote_address, 1, 16 );
129129

@@ -199,8 +199,8 @@ bool test_coap_connection_handler_virtual_recv()
199199
return false;
200200

201201
//handler->socket->data still in memory
202-
coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t));
203-
memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t));
202+
coap_security_handler_stub.sec_obj = (coap_security_t *)malloc(sizeof(coap_security_t));
203+
memset(coap_security_handler_stub.sec_obj, 0, sizeof(coap_security_t));
204204
coap_security_handler_stub.sec_obj->_remote_port = 55;
205205
memset(coap_security_handler_stub.sec_obj->_remote_address, 4, 16 );
206206

@@ -298,8 +298,8 @@ bool test_timer_callbacks()
298298
return false;
299299

300300
//handler->socket->data still in memory
301-
coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t));
302-
memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t));
301+
coap_security_handler_stub.sec_obj = (coap_security_t *)malloc(sizeof(coap_security_t));
302+
memset(coap_security_handler_stub.sec_obj, 0, sizeof(coap_security_t));
303303
coap_security_handler_stub.sec_obj->_remote_port = 55;
304304
memset(coap_security_handler_stub.sec_obj->_remote_address, 4, 16 );
305305
coap_security_handler_stub.sec_obj->_timer_id = 5;
@@ -351,8 +351,8 @@ bool test_socket_api_callbacks()
351351
socket_callback_t *sckt_data = (socket_callback_t *)malloc(sizeof(socket_callback_t));
352352
memset(sckt_data, 0, sizeof(socket_callback_t));
353353

354-
coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t));
355-
memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t));
354+
coap_security_handler_stub.sec_obj = (coap_security_t *)malloc(sizeof(coap_security_t));
355+
memset(coap_security_handler_stub.sec_obj, 0, sizeof(coap_security_t));
356356

357357
socket_api_stub.int8_value = 0;
358358
nsdynmemlib_stub.returnCounter = 1;
@@ -431,8 +431,8 @@ bool test_security_callbacks()
431431
socket_callback_t *sckt_data = (socket_callback_t *)malloc(sizeof(socket_callback_t));
432432
memset(sckt_data, 0, sizeof(socket_callback_t));
433433

434-
coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t));
435-
memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t));
434+
coap_security_handler_stub.sec_obj = (coap_security_t *)malloc(sizeof(coap_security_t));
435+
memset(coap_security_handler_stub.sec_obj, 0, sizeof(coap_security_t));
436436

437437
nsdynmemlib_stub.returnCounter = 1;
438438
thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);

test/coap-service/unittest/coap_security_handler/test_coap_security_handler.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ bool test_thread_security_create()
5050

5151
nsdynmemlib_stub.returnCounter = 2;
5252
mbedtls_stub.crt_expected_int = 0;
53-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
53+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
5454
if( NULL == handle )
5555
return false;
5656

57-
ns_dyn_mem_free(handle);
57+
thread_security_destroy(handle);
5858

5959
return true;
6060
}
@@ -64,7 +64,7 @@ bool test_thread_security_destroy()
6464
uint8_t buf[16];
6565
nsdynmemlib_stub.returnCounter = 2;
6666
mbedtls_stub.crt_expected_int = 0;
67-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
67+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
6868
if( NULL == handle )
6969
return false;
7070

@@ -77,7 +77,7 @@ bool test_coap_security_handler_connect()
7777
uint8_t buf[16];
7878
nsdynmemlib_stub.returnCounter = 2;
7979
mbedtls_stub.crt_expected_int = 0;
80-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
80+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
8181
if( NULL == handle )
8282
return false;
8383

@@ -174,7 +174,7 @@ bool test_coap_security_handler_continue_connecting()
174174
uint8_t buf[16];
175175
nsdynmemlib_stub.returnCounter = 2;
176176
mbedtls_stub.crt_expected_int = 0;
177-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
177+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
178178
if( NULL == handle )
179179
return false;
180180

@@ -222,7 +222,7 @@ bool test_coap_security_handler_send_message()
222222
uint8_t buf[16];
223223
nsdynmemlib_stub.returnCounter = 2;
224224
mbedtls_stub.crt_expected_int = 0;
225-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
225+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
226226
if( NULL == handle )
227227
return false;
228228

@@ -243,7 +243,7 @@ bool test_thread_security_send_close_alert()
243243
uint8_t buf[16];
244244
nsdynmemlib_stub.returnCounter = 2;
245245
mbedtls_stub.crt_expected_int = 0;
246-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
246+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
247247
if( NULL == handle )
248248
return false;
249249

@@ -263,7 +263,7 @@ bool test_coap_security_handler_read()
263263
uint8_t buf[16];
264264
nsdynmemlib_stub.returnCounter = 2;
265265
mbedtls_stub.crt_expected_int = 0;
266-
thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
266+
coap_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
267267
if( NULL == handle )
268268
return false;
269269

test/coap-service/unittest/stub/coap_security_handler_stub.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
thread_sec_def coap_security_handler_stub;
1414

15-
thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port,
15+
coap_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port,
1616
int (*send_cb)(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *, size_t),
1717
int (*receive_cb)(int8_t socket_id, unsigned char *, size_t),
1818
void (*start_timer_cb)(int8_t timer_id, uint32_t min, uint32_t fin),
@@ -25,12 +25,12 @@ thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uin
2525
return coap_security_handler_stub.sec_obj;
2626
}
2727

28-
void thread_security_destroy(thread_security_t *sec)
28+
void thread_security_destroy(coap_security_t *sec)
2929
{
3030

3131
}
3232

33-
int coap_security_handler_connect(thread_security_t *sec, bool is_server, const unsigned char *pw, uint8_t len)
33+
int coap_security_handler_connect(coap_security_t *sec, bool is_server, const unsigned char *pw, uint8_t len)
3434
{
3535
sec->_is_started = true;
3636
if( coap_security_handler_stub.counter >= 0){
@@ -39,7 +39,7 @@ int coap_security_handler_connect(thread_security_t *sec, bool is_server, const
3939
return coap_security_handler_stub.int_value;
4040
}
4141

42-
int coap_security_handler_continue_connecting(thread_security_t *sec)
42+
int coap_security_handler_continue_connecting(coap_security_t *sec)
4343
{
4444
if( coap_security_handler_stub.counter >= 0){
4545
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
@@ -49,23 +49,23 @@ int coap_security_handler_continue_connecting(thread_security_t *sec)
4949
}
5050

5151

52-
int coap_security_handler_send_message(thread_security_t *sec, unsigned char *message, size_t len)
52+
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len)
5353
{
5454
if( coap_security_handler_stub.counter >= 0){
5555
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
5656
}
5757
return coap_security_handler_stub.int_value;
5858
}
5959

60-
int thread_security_send_close_alert(thread_security_t *sec)
60+
int thread_security_send_close_alert(coap_security_t *sec)
6161
{
6262
if( coap_security_handler_stub.counter >= 0){
6363
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
6464
}
6565
return coap_security_handler_stub.int_value;
6666
}
6767

68-
int coap_security_handler_read(thread_security_t *sec, unsigned char* buffer, size_t len)
68+
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len)
6969
{
7070
if( coap_security_handler_stub.counter >= 0){
7171
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];

test/coap-service/unittest/stub/coap_security_handler_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "coap_security_handler.h"
99

1010
typedef struct tsh{
11-
thread_security_t *sec_obj;
11+
coap_security_t *sec_obj;
1212
int int_value;
1313
int counter;
1414
int values[10];

0 commit comments

Comments
 (0)