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

« Back to documentation index

Show/hide line numbers test_m2mresourceinstance.cpp Source File

test_m2mresourceinstance.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_m2mresourceinstance.h"
00018 #include "CppUTest/MemoryLeakDetectorMallocMacros.h"
00019 #include "m2mbase_stub.h"
00020 #include "m2mobservationhandler.h"
00021 #include "m2mreporthandler.h"
00022 #include "m2mreporthandler_stub.h"
00023 #include "common_stub.h"
00024 #include "m2mtlvdeserializer_stub.h"
00025 #include "m2mblockmessage_stub.h"
00026 #include "m2mobjectinstance_stub.h"
00027 #include "m2mobject_stub.h"
00028 #include "m2mresource_stub.h"
00029 
00030 static bool cb_visited = false;
00031 static void callback_function(void *args)
00032 {
00033     cb_visited = true;
00034 }
00035 static void global_notification_sent_function()
00036 {
00037     cb_visited = true;
00038 }
00039 
00040 class MyTest{
00041 public:
00042     void execute_function(void */*argument*/) {
00043         visited = true;
00044     }
00045     void block_message_received(M2MBlockMessage */*argument*/) {
00046         block_received = true;
00047     }
00048     void block_message_requested(const String& /*resource*/, uint8_t *&/*data*/, uint32_t &/*len*/) {
00049         block_requested = true;
00050     }
00051     void notification_sent() {
00052         visited = true;
00053     }
00054 
00055     bool visited;
00056     bool block_received;
00057     bool block_requested;
00058 };
00059 
00060 class ResourceCallback : public M2MResourceCallback {
00061 
00062 public:
00063 
00064     ResourceCallback() : visited(false) {}
00065     ~ResourceCallback(){}
00066     void notification_update() {
00067         visited = true;
00068     }
00069 
00070     void clear() {visited = false;}
00071     bool visited;
00072 };
00073 
00074 class TestReportObserver :  public M2MReportObserver{
00075 public :
00076     TestReportObserver() {}
00077     ~TestReportObserver() {}
00078     void observation_to_be_sent(m2m::Vector<uint16_t>,bool){ }
00079 };
00080 
00081 class Handler : public M2MObservationHandler {
00082 
00083 public:
00084 
00085     Handler(){}
00086     ~Handler(){}
00087     void observation_to_be_sent(M2MBase *, uint16_t, m2m::Vector<uint16_t>, bool){
00088         visited = true;
00089     }
00090     void send_delayed_response(M2MBase *){}
00091     void resource_to_be_deleted(M2MBase *){visited=true;}
00092     void remove_object(M2MBase *){visited = true;}
00093     void value_updated(M2MBase *,const String&){visited = true;}
00094 
00095     void clear() {visited = false;}
00096     bool visited;
00097 };
00098 
00099 Test_M2MResourceInstance::Test_M2MResourceInstance()
00100 {
00101     handler = new Handler();
00102     obj = new M2MObject("name", "name");
00103     m2mresource_stub::object_instance = new M2MObjectInstance(*obj, "name", "", "");
00104     m2mobjectinstance_stub::resource = new M2MResource(*m2mresource_stub::object_instance,
00105                                                        "name",
00106                                                        "type",
00107                                                        M2MResourceInstance::STRING,
00108                                                        false,
00109                                                        "name");
00110 
00111     resource_instance = new M2MResourceInstance(*m2mobjectinstance_stub::resource,
00112                           "name",
00113                           "resource_type",
00114                           M2MResourceInstance::STRING,
00115                           0,
00116                           "name",
00117                           false);
00118 }
00119 
00120 Test_M2MResourceInstance::~Test_M2MResourceInstance()
00121 {
00122     delete m2mresource_stub::object_instance;
00123     delete m2mobjectinstance_stub::resource;
00124     delete resource_instance;
00125     delete obj;
00126     delete handler;
00127 }
00128 
00129 void Test_M2MResourceInstance::test_resource_instance_type()
00130 {
00131     CHECK(resource_instance->resource_instance_type() == M2MResourceInstance::STRING);
00132 }
00133 
00134 void Test_M2MResourceInstance::test_static_resource_instance()
00135 {
00136     u_int8_t value[] = {"value"};
00137     m2mbase_stub::mode_value = M2MBase::Dynamic;
00138     M2MResourceInstance *res = new M2MResourceInstance(*m2mobjectinstance_stub::resource,
00139                                                        "name1",
00140                                                        "type1",
00141                                                        M2MResourceInstance::INTEGER,
00142                                                        value, (uint32_t)sizeof(value),
00143                                                        0,
00144                                                        "name1",
00145                                                        false);
00146 
00147     CHECK(res != NULL);
00148     delete res;
00149     res = NULL;
00150 
00151     m2mbase_stub::mode_value = M2MBase::Static;
00152     m2mbase_stub::nsdl_resource = (sn_nsdl_dynamic_resource_parameters_s*)malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s));
00153     m2mbase_stub::nsdl_resource->static_resource_parameters =
00154             (sn_nsdl_static_resource_parameters_s*)malloc(sizeof(sn_nsdl_static_resource_parameters_s));
00155 
00156     res = new M2MResourceInstance(*m2mobjectinstance_stub::resource,
00157                                                        "name1",
00158                                                        "type1",
00159                                                        M2MResourceInstance::INTEGER,
00160                                                        value, (uint32_t)sizeof(value),
00161                                                        0,
00162                                                        "name1",
00163                                                        false);
00164 
00165     free(m2mbase_stub::nsdl_resource->static_resource_parameters->resource);
00166     free(m2mbase_stub::nsdl_resource->static_resource_parameters);
00167     free(m2mbase_stub::nsdl_resource);
00168     CHECK(res != NULL);
00169     delete res;
00170 }
00171 
00172 void Test_M2MResourceInstance::test_base_type()
00173 {
00174     m2mbase_stub::base_type = M2MBase::Resource;
00175     CHECK(M2MBase::Resource == resource_instance->base_type());
00176 }
00177 
00178 void Test_M2MResourceInstance::test_handle_observation_attribute()
00179 {
00180     char *d = "s";
00181     TestReportObserver obs;
00182     m2mbase_stub::report = new M2MReportHandler(obs);
00183 
00184     CHECK(false == resource_instance->handle_observation_attribute(d));
00185 
00186     resource_instance->_resource_type = M2MResourceInstance::INTEGER;
00187     CHECK(false == resource_instance->handle_observation_attribute(d));
00188 
00189     resource_instance->_resource_type = M2MResourceInstance::FLOAT;
00190     CHECK(false == resource_instance->handle_observation_attribute(d));
00191 
00192     m2mreporthandler_stub::bool_return = true;
00193     CHECK(true == resource_instance->handle_observation_attribute(d));
00194 
00195     m2mbase_stub::bool_value = false;
00196     CHECK(true == resource_instance->handle_observation_attribute(d));
00197 
00198     delete m2mbase_stub::report;
00199     m2mbase_stub::report = NULL;
00200 }
00201 
00202 void Test_M2MResourceInstance::test_set_execute_function()
00203 {
00204     MyTest test;
00205     resource_instance->set_execute_function(execute_callback (&test,&MyTest::execute_function));
00206     resource_instance->set_execute_function(callback_function);
00207 }
00208 
00209 void Test_M2MResourceInstance::test_execute()
00210 {
00211     MyTest test;
00212     void *args = NULL;
00213 
00214     resource_instance->set_execute_function(execute_callback (&test,&MyTest::execute_function));
00215     resource_instance->execute(args);
00216 
00217     cb_visited = false;
00218     resource_instance->set_execute_function(callback_function);
00219     resource_instance->execute(args);
00220     CHECK(true == cb_visited);
00221 
00222     // Check delete
00223     cb_visited = false;
00224     resource_instance->set_execute_function(callback_function);
00225     resource_instance->execute(args);
00226     CHECK(true == cb_visited);
00227 }
00228 
00229 void Test_M2MResourceInstance::test_set_value()
00230 {
00231     u_int8_t value[] = {"value2"};
00232     resource_instance->_value = (u_int8_t*)malloc(sizeof(u_int8_t));
00233     m2mbase_stub::bool_value = true;
00234 
00235     CHECK(resource_instance->set_value(value,(u_int32_t)sizeof(value)) == true);
00236     CHECK( resource_instance->_value_length == sizeof(value));
00237     CHECK( *resource_instance->_value == *value);
00238 
00239     m2mbase_stub::observe = (M2MObservationHandler*)handler;
00240 
00241     u_int8_t value2[] = {"12"};
00242     CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true);
00243 
00244     u_int8_t value3[] = {"13"};
00245     CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true);
00246 
00247     CHECK(resource_instance->set_value(123456789) == true);
00248     CHECK(memcmp(resource_instance->_value, "123456789", 9) == 0);
00249 
00250     // verify int value helper
00251     CHECK(resource_instance->get_value_int() == 123456789);
00252 
00253     // verify string value helper
00254     CHECK(resource_instance->get_value_string() == "123456789");
00255 
00256     free(resource_instance->_value);
00257     resource_instance->_value_length = 0;
00258 
00259     CHECK(resource_instance->set_value(NULL,0) == false);
00260 
00261     CHECK(resource_instance->set_value(NULL,0) == false);
00262 
00263     m2mbase_stub::observation_level_value = M2MBase::R_Attribute;
00264     resource_instance->_value = (u_int8_t*)malloc(sizeof(value)+1);
00265     memset(resource_instance->_value,0,sizeof(value)+1);
00266     memcpy(resource_instance->_value,value,sizeof(value));
00267     resource_instance->_value_length = sizeof(value);
00268     TestReportObserver obs;
00269     m2mbase_stub::report = new M2MReportHandler(obs);
00270 
00271     u_int8_t value4[] = {"value4"};
00272     CHECK(resource_instance->set_value(value4,(u_int32_t)sizeof(value4)) == true);
00273 
00274 
00275     m2mbase_stub::base_type = M2MBase::ResourceInstance;
00276     m2mbase_stub::observation_level_value = M2MBase::O_Attribute;
00277     resource_instance->_resource_type = M2MResourceInstance::INTEGER;
00278     m2mbase_stub::mode_value = M2MBase::Dynamic;
00279     ResourceCallback *resource_cb = new ResourceCallback();
00280     resource_instance->set_resource_observer(resource_cb);
00281     CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true);
00282 
00283     // XXX: the callback will not be called on current code with combination of
00284     // M2MBase::Dynamic and M2MBase::R_Attribute.
00285     CHECK(resource_cb->visited == false);
00286 
00287     resource_cb->visited = false;
00288     m2mbase_stub::observation_level_value = M2MBase::R_Attribute;
00289     CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true);
00290     CHECK(resource_cb->visited == true);
00291 
00292     resource_instance->set_resource_observer(NULL);
00293     resource_cb->visited = false;
00294     m2mbase_stub::observation_level_value = M2MBase::R_Attribute;
00295     CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true);
00296     CHECK(resource_cb->visited == false);
00297 
00298 
00299     CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true);
00300 
00301     m2mbase_stub::observation_level_value = M2MBase::OI_Attribute;
00302 
00303     resource_instance->_resource_type = M2MResourceInstance::INTEGER;
00304 
00305     m2mbase_stub::mode_value = M2MBase::Dynamic;
00306 
00307     CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true);
00308 
00309     m2mbase_stub::observation_level_value = M2MBase::OOI_Attribute;
00310 
00311     resource_instance->_resource_type = M2MResourceInstance::INTEGER;
00312 
00313     m2mbase_stub::mode_value = M2MBase::Dynamic;
00314 
00315     CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true);
00316 
00317     delete m2mbase_stub::report;
00318     m2mbase_stub::report = NULL;
00319     delete resource_cb;
00320 }
00321 
00322 void Test_M2MResourceInstance::test_clear_value()
00323 {
00324     u_int8_t value[] = {"value"};
00325     resource_instance->_value = (u_int8_t*)malloc(sizeof(u_int8_t));
00326 
00327     m2mbase_stub::observe = handler;
00328     TestReportObserver obs;
00329     m2mbase_stub::report = new M2MReportHandler(obs);
00330 
00331     CHECK(resource_instance->set_value(value,(u_int32_t)sizeof(value)) == true);
00332     CHECK( resource_instance->_value_length == sizeof(value));
00333     CHECK( *resource_instance->_value == *value);
00334     resource_instance->clear_value();
00335 
00336     CHECK( resource_instance->_value_length == 0);
00337     CHECK( resource_instance->_value == NULL);
00338 
00339     m2mbase_stub::bool_value = true;
00340     m2mbase_stub::mode_value = M2MBase::Dynamic;
00341     m2mbase_stub::observation_level_value = M2MBase::R_Attribute;
00342     resource_instance->_resource_type = M2MResourceInstance::INTEGER;
00343     resource_instance->clear_value();
00344 
00345     CHECK( resource_instance->_value_length == 0);
00346     CHECK( resource_instance->_value == NULL);
00347 
00348     delete m2mbase_stub::report;
00349     m2mbase_stub::report = NULL;
00350 }
00351 
00352 void Test_M2MResourceInstance::test_get_value()
00353 {
00354     u_int8_t test_value[] = {"value3"};
00355     u_int32_t value_length((u_int32_t)sizeof(test_value));
00356 
00357     resource_instance->_value = (u_int8_t *)malloc(value_length);
00358     resource_instance->_value_length = value_length;
00359     memcpy((u_int8_t *)resource_instance->_value, (u_int8_t *)test_value, value_length);
00360 
00361     uint8_t* buffer = (uint8_t*)malloc(5);
00362     uint32_t val_size = 0;
00363     resource_instance->get_value(buffer, val_size);
00364     CHECK(val_size == value_length);
00365     free(buffer);
00366 
00367     resource_instance->clear_value();
00368     CHECK(resource_instance->_value == NULL);
00369 
00370 
00371 }
00372 
00373 void Test_M2MResourceInstance::test_value()
00374 {
00375     CHECK(resource_instance->value() == NULL);
00376 }
00377 
00378 void Test_M2MResourceInstance::test_value_length()
00379 {
00380     CHECK(resource_instance->value_length() == 0);
00381 }
00382 
00383 void Test_M2MResourceInstance::test_handle_get_request()
00384 {
00385     uint8_t value[] = {"name"};
00386     sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
00387     memset(coap_header, 0, sizeof(sn_coap_hdr_s));
00388 
00389     coap_header->uri_path_ptr = value;
00390     coap_header->uri_path_len = sizeof(value);
00391 
00392     coap_header->msg_code = COAP_MSG_CODE_REQUEST_GET;
00393 
00394     common_stub::int_value = 0;
00395     m2mbase_stub::string_value = "name";
00396 
00397     m2mbase_stub::operation = M2MBase::GET_ALLOWED;
00398     m2mbase_stub::uint8_value = 200;
00399     common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_));
00400     memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_));
00401 
00402     coap_header->token_ptr = (uint8_t*)malloc(sizeof(value));
00403     memcpy(coap_header->token_ptr, value, sizeof(value));
00404 
00405     common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
00406     coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
00407     coap_header->options_list_ptr->observe = 0;
00408 
00409     coap_header->content_format = sn_coap_content_format_e(110);
00410 
00411     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00412 
00413     MyTest test;
00414     test.block_requested = false;
00415     resource_instance->set_incoming_block_message_callback(
00416                 incoming_block_message_callback(&test, &MyTest::block_message_received));
00417     resource_instance->set_outgoing_block_message_callback(
00418         outgoing_block_message_callback(&test,&MyTest::block_message_requested));
00419     m2mblockmessage_stub::is_block_message = true;
00420     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00421     CHECK(test.block_requested == true);
00422     m2mblockmessage_stub::is_block_message = false;
00423 
00424     // OMA OPAQUE
00425     resource_instance->_resource_type = M2MResourceInstance::OPAQUE;
00426 
00427     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00428 
00429     // Not OMA TLV or JSON
00430     m2mbase_stub::uint8_value = 110;
00431     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00432 
00433     // OMA TLV
00434     m2mbase_stub::uint8_value = 99;
00435     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00436     // OMA JSON
00437     m2mbase_stub::uint8_value = 100;
00438     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00439 
00440     coap_header->options_list_ptr->observe = 0;
00441     m2mbase_stub::uint16_value = 0x1c1c;
00442     m2mbase_stub::bool_value = true;
00443 
00444     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00445 
00446     // Not observable
00447     m2mbase_stub::bool_value = false;
00448     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00449 
00450     m2mbase_stub::bool_value = true;
00451 
00452     coap_header->options_list_ptr->observe = 0;
00453 
00454     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00455 
00456     coap_header->options_list_ptr->observe = 1;
00457     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00458 
00459     m2mbase_stub::operation = M2MBase::NOT_ALLOWED;
00460     CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL);
00461 
00462     CHECK(resource_instance->handle_get_request(NULL,NULL,handler) != NULL);
00463 
00464     if(coap_header->token_ptr) {
00465         free(coap_header->token_ptr);
00466         coap_header->token_ptr = NULL;
00467     }
00468     if(coap_header->options_list_ptr) {
00469         free(coap_header->options_list_ptr);
00470         coap_header->options_list_ptr = NULL;
00471     }
00472 
00473     if(common_stub::coap_header){
00474         if(common_stub::coap_header->options_list_ptr) {
00475             free(common_stub::coap_header->options_list_ptr);
00476             common_stub::coap_header->options_list_ptr = NULL;
00477         }
00478         free(common_stub::coap_header);
00479         common_stub::coap_header = NULL;
00480     }
00481     free(coap_header);
00482     coap_header = NULL;
00483 
00484     m2mbase_stub::clear();
00485     common_stub::clear();
00486 }
00487 
00488 void Test_M2MResourceInstance::test_handle_put_request()
00489 {
00490     uint8_t value[] = {"name"};
00491     bool execute_value_updated = false;
00492     sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
00493     memset(coap_header, 0, sizeof(sn_coap_hdr_s));
00494 
00495     coap_header->uri_path_ptr = value;
00496     coap_header->uri_path_len = sizeof(value);
00497 
00498     coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT;
00499 
00500     common_stub::int_value = 0;
00501     m2mbase_stub::string_value = "name";
00502 
00503     m2mbase_stub::operation = M2MBase::PUT_ALLOWED;
00504     m2mbase_stub::uint8_value = 200;
00505 
00506     common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_));
00507     memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_));
00508 
00509     coap_header->payload_ptr = (uint8_t*)malloc(1);
00510 
00511     coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
00512     coap_header->options_list_ptr->uri_query_ptr = value;
00513     coap_header->options_list_ptr->uri_query_len = sizeof(value);
00514 
00515     coap_header->content_format = sn_coap_content_format_e(99);
00516     m2mtlvdeserializer_stub::bool_value = true;
00517 
00518     m2mbase_stub::bool_value = false;
00519 
00520     sn_coap_hdr_s *coap_response = NULL;
00521     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00522     CHECK( coap_response != NULL);
00523 
00524     free(coap_header->options_list_ptr);
00525     coap_header->options_list_ptr = NULL;
00526 
00527     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00528     CHECK( coap_response != NULL);
00529 
00530     m2mtlvdeserializer_stub::bool_value = false;
00531 
00532     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00533 
00534     CHECK( coap_response != NULL);
00535 
00536     coap_header->content_format = sn_coap_content_format_e(100);
00537 
00538     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00539 
00540     CHECK( coap_response != NULL);
00541 
00542     m2mbase_stub::bool_value = true;
00543 
00544     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00545 
00546     CHECK( coap_response != NULL);
00547 
00548     m2mbase_stub::operation = M2MBase::NOT_ALLOWED;
00549 
00550     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00551 
00552     CHECK( coap_response != NULL);
00553 
00554     coap_response = resource_instance->handle_put_request(NULL,NULL,handler,execute_value_updated);
00555 
00556     CHECK( coap_response != NULL);
00557 
00558     MyTest test;
00559     test.block_received = false;
00560     m2mbase_stub::operation = M2MBase::PUT_ALLOWED;
00561     m2mblockmessage_stub::is_block_message = true;
00562     m2mblockmessage_stub::is_last_block = false;
00563     resource_instance->set_incoming_block_message_callback(
00564                 incoming_block_message_callback(&test, &MyTest::block_message_received));
00565     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00566     CHECK(test.block_received == true);
00567     CHECK( coap_response != NULL);
00568 
00569     test.block_received = false;
00570     m2mblockmessage_stub::is_block_message = true;
00571     m2mblockmessage_stub::is_last_block = true;
00572     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00573     CHECK(test.block_received == true);
00574     CHECK( coap_response != NULL);
00575 
00576     test.block_received = false;
00577     m2mblockmessage_stub::is_block_message = false;
00578     m2mblockmessage_stub::is_last_block = false;
00579     coap_response = resource_instance->handle_put_request(NULL,coap_header,handler,execute_value_updated);
00580     CHECK(test.block_received == false);
00581     CHECK( coap_response != NULL);
00582 
00583     free(coap_header->options_list_ptr);
00584     free(coap_header->payload_ptr);
00585     free(common_stub::coap_header);
00586     free(coap_header);
00587 
00588     m2mtlvdeserializer_stub::clear();
00589     common_stub::clear();
00590     m2mbase_stub::clear();
00591 }
00592 
00593 void Test_M2MResourceInstance::test_set_resource_observer()
00594 {
00595     ResourceCallback *resource_cb = new ResourceCallback();
00596     resource_instance->set_resource_observer(resource_cb);
00597     CHECK(resource_instance->_resource_callback == resource_cb)
00598     delete resource_cb;
00599 }
00600 
00601 
00602 void Test_M2MResourceInstance::test_get_object_name()
00603 {
00604     m2mbase_stub::string_value = "name";
00605     CHECK(resource_instance->object_name() == "name");
00606 }
00607 
00608 void Test_M2MResourceInstance::test_get_object_instance_id()
00609 {
00610     resource_instance->_object_instance_id = 100;
00611     CHECK(resource_instance->object_instance_id() == 100);
00612 }
00613 
00614 void Test_M2MResourceInstance::test_set_notification_sent_function()
00615 {
00616     MyTest test;
00617     resource_instance->set_notification_sent_callback(
00618                 notification_sent_callback(&test,&MyTest::notification_sent));
00619     resource_instance->set_notification_sent_callback(global_notification_sent_function);
00620 }
00621 
00622 void Test_M2MResourceInstance::test_notification_sent()
00623 {
00624     MyTest test;
00625     void *args = NULL;
00626 
00627     resource_instance->set_notification_sent_callback(
00628                 notification_sent_callback(&test,&MyTest::notification_sent));
00629     resource_instance->notification_sent();
00630 
00631     cb_visited = false;
00632     resource_instance->set_notification_sent_callback(global_notification_sent_function);
00633     resource_instance->notification_sent();
00634     CHECK(true == cb_visited);
00635 
00636     // Check delete
00637     cb_visited = false;
00638     resource_instance->set_notification_sent_callback(global_notification_sent_function);
00639     resource_instance->notification_sent();
00640     CHECK(true == cb_visited);
00641 }
00642 
00643 void Test_M2MResourceInstance::test_ctor()
00644 {
00645     M2MResourceInstance* instance = new M2MResourceInstance(*m2mobjectinstance_stub::resource, &params,
00646                                                             M2MResourceInstance::STRING, 0);
00647     CHECK(instance != NULL);
00648     delete instance;
00649 }
00650 
00651 void Test_M2MResourceInstance::test_get_parent_resource()
00652 {
00653     M2MResourceInstance* instance = new M2MResourceInstance(*m2mobjectinstance_stub::resource, &params,
00654                                                             M2MResourceInstance::STRING, 0);
00655     // Only for the code coverage
00656     instance->get_parent_resource();
00657     delete instance;
00658 }