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