Ram Gandikota / Mbed OS ABCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_m2mobjectinstance.cpp Source File

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