Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/m2mblockmessage/test_m2mblockmessage.cpp@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | #include "CppUTest/TestHarness.h" |
ram54288 | 0:a7a43371b306 | 17 | #include "test_m2mblockmessage.h" |
ram54288 | 0:a7a43371b306 | 18 | #include "sn_coap_header.h" |
ram54288 | 0:a7a43371b306 | 19 | #include <string.h> |
ram54288 | 0:a7a43371b306 | 20 | Test_M2MBlockMessage::Test_M2MBlockMessage() |
ram54288 | 0:a7a43371b306 | 21 | { |
ram54288 | 0:a7a43371b306 | 22 | block_message = new M2MBlockMessage(); |
ram54288 | 0:a7a43371b306 | 23 | } |
ram54288 | 0:a7a43371b306 | 24 | |
ram54288 | 0:a7a43371b306 | 25 | Test_M2MBlockMessage::~Test_M2MBlockMessage() |
ram54288 | 0:a7a43371b306 | 26 | { |
ram54288 | 0:a7a43371b306 | 27 | delete block_message; |
ram54288 | 0:a7a43371b306 | 28 | } |
ram54288 | 0:a7a43371b306 | 29 | |
ram54288 | 0:a7a43371b306 | 30 | void Test_M2MBlockMessage::test_set_message_info() |
ram54288 | 0:a7a43371b306 | 31 | { |
ram54288 | 0:a7a43371b306 | 32 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 33 | memset(coap_header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 34 | block_message->set_message_info(NULL); |
ram54288 | 0:a7a43371b306 | 35 | CHECK(block_message->is_block_message() == false); |
ram54288 | 0:a7a43371b306 | 36 | CHECK(block_message->total_message_size() == 0); |
ram54288 | 0:a7a43371b306 | 37 | |
ram54288 | 0:a7a43371b306 | 38 | coap_header->options_list_ptr = (sn_coap_options_list_s *)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 39 | memset(coap_header->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 40 | coap_header->options_list_ptr->size1 = 0xffff; |
ram54288 | 0:a7a43371b306 | 41 | coap_header->options_list_ptr->use_size1 = true; |
ram54288 | 0:a7a43371b306 | 42 | coap_header->options_list_ptr->block1 = -1; |
ram54288 | 0:a7a43371b306 | 43 | |
ram54288 | 0:a7a43371b306 | 44 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 45 | CHECK(block_message->total_message_size() == 0xffff); |
ram54288 | 0:a7a43371b306 | 46 | CHECK(!block_message->is_block_message()); |
ram54288 | 0:a7a43371b306 | 47 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 48 | |
ram54288 | 0:a7a43371b306 | 49 | coap_header->options_list_ptr->size1 = 0xffffff; |
ram54288 | 0:a7a43371b306 | 50 | |
ram54288 | 0:a7a43371b306 | 51 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 52 | CHECK(block_message->error_code() == M2MBlockMessage::EntityTooLarge); |
ram54288 | 0:a7a43371b306 | 53 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 54 | |
ram54288 | 0:a7a43371b306 | 55 | coap_header->options_list_ptr->size1 = 0xffff; |
ram54288 | 0:a7a43371b306 | 56 | coap_header->options_list_ptr->block1 = 0x010101; |
ram54288 | 0:a7a43371b306 | 57 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 58 | CHECK(block_message->is_block_message()); |
ram54288 | 0:a7a43371b306 | 59 | CHECK(block_message->block_number() == 4112); |
ram54288 | 0:a7a43371b306 | 60 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 61 | |
ram54288 | 0:a7a43371b306 | 62 | coap_header->options_list_ptr->block1 = 0x0101; |
ram54288 | 0:a7a43371b306 | 63 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 64 | CHECK(block_message->is_block_message()); |
ram54288 | 0:a7a43371b306 | 65 | CHECK(block_message->block_number() == 16); |
ram54288 | 0:a7a43371b306 | 66 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 67 | |
ram54288 | 0:a7a43371b306 | 68 | coap_header->options_list_ptr->block1 = 0x01; |
ram54288 | 0:a7a43371b306 | 69 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 70 | CHECK(block_message->is_block_message()); |
ram54288 | 0:a7a43371b306 | 71 | CHECK(block_message->block_number() == 0); |
ram54288 | 0:a7a43371b306 | 72 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 73 | |
ram54288 | 0:a7a43371b306 | 74 | coap_header->options_list_ptr->block1 = 0x010108; |
ram54288 | 0:a7a43371b306 | 75 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 76 | CHECK(!block_message->is_last_block()); |
ram54288 | 0:a7a43371b306 | 77 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 78 | |
ram54288 | 0:a7a43371b306 | 79 | coap_header->payload_len = 10; |
ram54288 | 0:a7a43371b306 | 80 | coap_header->payload_ptr = (uint8_t *)malloc(10); |
ram54288 | 0:a7a43371b306 | 81 | memset(coap_header->payload_ptr, 'x', 10); |
ram54288 | 0:a7a43371b306 | 82 | block_message->set_message_info(coap_header); |
ram54288 | 0:a7a43371b306 | 83 | CHECK(!block_message->is_last_block()); |
ram54288 | 0:a7a43371b306 | 84 | CHECK(block_message->block_data_len() == 10); |
ram54288 | 0:a7a43371b306 | 85 | CHECK(memcmp(coap_header->payload_ptr, block_message->block_data(),10) == 0); |
ram54288 | 0:a7a43371b306 | 86 | block_message->clear_values(); |
ram54288 | 0:a7a43371b306 | 87 | |
ram54288 | 0:a7a43371b306 | 88 | free(coap_header->payload_ptr); |
ram54288 | 0:a7a43371b306 | 89 | free(coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 90 | free(coap_header); |
ram54288 | 0:a7a43371b306 | 91 | } |