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