@@ -81,6 +81,7 @@ bool test_coap_message_handler_init()
81
81
retCounter = 1 ;
82
82
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
83
83
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
84
+ nsdynmemlib_stub .returnCounter = 1 ;
84
85
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
85
86
if ( NULL == handle )
86
87
return false;
@@ -97,6 +98,7 @@ bool test_coap_message_handler_destroy()
97
98
retCounter = 1 ;
98
99
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
99
100
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
101
+ nsdynmemlib_stub .returnCounter = 1 ;
100
102
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
101
103
102
104
if ( 0 != coap_message_handler_destroy (handle ) )
@@ -113,6 +115,7 @@ bool test_coap_message_handler_find_transaction()
113
115
retCounter = 1 ;
114
116
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
115
117
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
118
+ nsdynmemlib_stub .returnCounter = 1 ;
116
119
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
117
120
118
121
uint8_t buf [16 ];
@@ -140,35 +143,39 @@ bool test_coap_message_handler_coap_msg_process()
140
143
{
141
144
uint8_t buf [16 ];
142
145
memset (& buf , 1 , 16 );
146
+ bool ret_val = false;
143
147
/*Handler is null*/
144
148
if ( -1 != coap_message_handler_coap_msg_process (NULL , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , NULL ))
145
- return false ;
149
+ goto exit ;
146
150
147
151
retCounter = 1 ;
148
152
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
149
153
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
154
+ nsdynmemlib_stub .returnCounter = 1 ;
150
155
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
151
156
152
157
sn_coap_protocol_stub .expectedHeader = NULL ;
153
158
/* Coap parse returns null */
154
159
if ( -1 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
155
- return false ;
160
+ goto exit ;
156
161
157
162
sn_coap_protocol_stub .expectedHeader = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
158
163
memset (sn_coap_protocol_stub .expectedHeader , 0 , sizeof (sn_coap_hdr_s ));
159
164
sn_coap_protocol_stub .expectedHeader -> coap_status = 66 ;
165
+ nsdynmemlib_stub .returnCounter = 1 ;
160
166
/* Coap library responds */
161
167
if ( -1 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
162
- return false ;
168
+ goto exit ;
163
169
164
170
sn_coap_protocol_stub .expectedHeader = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
165
171
memset (sn_coap_protocol_stub .expectedHeader , 0 , sizeof (sn_coap_hdr_s ));
166
172
sn_coap_protocol_stub .expectedHeader -> coap_status = COAP_STATUS_OK ;
167
173
sn_coap_protocol_stub .expectedHeader -> msg_code = 1 ;
168
174
retValue = 0 ;
169
175
/* request received */
176
+ nsdynmemlib_stub .returnCounter = 1 ;
170
177
if ( 0 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
171
- return false ;
178
+ goto exit ;
172
179
173
180
sn_coap_protocol_stub .expectedHeader = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
174
181
memset (sn_coap_protocol_stub .expectedHeader , 0 , sizeof (sn_coap_hdr_s ));
@@ -177,15 +184,16 @@ bool test_coap_message_handler_coap_msg_process()
177
184
nsdynmemlib_stub .returnCounter = 1 ;
178
185
retValue = -1 ;
179
186
if ( 0 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
180
- return false ;
187
+ goto exit ;
181
188
182
189
sn_coap_protocol_stub .expectedHeader = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
183
190
memset (sn_coap_protocol_stub .expectedHeader , 0 , sizeof (sn_coap_hdr_s ));
184
191
sn_coap_protocol_stub .expectedHeader -> coap_status = COAP_STATUS_OK ;
185
192
sn_coap_protocol_stub .expectedHeader -> msg_code = 333 ;
193
+ nsdynmemlib_stub .returnCounter = 1 ;
186
194
187
195
if ( -1 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
188
- return false ;
196
+ goto exit ;
189
197
190
198
sn_coap_protocol_stub .expectedHeader = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
191
199
memset (sn_coap_protocol_stub .expectedHeader , 0 , sizeof (sn_coap_hdr_s ));
@@ -200,27 +208,27 @@ bool test_coap_message_handler_coap_msg_process()
200
208
sn_coap_builder_stub .expectedUint16 = 1 ;
201
209
nsdynmemlib_stub .returnCounter = 3 ;
202
210
if ( 2 != coap_message_handler_request_send (handle , 3 , 0 , buf , 24 , 1 , 2 , & uri , 4 , NULL , 0 , & resp_recv ))
203
- return false ;
211
+ goto exit ;
204
212
205
213
sn_coap_protocol_stub .expectedHeader -> msg_id = 2 ;
206
- // sn_coap_protocol_stub.expectedHeader->token_ptr = (uint8_t*)malloc(4);
207
- // memset(sn_coap_protocol_stub.expectedHeader->token_ptr, 1, 4);
208
- if ( -1 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
209
- return false;
210
214
211
- // free(sn_coap_protocol_stub.expectedHeader->token_ptr);
215
+ if ( -1 != coap_message_handler_coap_msg_process (handle , 0 , buf , 22 , ns_in6addr_any , NULL , 0 , process_cb ))
216
+ goto exit ;
212
217
218
+ ret_val = true;
219
+ exit :
213
220
free (sn_coap_protocol_stub .expectedCoap );
214
221
sn_coap_protocol_stub .expectedCoap = NULL ;
215
222
coap_message_handler_destroy (handle );
216
- return true ;
223
+ return ret_val ;
217
224
}
218
225
219
226
bool test_coap_message_handler_request_send ()
220
227
{
221
228
retCounter = 1 ;
222
229
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
223
230
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
231
+ nsdynmemlib_stub .returnCounter = 1 ;
224
232
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
225
233
226
234
uint8_t buf [16 ];
@@ -293,6 +301,7 @@ bool test_coap_message_handler_request_delete()
293
301
retCounter = 1 ;
294
302
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
295
303
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
304
+ nsdynmemlib_stub .returnCounter = 1 ;
296
305
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
297
306
298
307
uint8_t buf [16 ];
@@ -329,6 +338,7 @@ bool test_coap_message_handler_response_send()
329
338
retCounter = 1 ;
330
339
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
331
340
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
341
+ nsdynmemlib_stub .returnCounter = 1 ;
332
342
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
333
343
sn_coap_hdr_s * header = (sn_coap_hdr_s * )malloc (sizeof (sn_coap_hdr_s ));
334
344
memset (header , 0 , sizeof (sn_coap_hdr_s ));
@@ -385,6 +395,7 @@ bool test_coap_message_handler_exec()
385
395
retCounter = 1 ;
386
396
sn_coap_protocol_stub .expectedCoap = (struct coap_s * )malloc (sizeof (struct coap_s ));
387
397
memset (sn_coap_protocol_stub .expectedCoap , 0 , sizeof (struct coap_s ));
398
+ nsdynmemlib_stub .returnCounter = 1 ;
388
399
coap_msg_handler_t * handle = coap_message_handler_init (& test_own_alloc , & test_own_free , & coap_tx_function );
389
400
390
401
if ( 0 != coap_message_handler_exec (handle , 0 ))
0 commit comments