Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
test_m2mtlvserializer.cpp
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "CppUTest/TestHarness.h" 00017 #include "test_m2mtlvserializer.h" 00018 #include "m2mobject_stub.h" 00019 #include "m2mobjectinstance_stub.h" 00020 #include "m2mresource_stub.h" 00021 #include "m2mresourceinstance_stub.h" 00022 #include "m2mbase_stub.h" 00023 00024 00025 Test_M2MTLVSerializer::Test_M2MTLVSerializer() 00026 { 00027 serializer = new M2MTLVSerializer(); 00028 } 00029 00030 Test_M2MTLVSerializer::~Test_M2MTLVSerializer() 00031 { 00032 delete serializer; 00033 } 00034 00035 void Test_M2MTLVSerializer::test_serialize_object() 00036 { 00037 uint32_t size = 0; 00038 uint8_t *data = 0; 00039 00040 String *name = new String("1"); 00041 M2MObject *object = new M2MObject(*name); 00042 M2MObjectInstance* instance = new M2MObjectInstance(*name,*object); 00043 00044 m2mobject_stub::instance_list.push_back(instance); 00045 00046 00047 00048 M2MResource* resource = new M2MResource(*instance, 00049 *name, 00050 *name, 00051 M2MResourceInstance::INTEGER, 00052 M2MResource::Dynamic, 00053 false); 00054 00055 00056 m2mobjectinstance_stub::resource_list.push_back(resource); 00057 00058 m2mbase_stub::name_id_value = 0; 00059 data = serializer->serialize( m2mobject_stub::instance_list,size); 00060 CHECK(data != NULL); 00061 00062 if(data) { 00063 free(data); 00064 data = 0; 00065 } 00066 00067 M2MResourceInstance* res_instance = new M2MResourceInstance(*name, 00068 *name, 00069 M2MResourceInstance::INTEGER, 00070 *instance); 00071 00072 M2MResourceInstance* res_instance_1 = new M2MResourceInstance("2", 00073 *name, 00074 M2MResourceInstance::INTEGER, 00075 *instance); 00076 00077 00078 m2mresource_stub::bool_value = true; 00079 m2mresource_stub::list.push_back(res_instance); 00080 m2mresource_stub::list.push_back(res_instance_1); 00081 data = serializer->serialize( m2mobject_stub::instance_list,size); 00082 CHECK(data != NULL); 00083 00084 if(data) { 00085 free(data); 00086 data = 0; 00087 } 00088 00089 m2mbase_stub::name_id_value = 256; 00090 00091 m2mresourceinstance_stub::int_value = 6; 00092 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value); 00093 data = serializer->serialize( m2mobject_stub::instance_list,size); 00094 CHECK(data != NULL); 00095 00096 if(data) { 00097 free(data); 00098 data = 0; 00099 } 00100 free(m2mresourceinstance_stub::value); 00101 m2mresourceinstance_stub::value = NULL; 00102 00103 m2mresourceinstance_stub::int_value = 256; 00104 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value); 00105 data = serializer->serialize( m2mobject_stub::instance_list,size); 00106 CHECK(data != NULL); 00107 00108 if(data) { 00109 free(data); 00110 data = 0; 00111 } 00112 free(m2mresourceinstance_stub::value); 00113 m2mresourceinstance_stub::value = NULL; 00114 00115 m2mresourceinstance_stub::int_value = 65536; 00116 m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value); 00117 data = serializer->serialize( m2mobject_stub::instance_list,size); 00118 CHECK(data != NULL); 00119 00120 if(data) { 00121 free(data); 00122 data = 0; 00123 } 00124 00125 m2mbase_stub::name_id_value = -1; 00126 data = serializer->serialize( m2mobject_stub::instance_list,size); 00127 CHECK(data == NULL); 00128 00129 delete name; 00130 delete res_instance_1; 00131 delete res_instance; 00132 delete resource; 00133 delete instance; 00134 delete object; 00135 00136 free(m2mresourceinstance_stub::value); 00137 00138 m2mresourceinstance_stub::clear(); 00139 m2mresource_stub::clear(); 00140 m2mobjectinstance_stub::clear(); 00141 m2mobject_stub::clear(); 00142 } 00143 00144 void Test_M2MTLVSerializer::test_serialize_object_instance() 00145 { 00146 String *name = new String("1"); 00147 M2MObject *object = new M2MObject(*name); 00148 M2MObjectInstance* instance = new M2MObjectInstance(*name,*object); 00149 00150 uint32_t size = 0; 00151 uint8_t *data = 0; 00152 m2mbase_stub::name_id_value = 0; 00153 M2MResource* resource = new M2MResource(*instance, 00154 *name, 00155 *name, 00156 M2MResourceInstance::INTEGER, 00157 M2MResource::Dynamic, 00158 false); 00159 00160 M2MResourceInstance* res_instance = new M2MResourceInstance(*name, 00161 *name, 00162 M2MResourceInstance::INTEGER, 00163 *instance); 00164 00165 00166 m2mobjectinstance_stub::resource_list.clear(); 00167 m2mobjectinstance_stub::resource_list.push_back(resource); 00168 00169 m2mresource_stub::bool_value = true; 00170 m2mresource_stub::list.push_back(res_instance); 00171 00172 m2mbase_stub::operation = M2MBase::GET_ALLOWED; 00173 00174 data = serializer->serialize( m2mobjectinstance_stub::resource_list,size); 00175 CHECK(data != NULL); 00176 00177 if(data) { 00178 free(data); 00179 data = NULL; 00180 } 00181 00182 00183 m2mbase_stub::name_id_value = -1; 00184 data = serializer->serialize( m2mobject_stub::instance_list,size); 00185 CHECK(data == NULL); 00186 00187 delete name; 00188 delete res_instance; 00189 delete resource; 00190 delete instance; 00191 delete object; 00192 00193 m2mresource_stub::clear(); 00194 m2mobjectinstance_stub::clear(); 00195 m2mobject_stub::clear(); 00196 } 00197 00198 void Test_M2MTLVSerializer::test_serialize_resource() 00199 { 00200 String *name = new String("1"); 00201 M2MObject *object = new M2MObject(*name); 00202 M2MObjectInstance* instance = new M2MObjectInstance(*name,*object); 00203 00204 uint32_t size = 0; 00205 uint8_t *data = 0; 00206 m2mbase_stub::name_id_value = 0; 00207 M2MResource* resource = new M2MResource(*instance, 00208 *name, 00209 *name, 00210 M2MResourceInstance::INTEGER, 00211 M2MResource::Dynamic, 00212 false); 00213 00214 M2MResourceInstance* res_instance = new M2MResourceInstance(*name, 00215 *name, 00216 M2MResourceInstance::INTEGER, 00217 *instance); 00218 00219 00220 m2mobjectinstance_stub::resource_list.clear(); 00221 m2mobjectinstance_stub::resource_list.push_back(resource); 00222 00223 m2mresource_stub::bool_value = true; 00224 m2mresource_stub::list.push_back(res_instance); 00225 00226 m2mbase_stub::operation = M2MBase::GET_ALLOWED; 00227 00228 data = serializer->serialize( resource,size); 00229 CHECK(data != NULL); 00230 00231 if(data) { 00232 free(data); 00233 data = NULL; 00234 } 00235 00236 00237 m2mbase_stub::name_id_value = -1; 00238 data = serializer->serialize( m2mobject_stub::instance_list,size); 00239 CHECK(data == NULL); 00240 00241 delete name; 00242 delete res_instance; 00243 delete resource; 00244 delete instance; 00245 delete object; 00246 00247 m2mresource_stub::clear(); 00248 m2mobjectinstance_stub::clear(); 00249 m2mobject_stub::clear(); 00250 00251 } 00252 00253 void Test_M2MTLVSerializer::test_serialize_resource_instance() 00254 { 00255 String *name = new String("1"); 00256 M2MObject *object = new M2MObject(*name); 00257 M2MObjectInstance* instance = new M2MObjectInstance(*name,*object); 00258 00259 uint32_t size = 0; 00260 uint8_t *data = 0; 00261 m2mbase_stub::name_id_value = 0; 00262 M2MResource* resource = new M2MResource(*instance, 00263 *name, 00264 *name, 00265 M2MResourceInstance::INTEGER, 00266 M2MResource::Dynamic, 00267 false); 00268 00269 M2MResourceInstance* res_instance = new M2MResourceInstance(*name, 00270 *name, 00271 M2MResourceInstance::INTEGER, 00272 *instance); 00273 00274 00275 m2mobjectinstance_stub::resource_list.clear(); 00276 m2mobjectinstance_stub::resource_list.push_back(resource); 00277 00278 m2mresource_stub::bool_value = true; 00279 m2mresource_stub::list.push_back(res_instance); 00280 00281 m2mbase_stub::operation = M2MBase::GET_ALLOWED; 00282 00283 data = serializer->serialize( m2mobjectinstance_stub::resource_list,size); 00284 CHECK(data != NULL); 00285 00286 if(data) { 00287 free(data); 00288 data = NULL; 00289 } 00290 00291 00292 m2mbase_stub::name_id_value = -1; 00293 data = serializer->serialize( m2mobject_stub::instance_list,size); 00294 CHECK(data == NULL); 00295 00296 delete name; 00297 delete res_instance; 00298 delete resource; 00299 delete instance; 00300 delete object; 00301 00302 m2mresource_stub::clear(); 00303 m2mobjectinstance_stub::clear(); 00304 m2mobject_stub::clear(); 00305 }
Generated on Tue Jul 12 2022 12:28:55 by
1.7.2
