@@ -127,6 +127,29 @@ static void test_gcoap__client_get_resp(void)
127127 }
128128}
129129
130+ /*
131+ * Client PUT request success case. Test request generation.
132+ * Set value of /riot/value resource to 1 from nanocoap server example.
133+ */
134+ static void test_gcoap__client_put_req (void )
135+ {
136+ uint8_t buf [GCOAP_PDU_BUF_SIZE ];
137+ coap_pkt_t pdu ;
138+ size_t len ;
139+ char path [] = "/riot/value" ;
140+ char payload [] = "1" ;
141+
142+ gcoap_req_init (& pdu , buf , GCOAP_PDU_BUF_SIZE , COAP_METHOD_PUT , path );
143+ memcpy (pdu .payload , payload , 1 );
144+ len = gcoap_finish (& pdu , 1 , COAP_FORMAT_TEXT );
145+
146+ coap_parse (& pdu , buf , len );
147+
148+ TEST_ASSERT_EQUAL_INT (COAP_METHOD_PUT , coap_get_code (& pdu ));
149+ TEST_ASSERT_EQUAL_INT (1 , pdu .payload_len );
150+ TEST_ASSERT_EQUAL_INT ('1' , (char )* pdu .payload );
151+ }
152+
130153/*
131154 * Helper for server_get tests below.
132155 * Request from libcoap example for gcoap_cli /cli/stats resource
@@ -289,6 +312,7 @@ Test *tests_gcoap_tests(void)
289312 EMB_UNIT_TESTFIXTURES (fixtures ) {
290313 new_TestFixture (test_gcoap__client_get_req ),
291314 new_TestFixture (test_gcoap__client_get_resp ),
315+ new_TestFixture (test_gcoap__client_put_req ),
292316 new_TestFixture (test_gcoap__server_get_req ),
293317 new_TestFixture (test_gcoap__server_get_resp ),
294318 new_TestFixture (test_gcoap__server_con_req ),
0 commit comments