1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "gtest/gtest.h"
22 #include "cainterface.h"
23 #include "cautilinterface.h"
25 #include "caprotocolmessage.h"
26 #include "cablockwisetransfer.h"
28 #define LARGE_PAYLOAD_LENGTH 1024
30 class CABlockTransferTests : public testing::Test {
37 virtual void TearDown()
43 TEST_F(CABlockTransferTests, CACreateNewDataSetTest)
45 CAEndpoint_t* tempRep = NULL;
46 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
48 coap_pdu_t *pdu = NULL;
49 coap_list_t *options = NULL;
50 coap_transport_type transport = coap_udp;
52 CAToken_t tempToken = NULL;
53 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
56 memset(&requestData, 0, sizeof(CAInfo_t));
57 requestData.token = tempToken;
58 requestData.tokenLength = CA_MAX_TOKEN_LEN;
59 requestData.type = CA_MSG_NONCONFIRM;
61 requestData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
62 if (!requestData.payload)
64 CADestroyToken(tempToken);
65 FAIL() << "requestData.payload allocation failed";
67 memset(requestData.payload, '1', sizeof(requestData.payload) - 1);
68 requestData.payloadSize = sizeof(requestData.payload);
69 requestData.type = CA_MSG_NONCONFIRM;
71 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
73 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
74 EXPECT_TRUE(cadata != NULL);
76 CABlockData_t *currData = CACreateNewBlockData(cadata);
77 EXPECT_TRUE(currData != NULL);
81 CAData_t *getData = CAGetDataSetFromBlockDataList(currData->blockDataId);
82 EXPECT_TRUE(getData != NULL);
84 EXPECT_EQ(CA_STATUS_OK, CARemoveBlockDataFromList(currData->blockDataId));
87 CADestroyDataSet(cadata);
88 coap_delete_list(options);
91 CADestroyToken(tempToken);
92 CADestroyEndpoint(tempRep);
93 free(requestData.payload);
96 TEST_F(CABlockTransferTests, CARemoveBlockDataFromListWithSeed)
98 CAEndpoint_t* tempRep = NULL;
99 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
101 coap_pdu_t *pdu = NULL;
102 coap_list_t *options = NULL;
103 coap_transport_type transport = coap_udp;
105 CAToken_t tempToken = NULL;
106 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
108 CAInfo_t requestData;
109 memset(&requestData, 0, sizeof(CAInfo_t));
110 requestData.token = tempToken;
111 requestData.tokenLength = CA_MAX_TOKEN_LEN;
112 requestData.type = CA_MSG_NONCONFIRM;
114 requestData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
115 if (!requestData.payload)
117 CADestroyToken(tempToken);
118 FAIL() << "requestData.payload allocation failed";
120 memset(requestData.payload, '1', sizeof(requestData.payload) - 1);
121 requestData.payloadSize = sizeof(requestData.payload);
122 requestData.type = CA_MSG_NONCONFIRM;
124 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
126 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
127 EXPECT_TRUE(cadata != NULL);
129 CABlockData_t *currData = CACreateNewBlockData(cadata);
130 EXPECT_TRUE(currData != NULL);
134 EXPECT_EQ(CA_STATUS_OK, CARemoveBlockDataFromListWithSeed(tempToken,
135 CA_MAX_TOKEN_LEN, 5683));
138 CADestroyDataSet(cadata);
139 coap_delete_list(options);
140 coap_delete_pdu(pdu);
142 CADestroyToken(tempToken);
143 CADestroyEndpoint(tempRep);
144 free(requestData.payload);
147 TEST_F(CABlockTransferTests, CAGetBlockDataFromBlockDataListTest)
149 CAEndpoint_t* tempRep = NULL;
150 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
152 coap_pdu_t *pdu = NULL;
153 coap_list_t *options = NULL;
154 coap_transport_type transport = coap_udp;
156 CAToken_t tempToken = NULL;
157 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
159 CAInfo_t requestData;
160 memset(&requestData, 0, sizeof(CAInfo_t));
161 requestData.token = tempToken;
162 requestData.tokenLength = CA_MAX_TOKEN_LEN;
163 requestData.type = CA_MSG_NONCONFIRM;
165 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
167 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
168 EXPECT_TRUE(cadata != NULL);
170 CABlockData_t *currData = CACreateNewBlockData(cadata);
171 EXPECT_TRUE(currData != NULL);
175 CABlockData_t *data = CAGetBlockDataFromBlockDataList(currData->blockDataId);
176 EXPECT_TRUE(data != NULL);
178 EXPECT_EQ(CA_STATUS_OK, CARemoveBlockDataFromList(currData->blockDataId));
181 CADestroyDataSet(cadata);
182 coap_delete_list(options);
183 coap_delete_pdu(pdu);
185 CADestroyToken(tempToken);
186 CADestroyEndpoint(tempRep);
187 free(requestData.payload);
190 TEST_F(CABlockTransferTests, CAGetPayloadFromBlockDataListTest)
192 CAEndpoint_t* tempRep = NULL;
193 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
195 coap_pdu_t *pdu = NULL;
196 coap_list_t *options = NULL;
197 coap_transport_type transport = coap_udp;
199 CAToken_t tempToken = NULL;
200 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
202 CAInfo_t requestData;
203 memset(&requestData, 0, sizeof(CAInfo_t));
204 requestData.token = tempToken;
205 requestData.tokenLength = CA_MAX_TOKEN_LEN;
206 requestData.type = CA_MSG_NONCONFIRM;
208 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
210 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
211 EXPECT_TRUE(cadata != NULL);
213 CABlockData_t *currData = CACreateNewBlockData(cadata);
214 EXPECT_TRUE(currData != NULL);
216 size_t fullPayload = 0;
217 CAPayload_t payload = CAGetPayloadFromBlockDataList(currData->blockDataId,
220 size_t payloadLen = (payload != NULL) ? strlen((const char*) payload) : 0;
221 EXPECT_TRUE(fullPayload == payloadLen);
223 CARemoveBlockDataFromList(currData->blockDataId);
224 CADestroyDataSet(cadata);
225 coap_delete_list(options);
226 coap_delete_pdu(pdu);
228 CADestroyToken(tempToken);
229 CADestroyEndpoint(tempRep);
230 free(requestData.payload);
233 // request and block option1
234 TEST_F(CABlockTransferTests, CAAddBlockOptionTest)
236 CAEndpoint_t* tempRep = NULL;
237 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
239 coap_pdu_t *pdu = NULL;
240 coap_list_t *options = NULL;
241 coap_transport_type transport = coap_udp;
243 CAToken_t tempToken = NULL;
244 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
246 CAInfo_t requestData;
247 memset(&requestData, 0, sizeof(CAInfo_t));
248 requestData.token = tempToken;
249 requestData.tokenLength = CA_MAX_TOKEN_LEN;
251 requestData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
252 if(!requestData.payload)
254 CADestroyToken(tempToken);
255 FAIL() << "requestData.payload allocation failed";
257 memset(requestData.payload, '1', sizeof(requestData.payload) - 1);
258 requestData.payloadSize = sizeof(requestData.payload);
259 requestData.type = CA_MSG_NONCONFIRM;
261 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
263 EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption(&pdu, &requestData, tempRep, &options));
265 coap_delete_list(options);
266 coap_delete_pdu(pdu);
268 CADestroyToken(tempToken);
269 CADestroyEndpoint(tempRep);
270 free(requestData.payload);
273 // request and block option1
274 TEST_F(CABlockTransferTests, CAAddBlockOption1InRequest)
276 CAEndpoint_t* tempRep = NULL;
277 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
279 coap_pdu_t *pdu = NULL;
280 coap_list_t *options = NULL;
281 coap_transport_type transport = coap_udp;
283 CAToken_t tempToken = NULL;
284 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
286 CAInfo_t requestData;
287 memset(&requestData, 0, sizeof(CAInfo_t));
288 requestData.token = tempToken;
289 requestData.tokenLength = CA_MAX_TOKEN_LEN;
291 requestData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
292 if(!requestData.payload)
294 CADestroyToken(tempToken);
295 FAIL() << "requestData.payload allocation failed";
297 memset(requestData.payload, '1', sizeof(requestData.payload) - 1);
298 requestData.payloadSize = sizeof(requestData.payload);
299 requestData.type = CA_MSG_NONCONFIRM;
301 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
303 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
304 EXPECT_TRUE(cadata != NULL);
306 CABlockData_t *currData = CACreateNewBlockData(cadata);
307 EXPECT_TRUE(currData != NULL);
309 EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
310 COAP_OPTION_BLOCK1));
312 EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &requestData,
313 requestData.payloadSize,
314 currData->blockDataId, &options));
316 CADestroyDataSet(cadata);
317 coap_delete_list(options);
318 coap_delete_pdu(pdu);
320 CADestroyToken(tempToken);
321 CADestroyEndpoint(tempRep);
322 free(requestData.payload);
325 // response and block option1
326 TEST_F(CABlockTransferTests, CAAddBlockOption1InResponse)
328 CAEndpoint_t* tempRep = NULL;
329 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
331 coap_pdu_t *pdu = NULL;
332 coap_list_t *options = NULL;
333 coap_transport_type transport = coap_udp;
335 CAToken_t tempToken = NULL;
336 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
338 CAInfo_t responseData;
339 memset(&responseData, 0, sizeof(CAInfo_t));
340 responseData.token = tempToken;
341 responseData.tokenLength = CA_MAX_TOKEN_LEN;
342 responseData.type = CA_MSG_NONCONFIRM;
343 responseData.messageId = 1;
345 responseData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
346 if(!responseData.payload)
348 CADestroyToken(tempToken);
349 FAIL() << "requestData.payload allocation failed";
351 memset(responseData.payload, '1', sizeof(responseData.payload) - 1);
352 responseData.payloadSize = sizeof(responseData.payload);
354 pdu = CAGeneratePDU(CA_CREATED, &responseData, tempRep, &options, &transport);
356 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
357 EXPECT_TRUE(cadata != NULL);
359 CABlockData_t *currData = CACreateNewBlockData(cadata);
360 EXPECT_TRUE(currData != NULL);
362 EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
363 COAP_OPTION_BLOCK1));
365 EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &responseData,
366 responseData.payloadSize,
367 currData->blockDataId, &options));
369 CADestroyDataSet(cadata);
370 coap_delete_list(options);
371 coap_delete_pdu(pdu);
373 CADestroyToken(tempToken);
374 CADestroyEndpoint(tempRep);
375 free(responseData.payload);
378 // response and block option2
379 TEST_F(CABlockTransferTests, CAAddBlockOption2InResponse)
381 CAEndpoint_t* tempRep = NULL;
382 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
384 coap_pdu_t *pdu = NULL;
385 coap_list_t *options = NULL;
386 coap_transport_type transport = coap_udp;
388 CAToken_t tempToken = NULL;
389 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
391 CAInfo_t responseData;
392 memset(&responseData, 0, sizeof(CAInfo_t));
393 responseData.token = tempToken;
394 responseData.tokenLength = CA_MAX_TOKEN_LEN;
395 responseData.type = CA_MSG_NONCONFIRM;
396 responseData.messageId = 1;
398 responseData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
399 if(!responseData.payload)
401 CADestroyToken(tempToken);
402 FAIL() << "requestData.payload allocation failed";
404 memset(responseData.payload, '1', sizeof(responseData.payload) - 1);
405 responseData.payloadSize = sizeof(responseData.payload);
407 pdu = CAGeneratePDU(CA_CREATED, &responseData, tempRep, &options, &transport);
409 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
410 EXPECT_TRUE(cadata != NULL);
412 CABlockData_t *currData = CACreateNewBlockData(cadata);
413 EXPECT_TRUE(currData != NULL);
415 EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
416 COAP_OPTION_BLOCK2));
418 EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &responseData,
419 responseData.payloadSize,
420 currData->blockDataId, &options));
422 CADestroyDataSet(cadata);
423 coap_delete_list(options);
424 coap_delete_pdu(pdu);
426 CADestroyToken(tempToken);
427 CADestroyEndpoint(tempRep);
428 free(responseData.payload);
431 // request and block option1
432 TEST_F(CABlockTransferTests, CAAddBlockOption2InRequest)
434 CAEndpoint_t* tempRep = NULL;
435 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
437 coap_pdu_t *pdu = NULL;
438 coap_list_t *options = NULL;
439 coap_transport_type transport = coap_udp;
441 CAToken_t tempToken = NULL;
442 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
444 CAInfo_t requestData;
445 memset(&requestData, 0, sizeof(CAInfo_t));
446 requestData.token = tempToken;
447 requestData.tokenLength = CA_MAX_TOKEN_LEN;
449 requestData.payload = (CAPayload_t) calloc(LARGE_PAYLOAD_LENGTH, sizeof(char));
450 if(!requestData.payload)
452 CADestroyToken(tempToken);
453 FAIL() << "requestData.payload allocation failed";
455 memset(requestData.payload, '1', sizeof(requestData.payload) - 1);
456 requestData.payloadSize = sizeof(requestData.payload);
457 requestData.type = CA_MSG_NONCONFIRM;
459 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
461 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
462 EXPECT_TRUE(cadata != NULL);
464 CABlockData_t *currData = CACreateNewBlockData(cadata);
465 EXPECT_TRUE(currData != NULL);
467 EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
468 COAP_OPTION_BLOCK2));
470 EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &requestData,
471 requestData.payloadSize,
472 currData->blockDataId, &options));
474 CARemoveBlockDataFromList(currData->blockDataId);
475 CADestroyDataSet(cadata);
476 coap_delete_list(options);
477 coap_delete_pdu(pdu);
479 CADestroyToken(tempToken);
480 CADestroyEndpoint(tempRep);
481 free(requestData.payload);
484 TEST_F(CABlockTransferTests, CAGetBlockSizeOptionFromPduTest)
486 CAEndpoint_t* tempRep = NULL;
487 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
489 coap_pdu_t *pdu = NULL;
490 coap_list_t *options = NULL;
491 coap_transport_type transport = coap_udp;
493 CAToken_t tempToken = NULL;
494 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
496 CAInfo_t requestData;
497 memset(&requestData, 0, sizeof(CAInfo_t));
498 requestData.token = tempToken;
499 requestData.tokenLength = CA_MAX_TOKEN_LEN;
500 requestData.type = CA_MSG_NONCONFIRM;
502 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
504 size_t totalPayloadLen = 0;
505 EXPECT_FALSE(CAIsPayloadLengthInPduWithBlockSizeOption(pdu, COAP_OPTION_SIZE1,
508 coap_delete_list(options);
509 coap_delete_pdu(pdu);
511 CADestroyToken(tempToken);
512 CADestroyEndpoint(tempRep);
513 free(requestData.payload);
516 TEST_F(CABlockTransferTests, CASetNextBlockOption1WithRequest)
518 CAEndpoint_t* tempRep = NULL;
519 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
521 coap_pdu_t *pdu = NULL;
522 coap_list_t *options = NULL;
523 coap_transport_type transport = coap_udp;
525 CAToken_t tempToken = NULL;
526 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
528 CAInfo_t requestData;
529 memset(&requestData, 0, sizeof(CAInfo_t));
530 requestData.token = tempToken;
531 requestData.tokenLength = CA_MAX_TOKEN_LEN;
532 requestData.type = CA_MSG_NONCONFIRM;
534 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
536 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
537 EXPECT_TRUE(cadata != NULL);
539 CABlockData_t *currData = CACreateNewBlockData(cadata);
540 EXPECT_TRUE(currData != NULL);
542 coap_block_t block = {0, 0, 0};
543 EXPECT_EQ(CA_STATUS_OK, CASetNextBlockOption1(pdu, tempRep, cadata, block, pdu->length));
545 CADestroyDataSet(cadata);
546 coap_delete_list(options);
547 coap_delete_pdu(pdu);
549 CADestroyToken(tempToken);
550 CADestroyEndpoint(tempRep);
551 free(requestData.payload);
554 TEST_F(CABlockTransferTests, CASetNextBlockOption1WithResponse)
556 CAEndpoint_t* tempRep = NULL;
557 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
559 coap_pdu_t *pdu = NULL;
560 coap_list_t *options = NULL;
561 coap_transport_type transport = coap_udp;
563 CAToken_t tempToken = NULL;
564 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
566 CAInfo_t responseData;
567 memset(&responseData, 0, sizeof(CAInfo_t));
568 responseData.token = tempToken;
569 responseData.tokenLength = CA_MAX_TOKEN_LEN;
570 responseData.type = CA_MSG_NONCONFIRM;
571 responseData.messageId = 1;
573 pdu = CAGeneratePDU(CA_CREATED, &responseData, tempRep, &options, &transport);
575 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
576 EXPECT_TRUE(cadata != NULL);
578 CABlockData_t *currData = CACreateNewBlockData(cadata);
579 EXPECT_TRUE(currData != NULL);
581 coap_block_t block = {0, 0, 0};
582 EXPECT_EQ(CA_STATUS_OK, CASetNextBlockOption1(pdu, tempRep, cadata, block, pdu->length));
584 CADestroyDataSet(cadata);
585 coap_delete_list(options);
586 coap_delete_pdu(pdu);
588 CADestroyToken(tempToken);
589 CADestroyEndpoint(tempRep);
590 free(responseData.payload);
593 TEST_F(CABlockTransferTests, CASetNextBlockOption2WithRequest)
595 CAEndpoint_t* tempRep = NULL;
596 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
598 coap_pdu_t *pdu = NULL;
599 coap_list_t *options = NULL;
600 coap_transport_type transport = coap_udp;
602 CAToken_t tempToken = NULL;
603 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
605 CAInfo_t requestData;
606 memset(&requestData, 0, sizeof(CAInfo_t));
607 requestData.token = tempToken;
608 requestData.tokenLength = CA_MAX_TOKEN_LEN;
609 requestData.type = CA_MSG_NONCONFIRM;
611 pdu = CAGeneratePDU(CA_GET, &requestData, tempRep, &options, &transport);
613 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
614 EXPECT_TRUE(cadata != NULL);
616 CABlockData_t *currData = CACreateNewBlockData(cadata);
617 EXPECT_TRUE(currData != NULL);
619 coap_block_t block = {0, 0, 0};
620 EXPECT_EQ(CA_STATUS_OK, CASetNextBlockOption2(pdu, tempRep, cadata, block, pdu->length));
622 CADestroyDataSet(cadata);
623 coap_delete_list(options);
624 coap_delete_pdu(pdu);
626 CADestroyToken(tempToken);
627 CADestroyEndpoint(tempRep);
628 free(requestData.payload);
631 TEST_F(CABlockTransferTests, CASetNextBlockOption2WithResponse)
633 CAEndpoint_t* tempRep = NULL;
634 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
636 coap_pdu_t *pdu = NULL;
637 coap_list_t *options = NULL;
638 coap_transport_type transport = coap_udp;
640 CAToken_t tempToken = NULL;
641 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
643 CAInfo_t responseData;
644 memset(&responseData, 0, sizeof(CAInfo_t));
645 responseData.token = tempToken;
646 responseData.tokenLength = CA_MAX_TOKEN_LEN;
647 responseData.type = CA_MSG_NONCONFIRM;
648 responseData.messageId = 1;
650 pdu = CAGeneratePDU(CA_CREATED, &responseData, tempRep, &options, &transport);
652 CAData_t *cadata = CACreateNewDataSet(pdu, tempRep);
653 EXPECT_TRUE(cadata != NULL);
655 CABlockData_t *currData = CACreateNewBlockData(cadata);
656 EXPECT_TRUE(currData != NULL);
658 coap_block_t block = {0, 0, 0};
659 EXPECT_EQ(CA_STATUS_OK, CASetNextBlockOption2(pdu, tempRep, cadata, block, pdu->length));
661 CADestroyDataSet(cadata);
662 coap_delete_list(options);
663 coap_delete_pdu(pdu);
665 CADestroyToken(tempToken);
666 CADestroyEndpoint(tempRep);
667 free(responseData.payload);
670 TEST_F(CABlockTransferTests, CAUpdatePayloadToCADataWithRequest)
672 CAEndpoint_t* tempRep = NULL;
673 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
675 CAToken_t tempToken = NULL;
676 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
678 CAInfo_t requestData;
679 requestData.type = CA_MSG_NONCONFIRM;
680 requestData.token = tempToken;
681 requestData.tokenLength = CA_MAX_TOKEN_LEN;
682 requestData.options = NULL;
683 requestData.payload = NULL;
684 requestData.payloadSize = 0;
686 CARequestInfo_t requestInfo;
687 requestInfo.method = CA_GET;
688 requestInfo.info = requestData;
689 requestInfo.isMulticast = false;
692 cadata.type = SEND_TYPE_UNICAST;
693 cadata.remoteEndpoint = tempRep;
694 cadata.requestInfo = &requestInfo;
695 cadata.dataType = CA_REQUEST_DATA;
697 CAPayload_t payload = (CAPayload_t) "requestPayload";
698 size_t payloadLen = strlen((const char*) payload) + 1;
700 EXPECT_EQ(CA_STATUS_OK, CAUpdatePayloadToCAData(&cadata, payload, payloadLen));
702 EXPECT_STREQ((const char*) payload, (const char*) cadata.requestInfo->info.payload);
705 TEST_F(CABlockTransferTests, CAUpdatePayloadToCADataWithResponse)
707 CAEndpoint_t* tempRep = NULL;
708 CACreateEndpoint(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, "127.0.0.1", 5683, &tempRep);
710 CAToken_t tempToken = NULL;
711 CAGenerateToken(&tempToken, CA_MAX_TOKEN_LEN);
713 CAInfo_t responseData;
714 responseData.type = CA_MSG_NONCONFIRM;
715 responseData.token = tempToken;
716 responseData.tokenLength = CA_MAX_TOKEN_LEN;
717 responseData.options = NULL;
718 responseData.payload = NULL;
719 responseData.payloadSize = 0;
721 CAResponseInfo_t responseInfo;
722 responseInfo.result = CA_VALID;
723 responseInfo.info = responseData;
726 cadata.type = SEND_TYPE_UNICAST;
727 cadata.remoteEndpoint = tempRep;
728 cadata.responseInfo = &responseInfo;
729 cadata.dataType = CA_RESPONSE_DATA;
731 CAPayload_t payload = (CAPayload_t) "responsePayload";
732 size_t payloadLen = strlen((const char*) payload) + 1;
734 EXPECT_EQ(CA_STATUS_OK, CAUpdatePayloadToCAData(&cadata, payload, payloadLen));
736 EXPECT_STREQ((const char*) payload, (const char*) cadata.responseInfo->info.payload);