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_m2mobject.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_m2mobject.h" 00018 #include "m2mobjectinstance_stub.h" 00019 #include "m2mresource_stub.h" 00020 #include "m2mbase_stub.h" 00021 #include "common_stub.h" 00022 #include "m2mtlvdeserializer_stub.h" 00023 #include "m2mtlvserializer_stub.h" 00024 #include "m2mreporthandler_stub.h" 00025 00026 class TestReportObserver : public M2MReportObserver{ 00027 public : 00028 TestReportObserver() {} 00029 ~TestReportObserver() {} 00030 void observation_to_be_sent(m2m::Vector<uint16_t>,bool){ } 00031 }; 00032 00033 class Handler : public M2MObservationHandler { 00034 00035 public: 00036 00037 Handler(){} 00038 ~Handler(){} 00039 void observation_to_be_sent(M2MBase *, uint16_t, m2m::Vector<uint16_t>,bool){ 00040 visited = true; 00041 } 00042 void send_delayed_response(M2MBase *){} 00043 void resource_to_be_deleted(const String &){visited=true;} 00044 void remove_object(M2MBase *){visited = true;} 00045 void value_updated(M2MBase *,const String&){visited = true;} 00046 00047 void clear() {visited = false;} 00048 bool visited; 00049 }; 00050 00051 Test_M2MObject::Test_M2MObject() 00052 { 00053 handler = new Handler(); 00054 object = new M2MObject("name"); 00055 } 00056 00057 Test_M2MObject::~Test_M2MObject() 00058 { 00059 m2mobjectinstance_stub::clear(); 00060 m2mresource_stub::clear(); 00061 m2mbase_stub::clear(); 00062 m2mbase_stub::string_value = new String("name"); 00063 m2mtlvdeserializer_stub::clear(); 00064 m2mtlvserializer_stub::clear(); 00065 delete object; 00066 delete handler; 00067 delete m2mbase_stub::string_value; 00068 m2mbase_stub::string_value = NULL; 00069 } 00070 00071 void Test_M2MObject::test_copy_constructor() 00072 { 00073 String *name = new String("name"); 00074 m2mbase_stub::string_value = name; 00075 00076 M2MObject* copy = new M2MObject(*name); 00077 M2MObjectInstance *ins = new M2MObjectInstance("name",*object); 00078 copy->set_instance_id(0); 00079 copy->_instance_list.push_back(ins); 00080 00081 M2MObject* copy1 = new M2MObject(*copy); 00082 00083 CHECK(1 == copy1->_instance_list.size()); 00084 00085 delete copy; 00086 delete copy1; 00087 delete name; 00088 name = NULL; 00089 } 00090 00091 void Test_M2MObject::test_create_object_instance() 00092 { 00093 m2mbase_stub::name_id_value = 1; 00094 CHECK(object->create_object_instance() != NULL); 00095 } 00096 00097 void Test_M2MObject::test_remove_object_instance() 00098 { 00099 m2mbase_stub::string_value = new String("name"); 00100 00101 M2MObjectInstance *ins = new M2MObjectInstance("name",*object); 00102 object->set_instance_id(0); 00103 object->_instance_list.push_back(ins); 00104 00105 CHECK(true == object->remove_object_instance(0)); 00106 00107 CHECK(false == object->remove_object_instance(0)); 00108 00109 delete m2mbase_stub::string_value; 00110 } 00111 00112 void Test_M2MObject::test_object_instance() 00113 { 00114 String *test = new String("name"); 00115 M2MObjectInstance *ins = new M2MObjectInstance(*test,*object); 00116 object->set_instance_id(0); 00117 object->_instance_list.push_back(ins); 00118 00119 m2mbase_stub::string_value = test; 00120 00121 M2MObjectInstance *obj = object->object_instance(0); 00122 00123 CHECK(obj != NULL); 00124 CHECK(0 == obj->name().compare(0,test->size(),*test)); 00125 00126 delete test; 00127 test = NULL; 00128 } 00129 00130 void Test_M2MObject::test_instances() 00131 { 00132 String *test = new String("name"); 00133 M2MObjectInstance *ins = new M2MObjectInstance(*test,*object); 00134 ins->set_instance_id(0); 00135 object->_instance_list.push_back(ins); 00136 00137 M2MObjectInstance *ins1 = new M2MObjectInstance(*test,*object); 00138 ins1->set_instance_id(1); 00139 object->_instance_list.push_back(ins1); 00140 00141 m2mbase_stub::string_value = test; 00142 00143 M2MObjectInstanceList list = object->instances(); 00144 00145 M2MObjectInstance *obj = list[0]; 00146 CHECK(2 == list.size()); 00147 CHECK(0 == obj->name().compare(0,test->size(),*test)); 00148 00149 delete test; 00150 test = NULL; 00151 } 00152 00153 void Test_M2MObject::test_instance_count() 00154 { 00155 String test = "name"; 00156 M2MObjectInstance *ins = new M2MObjectInstance(test,*object); 00157 object->set_instance_id(0); 00158 object->_instance_list.push_back(ins); 00159 00160 M2MObjectInstance *ins1 = new M2MObjectInstance(test,*object); 00161 object->set_instance_id(1); 00162 object->_instance_list.push_back(ins1); 00163 00164 CHECK(2 == object->instance_count()); 00165 00166 object->_instance_list.clear(); 00167 delete ins; 00168 delete ins1; 00169 } 00170 00171 void Test_M2MObject::test_base_type() 00172 { 00173 CHECK(M2MBase::Object == object->base_type()); 00174 } 00175 00176 void Test_M2MObject::test_handle_get_request() 00177 { 00178 M2MObjectInstance *ins = new M2MObjectInstance("name",*object); 00179 object->set_instance_id(0); 00180 object->_instance_list.push_back(ins); 00181 00182 uint8_t value[] = {"name"}; 00183 sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 00184 memset(coap_header, 0, sizeof(sn_coap_hdr_s)); 00185 00186 coap_header->uri_path_ptr = value; 00187 coap_header->uri_path_len = sizeof(value); 00188 00189 coap_header->msg_code = COAP_MSG_CODE_REQUEST_GET; 00190 00191 String *name = new String("name"); 00192 common_stub::int_value = 0; 00193 m2mbase_stub::string_value = name; 00194 00195 m2mbase_stub::operation = M2MBase::GET_ALLOWED; 00196 m2mbase_stub::uint8_value = 200; 00197 00198 common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); 00199 memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); 00200 00201 m2mtlvserializer_stub::uint8_value = (uint8_t*)malloc(1); 00202 00203 coap_header->token_ptr = (uint8_t*)malloc(sizeof(value)); 00204 memcpy(coap_header->token_ptr, value, sizeof(value)); 00205 00206 coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 00207 coap_header->options_list_ptr->observe = 0; 00208 00209 00210 coap_header->content_type_ptr = (uint8_t*)malloc(1); 00211 coap_header->content_type_len = 1; 00212 *coap_header->content_type_ptr = 110; 00213 00214 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00215 00216 if(coap_header->content_type_ptr) { 00217 free(coap_header->content_type_ptr); 00218 coap_header->content_type_ptr = NULL; 00219 } 00220 00221 if(common_stub::coap_header->content_type_ptr) { 00222 free(common_stub::coap_header->content_type_ptr); 00223 common_stub::coap_header->content_type_ptr = NULL; 00224 } 00225 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00226 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00227 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00228 } 00229 if(common_stub::coap_header->options_list_ptr) { 00230 free(common_stub::coap_header->options_list_ptr); 00231 common_stub::coap_header->options_list_ptr = NULL; 00232 } 00233 00234 // Not OMA TLV or JSON 00235 m2mbase_stub::uint8_value = 110; 00236 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00237 00238 if(common_stub::coap_header->content_type_ptr) { 00239 free(common_stub::coap_header->content_type_ptr); 00240 common_stub::coap_header->content_type_ptr = NULL; 00241 } 00242 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00243 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00244 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00245 } 00246 if(common_stub::coap_header->options_list_ptr) { 00247 free(common_stub::coap_header->options_list_ptr); 00248 common_stub::coap_header->options_list_ptr = NULL; 00249 } 00250 00251 // OMA TLV 00252 m2mbase_stub::uint8_value = 99; 00253 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00254 00255 if(common_stub::coap_header->content_type_ptr) { 00256 free(common_stub::coap_header->content_type_ptr); 00257 common_stub::coap_header->content_type_ptr = NULL; 00258 } 00259 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00260 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00261 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00262 } 00263 if(common_stub::coap_header->options_list_ptr) { 00264 free(common_stub::coap_header->options_list_ptr); 00265 common_stub::coap_header->options_list_ptr = NULL; 00266 } 00267 00268 // OMA JSON 00269 m2mbase_stub::uint8_value = 100; 00270 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00271 00272 if(common_stub::coap_header->content_type_ptr) { 00273 free(common_stub::coap_header->content_type_ptr); 00274 common_stub::coap_header->content_type_ptr = NULL; 00275 } 00276 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00277 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00278 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00279 } 00280 if(common_stub::coap_header->options_list_ptr) { 00281 free(common_stub::coap_header->options_list_ptr); 00282 common_stub::coap_header->options_list_ptr = NULL; 00283 } 00284 00285 coap_header->options_list_ptr->observe = 1; 00286 00287 uint8_t obs = 0; 00288 coap_header->options_list_ptr->observe_ptr = (uint8_t*)malloc(sizeof(obs)); 00289 memcpy(coap_header->options_list_ptr->observe_ptr,&obs,sizeof(obs)); 00290 coap_header->options_list_ptr->observe_len = 0; 00291 m2mbase_stub::uint16_value = 0x1c1c; 00292 m2mbase_stub::uint8_value = 99; 00293 m2mbase_stub::bool_value = true; 00294 00295 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00296 00297 if(common_stub::coap_header->content_type_ptr) { 00298 free(common_stub::coap_header->content_type_ptr); 00299 common_stub::coap_header->content_type_ptr = NULL; 00300 } 00301 00302 if(common_stub::coap_header->options_list_ptr->observe_ptr) { 00303 free(common_stub::coap_header->options_list_ptr->observe_ptr); 00304 common_stub::coap_header->options_list_ptr->observe_ptr = NULL; 00305 } 00306 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00307 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00308 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00309 } 00310 if(common_stub::coap_header->options_list_ptr) { 00311 free(common_stub::coap_header->options_list_ptr); 00312 common_stub::coap_header->options_list_ptr = NULL; 00313 } 00314 00315 00316 m2mbase_stub::uint16_value = 10; 00317 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00318 00319 if(common_stub::coap_header->content_type_ptr) { 00320 free(common_stub::coap_header->content_type_ptr); 00321 common_stub::coap_header->content_type_ptr = NULL; 00322 } 00323 00324 if(common_stub::coap_header->options_list_ptr->observe_ptr) { 00325 free(common_stub::coap_header->options_list_ptr->observe_ptr); 00326 common_stub::coap_header->options_list_ptr->observe_ptr = NULL; 00327 } 00328 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00329 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00330 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00331 } 00332 if(common_stub::coap_header->options_list_ptr) { 00333 free(common_stub::coap_header->options_list_ptr); 00334 common_stub::coap_header->options_list_ptr = NULL; 00335 } 00336 00337 // Not observable 00338 m2mbase_stub::bool_value = false; 00339 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00340 00341 m2mbase_stub::bool_value = true; 00342 if(common_stub::coap_header->content_type_ptr) { 00343 free(common_stub::coap_header->content_type_ptr); 00344 common_stub::coap_header->content_type_ptr = NULL; 00345 } 00346 00347 if(common_stub::coap_header->options_list_ptr->observe_ptr) { 00348 free(common_stub::coap_header->options_list_ptr->observe_ptr); 00349 common_stub::coap_header->options_list_ptr->observe_ptr = NULL; 00350 } 00351 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00352 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00353 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00354 } 00355 if(common_stub::coap_header->options_list_ptr) { 00356 free(common_stub::coap_header->options_list_ptr); 00357 common_stub::coap_header->options_list_ptr = NULL; 00358 } 00359 00360 coap_header->options_list_ptr->observe_len = 1; 00361 00362 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00363 00364 if(common_stub::coap_header->content_type_ptr) { 00365 free(common_stub::coap_header->content_type_ptr); 00366 common_stub::coap_header->content_type_ptr = NULL; 00367 } 00368 00369 if(common_stub::coap_header->options_list_ptr->observe_ptr) { 00370 free(common_stub::coap_header->options_list_ptr->observe_ptr); 00371 common_stub::coap_header->options_list_ptr->observe_ptr = NULL; 00372 } 00373 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00374 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00375 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00376 } 00377 00378 if(common_stub::coap_header->options_list_ptr) { 00379 free(common_stub::coap_header->options_list_ptr); 00380 common_stub::coap_header->options_list_ptr = NULL; 00381 } 00382 00383 00384 obs = 1; 00385 memcpy(coap_header->options_list_ptr->observe_ptr,&obs,sizeof(obs)); 00386 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00387 00388 if(common_stub::coap_header->content_type_ptr) { 00389 free(common_stub::coap_header->content_type_ptr); 00390 common_stub::coap_header->content_type_ptr = NULL; 00391 } 00392 00393 if(common_stub::coap_header->options_list_ptr->observe_ptr) { 00394 free(common_stub::coap_header->options_list_ptr->observe_ptr); 00395 common_stub::coap_header->options_list_ptr->observe_ptr = NULL; 00396 } 00397 if(common_stub::coap_header->options_list_ptr->max_age_ptr) { 00398 free(common_stub::coap_header->options_list_ptr->max_age_ptr); 00399 common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; 00400 } 00401 00402 if(common_stub::coap_header->options_list_ptr) { 00403 free(common_stub::coap_header->options_list_ptr); 00404 common_stub::coap_header->options_list_ptr = NULL; 00405 } 00406 00407 m2mbase_stub::operation = M2MBase::NOT_ALLOWED; 00408 CHECK(object->handle_get_request(NULL,coap_header,handler) != NULL); 00409 00410 CHECK(object->handle_get_request(NULL,NULL,handler) != NULL); 00411 00412 if(coap_header->token_ptr) { 00413 free(coap_header->token_ptr); 00414 coap_header->token_ptr = NULL; 00415 } 00416 if(coap_header->content_type_ptr) { 00417 free(coap_header->content_type_ptr); 00418 coap_header->content_type_ptr = NULL; 00419 } 00420 if(coap_header->options_list_ptr->observe_ptr) { 00421 free(coap_header->options_list_ptr->observe_ptr); 00422 coap_header->options_list_ptr->observe_ptr = NULL; 00423 } 00424 if(coap_header->options_list_ptr) { 00425 free(coap_header->options_list_ptr); 00426 coap_header->options_list_ptr = NULL; 00427 } 00428 00429 if(common_stub::coap_header){ 00430 if(common_stub::coap_header->content_type_ptr) { 00431 free(common_stub::coap_header->content_type_ptr); 00432 common_stub::coap_header->content_type_ptr = NULL; 00433 } 00434 if(common_stub::coap_header->options_list_ptr) { 00435 free(common_stub::coap_header->options_list_ptr); 00436 common_stub::coap_header->options_list_ptr = NULL; 00437 } 00438 free(common_stub::coap_header); 00439 common_stub::coap_header = NULL; 00440 } 00441 free(coap_header); 00442 coap_header = NULL; 00443 00444 delete name; 00445 name = NULL; 00446 00447 if(m2mtlvserializer_stub::uint8_value) { 00448 free(m2mtlvserializer_stub::uint8_value); 00449 } 00450 m2mtlvserializer_stub::clear(); 00451 00452 m2mbase_stub::clear(); 00453 common_stub::clear(); 00454 00455 object->_instance_list.clear(); 00456 delete ins; 00457 } 00458 00459 void Test_M2MObject::test_handle_put_request() 00460 { 00461 uint8_t value[] = {"name"}; 00462 bool execute_value_updated = false; 00463 sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 00464 memset(coap_header, 0, sizeof(sn_coap_hdr_s)); 00465 sn_coap_hdr_s * coap_response = NULL; 00466 00467 coap_header->uri_path_ptr = value; 00468 coap_header->uri_path_len = sizeof(value); 00469 00470 coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00471 00472 String *name = new String("name"); 00473 common_stub::int_value = 0; 00474 m2mbase_stub::string_value = name; 00475 00476 m2mbase_stub::operation = M2MBase::PUT_ALLOWED; 00477 m2mbase_stub::uint8_value = 200; 00478 00479 common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); 00480 memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); 00481 00482 coap_header->payload_ptr = (uint8_t*)malloc(1); 00483 00484 CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); 00485 free(coap_header->payload_ptr); 00486 coap_header->payload_ptr = NULL; 00487 00488 CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); 00489 00490 coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 00491 coap_header->options_list_ptr->uri_query_ptr = value; 00492 coap_header->options_list_ptr->uri_query_len = sizeof(value); 00493 00494 coap_header->content_type_ptr = (uint8_t*)malloc(1); 00495 coap_header->content_type_len = 1; 00496 *coap_header->content_type_ptr = 99; 00497 m2mtlvdeserializer_stub::bool_value = true; 00498 00499 m2mbase_stub::bool_value = false; 00500 00501 CHECK(object->handle_put_request(NULL,coap_header,handler,execute_value_updated) != NULL); 00502 00503 m2mtlvdeserializer_stub::bool_value = false; 00504 00505 CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); 00506 00507 *coap_header->content_type_ptr = 100; 00508 00509 CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); 00510 00511 m2mbase_stub::bool_value = true; 00512 00513 CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); 00514 00515 m2mbase_stub::operation = M2MBase::NOT_ALLOWED; 00516 00517 CHECK(object->handle_put_request(NULL,coap_header,handler, execute_value_updated) != NULL); 00518 00519 CHECK(object->handle_put_request(NULL,NULL,handler, execute_value_updated) != NULL); 00520 00521 m2mbase_stub::operation = M2MBase::PUT_ALLOWED; 00522 00523 00524 00525 00526 free(coap_header->payload_ptr); 00527 coap_header->payload_ptr = NULL; 00528 coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); 00529 CHECK(coap_response != NULL); 00530 CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_CHANGED); 00531 if(coap_response) { 00532 if(coap_response->content_type_ptr) { 00533 free(coap_response->content_type_ptr); 00534 coap_response->content_type_ptr = NULL; 00535 } 00536 } 00537 m2mbase_stub::bool_value = false; 00538 coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); 00539 CHECK(coap_response != NULL); 00540 CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_BAD_REQUEST); 00541 if(coap_response) { 00542 if(coap_response->content_type_ptr) { 00543 free(coap_response->content_type_ptr); 00544 coap_response->content_type_ptr = NULL; 00545 } 00546 } 00547 00548 free(coap_header->options_list_ptr); 00549 coap_header->options_list_ptr = NULL; 00550 coap_response = object->handle_put_request(NULL,coap_header,handler,execute_value_updated); 00551 CHECK(coap_response != NULL); 00552 CHECK(coap_response->msg_code == COAP_MSG_CODE_RESPONSE_BAD_REQUEST); 00553 if(coap_response) { 00554 if(coap_response->content_type_ptr) { 00555 free(coap_response->content_type_ptr); 00556 coap_response->content_type_ptr = NULL; 00557 } 00558 } 00559 00560 free(coap_header->content_type_ptr); 00561 free(coap_header->options_list_ptr); 00562 free(common_stub::coap_header); 00563 delete name; 00564 free(coap_header); 00565 00566 m2mtlvdeserializer_stub::clear(); 00567 common_stub::clear(); 00568 m2mbase_stub::clear(); 00569 } 00570 00571 void Test_M2MObject::test_handle_post_request() 00572 { 00573 uint8_t value[] = {"name"}; 00574 bool execute_value_updated = false; 00575 sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 00576 memset(coap_header, 0, sizeof(sn_coap_hdr_s)); 00577 00578 coap_header->uri_path_ptr = value; 00579 coap_header->uri_path_len = sizeof(value); 00580 00581 coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; 00582 00583 String *name = new String("name"); 00584 common_stub::int_value = 0; 00585 m2mbase_stub::string_value = name; 00586 00587 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00588 m2mbase_stub::uint8_value = 200; 00589 00590 common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); 00591 memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); 00592 00593 m2mbase_stub::bool_value = false; 00594 00595 sn_coap_hdr_s * coap_response = NULL; 00596 m2mbase_stub::uint8_value = 99; 00597 00598 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00599 CHECK( coap_response != NULL); 00600 00601 00602 m2mbase_stub::uint8_value = 100; 00603 00604 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00605 CHECK( coap_response != NULL); 00606 00607 coap_header->payload_ptr = (uint8_t*)malloc(1); 00608 00609 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00610 CHECK( coap_response != NULL); 00611 00612 m2mbase_stub::uint8_value = 99; 00613 00614 object->_max_instance_count = 0; 00615 00616 String *test = new String("name"); 00617 M2MObjectInstance *ins = new M2MObjectInstance(*test,*object); 00618 ins->set_instance_id(0); 00619 object->_instance_list.push_back(ins); 00620 00621 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00622 CHECK( coap_response != NULL); 00623 00624 object->remove_object_instance(0); 00625 delete test; 00626 00627 object->_max_instance_count = 65535; 00628 00629 m2mbase_stub::uint8_value = 0; 00630 00631 coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 00632 coap_header->options_list_ptr->uri_query_ptr = value; 00633 coap_header->options_list_ptr->uri_query_len = sizeof(value); 00634 00635 coap_header->content_type_ptr = (uint8_t*)malloc(1); 00636 coap_header->content_type_len = 1; 00637 *coap_header->content_type_ptr = 99; 00638 m2mtlvdeserializer_stub::is_object_bool_value = true; 00639 m2mtlvdeserializer_stub::bool_value = false; 00640 m2mbase_stub::bool_value = false; 00641 00642 m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; 00643 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00644 00645 CHECK( coap_response != NULL); 00646 if(coap_response) { 00647 if(coap_response->content_type_ptr) { 00648 free(coap_response->content_type_ptr); 00649 coap_response->content_type_ptr = NULL; 00650 } 00651 if (coap_response->options_list_ptr->location_path_ptr) { 00652 free(coap_response->options_list_ptr->location_path_ptr); 00653 coap_response->options_list_ptr->location_path_ptr = NULL; 00654 } 00655 if (coap_response->options_list_ptr) { 00656 free(coap_response->options_list_ptr); 00657 coap_response->options_list_ptr = NULL; 00658 } 00659 } 00660 00661 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00662 m2mtlvdeserializer_stub::is_object_bool_value = true; 00663 m2mtlvdeserializer_stub::bool_value = false; 00664 m2mtlvdeserializer_stub::int_value = 10; 00665 m2mbase_stub::bool_value = false; 00666 00667 m2mtlvdeserializer_stub::error = M2MTLVDeserializer::NotAllowed; 00668 00669 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00670 00671 CHECK( coap_response != NULL); 00672 if(coap_response) { 00673 if(coap_response->content_type_ptr) { 00674 free(coap_response->content_type_ptr); 00675 coap_response->content_type_ptr = NULL; 00676 } 00677 if (coap_response->options_list_ptr) { 00678 if (coap_response->options_list_ptr->location_path_ptr) { 00679 free(coap_response->options_list_ptr->location_path_ptr); 00680 coap_response->options_list_ptr->location_path_ptr = NULL; 00681 } 00682 free(coap_response->options_list_ptr); 00683 coap_response->options_list_ptr = NULL; 00684 } 00685 } 00686 00687 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00688 m2mtlvdeserializer_stub::is_object_bool_value = false; 00689 m2mtlvdeserializer_stub::bool_value = true; 00690 m2mbase_stub::bool_value = false; 00691 m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; 00692 00693 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00694 00695 CHECK( coap_response != NULL); 00696 if(coap_response) { 00697 if(coap_response->content_type_ptr) { 00698 free(coap_response->content_type_ptr); 00699 coap_response->content_type_ptr = NULL; 00700 } 00701 if (coap_response->options_list_ptr) { 00702 if (coap_response->options_list_ptr->location_path_ptr) { 00703 free(coap_response->options_list_ptr->location_path_ptr); 00704 coap_response->options_list_ptr->location_path_ptr = NULL; 00705 } 00706 free(coap_response->options_list_ptr); 00707 coap_response->options_list_ptr = NULL; 00708 } 00709 } 00710 00711 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00712 m2mtlvdeserializer_stub::is_object_bool_value = false; 00713 m2mtlvdeserializer_stub::bool_value = true; 00714 m2mbase_stub::bool_value = false; 00715 m2mtlvdeserializer_stub::error = M2MTLVDeserializer::NotFound; 00716 00717 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00718 00719 CHECK( coap_response != NULL); 00720 if(coap_response) { 00721 if(coap_response->content_type_ptr) { 00722 free(coap_response->content_type_ptr); 00723 coap_response->content_type_ptr = NULL; 00724 } 00725 if (coap_response->options_list_ptr) { 00726 if (coap_response->options_list_ptr->location_path_ptr) { 00727 free(coap_response->options_list_ptr->location_path_ptr); 00728 coap_response->options_list_ptr->location_path_ptr = NULL; 00729 } 00730 free(coap_response->options_list_ptr); 00731 coap_response->options_list_ptr = NULL; 00732 } 00733 } 00734 00735 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00736 m2mtlvdeserializer_stub::bool_value = false; 00737 00738 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00739 00740 CHECK( coap_response != NULL); 00741 if(coap_response) { 00742 if(coap_response->content_type_ptr) { 00743 free(coap_response->content_type_ptr); 00744 coap_response->content_type_ptr = NULL; 00745 } 00746 if (coap_response->options_list_ptr) { 00747 if (coap_response->options_list_ptr->location_path_ptr) { 00748 free(coap_response->options_list_ptr->location_path_ptr); 00749 coap_response->options_list_ptr->location_path_ptr = NULL; 00750 } 00751 free(coap_response->options_list_ptr); 00752 coap_response->options_list_ptr = NULL; 00753 } 00754 } 00755 00756 00757 *coap_header->content_type_ptr = 100; 00758 00759 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00760 00761 CHECK( coap_response != NULL); 00762 if(coap_response) { 00763 if(coap_response->content_type_ptr) { 00764 free(coap_response->content_type_ptr); 00765 coap_response->content_type_ptr = NULL; 00766 } 00767 if (coap_response->options_list_ptr) { 00768 if (coap_response->options_list_ptr->location_path_ptr) { 00769 free(coap_response->options_list_ptr->location_path_ptr); 00770 coap_response->options_list_ptr->location_path_ptr = NULL; 00771 } 00772 free(coap_response->options_list_ptr); 00773 coap_response->options_list_ptr = NULL; 00774 } 00775 } 00776 00777 00778 m2mbase_stub::bool_value = true; 00779 00780 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00781 00782 CHECK( coap_response != NULL); 00783 if(coap_response) { 00784 if(coap_response->content_type_ptr) { 00785 free(coap_response->content_type_ptr); 00786 coap_response->content_type_ptr = NULL; 00787 } 00788 if (coap_response->options_list_ptr) { 00789 if (coap_response->options_list_ptr->location_path_ptr) { 00790 free(coap_response->options_list_ptr->location_path_ptr); 00791 coap_response->options_list_ptr->location_path_ptr = NULL; 00792 } 00793 free(coap_response->options_list_ptr); 00794 coap_response->options_list_ptr = NULL; 00795 } 00796 } 00797 00798 00799 m2mbase_stub::operation = M2MBase::NOT_ALLOWED; 00800 00801 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00802 00803 CHECK( coap_response != NULL); 00804 if(coap_response) { 00805 if(coap_response->content_type_ptr) { 00806 free(coap_response->content_type_ptr); 00807 coap_response->content_type_ptr = NULL; 00808 } 00809 } 00810 00811 coap_response = object->handle_post_request(NULL,NULL,handler,execute_value_updated); 00812 00813 CHECK( coap_response != NULL); 00814 if(coap_response) { 00815 if(coap_response->content_type_ptr) { 00816 free(coap_response->content_type_ptr); 00817 coap_response->content_type_ptr = NULL; 00818 } 00819 if (coap_response->options_list_ptr) { 00820 if (coap_response->options_list_ptr->location_path_ptr) { 00821 free(coap_response->options_list_ptr->location_path_ptr); 00822 coap_response->options_list_ptr->location_path_ptr = NULL; 00823 } 00824 free(coap_response->options_list_ptr); 00825 coap_response->options_list_ptr = NULL; 00826 } 00827 } 00828 00829 m2mbase_stub::operation = M2MBase::POST_ALLOWED; 00830 m2mtlvdeserializer_stub::int_value = 0; 00831 m2mtlvdeserializer_stub::is_object_bool_value = true; 00832 *coap_header->content_type_ptr = 99; 00833 coap_response = object->handle_post_request(NULL,coap_header,handler,execute_value_updated); 00834 00835 CHECK( coap_response != NULL); 00836 if(coap_response) { 00837 if(coap_response->content_type_ptr) { 00838 free(coap_response->content_type_ptr); 00839 coap_response->content_type_ptr = NULL; 00840 } 00841 if (coap_response->options_list_ptr) { 00842 if (coap_response->options_list_ptr->location_path_ptr) { 00843 free(coap_response->options_list_ptr->location_path_ptr); 00844 coap_response->options_list_ptr->location_path_ptr = NULL; 00845 } 00846 free(coap_response->options_list_ptr); 00847 coap_response->options_list_ptr = NULL; 00848 } 00849 } 00850 00851 free(coap_header->content_type_ptr); 00852 free(coap_header->options_list_ptr); 00853 free(coap_header->payload_ptr); 00854 free(common_stub::coap_header); 00855 delete name; 00856 free(coap_header); 00857 00858 m2mtlvdeserializer_stub::clear(); 00859 common_stub::clear(); 00860 m2mbase_stub::clear(); 00861 } 00862 00863 void Test_M2MObject::test_notification_update() 00864 { 00865 TestReportObserver obs; 00866 m2mbase_stub::report = new M2MReportHandler(obs); 00867 m2mbase_stub::bool_value = true; 00868 00869 object->notification_update(0); 00870 00871 delete m2mbase_stub::report; 00872 m2mbase_stub::report = NULL; 00873 } 00874
Generated on Tue Jul 12 2022 12:28:54 by
