@@ -125,6 +125,7 @@ ZTEST(ot_rpc_coap, test_otCoapNewMessage_max)
125
125
mock_nrf_rpc_tr_expect_done ();
126
126
127
127
zassert_equal (otCoapNewMessage_fake .call_count , 1 );
128
+ zassert_not_null (ot_msg_get (1 ));
128
129
}
129
130
130
131
/*
@@ -361,7 +362,7 @@ static void otCoapRemoveResource_custom_func(otInstance *instance, otCoapResourc
361
362
ZTEST (ot_rpc_coap , test_otCoapAddResource_otCoapRemoveResource )
362
363
{
363
364
/*
364
- * Message key is allocated by the default handler encoder function but we know that
365
+ * Message key is allocated by the resource handler encoder function but we know that
365
366
* the first free slot will be selected so it will be 1.
366
367
*/
367
368
ot_msg_key message_rep = 1 ;
@@ -393,6 +394,7 @@ ZTEST(ot_rpc_coap, test_otCoapAddResource_otCoapRemoveResource)
393
394
otCoapAddResource_fake .arg1_val -> mHandler (otCoapAddResource_fake .arg1_val -> mContext ,
394
395
(otMessage * )MSG_ADDR , & message_info );
395
396
mock_nrf_rpc_tr_expect_done ();
397
+ zassert_is_null (ot_msg_get (message_rep ));
396
398
397
399
/* Test reception of otCoapRemoveResource() */
398
400
otCoapRemoveResource_fake .custom_fake = otCoapRemoveResource_custom_func ;
@@ -440,6 +442,7 @@ ZTEST(ot_rpc_coap, test_otCoapSetDefaultHandler)
440
442
otCoapSetDefaultHandler_fake .arg1_val (otCoapSetDefaultHandler_fake .arg2_val ,
441
443
(otMessage * )MSG_ADDR , & message_info );
442
444
mock_nrf_rpc_tr_expect_done ();
445
+ zassert_is_null (ot_msg_get (message_rep ));
443
446
444
447
/* Test reception of otCoapSetDefaultHandler() command that unsets the default handler */
445
448
RESET_FAKE (otCoapSetDefaultHandler );
@@ -454,6 +457,8 @@ ZTEST(ot_rpc_coap, test_otCoapSetDefaultHandler)
454
457
455
458
/*
456
459
* Test reception of otCoapSendRequest().
460
+ * Test serialization of the result: OT_ERROR_NONE.
461
+ * Test response handler invocation.
457
462
*/
458
463
ZTEST (ot_rpc_coap , test_otCoapSendRequest )
459
464
{
@@ -484,9 +489,9 @@ ZTEST(ot_rpc_coap, test_otCoapSendRequest)
484
489
mock_nrf_rpc_tr_expect_done ();
485
490
486
491
zassert_equal (otCoapSendRequestWithParameters_fake .call_count , 1 );
487
- zassert_equal (otCoapSendRequestWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
488
- zassert_not_null (otCoapSendRequestWithParameters_fake .arg2_val );
489
- zassert_not_null (otCoapSendRequestWithParameters_fake .arg3_val );
492
+ zexpect_equal (otCoapSendRequestWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
493
+ zexpect_not_null (otCoapSendRequestWithParameters_fake .arg2_val );
494
+ zexpect_not_null (otCoapSendRequestWithParameters_fake .arg3_val );
490
495
491
496
/* Test serialization of the response handler call */
492
497
mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_COAP_RESPONSE_HANDLER , request_rep ,
@@ -498,22 +503,70 @@ ZTEST(ot_rpc_coap, test_otCoapSendRequest)
498
503
mock_nrf_rpc_tr_expect_done ();
499
504
}
500
505
506
+ /*
507
+ * Test reception of otCoapSendRequest().
508
+ * Test serialization of the result: OT_ERROR_INVALID_STATE.
509
+ * Test that the message handle has not been released on failure.
510
+ */
511
+ ZTEST (ot_rpc_coap , test_otCoapSendRequest_failed )
512
+ {
513
+ ot_rpc_coap_request_key request_rep = 3 ;
514
+ ot_msg_key message_rep = ot_reg_msg_alloc ((otMessage * )MSG_ADDR );
515
+
516
+ otCoapSendRequestWithParameters_fake .return_val = OT_ERROR_INVALID_STATE ;
517
+
518
+ mock_nrf_rpc_tr_expect_add (RPC_RSP (OT_ERROR_INVALID_STATE ), NO_RSP );
519
+ mock_nrf_rpc_tr_receive (
520
+ RPC_CMD (OT_RPC_CMD_COAP_SEND_REQUEST , message_rep , CBOR_MSG_INFO , request_rep ));
521
+ mock_nrf_rpc_tr_expect_done ();
522
+
523
+ zassert_equal (otCoapSendRequestWithParameters_fake .call_count , 1 );
524
+ zexpect_equal (otCoapSendRequestWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
525
+ zexpect_not_null (otCoapSendRequestWithParameters_fake .arg2_val );
526
+ zexpect_not_null (otCoapSendRequestWithParameters_fake .arg3_val );
527
+ zassert_not_null (ot_msg_get (message_rep ));
528
+ }
529
+
501
530
/*
502
531
* Test reception of otCoapSendResponse().
532
+ * Test serialization of the result: OT_ERROR_NONE.
533
+ * Test that the response message handle has been released on success.
503
534
*/
504
535
ZTEST (ot_rpc_coap , test_otCoapSendResponse )
505
536
{
506
537
ot_msg_key message_rep = ot_reg_msg_alloc ((otMessage * )MSG_ADDR );
507
538
539
+ otCoapSendResponseWithParameters_fake .return_val = OT_ERROR_NONE ;
540
+
541
+ mock_nrf_rpc_tr_expect_add (RPC_RSP (OT_ERROR_NONE ), NO_RSP );
542
+ mock_nrf_rpc_tr_receive (RPC_CMD (OT_RPC_CMD_COAP_SEND_RESPONSE , message_rep , CBOR_MSG_INFO ));
543
+ mock_nrf_rpc_tr_expect_done ();
544
+
545
+ zassert_equal (otCoapSendResponseWithParameters_fake .call_count , 1 );
546
+ zexpect_equal (otCoapSendResponseWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
547
+ zexpect_not_null (otCoapSendResponseWithParameters_fake .arg2_val );
548
+ zassert_is_null (ot_msg_get (message_rep ));
549
+ }
550
+
551
+ /*
552
+ * Test reception of otCoapSendResponse().
553
+ * Test serialization of the result: OT_ERROR_INVALID_STATE.
554
+ * Test that the response message handle hasn't been released on failure.
555
+ */
556
+ ZTEST (ot_rpc_coap , test_otCoapSendResponse_failed )
557
+ {
558
+ ot_msg_key message_rep = ot_reg_msg_alloc ((otMessage * )MSG_ADDR );
559
+
508
560
otCoapSendResponseWithParameters_fake .return_val = OT_ERROR_INVALID_STATE ;
509
561
510
562
mock_nrf_rpc_tr_expect_add (RPC_RSP (OT_ERROR_INVALID_STATE ), NO_RSP );
511
563
mock_nrf_rpc_tr_receive (RPC_CMD (OT_RPC_CMD_COAP_SEND_RESPONSE , message_rep , CBOR_MSG_INFO ));
512
564
mock_nrf_rpc_tr_expect_done ();
513
565
514
566
zassert_equal (otCoapSendResponseWithParameters_fake .call_count , 1 );
515
- zassert_equal (otCoapSendResponseWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
516
- zassert_not_null (otCoapSendResponseWithParameters_fake .arg2_val );
567
+ zexpect_equal (otCoapSendResponseWithParameters_fake .arg1_val , (otMessage * )MSG_ADDR );
568
+ zexpect_not_null (otCoapSendResponseWithParameters_fake .arg2_val );
569
+ zassert_not_null (ot_msg_get (message_rep ));
517
570
}
518
571
519
572
ZTEST_SUITE (ot_rpc_coap , NULL , NULL , tc_setup , NULL , NULL );
0 commit comments