![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/m2mobject/test_m2mobject.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_m2mobject.h" |
ram54288 | 0:a7a43371b306 | 18 | #include "m2mobjectinstance_stub.h" |
ram54288 | 0:a7a43371b306 | 19 | #include "m2mresource_stub.h" |
ram54288 | 0:a7a43371b306 | 20 | #include "m2mbase_stub.h" |
ram54288 | 0:a7a43371b306 | 21 | #include "common_stub.h" |
ram54288 | 0:a7a43371b306 | 22 | #include "m2mtlvdeserializer_stub.h" |
ram54288 | 0:a7a43371b306 | 23 | #include "m2mtlvserializer_stub.h" |
ram54288 | 0:a7a43371b306 | 24 | #include "m2mreporthandler_stub.h" |
ram54288 | 0:a7a43371b306 | 25 | #include "nsdlaccesshelper_stub.h" |
ram54288 | 0:a7a43371b306 | 26 | |
ram54288 | 0:a7a43371b306 | 27 | class TestReportObserver : public M2MReportObserver{ |
ram54288 | 0:a7a43371b306 | 28 | public : |
ram54288 | 0:a7a43371b306 | 29 | TestReportObserver() {} |
ram54288 | 0:a7a43371b306 | 30 | ~TestReportObserver() {} |
ram54288 | 0:a7a43371b306 | 31 | void observation_to_be_sent(m2m::Vector<uint16_t>,bool){ } |
ram54288 | 0:a7a43371b306 | 32 | }; |
ram54288 | 0:a7a43371b306 | 33 | |
ram54288 | 0:a7a43371b306 | 34 | class Handler : public M2MObservationHandler { |
ram54288 | 0:a7a43371b306 | 35 | |
ram54288 | 0:a7a43371b306 | 36 | public: |
ram54288 | 0:a7a43371b306 | 37 | |
ram54288 | 0:a7a43371b306 | 38 | Handler(){} |
ram54288 | 0:a7a43371b306 | 39 | ~Handler(){} |
ram54288 | 0:a7a43371b306 | 40 | void observation_to_be_sent(M2MBase *, uint16_t, m2m::Vector<uint16_t>,bool){ |
ram54288 | 0:a7a43371b306 | 41 | visited = true; |
ram54288 | 0:a7a43371b306 | 42 | } |
ram54288 | 0:a7a43371b306 | 43 | void send_delayed_response(M2MBase *){} |
ram54288 | 0:a7a43371b306 | 44 | void resource_to_be_deleted(M2MBase *){visited=true;} |
ram54288 | 0:a7a43371b306 | 45 | void remove_object(M2MBase *){visited = true;} |
ram54288 | 0:a7a43371b306 | 46 | void value_updated(M2MBase *,const String&){visited = true;} |
ram54288 | 0:a7a43371b306 | 47 | |
ram54288 | 0:a7a43371b306 | 48 | void clear() {visited = false;} |
ram54288 | 0:a7a43371b306 | 49 | bool visited; |
ram54288 | 0:a7a43371b306 | 50 | }; |
ram54288 | 0:a7a43371b306 | 51 | |
ram54288 | 0:a7a43371b306 | 52 | Test_M2MObject::Test_M2MObject() |
ram54288 | 0:a7a43371b306 | 53 | { |
ram54288 | 0:a7a43371b306 | 54 | handler = new Handler(); |
ram54288 | 0:a7a43371b306 | 55 | object = new M2MObject("name", "name"); |
ram54288 | 0:a7a43371b306 | 56 | } |
ram54288 | 0:a7a43371b306 | 57 | |
ram54288 | 0:a7a43371b306 | 58 | Test_M2MObject::~Test_M2MObject() |
ram54288 | 0:a7a43371b306 | 59 | { |
ram54288 | 0:a7a43371b306 | 60 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:a7a43371b306 | 61 | m2mresource_stub::clear(); |
ram54288 | 0:a7a43371b306 | 62 | m2mbase_stub::clear(); |
ram54288 | 0:a7a43371b306 | 63 | m2mtlvdeserializer_stub::clear(); |
ram54288 | 0:a7a43371b306 | 64 | m2mtlvserializer_stub::clear(); |
ram54288 | 0:a7a43371b306 | 65 | delete object; |
ram54288 | 0:a7a43371b306 | 66 | delete handler; |
ram54288 | 0:a7a43371b306 | 67 | } |
ram54288 | 0:a7a43371b306 | 68 | |
ram54288 | 0:a7a43371b306 | 69 | void Test_M2MObject::test_ctor() |
ram54288 | 0:a7a43371b306 | 70 | { |
ram54288 | 0:a7a43371b306 | 71 | M2MObject *object = new M2MObject(¶ms); |
ram54288 | 0:a7a43371b306 | 72 | delete object; |
ram54288 | 0:a7a43371b306 | 73 | } |
ram54288 | 0:a7a43371b306 | 74 | |
ram54288 | 0:a7a43371b306 | 75 | void Test_M2MObject::test_create_object_instance() |
ram54288 | 0:a7a43371b306 | 76 | { |
ram54288 | 0:a7a43371b306 | 77 | m2mbase_stub::name_id_value = 1; |
ram54288 | 0:a7a43371b306 | 78 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 79 | CHECK(object->create_object_instance() != NULL); |
ram54288 | 0:a7a43371b306 | 80 | CHECK(object->create_object_instance(¶ms) != NULL); |
ram54288 | 0:a7a43371b306 | 81 | } |
ram54288 | 0:a7a43371b306 | 82 | |
ram54288 | 0:a7a43371b306 | 83 | void Test_M2MObject::test_remove_object_instance() |
ram54288 | 0:a7a43371b306 | 84 | { |
ram54288 | 0:a7a43371b306 | 85 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 86 | |
ram54288 | 0:a7a43371b306 | 87 | M2MObjectInstance *ins = new M2MObjectInstance(*object,"name","type", ""); |
ram54288 | 0:a7a43371b306 | 88 | object->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 89 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 90 | |
ram54288 | 0:a7a43371b306 | 91 | CHECK(true == object->remove_object_instance(0)); |
ram54288 | 0:a7a43371b306 | 92 | |
ram54288 | 0:a7a43371b306 | 93 | CHECK(false == object->remove_object_instance(0)); |
ram54288 | 0:a7a43371b306 | 94 | } |
ram54288 | 0:a7a43371b306 | 95 | |
ram54288 | 0:a7a43371b306 | 96 | void Test_M2MObject::test_object_instance() |
ram54288 | 0:a7a43371b306 | 97 | { |
ram54288 | 0:a7a43371b306 | 98 | M2MObjectInstance *ins = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 99 | object->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 100 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 101 | |
ram54288 | 0:a7a43371b306 | 102 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 103 | |
ram54288 | 0:a7a43371b306 | 104 | M2MObjectInstance *obj = object->object_instance(0); |
ram54288 | 0:a7a43371b306 | 105 | |
ram54288 | 0:a7a43371b306 | 106 | CHECK(obj != NULL); |
ram54288 | 0:a7a43371b306 | 107 | STRCMP_EQUAL(obj->name(), "name"); |
ram54288 | 0:a7a43371b306 | 108 | //CHECK(0 == obj->name().compare(0,test->size(),*test)); |
ram54288 | 0:a7a43371b306 | 109 | } |
ram54288 | 0:a7a43371b306 | 110 | |
ram54288 | 0:a7a43371b306 | 111 | void Test_M2MObject::test_instances() |
ram54288 | 0:a7a43371b306 | 112 | { |
ram54288 | 0:a7a43371b306 | 113 | |
ram54288 | 0:a7a43371b306 | 114 | M2MObjectInstance *ins = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 115 | ins->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 116 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 117 | |
ram54288 | 0:a7a43371b306 | 118 | M2MObjectInstance *ins1 = new M2MObjectInstance(*object, "name","type", ""); |
ram54288 | 0:a7a43371b306 | 119 | ins1->set_instance_id(1); |
ram54288 | 0:a7a43371b306 | 120 | object->_instance_list.push_back(ins1); |
ram54288 | 0:a7a43371b306 | 121 | |
ram54288 | 0:a7a43371b306 | 122 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 123 | |
ram54288 | 0:a7a43371b306 | 124 | M2MObjectInstanceList list = object->instances(); |
ram54288 | 0:a7a43371b306 | 125 | |
ram54288 | 0:a7a43371b306 | 126 | M2MObjectInstance *obj = list[0]; |
ram54288 | 0:a7a43371b306 | 127 | CHECK(2 == list.size()); |
ram54288 | 0:a7a43371b306 | 128 | STRCMP_EQUAL(obj->name(), "name"); |
ram54288 | 0:a7a43371b306 | 129 | //CHECK(0 == obj->name().compare(0,test->size(),*test)); |
ram54288 | 0:a7a43371b306 | 130 | } |
ram54288 | 0:a7a43371b306 | 131 | |
ram54288 | 0:a7a43371b306 | 132 | void Test_M2MObject::test_instance_count() |
ram54288 | 0:a7a43371b306 | 133 | { |
ram54288 | 0:a7a43371b306 | 134 | M2MObjectInstance *ins = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 135 | object->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 136 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 137 | |
ram54288 | 0:a7a43371b306 | 138 | M2MObjectInstance *ins1 = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 139 | object->set_instance_id(1); |
ram54288 | 0:a7a43371b306 | 140 | object->_instance_list.push_back(ins1); |
ram54288 | 0:a7a43371b306 | 141 | |
ram54288 | 0:a7a43371b306 | 142 | CHECK(2 == object->instance_count()); |
ram54288 | 0:a7a43371b306 | 143 | |
ram54288 | 0:a7a43371b306 | 144 | object->_instance_list.clear(); |
ram54288 | 0:a7a43371b306 | 145 | delete ins; |
ram54288 | 0:a7a43371b306 | 146 | delete ins1; |
ram54288 | 0:a7a43371b306 | 147 | } |
ram54288 | 0:a7a43371b306 | 148 | |
ram54288 | 0:a7a43371b306 | 149 | void Test_M2MObject::test_base_type() |
ram54288 | 0:a7a43371b306 | 150 | { |
ram54288 | 0:a7a43371b306 | 151 | CHECK(M2MBase::Object == object->base_type()); |
ram54288 | 0:a7a43371b306 | 152 | } |
ram54288 | 0:a7a43371b306 | 153 | |
ram54288 | 0:a7a43371b306 | 154 | void Test_M2MObject::test_handle_get_request() |
ram54288 | 0:a7a43371b306 | 155 | { |
ram54288 | 0:a7a43371b306 | 156 | M2MObjectInstance *ins = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 157 | object->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 158 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 159 | |
ram54288 | 0:a7a43371b306 | 160 | uint8_t value[] = {"name"}; |
ram54288 | 0:a7a43371b306 | 161 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 162 | memset(coap_header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 163 | |
ram54288 | 0:a7a43371b306 | 164 | coap_header->uri_path_ptr = value; |
ram54288 | 0:a7a43371b306 | 165 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:a7a43371b306 | 166 | |
ram54288 | 0:a7a43371b306 | 167 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_GET; |
ram54288 | 0:a7a43371b306 | 168 | |
ram54288 | 0:a7a43371b306 | 169 | common_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 170 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 171 | |
ram54288 | 0:a7a43371b306 | 172 | m2mbase_stub::operation = M2MBase::GET_ALLOWED; |
ram54288 | 0:a7a43371b306 | 173 | m2mbase_stub::uint8_value = 200; |
ram54288 | 0:a7a43371b306 | 174 | |
ram54288 | 0:a7a43371b306 | 175 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 176 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 177 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 178 | m2mtlvserializer_stub::uint8_value = (uint8_t*)malloc(1); |
ram54288 | 0:a7a43371b306 | 179 | |
ram54288 | 0:a7a43371b306 | 180 | coap_header->token_ptr = (uint8_t*)malloc(sizeof(value)); |
ram54288 | 0:a7a43371b306 | 181 | memcpy(coap_header->token_ptr, value, sizeof(value)); |
ram54288 | 0:a7a43371b306 | 182 | |
ram54288 | 0:a7a43371b306 | 183 | coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 184 | coap_header->options_list_ptr->observe = 0; |
ram54288 | 0:a7a43371b306 | 185 | |
ram54288 | 0:a7a43371b306 | 186 | coap_header->content_format = sn_coap_content_format_e(110); |
ram54288 | 0:a7a43371b306 | 187 | |
ram54288 | 0:a7a43371b306 | 188 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 189 | |
ram54288 | 0:a7a43371b306 | 190 | // Not OMA TLV or JSON |
ram54288 | 0:a7a43371b306 | 191 | m2mbase_stub::uint8_value = 110; |
ram54288 | 0:a7a43371b306 | 192 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 193 | |
ram54288 | 0:a7a43371b306 | 194 | // Content type set CT_NONE |
ram54288 | 0:a7a43371b306 | 195 | m2mbase_stub::uint8_value = 99; |
ram54288 | 0:a7a43371b306 | 196 | coap_header->content_format = sn_coap_content_format_e(-1); |
ram54288 | 0:a7a43371b306 | 197 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 198 | |
ram54288 | 0:a7a43371b306 | 199 | common_stub::coap_header->content_format = sn_coap_content_format_e(-1); // CT_NONE |
ram54288 | 0:a7a43371b306 | 200 | m2mbase_stub::uint8_value = 100; |
ram54288 | 0:a7a43371b306 | 201 | coap_header->content_format = sn_coap_content_format_e(-1); |
ram54288 | 0:a7a43371b306 | 202 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 203 | |
ram54288 | 0:a7a43371b306 | 204 | // OMA TLV |
ram54288 | 0:a7a43371b306 | 205 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:a7a43371b306 | 206 | m2mbase_stub::uint8_value = 99; |
ram54288 | 0:a7a43371b306 | 207 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 208 | |
ram54288 | 0:a7a43371b306 | 209 | // OMA JSON |
ram54288 | 0:a7a43371b306 | 210 | coap_header->content_format = sn_coap_content_format_e(100); |
ram54288 | 0:a7a43371b306 | 211 | m2mbase_stub::uint8_value = 100; |
ram54288 | 0:a7a43371b306 | 212 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 213 | |
ram54288 | 0:a7a43371b306 | 214 | coap_header->options_list_ptr->observe = 0; |
ram54288 | 0:a7a43371b306 | 215 | m2mbase_stub::uint16_value = 0x1c1c; |
ram54288 | 0:a7a43371b306 | 216 | m2mbase_stub::uint8_value = 99; |
ram54288 | 0:a7a43371b306 | 217 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 218 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:a7a43371b306 | 219 | |
ram54288 | 0:a7a43371b306 | 220 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 221 | |
ram54288 | 0:a7a43371b306 | 222 | m2mbase_stub::uint16_value = 10; |
ram54288 | 0:a7a43371b306 | 223 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 224 | |
ram54288 | 0:a7a43371b306 | 225 | // Not observable |
ram54288 | 0:a7a43371b306 | 226 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 227 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 228 | |
ram54288 | 0:a7a43371b306 | 229 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 230 | coap_header->options_list_ptr->observe = 0; |
ram54288 | 0:a7a43371b306 | 231 | |
ram54288 | 0:a7a43371b306 | 232 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 233 | |
ram54288 | 0:a7a43371b306 | 234 | coap_header->options_list_ptr->observe = 1; |
ram54288 | 0:a7a43371b306 | 235 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 236 | |
ram54288 | 0:a7a43371b306 | 237 | m2mbase_stub::operation = M2MBase::NOT_ALLOWED; |
ram54288 | 0:a7a43371b306 | 238 | CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 239 | |
ram54288 | 0:a7a43371b306 | 240 | CHECK(object->handle_get_request(NULL,NULL,handler) != NULL); |
ram54288 | 0:a7a43371b306 | 241 | |
ram54288 | 0:a7a43371b306 | 242 | if(coap_header->token_ptr) { |
ram54288 | 0:a7a43371b306 | 243 | free(coap_header->token_ptr); |
ram54288 | 0:a7a43371b306 | 244 | coap_header->token_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 245 | } |
ram54288 | 0:a7a43371b306 | 246 | if(coap_header->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 247 | free(coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 248 | coap_header->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 249 | } |
ram54288 | 0:a7a43371b306 | 250 | |
ram54288 | 0:a7a43371b306 | 251 | if(common_stub::coap_header){ |
ram54288 | 0:a7a43371b306 | 252 | if(common_stub::coap_header->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 253 | free(common_stub::coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 254 | common_stub::coap_header->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 255 | } |
ram54288 | 0:a7a43371b306 | 256 | free(common_stub::coap_header); |
ram54288 | 0:a7a43371b306 | 257 | common_stub::coap_header = NULL; |
ram54288 | 0:a7a43371b306 | 258 | } |
ram54288 | 0:a7a43371b306 | 259 | free(coap_header); |
ram54288 | 0:a7a43371b306 | 260 | coap_header = NULL; |
ram54288 | 0:a7a43371b306 | 261 | |
ram54288 | 0:a7a43371b306 | 262 | if(m2mtlvserializer_stub::uint8_value) { |
ram54288 | 0:a7a43371b306 | 263 | free(m2mtlvserializer_stub::uint8_value); |
ram54288 | 0:a7a43371b306 | 264 | } |
ram54288 | 0:a7a43371b306 | 265 | m2mtlvserializer_stub::clear(); |
ram54288 | 0:a7a43371b306 | 266 | |
ram54288 | 0:a7a43371b306 | 267 | m2mbase_stub::clear(); |
ram54288 | 0:a7a43371b306 | 268 | common_stub::clear(); |
ram54288 | 0:a7a43371b306 | 269 | |
ram54288 | 0:a7a43371b306 | 270 | object->_instance_list.clear(); |
ram54288 | 0:a7a43371b306 | 271 | delete ins; |
ram54288 | 0:a7a43371b306 | 272 | } |
ram54288 | 0:a7a43371b306 | 273 | |
ram54288 | 0:a7a43371b306 | 274 | void Test_M2MObject::test_handle_put_request() |
ram54288 | 0:a7a43371b306 | 275 | { |
ram54288 | 0:a7a43371b306 | 276 | uint8_t value[] = {"name"}; |
ram54288 | 0:a7a43371b306 | 277 | bool execute_value_updated = false; |
ram54288 | 0:a7a43371b306 | 278 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 279 | memset(coap_header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 280 | sn_coap_hdr_s * coap_response = NULL; |
ram54288 | 0:a7a43371b306 | 281 | |
ram54288 | 0:a7a43371b306 | 282 | coap_header->uri_path_ptr = value; |
ram54288 | 0:a7a43371b306 | 283 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:a7a43371b306 | 284 | |
ram54288 | 0:a7a43371b306 | 285 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
ram54288 | 0:a7a43371b306 | 286 | |
ram54288 | 0:a7a43371b306 | 287 | common_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 288 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 289 | |
ram54288 | 0:a7a43371b306 | 290 | m2mbase_stub::operation = M2MBase::PUT_ALLOWED; |
ram54288 | 0:a7a43371b306 | 291 | m2mbase_stub::uint8_value = 200; |
ram54288 | 0:a7a43371b306 | 292 | |
ram54288 | 0:a7a43371b306 | 293 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 294 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 295 | |
ram54288 | 0:a7a43371b306 | 296 | coap_header->payload_ptr = (uint8_t*)malloc(1); |
ram54288 | 0:a7a43371b306 | 297 | |
ram54288 | 0:a7a43371b306 | 298 | CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 299 | free(coap_header->payload_ptr); |
ram54288 | 0:a7a43371b306 | 300 | coap_header->payload_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 301 | |
ram54288 | 0:a7a43371b306 | 302 | CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 303 | |
ram54288 | 0:a7a43371b306 | 304 | coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 305 | coap_header->options_list_ptr->uri_query_ptr = value; |
ram54288 | 0:a7a43371b306 | 306 | coap_header->options_list_ptr->uri_query_len = sizeof(value); |
ram54288 | 0:a7a43371b306 | 307 | |
ram54288 | 0:a7a43371b306 | 308 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:a7a43371b306 | 309 | m2mtlvdeserializer_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 310 | |
ram54288 | 0:a7a43371b306 | 311 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 312 | |
ram54288 | 0:a7a43371b306 | 313 | CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 314 | |
ram54288 | 0:a7a43371b306 | 315 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 316 | |
ram54288 | 0:a7a43371b306 | 317 | CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 318 | |
ram54288 | 0:a7a43371b306 | 319 | coap_header->content_format = sn_coap_content_format_e(100); |
ram54288 | 0:a7a43371b306 | 320 | |
ram54288 | 0:a7a43371b306 | 321 | CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 322 | |
ram54288 | 0:a7a43371b306 | 323 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 324 | |
ram54288 | 0:a7a43371b306 | 325 | CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 326 | |
ram54288 | 0:a7a43371b306 | 327 | m2mbase_stub::operation = M2MBase::NOT_ALLOWED; |
ram54288 | 0:a7a43371b306 | 328 | |
ram54288 | 0:a7a43371b306 | 329 | CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 330 | |
ram54288 | 0:a7a43371b306 | 331 | CHECK(object->handle_put_request(NULL,NULL,handler, execute_value_updated) != NULL); |
ram54288 | 0:a7a43371b306 | 332 | |
ram54288 | 0:a7a43371b306 | 333 | m2mbase_stub::operation = M2MBase::PUT_ALLOWED; |
ram54288 | 0:a7a43371b306 | 334 | |
ram54288 | 0:a7a43371b306 | 335 | free(coap_header->payload_ptr); |
ram54288 | 0:a7a43371b306 | 336 | coap_header->payload_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 337 | coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 338 | CHECK(coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 339 | CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_CHANGED); |
ram54288 | 0:a7a43371b306 | 340 | |
ram54288 | 0:a7a43371b306 | 341 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 342 | coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 343 | CHECK(coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 344 | CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_BAD_REQUEST); |
ram54288 | 0:a7a43371b306 | 345 | |
ram54288 | 0:a7a43371b306 | 346 | free(coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 347 | coap_header->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 348 | coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 349 | CHECK(coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 350 | CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_BAD_REQUEST); |
ram54288 | 0:a7a43371b306 | 351 | |
ram54288 | 0:a7a43371b306 | 352 | free(coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 353 | free(common_stub::coap_header); |
ram54288 | 0:a7a43371b306 | 354 | free(coap_header); |
ram54288 | 0:a7a43371b306 | 355 | |
ram54288 | 0:a7a43371b306 | 356 | m2mtlvdeserializer_stub::clear(); |
ram54288 | 0:a7a43371b306 | 357 | common_stub::clear(); |
ram54288 | 0:a7a43371b306 | 358 | m2mbase_stub::clear(); |
ram54288 | 0:a7a43371b306 | 359 | } |
ram54288 | 0:a7a43371b306 | 360 | |
ram54288 | 0:a7a43371b306 | 361 | void Test_M2MObject::test_handle_post_request() |
ram54288 | 0:a7a43371b306 | 362 | { |
ram54288 | 0:a7a43371b306 | 363 | uint8_t value[] = {"name"}; |
ram54288 | 0:a7a43371b306 | 364 | bool execute_value_updated = false; |
ram54288 | 0:a7a43371b306 | 365 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 366 | memset(coap_header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:a7a43371b306 | 367 | |
ram54288 | 0:a7a43371b306 | 368 | coap_header->uri_path_ptr = value; |
ram54288 | 0:a7a43371b306 | 369 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:a7a43371b306 | 370 | |
ram54288 | 0:a7a43371b306 | 371 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:a7a43371b306 | 372 | |
ram54288 | 0:a7a43371b306 | 373 | common_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 374 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:a7a43371b306 | 375 | |
ram54288 | 0:a7a43371b306 | 376 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 377 | m2mbase_stub::uint8_value = 200; |
ram54288 | 0:a7a43371b306 | 378 | |
ram54288 | 0:a7a43371b306 | 379 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 380 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:a7a43371b306 | 381 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 382 | |
ram54288 | 0:a7a43371b306 | 383 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 384 | |
ram54288 | 0:a7a43371b306 | 385 | sn_coap_hdr_s * coap_response = NULL; |
ram54288 | 0:a7a43371b306 | 386 | m2mbase_stub::uint8_value = 99; |
ram54288 | 0:a7a43371b306 | 387 | |
ram54288 | 0:a7a43371b306 | 388 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 389 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 390 | |
ram54288 | 0:a7a43371b306 | 391 | |
ram54288 | 0:a7a43371b306 | 392 | m2mbase_stub::uint8_value = 100; |
ram54288 | 0:a7a43371b306 | 393 | |
ram54288 | 0:a7a43371b306 | 394 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 395 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 396 | |
ram54288 | 0:a7a43371b306 | 397 | coap_header->payload_ptr = (uint8_t*)malloc(1); |
ram54288 | 0:a7a43371b306 | 398 | |
ram54288 | 0:a7a43371b306 | 399 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 400 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 401 | |
ram54288 | 0:a7a43371b306 | 402 | m2mbase_stub::uint8_value = 99; |
ram54288 | 0:a7a43371b306 | 403 | |
ram54288 | 0:a7a43371b306 | 404 | object->_max_instance_count = 0; |
ram54288 | 0:a7a43371b306 | 405 | |
ram54288 | 0:a7a43371b306 | 406 | M2MObjectInstance *ins = new M2MObjectInstance(*object, "name", "type", ""); |
ram54288 | 0:a7a43371b306 | 407 | ins->set_instance_id(0); |
ram54288 | 0:a7a43371b306 | 408 | object->_instance_list.push_back(ins); |
ram54288 | 0:a7a43371b306 | 409 | coap_header->content_format = sn_coap_content_format_e(-1); |
ram54288 | 0:a7a43371b306 | 410 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 411 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 412 | |
ram54288 | 0:a7a43371b306 | 413 | object->remove_object_instance(0); |
ram54288 | 0:a7a43371b306 | 414 | |
ram54288 | 0:a7a43371b306 | 415 | |
ram54288 | 0:a7a43371b306 | 416 | object->_max_instance_count = 65535; |
ram54288 | 0:a7a43371b306 | 417 | |
ram54288 | 0:a7a43371b306 | 418 | m2mbase_stub::uint8_value = 0; |
ram54288 | 0:a7a43371b306 | 419 | |
ram54288 | 0:a7a43371b306 | 420 | coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:a7a43371b306 | 421 | coap_header->options_list_ptr->uri_query_ptr = value; |
ram54288 | 0:a7a43371b306 | 422 | coap_header->options_list_ptr->uri_query_len = sizeof(value); |
ram54288 | 0:a7a43371b306 | 423 | |
ram54288 | 0:a7a43371b306 | 424 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:a7a43371b306 | 425 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:a7a43371b306 | 426 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 427 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 428 | |
ram54288 | 0:a7a43371b306 | 429 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; |
ram54288 | 0:a7a43371b306 | 430 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 431 | |
ram54288 | 0:a7a43371b306 | 432 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 433 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 434 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 435 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 436 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 437 | } |
ram54288 | 0:a7a43371b306 | 438 | // if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 439 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 440 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 441 | // } |
ram54288 | 0:a7a43371b306 | 442 | } |
ram54288 | 0:a7a43371b306 | 443 | |
ram54288 | 0:a7a43371b306 | 444 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 445 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:a7a43371b306 | 446 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 447 | m2mtlvdeserializer_stub::int_value = 10; |
ram54288 | 0:a7a43371b306 | 448 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 449 | |
ram54288 | 0:a7a43371b306 | 450 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::NotAllowed; |
ram54288 | 0:a7a43371b306 | 451 | |
ram54288 | 0:a7a43371b306 | 452 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 453 | |
ram54288 | 0:a7a43371b306 | 454 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 455 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 456 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 457 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 458 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 459 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 460 | } |
ram54288 | 0:a7a43371b306 | 461 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 462 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 463 | } |
ram54288 | 0:a7a43371b306 | 464 | } |
ram54288 | 0:a7a43371b306 | 465 | |
ram54288 | 0:a7a43371b306 | 466 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 467 | m2mtlvdeserializer_stub::is_object_bool_value = false; |
ram54288 | 0:a7a43371b306 | 468 | m2mtlvdeserializer_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 469 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 470 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; |
ram54288 | 0:a7a43371b306 | 471 | |
ram54288 | 0:a7a43371b306 | 472 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 473 | |
ram54288 | 0:a7a43371b306 | 474 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 475 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 476 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 477 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 478 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 479 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 480 | } |
ram54288 | 0:a7a43371b306 | 481 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 482 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 483 | } |
ram54288 | 0:a7a43371b306 | 484 | } |
ram54288 | 0:a7a43371b306 | 485 | |
ram54288 | 0:a7a43371b306 | 486 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 487 | m2mtlvdeserializer_stub::is_object_bool_value = false; |
ram54288 | 0:a7a43371b306 | 488 | m2mtlvdeserializer_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 489 | m2mbase_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 490 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::NotFound; |
ram54288 | 0:a7a43371b306 | 491 | |
ram54288 | 0:a7a43371b306 | 492 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 493 | |
ram54288 | 0:a7a43371b306 | 494 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 495 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 496 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 497 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 498 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 499 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 500 | } |
ram54288 | 0:a7a43371b306 | 501 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 502 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 503 | } |
ram54288 | 0:a7a43371b306 | 504 | } |
ram54288 | 0:a7a43371b306 | 505 | |
ram54288 | 0:a7a43371b306 | 506 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 507 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 508 | |
ram54288 | 0:a7a43371b306 | 509 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 510 | |
ram54288 | 0:a7a43371b306 | 511 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 512 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 513 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 514 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 515 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 516 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 517 | } |
ram54288 | 0:a7a43371b306 | 518 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 519 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 520 | } |
ram54288 | 0:a7a43371b306 | 521 | } |
ram54288 | 0:a7a43371b306 | 522 | |
ram54288 | 0:a7a43371b306 | 523 | |
ram54288 | 0:a7a43371b306 | 524 | coap_header->content_format = sn_coap_content_format_e(100); |
ram54288 | 0:a7a43371b306 | 525 | |
ram54288 | 0:a7a43371b306 | 526 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 527 | |
ram54288 | 0:a7a43371b306 | 528 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 529 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 530 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 531 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 532 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 533 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 534 | } |
ram54288 | 0:a7a43371b306 | 535 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 536 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 537 | } |
ram54288 | 0:a7a43371b306 | 538 | } |
ram54288 | 0:a7a43371b306 | 539 | |
ram54288 | 0:a7a43371b306 | 540 | |
ram54288 | 0:a7a43371b306 | 541 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 542 | |
ram54288 | 0:a7a43371b306 | 543 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 544 | |
ram54288 | 0:a7a43371b306 | 545 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 546 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 547 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 548 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 549 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 550 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 551 | } |
ram54288 | 0:a7a43371b306 | 552 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 553 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 554 | } |
ram54288 | 0:a7a43371b306 | 555 | } |
ram54288 | 0:a7a43371b306 | 556 | |
ram54288 | 0:a7a43371b306 | 557 | |
ram54288 | 0:a7a43371b306 | 558 | m2mbase_stub::operation = M2MBase::NOT_ALLOWED; |
ram54288 | 0:a7a43371b306 | 559 | |
ram54288 | 0:a7a43371b306 | 560 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 561 | |
ram54288 | 0:a7a43371b306 | 562 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 563 | |
ram54288 | 0:a7a43371b306 | 564 | coap_response = object->handle_post_request(NULL,NULL,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 565 | |
ram54288 | 0:a7a43371b306 | 566 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 567 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 568 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 569 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 570 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 571 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 572 | } |
ram54288 | 0:a7a43371b306 | 573 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 574 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 575 | } |
ram54288 | 0:a7a43371b306 | 576 | } |
ram54288 | 0:a7a43371b306 | 577 | |
ram54288 | 0:a7a43371b306 | 578 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:a7a43371b306 | 579 | m2mtlvdeserializer_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 580 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:a7a43371b306 | 581 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:a7a43371b306 | 582 | coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); |
ram54288 | 0:a7a43371b306 | 583 | |
ram54288 | 0:a7a43371b306 | 584 | CHECK( coap_response != NULL); |
ram54288 | 0:a7a43371b306 | 585 | if(coap_response) { |
ram54288 | 0:a7a43371b306 | 586 | if (coap_response->options_list_ptr) { |
ram54288 | 0:a7a43371b306 | 587 | if (coap_response->options_list_ptr->location_path_ptr) { |
ram54288 | 0:a7a43371b306 | 588 | free(coap_response->options_list_ptr->location_path_ptr); |
ram54288 | 0:a7a43371b306 | 589 | coap_response->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 590 | } |
ram54288 | 0:a7a43371b306 | 591 | // free(coap_response->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 592 | // coap_response->options_list_ptr = NULL; |
ram54288 | 0:a7a43371b306 | 593 | } |
ram54288 | 0:a7a43371b306 | 594 | } |
ram54288 | 0:a7a43371b306 | 595 | |
ram54288 | 0:a7a43371b306 | 596 | free(coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 597 | free(coap_header->payload_ptr); |
ram54288 | 0:a7a43371b306 | 598 | free(common_stub::coap_header->options_list_ptr); |
ram54288 | 0:a7a43371b306 | 599 | free(common_stub::coap_header); |
ram54288 | 0:a7a43371b306 | 600 | free(coap_header); |
ram54288 | 0:a7a43371b306 | 601 | |
ram54288 | 0:a7a43371b306 | 602 | m2mtlvdeserializer_stub::clear(); |
ram54288 | 0:a7a43371b306 | 603 | common_stub::clear(); |
ram54288 | 0:a7a43371b306 | 604 | m2mbase_stub::clear(); |
ram54288 | 0:a7a43371b306 | 605 | } |
ram54288 | 0:a7a43371b306 | 606 | |
ram54288 | 0:a7a43371b306 | 607 | void Test_M2MObject::test_notification_update() |
ram54288 | 0:a7a43371b306 | 608 | { |
ram54288 | 0:a7a43371b306 | 609 | TestReportObserver obs; |
ram54288 | 0:a7a43371b306 | 610 | m2mbase_stub::report = new M2MReportHandler(obs); |
ram54288 | 0:a7a43371b306 | 611 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 612 | |
ram54288 | 0:a7a43371b306 | 613 | object->notification_update(0); |
ram54288 | 0:a7a43371b306 | 614 | |
ram54288 | 0:a7a43371b306 | 615 | delete m2mbase_stub::report; |
ram54288 | 0:a7a43371b306 | 616 | m2mbase_stub::report = NULL; |
ram54288 | 0:a7a43371b306 | 617 | } |
ram54288 | 0:a7a43371b306 | 618 |