A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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_m2mtlvdeserializer.h"
ram54288 0:a7a43371b306 18 #include "m2mtlvserializer.h"
ram54288 0:a7a43371b306 19 #include "m2mobject_stub.h"
ram54288 0:a7a43371b306 20 #include "m2mobjectinstance_stub.h"
ram54288 0:a7a43371b306 21 #include "m2mresource_stub.h"
ram54288 0:a7a43371b306 22 #include "m2mresourceinstance_stub.h"
ram54288 0:a7a43371b306 23 #include "m2mbase_stub.h"
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25
ram54288 0:a7a43371b306 26 Test_M2MTLVDeserializer::Test_M2MTLVDeserializer()
ram54288 0:a7a43371b306 27 {
ram54288 0:a7a43371b306 28 deserializer = new M2MTLVDeserializer();
ram54288 0:a7a43371b306 29 }
ram54288 0:a7a43371b306 30
ram54288 0:a7a43371b306 31 Test_M2MTLVDeserializer::~Test_M2MTLVDeserializer()
ram54288 0:a7a43371b306 32 {
ram54288 0:a7a43371b306 33 delete deserializer;
ram54288 0:a7a43371b306 34 m2mbase_stub::clear();
ram54288 0:a7a43371b306 35 m2mresourceinstance_stub::clear();
ram54288 0:a7a43371b306 36 m2mobjectinstance_stub::clear();
ram54288 0:a7a43371b306 37 m2mobject_stub::clear();
ram54288 0:a7a43371b306 38 m2mresource_stub::clear();
ram54288 0:a7a43371b306 39 }
ram54288 0:a7a43371b306 40
ram54288 0:a7a43371b306 41 void Test_M2MTLVDeserializer::test_is_object_instance()
ram54288 0:a7a43371b306 42 {
ram54288 0:a7a43371b306 43 uint8_t data_resource[] = {0xC3,0x0};
ram54288 0:a7a43371b306 44 uint8_t data_object[] = {0x08,0x0};
ram54288 0:a7a43371b306 45
ram54288 0:a7a43371b306 46 CHECK(deserializer->is_object_instance(data_resource) == false);
ram54288 0:a7a43371b306 47 CHECK(deserializer->is_object_instance(data_object) == true);
ram54288 0:a7a43371b306 48 }
ram54288 0:a7a43371b306 49
ram54288 0:a7a43371b306 50 void Test_M2MTLVDeserializer::test_is_resource()
ram54288 0:a7a43371b306 51 {
ram54288 0:a7a43371b306 52 uint8_t data_resource[] = {0xC3,0x0};
ram54288 0:a7a43371b306 53 uint8_t data_object[] = {0x08,0x0};
ram54288 0:a7a43371b306 54
ram54288 0:a7a43371b306 55 CHECK(deserializer->is_resource(data_resource) == true);
ram54288 0:a7a43371b306 56 CHECK(deserializer->is_resource(data_object) == false);
ram54288 0:a7a43371b306 57
ram54288 0:a7a43371b306 58 }
ram54288 0:a7a43371b306 59
ram54288 0:a7a43371b306 60 void Test_M2MTLVDeserializer::test_is_multiple_resource()
ram54288 0:a7a43371b306 61 {
ram54288 0:a7a43371b306 62 uint8_t data_resource[] = {0xC3,0x0};
ram54288 0:a7a43371b306 63 uint8_t data_object[] = {0x88,0x0};
ram54288 0:a7a43371b306 64
ram54288 0:a7a43371b306 65 CHECK(deserializer->is_multiple_resource(data_resource) == false);
ram54288 0:a7a43371b306 66 CHECK(deserializer->is_multiple_resource(data_object) == true);
ram54288 0:a7a43371b306 67 }
ram54288 0:a7a43371b306 68
ram54288 0:a7a43371b306 69 void Test_M2MTLVDeserializer::test_is_resource_instance()
ram54288 0:a7a43371b306 70 {
ram54288 0:a7a43371b306 71 uint8_t data_resource[] = {0xC3,0x0};
ram54288 0:a7a43371b306 72 uint8_t data_object[] = {0x44,0x0};
ram54288 0:a7a43371b306 73
ram54288 0:a7a43371b306 74 CHECK(deserializer->is_resource_instance(data_object) == true);
ram54288 0:a7a43371b306 75 CHECK(deserializer->is_resource_instance(data_resource) == false);
ram54288 0:a7a43371b306 76 }
ram54288 0:a7a43371b306 77
ram54288 0:a7a43371b306 78 void Test_M2MTLVDeserializer::test_deserialise_object_instances()
ram54288 0:a7a43371b306 79 {
ram54288 0:a7a43371b306 80 uint32_t size = 0;
ram54288 0:a7a43371b306 81 uint8_t *data = 0;
ram54288 0:a7a43371b306 82
ram54288 0:a7a43371b306 83
ram54288 0:a7a43371b306 84 M2MObject *object = new M2MObject("1", "1");
ram54288 0:a7a43371b306 85 M2MObjectInstance* instance = new M2MObjectInstance(*object,"1", "type", "1");
ram54288 0:a7a43371b306 86
ram54288 0:a7a43371b306 87 M2MObjectInstance* instance_1 = new M2MObjectInstance(*object,"2", "type", "2");
ram54288 0:a7a43371b306 88
ram54288 0:a7a43371b306 89
ram54288 0:a7a43371b306 90 m2mobject_stub::instance_list.push_back(instance);
ram54288 0:a7a43371b306 91
ram54288 0:a7a43371b306 92 M2MResource* resource = new M2MResource(*instance,
ram54288 0:a7a43371b306 93 "1",
ram54288 0:a7a43371b306 94 "type",
ram54288 0:a7a43371b306 95 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 96 false,
ram54288 0:a7a43371b306 97 "1");
ram54288 0:a7a43371b306 98
ram54288 0:a7a43371b306 99 M2MResource* resource_1 = new M2MResource(*instance,
ram54288 0:a7a43371b306 100 "2",
ram54288 0:a7a43371b306 101 "type",
ram54288 0:a7a43371b306 102 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 103 false,
ram54288 0:a7a43371b306 104 "2");
ram54288 0:a7a43371b306 105
ram54288 0:a7a43371b306 106 m2mobjectinstance_stub::resource_list.push_back(resource);
ram54288 0:a7a43371b306 107 m2mobjectinstance_stub::resource_list.push_back(resource_1);
ram54288 0:a7a43371b306 108
ram54288 0:a7a43371b306 109 m2mbase_stub::name_id_value = 0;
ram54288 0:a7a43371b306 110 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 111
ram54288 0:a7a43371b306 112 M2MTLVSerializer *serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 113
ram54288 0:a7a43371b306 114 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 115
ram54288 0:a7a43371b306 116 CHECK(M2MTLVDeserializer::None == deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 117
ram54288 0:a7a43371b306 118 size = 0;
ram54288 0:a7a43371b306 119
ram54288 0:a7a43371b306 120 if(data) {
ram54288 0:a7a43371b306 121 free(data);
ram54288 0:a7a43371b306 122 data = 0;
ram54288 0:a7a43371b306 123 }
ram54288 0:a7a43371b306 124
ram54288 0:a7a43371b306 125 m2mbase_stub::operation = M2MBase::GET_ALLOWED;
ram54288 0:a7a43371b306 126
ram54288 0:a7a43371b306 127 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 128
ram54288 0:a7a43371b306 129 CHECK(M2MTLVDeserializer::NotAllowed == deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 130
ram54288 0:a7a43371b306 131 size = 0;
ram54288 0:a7a43371b306 132
ram54288 0:a7a43371b306 133 if(data) {
ram54288 0:a7a43371b306 134 free(data);
ram54288 0:a7a43371b306 135 data = 0;
ram54288 0:a7a43371b306 136 }
ram54288 0:a7a43371b306 137
ram54288 0:a7a43371b306 138 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 139
ram54288 0:a7a43371b306 140 u_int8_t value[] = {"value"};
ram54288 0:a7a43371b306 141 m2mresourceinstance_stub::value = value;
ram54288 0:a7a43371b306 142 m2mresourceinstance_stub::int_value = sizeof(value);
ram54288 0:a7a43371b306 143
ram54288 0:a7a43371b306 144 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 145
ram54288 0:a7a43371b306 146 delete serializer;
ram54288 0:a7a43371b306 147
ram54288 0:a7a43371b306 148 CHECK(M2MTLVDeserializer::None == deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 149 CHECK(M2MTLVDeserializer::None == deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Put));
ram54288 0:a7a43371b306 150
ram54288 0:a7a43371b306 151 size = 0;
ram54288 0:a7a43371b306 152
ram54288 0:a7a43371b306 153 if(data) {
ram54288 0:a7a43371b306 154 free(data);
ram54288 0:a7a43371b306 155 data = 0;
ram54288 0:a7a43371b306 156 }
ram54288 0:a7a43371b306 157
ram54288 0:a7a43371b306 158 m2mobject_stub::instance_list.push_back(instance_1);
ram54288 0:a7a43371b306 159
ram54288 0:a7a43371b306 160 m2mbase_stub::operation = M2MBase::NOT_ALLOWED;
ram54288 0:a7a43371b306 161 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 162
ram54288 0:a7a43371b306 163 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 164
ram54288 0:a7a43371b306 165 delete serializer;
ram54288 0:a7a43371b306 166
ram54288 0:a7a43371b306 167 CHECK(M2MTLVDeserializer::None != deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 168 size = 0;
ram54288 0:a7a43371b306 169
ram54288 0:a7a43371b306 170 if(data) {
ram54288 0:a7a43371b306 171 free(data);
ram54288 0:a7a43371b306 172 data = 0;
ram54288 0:a7a43371b306 173 }
ram54288 0:a7a43371b306 174
ram54288 0:a7a43371b306 175 CHECK(M2MTLVDeserializer::NotValid == deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 176
ram54288 0:a7a43371b306 177 M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 178 "1",
ram54288 0:a7a43371b306 179 "type",
ram54288 0:a7a43371b306 180 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 181 0,
ram54288 0:a7a43371b306 182 "1",
ram54288 0:a7a43371b306 183 false);
ram54288 0:a7a43371b306 184
ram54288 0:a7a43371b306 185
ram54288 0:a7a43371b306 186 M2MResourceInstance* res_instance_1 = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 187 "2",
ram54288 0:a7a43371b306 188 "type",
ram54288 0:a7a43371b306 189 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 190 0,
ram54288 0:a7a43371b306 191 "1",
ram54288 0:a7a43371b306 192 false);
ram54288 0:a7a43371b306 193
ram54288 0:a7a43371b306 194 m2mresource_stub::bool_value = true;
ram54288 0:a7a43371b306 195 m2mresource_stub::list.push_back(res_instance);
ram54288 0:a7a43371b306 196 m2mresource_stub::list.push_back(res_instance_1);
ram54288 0:a7a43371b306 197
ram54288 0:a7a43371b306 198 m2mobject_stub::instance_list.pop_back();
ram54288 0:a7a43371b306 199
ram54288 0:a7a43371b306 200 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 201 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 202 delete serializer;
ram54288 0:a7a43371b306 203
ram54288 0:a7a43371b306 204 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 205
ram54288 0:a7a43371b306 206 m2mbase_stub::string_value = "name";
ram54288 0:a7a43371b306 207 m2mobjectinstance_stub::create_resource_instance = new M2MResource(*instance,
ram54288 0:a7a43371b306 208 "1",
ram54288 0:a7a43371b306 209 "type",
ram54288 0:a7a43371b306 210 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 211 false,
ram54288 0:a7a43371b306 212 "1");
ram54288 0:a7a43371b306 213
ram54288 0:a7a43371b306 214 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 215
ram54288 0:a7a43371b306 216 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 217
ram54288 0:a7a43371b306 218 size = 0;
ram54288 0:a7a43371b306 219 if(data) {
ram54288 0:a7a43371b306 220 free(data);
ram54288 0:a7a43371b306 221 data = 0;
ram54288 0:a7a43371b306 222 }
ram54288 0:a7a43371b306 223
ram54288 0:a7a43371b306 224 m2mbase_stub::name_id_value = 300;
ram54288 0:a7a43371b306 225
ram54288 0:a7a43371b306 226 m2mresourceinstance_stub::int_value = 6;
ram54288 0:a7a43371b306 227 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 228 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 229 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 230 delete serializer;
ram54288 0:a7a43371b306 231
ram54288 0:a7a43371b306 232 deserializer->deserialise_object_instances(data,size,*object, M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 233 deserializer->deserialise_object_instances(data,size,*object, M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 234 size = 0;
ram54288 0:a7a43371b306 235
ram54288 0:a7a43371b306 236 if(data) {
ram54288 0:a7a43371b306 237 free(data);
ram54288 0:a7a43371b306 238 data = 0;
ram54288 0:a7a43371b306 239 }
ram54288 0:a7a43371b306 240 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 241 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 242
ram54288 0:a7a43371b306 243 m2mresourceinstance_stub::int_value = 256;
ram54288 0:a7a43371b306 244 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 245 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 246 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 247 delete serializer;
ram54288 0:a7a43371b306 248
ram54288 0:a7a43371b306 249 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 250 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 251 size = 0;
ram54288 0:a7a43371b306 252
ram54288 0:a7a43371b306 253 if(data) {
ram54288 0:a7a43371b306 254 free(data);
ram54288 0:a7a43371b306 255 data = 0;
ram54288 0:a7a43371b306 256 }
ram54288 0:a7a43371b306 257 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 258 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 259
ram54288 0:a7a43371b306 260 m2mresourceinstance_stub::int_value = 65536;
ram54288 0:a7a43371b306 261 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 262 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 263 data = serializer->serialize( m2mobject_stub::instance_list,size);
ram54288 0:a7a43371b306 264 delete serializer;
ram54288 0:a7a43371b306 265
ram54288 0:a7a43371b306 266 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 267 deserializer->deserialise_object_instances(data,size,*object,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 268 size = 0;
ram54288 0:a7a43371b306 269
ram54288 0:a7a43371b306 270 if(data) {
ram54288 0:a7a43371b306 271 free(data);
ram54288 0:a7a43371b306 272 data = 0;
ram54288 0:a7a43371b306 273 }
ram54288 0:a7a43371b306 274
ram54288 0:a7a43371b306 275 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 276 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 277
ram54288 0:a7a43371b306 278 delete m2mobjectinstance_stub::create_resource_instance;
ram54288 0:a7a43371b306 279 m2mobjectinstance_stub::create_resource_instance = NULL;
ram54288 0:a7a43371b306 280
ram54288 0:a7a43371b306 281 delete res_instance;
ram54288 0:a7a43371b306 282 delete res_instance_1;
ram54288 0:a7a43371b306 283 delete resource;
ram54288 0:a7a43371b306 284 delete resource_1;
ram54288 0:a7a43371b306 285 delete instance;
ram54288 0:a7a43371b306 286 delete instance_1;
ram54288 0:a7a43371b306 287 delete object;
ram54288 0:a7a43371b306 288 }
ram54288 0:a7a43371b306 289
ram54288 0:a7a43371b306 290 void Test_M2MTLVDeserializer::test_deserialize_resources()
ram54288 0:a7a43371b306 291 {
ram54288 0:a7a43371b306 292 uint8_t data_resource[] = {0xC3,0x0,'A','R','M'};
ram54288 0:a7a43371b306 293
ram54288 0:a7a43371b306 294 M2MObject *object = new M2MObject("1","1");
ram54288 0:a7a43371b306 295 M2MObjectInstance* instance = new M2MObjectInstance(*object,"1","type", "1");
ram54288 0:a7a43371b306 296
ram54288 0:a7a43371b306 297 m2mobject_stub::instance_list.push_back(instance);
ram54288 0:a7a43371b306 298
ram54288 0:a7a43371b306 299 M2MResource* resource = new M2MResource(*instance,
ram54288 0:a7a43371b306 300 "1",
ram54288 0:a7a43371b306 301 "type",
ram54288 0:a7a43371b306 302 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 303 false,
ram54288 0:a7a43371b306 304 "1");
ram54288 0:a7a43371b306 305
ram54288 0:a7a43371b306 306
ram54288 0:a7a43371b306 307 m2mobjectinstance_stub::resource_list.push_back(resource);
ram54288 0:a7a43371b306 308
ram54288 0:a7a43371b306 309 CHECK(deserializer->is_resource(data_resource) == true);
ram54288 0:a7a43371b306 310
ram54288 0:a7a43371b306 311 uint8_t invalid_data_resource[] = {0x65,0x0,'A','R','M'};
ram54288 0:a7a43371b306 312
ram54288 0:a7a43371b306 313 CHECK( M2MTLVDeserializer::NotValid == deserializer->deserialize_resources(invalid_data_resource,
ram54288 0:a7a43371b306 314 sizeof(invalid_data_resource),
ram54288 0:a7a43371b306 315 *instance,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 316
ram54288 0:a7a43371b306 317 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 318
ram54288 0:a7a43371b306 319 m2mobjectinstance_stub::create_resource = new M2MResource(*instance,
ram54288 0:a7a43371b306 320 "1",
ram54288 0:a7a43371b306 321 "type",
ram54288 0:a7a43371b306 322 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 323 false,
ram54288 0:a7a43371b306 324 "1");
ram54288 0:a7a43371b306 325
ram54288 0:a7a43371b306 326 CHECK( M2MTLVDeserializer::None == deserializer->deserialize_resources(data_resource,sizeof(data_resource),*instance,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 327
ram54288 0:a7a43371b306 328 delete m2mobjectinstance_stub::create_resource;
ram54288 0:a7a43371b306 329 m2mobjectinstance_stub::create_resource = NULL;
ram54288 0:a7a43371b306 330
ram54288 0:a7a43371b306 331 CHECK( M2MTLVDeserializer::NotFound == deserializer->deserialize_resources(data_resource,sizeof(data_resource),*instance,M2MTLVDeserializer::Put));
ram54288 0:a7a43371b306 332
ram54288 0:a7a43371b306 333 m2mbase_stub::operation = M2MBase::NOT_ALLOWED;
ram54288 0:a7a43371b306 334
ram54288 0:a7a43371b306 335 deserializer->deserialize_resources(data_resource,sizeof(data_resource),*instance,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 336
ram54288 0:a7a43371b306 337
ram54288 0:a7a43371b306 338 M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 339 "1",
ram54288 0:a7a43371b306 340 "type",
ram54288 0:a7a43371b306 341 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 342 0,
ram54288 0:a7a43371b306 343 "1",
ram54288 0:a7a43371b306 344 false);
ram54288 0:a7a43371b306 345
ram54288 0:a7a43371b306 346
ram54288 0:a7a43371b306 347 m2mresource_stub::bool_value = true;
ram54288 0:a7a43371b306 348 m2mresource_stub::list.push_back(res_instance);
ram54288 0:a7a43371b306 349
ram54288 0:a7a43371b306 350 // M2MResourceInstance* res_instance_1 = new M2MResourceInstance("2",
ram54288 0:a7a43371b306 351 // *name,
ram54288 0:a7a43371b306 352 // M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 353 // *instance);
ram54288 0:a7a43371b306 354
ram54288 0:a7a43371b306 355 // m2mresource_stub::list.push_back(res_instance_1);
ram54288 0:a7a43371b306 356 m2mbase_stub::string_value = "1";
ram54288 0:a7a43371b306 357 uint8_t data_multiple_resource[] = {0x86,0x6, 0x81,0x0, 0x01, 0x41, 0x01, 0x05};
ram54288 0:a7a43371b306 358 CHECK(deserializer->is_multiple_resource(data_multiple_resource) == true);
ram54288 0:a7a43371b306 359 deserializer->deserialize_resources(data_multiple_resource,sizeof(data_multiple_resource),*instance,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 360
ram54288 0:a7a43371b306 361 M2MTLVSerializer *serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 362
ram54288 0:a7a43371b306 363 m2mbase_stub::name_id_value = 1;
ram54288 0:a7a43371b306 364 uint32_t size = 0;
ram54288 0:a7a43371b306 365 uint8_t* data = serializer->serialize(resource,size);
ram54288 0:a7a43371b306 366
ram54288 0:a7a43371b306 367 delete serializer;
ram54288 0:a7a43371b306 368
ram54288 0:a7a43371b306 369 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 370
ram54288 0:a7a43371b306 371 deserializer->deserialize_resources(data,size,*instance,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 372
ram54288 0:a7a43371b306 373 free(data);
ram54288 0:a7a43371b306 374
ram54288 0:a7a43371b306 375 delete res_instance;
ram54288 0:a7a43371b306 376 // delete res_instance_1;
ram54288 0:a7a43371b306 377 delete resource;
ram54288 0:a7a43371b306 378 delete instance;
ram54288 0:a7a43371b306 379 delete object;
ram54288 0:a7a43371b306 380
ram54288 0:a7a43371b306 381 m2mresourceinstance_stub::clear();
ram54288 0:a7a43371b306 382 m2mresource_stub::clear();
ram54288 0:a7a43371b306 383 m2mobjectinstance_stub::clear();
ram54288 0:a7a43371b306 384 m2mobject_stub::clear();
ram54288 0:a7a43371b306 385 }
ram54288 0:a7a43371b306 386
ram54288 0:a7a43371b306 387 void Test_M2MTLVDeserializer::test_deserialize_resource_instance_1()
ram54288 0:a7a43371b306 388 {
ram54288 0:a7a43371b306 389 uint8_t data_resource[] = {0xC3,0x0,'A','R','M'};
ram54288 0:a7a43371b306 390
ram54288 0:a7a43371b306 391 m2mbase_stub::name_id_value = 1;
ram54288 0:a7a43371b306 392
ram54288 0:a7a43371b306 393 M2MObject *object = new M2MObject("1","1");
ram54288 0:a7a43371b306 394 M2MObjectInstance* instance = new M2MObjectInstance(*object,"1","type", "1");
ram54288 0:a7a43371b306 395
ram54288 0:a7a43371b306 396 m2mobject_stub::instance_list.push_back(instance);
ram54288 0:a7a43371b306 397
ram54288 0:a7a43371b306 398 M2MResource* resource = new M2MResource(*instance,
ram54288 0:a7a43371b306 399 "1",
ram54288 0:a7a43371b306 400 "type",
ram54288 0:a7a43371b306 401 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 402 false,
ram54288 0:a7a43371b306 403 "1");
ram54288 0:a7a43371b306 404
ram54288 0:a7a43371b306 405 m2mobjectinstance_stub::resource_list.push_back(resource);
ram54288 0:a7a43371b306 406
ram54288 0:a7a43371b306 407 CHECK(deserializer->is_resource(data_resource) == true);
ram54288 0:a7a43371b306 408
ram54288 0:a7a43371b306 409 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 410
ram54288 0:a7a43371b306 411 deserializer->deserialize_resource_instances(data_resource,sizeof(data_resource),
ram54288 0:a7a43371b306 412 *resource,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 413
ram54288 0:a7a43371b306 414 M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 415 "1",
ram54288 0:a7a43371b306 416 "type",
ram54288 0:a7a43371b306 417 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 418 0,
ram54288 0:a7a43371b306 419 "1",
ram54288 0:a7a43371b306 420 false);
ram54288 0:a7a43371b306 421
ram54288 0:a7a43371b306 422 m2mresource_stub::bool_value = true;
ram54288 0:a7a43371b306 423 m2mresource_stub::list.push_back(res_instance);
ram54288 0:a7a43371b306 424
ram54288 0:a7a43371b306 425 M2MResourceInstance* res_instance_1 = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 426 "2",
ram54288 0:a7a43371b306 427 "type",
ram54288 0:a7a43371b306 428 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 429 0,
ram54288 0:a7a43371b306 430 "2",
ram54288 0:a7a43371b306 431 false);
ram54288 0:a7a43371b306 432
ram54288 0:a7a43371b306 433 m2mresource_stub::list.push_back(res_instance_1);
ram54288 0:a7a43371b306 434
ram54288 0:a7a43371b306 435 M2MTLVSerializer *serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 436
ram54288 0:a7a43371b306 437 uint32_t size = 0;
ram54288 0:a7a43371b306 438 uint8_t* data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 439
ram54288 0:a7a43371b306 440 delete serializer;
ram54288 0:a7a43371b306 441
ram54288 0:a7a43371b306 442 deserializer->deserialize_resource_instances(data,size,
ram54288 0:a7a43371b306 443 *resource,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 444
ram54288 0:a7a43371b306 445
ram54288 0:a7a43371b306 446 free(data);
ram54288 0:a7a43371b306 447
ram54288 0:a7a43371b306 448 delete res_instance;
ram54288 0:a7a43371b306 449 delete res_instance_1;
ram54288 0:a7a43371b306 450 delete resource;
ram54288 0:a7a43371b306 451 delete instance;
ram54288 0:a7a43371b306 452 delete object;
ram54288 0:a7a43371b306 453
ram54288 0:a7a43371b306 454 m2mresourceinstance_stub::clear();
ram54288 0:a7a43371b306 455 m2mresource_stub::clear();
ram54288 0:a7a43371b306 456 m2mobjectinstance_stub::clear();
ram54288 0:a7a43371b306 457 m2mobject_stub::clear();
ram54288 0:a7a43371b306 458 }
ram54288 0:a7a43371b306 459
ram54288 0:a7a43371b306 460
ram54288 0:a7a43371b306 461 void Test_M2MTLVDeserializer::test_deserialize_resource_instance()
ram54288 0:a7a43371b306 462 {
ram54288 0:a7a43371b306 463 uint32_t size = 0;
ram54288 0:a7a43371b306 464 uint8_t *data = 0;
ram54288 0:a7a43371b306 465
ram54288 0:a7a43371b306 466 M2MObject *object = new M2MObject("1","1");
ram54288 0:a7a43371b306 467 M2MObjectInstance* instance = new M2MObjectInstance(*object,"1","type", "1");
ram54288 0:a7a43371b306 468
ram54288 0:a7a43371b306 469 M2MObjectInstance* instance_1 = new M2MObjectInstance(*object,"2","type", "1");
ram54288 0:a7a43371b306 470
ram54288 0:a7a43371b306 471
ram54288 0:a7a43371b306 472 m2mobject_stub::instance_list.push_back(instance);
ram54288 0:a7a43371b306 473 m2mobject_stub::instance_list.push_back(instance_1);
ram54288 0:a7a43371b306 474
ram54288 0:a7a43371b306 475
ram54288 0:a7a43371b306 476 M2MResource* resource = new M2MResource(*instance,
ram54288 0:a7a43371b306 477 "1",
ram54288 0:a7a43371b306 478 "type",
ram54288 0:a7a43371b306 479 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 480 false,
ram54288 0:a7a43371b306 481 "1");
ram54288 0:a7a43371b306 482
ram54288 0:a7a43371b306 483 M2MResource* resource_1 = new M2MResource(*instance,
ram54288 0:a7a43371b306 484 "2",
ram54288 0:a7a43371b306 485 "type",
ram54288 0:a7a43371b306 486 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 487 false,
ram54288 0:a7a43371b306 488 "2");
ram54288 0:a7a43371b306 489
ram54288 0:a7a43371b306 490 m2mobjectinstance_stub::resource_list.push_back(resource);
ram54288 0:a7a43371b306 491 m2mobjectinstance_stub::resource_list.push_back(resource_1);
ram54288 0:a7a43371b306 492
ram54288 0:a7a43371b306 493 m2mbase_stub::name_id_value = 0;
ram54288 0:a7a43371b306 494
ram54288 0:a7a43371b306 495 M2MTLVSerializer *serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 496
ram54288 0:a7a43371b306 497 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 498
ram54288 0:a7a43371b306 499 delete serializer;
ram54288 0:a7a43371b306 500
ram54288 0:a7a43371b306 501 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 502
ram54288 0:a7a43371b306 503 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 504 size = 0;
ram54288 0:a7a43371b306 505
ram54288 0:a7a43371b306 506 if(data) {
ram54288 0:a7a43371b306 507 free(data);
ram54288 0:a7a43371b306 508 data = 0;
ram54288 0:a7a43371b306 509 }
ram54288 0:a7a43371b306 510
ram54288 0:a7a43371b306 511 m2mbase_stub::operation = M2MBase::NOT_ALLOWED;
ram54288 0:a7a43371b306 512
ram54288 0:a7a43371b306 513 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 514 size = 0;
ram54288 0:a7a43371b306 515
ram54288 0:a7a43371b306 516 if(data) {
ram54288 0:a7a43371b306 517 free(data);
ram54288 0:a7a43371b306 518 data = 0;
ram54288 0:a7a43371b306 519 }
ram54288 0:a7a43371b306 520
ram54288 0:a7a43371b306 521 M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 522 "1",
ram54288 0:a7a43371b306 523 "type",
ram54288 0:a7a43371b306 524 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 525 0,
ram54288 0:a7a43371b306 526 "1",
ram54288 0:a7a43371b306 527 false);
ram54288 0:a7a43371b306 528
ram54288 0:a7a43371b306 529 M2MResourceInstance* res_instance_1 = new M2MResourceInstance(*resource,
ram54288 0:a7a43371b306 530 "2",
ram54288 0:a7a43371b306 531 "type",
ram54288 0:a7a43371b306 532 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 533 0,
ram54288 0:a7a43371b306 534 "2",
ram54288 0:a7a43371b306 535 false);
ram54288 0:a7a43371b306 536
ram54288 0:a7a43371b306 537
ram54288 0:a7a43371b306 538 m2mbase_stub::operation = M2MBase::GET_ALLOWED;
ram54288 0:a7a43371b306 539
ram54288 0:a7a43371b306 540 m2mresource_stub::bool_value = true;
ram54288 0:a7a43371b306 541 m2mresource_stub::list.push_back(res_instance);
ram54288 0:a7a43371b306 542 m2mresource_stub::list.push_back(res_instance_1);
ram54288 0:a7a43371b306 543 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 544 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 545 delete serializer;
ram54288 0:a7a43371b306 546
ram54288 0:a7a43371b306 547 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 548
ram54288 0:a7a43371b306 549 m2mbase_stub::operation = M2MBase::GET_PUT_POST_ALLOWED;
ram54288 0:a7a43371b306 550 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 551
ram54288 0:a7a43371b306 552 m2mresource_stub::list.pop_back();
ram54288 0:a7a43371b306 553 m2mresource_stub::list.pop_back();
ram54288 0:a7a43371b306 554
ram54288 0:a7a43371b306 555 CHECK(M2MTLVDeserializer::NotAllowed ==deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post));
ram54288 0:a7a43371b306 556
ram54288 0:a7a43371b306 557 CHECK(M2MTLVDeserializer::NotFound == deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Put));
ram54288 0:a7a43371b306 558
ram54288 0:a7a43371b306 559 size = 0;
ram54288 0:a7a43371b306 560 if(data) {
ram54288 0:a7a43371b306 561 free(data);
ram54288 0:a7a43371b306 562 data = 0;
ram54288 0:a7a43371b306 563 }
ram54288 0:a7a43371b306 564
ram54288 0:a7a43371b306 565 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 566 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 567 delete serializer;
ram54288 0:a7a43371b306 568
ram54288 0:a7a43371b306 569 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Put);
ram54288 0:a7a43371b306 570 size = 0;
ram54288 0:a7a43371b306 571 if(data) {
ram54288 0:a7a43371b306 572 free(data);
ram54288 0:a7a43371b306 573 data = 0;
ram54288 0:a7a43371b306 574 }
ram54288 0:a7a43371b306 575
ram54288 0:a7a43371b306 576 m2mresource_stub::list.push_back(res_instance);
ram54288 0:a7a43371b306 577 m2mresource_stub::list.push_back(res_instance_1);
ram54288 0:a7a43371b306 578
ram54288 0:a7a43371b306 579 m2mbase_stub::name_id_value = 300;
ram54288 0:a7a43371b306 580
ram54288 0:a7a43371b306 581 m2mresourceinstance_stub::int_value = 6;
ram54288 0:a7a43371b306 582 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 583 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 584 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 585 delete serializer;
ram54288 0:a7a43371b306 586
ram54288 0:a7a43371b306 587 deserializer->deserialize_resource_instances(data,size,*resource, M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 588 size = 0;
ram54288 0:a7a43371b306 589
ram54288 0:a7a43371b306 590 if(data) {
ram54288 0:a7a43371b306 591 free(data);
ram54288 0:a7a43371b306 592 data = 0;
ram54288 0:a7a43371b306 593 }
ram54288 0:a7a43371b306 594 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 595 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 596
ram54288 0:a7a43371b306 597 m2mresourceinstance_stub::int_value = 256;
ram54288 0:a7a43371b306 598 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 599 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 600 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 601 delete serializer;
ram54288 0:a7a43371b306 602
ram54288 0:a7a43371b306 603 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 604 size = 0;
ram54288 0:a7a43371b306 605
ram54288 0:a7a43371b306 606 if(data) {
ram54288 0:a7a43371b306 607 free(data);
ram54288 0:a7a43371b306 608 data = 0;
ram54288 0:a7a43371b306 609 }
ram54288 0:a7a43371b306 610 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 611 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 612
ram54288 0:a7a43371b306 613 m2mresourceinstance_stub::int_value = 65536;
ram54288 0:a7a43371b306 614 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
ram54288 0:a7a43371b306 615 serializer = new M2MTLVSerializer();
ram54288 0:a7a43371b306 616 data = serializer->serialize( resource,size);
ram54288 0:a7a43371b306 617 delete serializer;
ram54288 0:a7a43371b306 618
ram54288 0:a7a43371b306 619 deserializer->deserialize_resource_instances(data,size,*resource,M2MTLVDeserializer::Post);
ram54288 0:a7a43371b306 620 size = 0;
ram54288 0:a7a43371b306 621
ram54288 0:a7a43371b306 622 if(data) {
ram54288 0:a7a43371b306 623 free(data);
ram54288 0:a7a43371b306 624 data = 0;
ram54288 0:a7a43371b306 625 }
ram54288 0:a7a43371b306 626
ram54288 0:a7a43371b306 627 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 628 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 629
ram54288 0:a7a43371b306 630 delete res_instance;
ram54288 0:a7a43371b306 631 delete res_instance_1;
ram54288 0:a7a43371b306 632 delete resource;
ram54288 0:a7a43371b306 633 delete resource_1;
ram54288 0:a7a43371b306 634 delete instance;
ram54288 0:a7a43371b306 635 delete instance_1;
ram54288 0:a7a43371b306 636 delete object;
ram54288 0:a7a43371b306 637 }
ram54288 0:a7a43371b306 638
ram54288 0:a7a43371b306 639 void Test_M2MTLVDeserializer::test_instance_id()
ram54288 0:a7a43371b306 640 {
ram54288 0:a7a43371b306 641 uint8_t data_resource[] = {0xC3,0x1};
ram54288 0:a7a43371b306 642 uint8_t data_object[] = {0x08,0x2};
ram54288 0:a7a43371b306 643
ram54288 0:a7a43371b306 644 CHECK(deserializer->instance_id(data_resource) == 1);
ram54288 0:a7a43371b306 645 CHECK(deserializer->instance_id(data_object) == 2);
ram54288 0:a7a43371b306 646 }