Ram Gandikota
/
IOTMetronome
FRDM K64F Metronome
mbed-client/test/mbedclient/utest/m2mnsdlinterface/test_m2mnsdlinterface.cpp@0:dbad57390bd1, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:37:05 2017 +0000
- Revision:
- 0:dbad57390bd1
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:dbad57390bd1 | 1 | /* |
ram54288 | 0:dbad57390bd1 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:dbad57390bd1 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:dbad57390bd1 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:dbad57390bd1 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:dbad57390bd1 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:dbad57390bd1 | 7 | * |
ram54288 | 0:dbad57390bd1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:dbad57390bd1 | 9 | * |
ram54288 | 0:dbad57390bd1 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:dbad57390bd1 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:dbad57390bd1 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:dbad57390bd1 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:dbad57390bd1 | 14 | * limitations under the License. |
ram54288 | 0:dbad57390bd1 | 15 | */ |
ram54288 | 0:dbad57390bd1 | 16 | #include "CppUTest/TestHarness.h" |
ram54288 | 0:dbad57390bd1 | 17 | #include "test_m2mnsdlinterface.h" |
ram54288 | 0:dbad57390bd1 | 18 | #include "common_stub.h" |
ram54288 | 0:dbad57390bd1 | 19 | #include "m2msecurity_stub.h" |
ram54288 | 0:dbad57390bd1 | 20 | #include "m2mnsdlobserver.h" |
ram54288 | 0:dbad57390bd1 | 21 | #include "m2mobject_stub.h" |
ram54288 | 0:dbad57390bd1 | 22 | #include "m2mobjectinstance_stub.h" |
ram54288 | 0:dbad57390bd1 | 23 | #include "m2mresource_stub.h" |
ram54288 | 0:dbad57390bd1 | 24 | #include "m2mresourceinstance_stub.h" |
ram54288 | 0:dbad57390bd1 | 25 | #include "m2mresource.h" |
ram54288 | 0:dbad57390bd1 | 26 | #include "m2mbase_stub.h" |
ram54288 | 0:dbad57390bd1 | 27 | #include "m2mserver.h" |
ram54288 | 0:dbad57390bd1 | 28 | #include "m2msecurity.h" |
ram54288 | 0:dbad57390bd1 | 29 | #include "m2mtlvdeserializer_stub.h" |
ram54288 | 0:dbad57390bd1 | 30 | class TestObserver : public M2MNsdlObserver { |
ram54288 | 0:dbad57390bd1 | 31 | |
ram54288 | 0:dbad57390bd1 | 32 | public: |
ram54288 | 0:dbad57390bd1 | 33 | TestObserver(){} |
ram54288 | 0:dbad57390bd1 | 34 | virtual ~TestObserver(){} |
ram54288 | 0:dbad57390bd1 | 35 | void coap_message_ready(uint8_t *, |
ram54288 | 0:dbad57390bd1 | 36 | uint16_t, |
ram54288 | 0:dbad57390bd1 | 37 | sn_nsdl_addr_s *){ |
ram54288 | 0:dbad57390bd1 | 38 | message_ready = true; |
ram54288 | 0:dbad57390bd1 | 39 | } |
ram54288 | 0:dbad57390bd1 | 40 | |
ram54288 | 0:dbad57390bd1 | 41 | void client_registered(M2MServer *){ |
ram54288 | 0:dbad57390bd1 | 42 | registered = true; |
ram54288 | 0:dbad57390bd1 | 43 | } |
ram54288 | 0:dbad57390bd1 | 44 | |
ram54288 | 0:dbad57390bd1 | 45 | void registration_updated(const M2MServer &){ |
ram54288 | 0:dbad57390bd1 | 46 | register_updated = true; |
ram54288 | 0:dbad57390bd1 | 47 | } |
ram54288 | 0:dbad57390bd1 | 48 | |
ram54288 | 0:dbad57390bd1 | 49 | void registration_error(uint8_t, bool retry = false){ |
ram54288 | 0:dbad57390bd1 | 50 | register_error = true; |
ram54288 | 0:dbad57390bd1 | 51 | } |
ram54288 | 0:dbad57390bd1 | 52 | |
ram54288 | 0:dbad57390bd1 | 53 | void client_unregistered(){ |
ram54288 | 0:dbad57390bd1 | 54 | unregistered = true; |
ram54288 | 0:dbad57390bd1 | 55 | } |
ram54288 | 0:dbad57390bd1 | 56 | |
ram54288 | 0:dbad57390bd1 | 57 | void bootstrap_done(M2MSecurity *sec){ |
ram54288 | 0:dbad57390bd1 | 58 | if(sec) { |
ram54288 | 0:dbad57390bd1 | 59 | boot_done = true; |
ram54288 | 0:dbad57390bd1 | 60 | delete sec; |
ram54288 | 0:dbad57390bd1 | 61 | sec = NULL; |
ram54288 | 0:dbad57390bd1 | 62 | } |
ram54288 | 0:dbad57390bd1 | 63 | } |
ram54288 | 0:dbad57390bd1 | 64 | |
ram54288 | 0:dbad57390bd1 | 65 | void bootstrap_wait(M2MSecurity *sec){ |
ram54288 | 0:dbad57390bd1 | 66 | if(sec) { |
ram54288 | 0:dbad57390bd1 | 67 | boot_wait = true; |
ram54288 | 0:dbad57390bd1 | 68 | delete sec; |
ram54288 | 0:dbad57390bd1 | 69 | sec = NULL; |
ram54288 | 0:dbad57390bd1 | 70 | } |
ram54288 | 0:dbad57390bd1 | 71 | } |
ram54288 | 0:dbad57390bd1 | 72 | |
ram54288 | 0:dbad57390bd1 | 73 | void bootstrap_error(){ |
ram54288 | 0:dbad57390bd1 | 74 | boot_error = true; |
ram54288 | 0:dbad57390bd1 | 75 | } |
ram54288 | 0:dbad57390bd1 | 76 | |
ram54288 | 0:dbad57390bd1 | 77 | void coap_data_processed(){ |
ram54288 | 0:dbad57390bd1 | 78 | data_processed = true; |
ram54288 | 0:dbad57390bd1 | 79 | } |
ram54288 | 0:dbad57390bd1 | 80 | |
ram54288 | 0:dbad57390bd1 | 81 | void value_updated(M2MBase *){ |
ram54288 | 0:dbad57390bd1 | 82 | value_update = true; |
ram54288 | 0:dbad57390bd1 | 83 | } |
ram54288 | 0:dbad57390bd1 | 84 | |
ram54288 | 0:dbad57390bd1 | 85 | bool register_error; |
ram54288 | 0:dbad57390bd1 | 86 | bool boot_error; |
ram54288 | 0:dbad57390bd1 | 87 | bool boot_wait; |
ram54288 | 0:dbad57390bd1 | 88 | bool boot_done; |
ram54288 | 0:dbad57390bd1 | 89 | bool registered; |
ram54288 | 0:dbad57390bd1 | 90 | bool register_updated; |
ram54288 | 0:dbad57390bd1 | 91 | bool data_processed; |
ram54288 | 0:dbad57390bd1 | 92 | bool unregistered; |
ram54288 | 0:dbad57390bd1 | 93 | bool message_ready; |
ram54288 | 0:dbad57390bd1 | 94 | bool value_update; |
ram54288 | 0:dbad57390bd1 | 95 | }; |
ram54288 | 0:dbad57390bd1 | 96 | |
ram54288 | 0:dbad57390bd1 | 97 | struct nsdl_s { |
ram54288 | 0:dbad57390bd1 | 98 | uint16_t update_register_msg_id; |
ram54288 | 0:dbad57390bd1 | 99 | uint16_t register_msg_len; |
ram54288 | 0:dbad57390bd1 | 100 | uint16_t update_register_msg_len; |
ram54288 | 0:dbad57390bd1 | 101 | |
ram54288 | 0:dbad57390bd1 | 102 | uint16_t register_msg_id; |
ram54288 | 0:dbad57390bd1 | 103 | uint16_t unregister_msg_id; |
ram54288 | 0:dbad57390bd1 | 104 | |
ram54288 | 0:dbad57390bd1 | 105 | uint16_t bootstrap_msg_id; |
ram54288 | 0:dbad57390bd1 | 106 | uint16_t oma_bs_port; /* Bootstrap port */ |
ram54288 | 0:dbad57390bd1 | 107 | uint8_t oma_bs_address_len; /* Bootstrap address length */ |
ram54288 | 0:dbad57390bd1 | 108 | unsigned int sn_nsdl_endpoint_registered:1; |
ram54288 | 0:dbad57390bd1 | 109 | bool handle_bootstrap_msg:1; |
ram54288 | 0:dbad57390bd1 | 110 | |
ram54288 | 0:dbad57390bd1 | 111 | struct grs_s *grs; |
ram54288 | 0:dbad57390bd1 | 112 | uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */ |
ram54288 | 0:dbad57390bd1 | 113 | sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. |
ram54288 | 0:dbad57390bd1 | 114 | sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information |
ram54288 | 0:dbad57390bd1 | 115 | |
ram54288 | 0:dbad57390bd1 | 116 | void (*sn_nsdl_oma_bs_done_cb)(sn_nsdl_oma_server_info_t *server_info_ptr); /* Callback to inform application when bootstrap is done */ |
ram54288 | 0:dbad57390bd1 | 117 | void *(*sn_nsdl_alloc)(uint16_t); |
ram54288 | 0:dbad57390bd1 | 118 | void (*sn_nsdl_free)(void *); |
ram54288 | 0:dbad57390bd1 | 119 | uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); |
ram54288 | 0:dbad57390bd1 | 120 | uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); |
ram54288 | 0:dbad57390bd1 | 121 | void (*sn_nsdl_oma_bs_done_cb_handle)(sn_nsdl_oma_server_info_t *server_info_ptr, |
ram54288 | 0:dbad57390bd1 | 122 | struct nsdl_s *handle); /* Callback to inform application when bootstrap is done with nsdl handle */ |
ram54288 | 0:dbad57390bd1 | 123 | }; |
ram54288 | 0:dbad57390bd1 | 124 | |
ram54288 | 0:dbad57390bd1 | 125 | Test_M2MNsdlInterface::Test_M2MNsdlInterface() |
ram54288 | 0:dbad57390bd1 | 126 | { |
ram54288 | 0:dbad57390bd1 | 127 | observer = new TestObserver(); |
ram54288 | 0:dbad57390bd1 | 128 | nsdl = new M2MNsdlInterface(*observer); |
ram54288 | 0:dbad57390bd1 | 129 | //nsdl->_server = new M2MServer(); |
ram54288 | 0:dbad57390bd1 | 130 | } |
ram54288 | 0:dbad57390bd1 | 131 | |
ram54288 | 0:dbad57390bd1 | 132 | Test_M2MNsdlInterface:: ~Test_M2MNsdlInterface() |
ram54288 | 0:dbad57390bd1 | 133 | { |
ram54288 | 0:dbad57390bd1 | 134 | delete nsdl; |
ram54288 | 0:dbad57390bd1 | 135 | nsdl = NULL; |
ram54288 | 0:dbad57390bd1 | 136 | delete observer; |
ram54288 | 0:dbad57390bd1 | 137 | observer = NULL; |
ram54288 | 0:dbad57390bd1 | 138 | } |
ram54288 | 0:dbad57390bd1 | 139 | |
ram54288 | 0:dbad57390bd1 | 140 | void Test_M2MNsdlInterface::test_create_endpoint() |
ram54288 | 0:dbad57390bd1 | 141 | { |
ram54288 | 0:dbad57390bd1 | 142 | u_int8_t value[] = {"120"}; |
ram54288 | 0:dbad57390bd1 | 143 | if( nsdl->_endpoint == NULL){ |
ram54288 | 0:dbad57390bd1 | 144 | nsdl->_endpoint = (sn_nsdl_ep_parameters_s*)nsdl->memory_alloc(sizeof(sn_nsdl_ep_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 145 | } |
ram54288 | 0:dbad57390bd1 | 146 | |
ram54288 | 0:dbad57390bd1 | 147 | nsdl->create_endpoint("name", "type",120,"domain",100,"context"); |
ram54288 | 0:dbad57390bd1 | 148 | CHECK(nsdl->_endpoint->lifetime_len == 3); |
ram54288 | 0:dbad57390bd1 | 149 | CHECK(*nsdl->_endpoint->lifetime_ptr == *value); |
ram54288 | 0:dbad57390bd1 | 150 | } |
ram54288 | 0:dbad57390bd1 | 151 | |
ram54288 | 0:dbad57390bd1 | 152 | void Test_M2MNsdlInterface::test_delete_endpoint() |
ram54288 | 0:dbad57390bd1 | 153 | { |
ram54288 | 0:dbad57390bd1 | 154 | if( nsdl->_endpoint == NULL){ |
ram54288 | 0:dbad57390bd1 | 155 | nsdl->_endpoint = (sn_nsdl_ep_parameters_s*)nsdl->memory_alloc(sizeof(sn_nsdl_ep_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 156 | } |
ram54288 | 0:dbad57390bd1 | 157 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 158 | |
ram54288 | 0:dbad57390bd1 | 159 | nsdl->delete_endpoint(); |
ram54288 | 0:dbad57390bd1 | 160 | CHECK(nsdl->_endpoint == NULL); |
ram54288 | 0:dbad57390bd1 | 161 | } |
ram54288 | 0:dbad57390bd1 | 162 | |
ram54288 | 0:dbad57390bd1 | 163 | void Test_M2MNsdlInterface::test_create_nsdl_list_structure() |
ram54288 | 0:dbad57390bd1 | 164 | { |
ram54288 | 0:dbad57390bd1 | 165 | String *name = new String("name"); |
ram54288 | 0:dbad57390bd1 | 166 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 167 | m2mbase_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 168 | M2MObject *object = new M2MObject(*name, (char*)name->c_str()); |
ram54288 | 0:dbad57390bd1 | 169 | M2MObjectInstance* instance = new M2MObjectInstance(*object,*name, "", "name/0"); |
ram54288 | 0:dbad57390bd1 | 170 | |
ram54288 | 0:dbad57390bd1 | 171 | M2MResource* create_resource = new M2MResource(*instance, |
ram54288 | 0:dbad57390bd1 | 172 | *name, |
ram54288 | 0:dbad57390bd1 | 173 | *name, |
ram54288 | 0:dbad57390bd1 | 174 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 175 | false, |
ram54288 | 0:dbad57390bd1 | 176 | "name"); |
ram54288 | 0:dbad57390bd1 | 177 | |
ram54288 | 0:dbad57390bd1 | 178 | M2MResourceInstance* res_instance = new M2MResourceInstance(*create_resource, *name, *name, |
ram54288 | 0:dbad57390bd1 | 179 | M2MResourceInstance::INTEGER, 0, (char*)name->c_str(), false); |
ram54288 | 0:dbad57390bd1 | 180 | |
ram54288 | 0:dbad57390bd1 | 181 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 182 | m2mobject_stub::instance_list.push_back(instance); |
ram54288 | 0:dbad57390bd1 | 183 | |
ram54288 | 0:dbad57390bd1 | 184 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 185 | m2mobjectinstance_stub::resource_list.push_back(create_resource); |
ram54288 | 0:dbad57390bd1 | 186 | |
ram54288 | 0:dbad57390bd1 | 187 | M2MObjectList list; |
ram54288 | 0:dbad57390bd1 | 188 | list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 189 | |
ram54288 | 0:dbad57390bd1 | 190 | m2mbase_stub::string_value = name->c_str(); |
ram54288 | 0:dbad57390bd1 | 191 | m2mbase_stub::mode_value = M2MBase::Static; |
ram54288 | 0:dbad57390bd1 | 192 | |
ram54288 | 0:dbad57390bd1 | 193 | |
ram54288 | 0:dbad57390bd1 | 194 | CHECK(nsdl->create_nsdl_list_structure(list)== true); |
ram54288 | 0:dbad57390bd1 | 195 | |
ram54288 | 0:dbad57390bd1 | 196 | m2mresource_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 197 | m2mbase_stub::mode_value = M2MBase::Dynamic; |
ram54288 | 0:dbad57390bd1 | 198 | |
ram54288 | 0:dbad57390bd1 | 199 | m2mresource_stub::list.push_back(res_instance); |
ram54288 | 0:dbad57390bd1 | 200 | m2mresourceinstance_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 201 | |
ram54288 | 0:dbad57390bd1 | 202 | CHECK(nsdl->create_nsdl_list_structure(list)== true); |
ram54288 | 0:dbad57390bd1 | 203 | |
ram54288 | 0:dbad57390bd1 | 204 | m2mbase_stub::mode_value = M2MBase::Directory; |
ram54288 | 0:dbad57390bd1 | 205 | CHECK(nsdl->create_nsdl_list_structure(list)== true); |
ram54288 | 0:dbad57390bd1 | 206 | |
ram54288 | 0:dbad57390bd1 | 207 | list.clear(); |
ram54288 | 0:dbad57390bd1 | 208 | delete object; |
ram54288 | 0:dbad57390bd1 | 209 | delete name; |
ram54288 | 0:dbad57390bd1 | 210 | name = NULL; |
ram54288 | 0:dbad57390bd1 | 211 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 212 | delete instance; |
ram54288 | 0:dbad57390bd1 | 213 | instance = NULL; |
ram54288 | 0:dbad57390bd1 | 214 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 215 | delete create_resource; |
ram54288 | 0:dbad57390bd1 | 216 | create_resource = NULL; |
ram54288 | 0:dbad57390bd1 | 217 | |
ram54288 | 0:dbad57390bd1 | 218 | m2mresource_stub::list.clear(); |
ram54288 | 0:dbad57390bd1 | 219 | delete res_instance; |
ram54288 | 0:dbad57390bd1 | 220 | res_instance = NULL; |
ram54288 | 0:dbad57390bd1 | 221 | } |
ram54288 | 0:dbad57390bd1 | 222 | |
ram54288 | 0:dbad57390bd1 | 223 | void Test_M2MNsdlInterface::test_delete_nsdl_resource() |
ram54288 | 0:dbad57390bd1 | 224 | { |
ram54288 | 0:dbad57390bd1 | 225 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 226 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 227 | |
ram54288 | 0:dbad57390bd1 | 228 | CHECK(nsdl->remove_nsdl_resource(object) == false); |
ram54288 | 0:dbad57390bd1 | 229 | |
ram54288 | 0:dbad57390bd1 | 230 | common_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 231 | |
ram54288 | 0:dbad57390bd1 | 232 | CHECK(nsdl->remove_nsdl_resource(object) == true); |
ram54288 | 0:dbad57390bd1 | 233 | delete object; |
ram54288 | 0:dbad57390bd1 | 234 | } |
ram54288 | 0:dbad57390bd1 | 235 | |
ram54288 | 0:dbad57390bd1 | 236 | void Test_M2MNsdlInterface::test_create_bootstrap_resource() |
ram54288 | 0:dbad57390bd1 | 237 | { |
ram54288 | 0:dbad57390bd1 | 238 | common_stub::uint_value = 11; |
ram54288 | 0:dbad57390bd1 | 239 | CHECK(nsdl->create_bootstrap_resource(NULL, "") == true); |
ram54288 | 0:dbad57390bd1 | 240 | |
ram54288 | 0:dbad57390bd1 | 241 | common_stub::uint_value = 0; |
ram54288 | 0:dbad57390bd1 | 242 | CHECK(nsdl->create_bootstrap_resource(NULL, "") == false); |
ram54288 | 0:dbad57390bd1 | 243 | } |
ram54288 | 0:dbad57390bd1 | 244 | |
ram54288 | 0:dbad57390bd1 | 245 | void Test_M2MNsdlInterface::test_send_register_message() |
ram54288 | 0:dbad57390bd1 | 246 | { |
ram54288 | 0:dbad57390bd1 | 247 | common_stub::uint_value = 12; |
ram54288 | 0:dbad57390bd1 | 248 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 249 | CHECK(nsdl->send_register_message(NULL,4,100,SN_NSDL_ADDRESS_TYPE_IPV6) == true); |
ram54288 | 0:dbad57390bd1 | 250 | |
ram54288 | 0:dbad57390bd1 | 251 | common_stub::uint_value = 0; |
ram54288 | 0:dbad57390bd1 | 252 | CHECK(nsdl->send_register_message(NULL,4,100,SN_NSDL_ADDRESS_TYPE_IPV6) == false); |
ram54288 | 0:dbad57390bd1 | 253 | } |
ram54288 | 0:dbad57390bd1 | 254 | |
ram54288 | 0:dbad57390bd1 | 255 | void Test_M2MNsdlInterface::test_send_update_registration() |
ram54288 | 0:dbad57390bd1 | 256 | { |
ram54288 | 0:dbad57390bd1 | 257 | common_stub::uint_value = 23; |
ram54288 | 0:dbad57390bd1 | 258 | nsdl->_nsdl_handle = (nsdl_s*)malloc(sizeof(1)); |
ram54288 | 0:dbad57390bd1 | 259 | CHECK(nsdl->send_update_registration(120) == true); |
ram54288 | 0:dbad57390bd1 | 260 | |
ram54288 | 0:dbad57390bd1 | 261 | // Update lifetime value |
ram54288 | 0:dbad57390bd1 | 262 | common_stub::uint_value = 1; |
ram54288 | 0:dbad57390bd1 | 263 | CHECK(nsdl->send_update_registration(100) == true); |
ram54288 | 0:dbad57390bd1 | 264 | |
ram54288 | 0:dbad57390bd1 | 265 | // Lifetime value is 0, don't change the existing lifetime value |
ram54288 | 0:dbad57390bd1 | 266 | common_stub::uint_value = 1; |
ram54288 | 0:dbad57390bd1 | 267 | CHECK(nsdl->send_update_registration(0) == true); |
ram54288 | 0:dbad57390bd1 | 268 | |
ram54288 | 0:dbad57390bd1 | 269 | free(nsdl->_nsdl_handle); |
ram54288 | 0:dbad57390bd1 | 270 | } |
ram54288 | 0:dbad57390bd1 | 271 | |
ram54288 | 0:dbad57390bd1 | 272 | void Test_M2MNsdlInterface::test_send_unregister_message() |
ram54288 | 0:dbad57390bd1 | 273 | { |
ram54288 | 0:dbad57390bd1 | 274 | common_stub::uint_value = 22; |
ram54288 | 0:dbad57390bd1 | 275 | CHECK(nsdl->send_unregister_message() == true); |
ram54288 | 0:dbad57390bd1 | 276 | |
ram54288 | 0:dbad57390bd1 | 277 | // Unreg already in progress |
ram54288 | 0:dbad57390bd1 | 278 | common_stub::uint_value = 0; |
ram54288 | 0:dbad57390bd1 | 279 | CHECK(nsdl->send_unregister_message() == true); |
ram54288 | 0:dbad57390bd1 | 280 | } |
ram54288 | 0:dbad57390bd1 | 281 | |
ram54288 | 0:dbad57390bd1 | 282 | void Test_M2MNsdlInterface::test_memory_alloc() |
ram54288 | 0:dbad57390bd1 | 283 | { |
ram54288 | 0:dbad57390bd1 | 284 | CHECK(nsdl->memory_alloc(0) == 0); |
ram54288 | 0:dbad57390bd1 | 285 | uint8_t *ptr = 0; |
ram54288 | 0:dbad57390bd1 | 286 | ptr = (uint8_t*)nsdl->memory_alloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 287 | CHECK(ptr != NULL); |
ram54288 | 0:dbad57390bd1 | 288 | nsdl->memory_free(ptr); |
ram54288 | 0:dbad57390bd1 | 289 | } |
ram54288 | 0:dbad57390bd1 | 290 | |
ram54288 | 0:dbad57390bd1 | 291 | void Test_M2MNsdlInterface::test_memory_free() |
ram54288 | 0:dbad57390bd1 | 292 | { |
ram54288 | 0:dbad57390bd1 | 293 | uint8_t *ptr = (uint8_t*)nsdl->memory_alloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 294 | nsdl->memory_free((void*)ptr); |
ram54288 | 0:dbad57390bd1 | 295 | //memory leak test will fail, if there is a leak, so no need for CHECK |
ram54288 | 0:dbad57390bd1 | 296 | } |
ram54288 | 0:dbad57390bd1 | 297 | |
ram54288 | 0:dbad57390bd1 | 298 | void Test_M2MNsdlInterface::test_send_to_server_callback() |
ram54288 | 0:dbad57390bd1 | 299 | { |
ram54288 | 0:dbad57390bd1 | 300 | uint8_t *data_ptr = (uint8_t*)malloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 301 | uint16_t data_len = sizeof(uint8_t); |
ram54288 | 0:dbad57390bd1 | 302 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 303 | |
ram54288 | 0:dbad57390bd1 | 304 | nsdl->send_to_server_callback(NULL, SN_NSDL_PROTOCOL_COAP, data_ptr,data_len,address); |
ram54288 | 0:dbad57390bd1 | 305 | CHECK(observer->message_ready == true); |
ram54288 | 0:dbad57390bd1 | 306 | |
ram54288 | 0:dbad57390bd1 | 307 | free(data_ptr); |
ram54288 | 0:dbad57390bd1 | 308 | free(address); |
ram54288 | 0:dbad57390bd1 | 309 | } |
ram54288 | 0:dbad57390bd1 | 310 | |
ram54288 | 0:dbad57390bd1 | 311 | void Test_M2MNsdlInterface::test_received_from_server_callback() |
ram54288 | 0:dbad57390bd1 | 312 | { |
ram54288 | 0:dbad57390bd1 | 313 | nsdl_s* handle = (nsdl_s*)malloc(sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 314 | memset(handle,0,sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 315 | |
ram54288 | 0:dbad57390bd1 | 316 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 317 | memset(coap_header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 318 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; |
ram54288 | 0:dbad57390bd1 | 319 | |
ram54288 | 0:dbad57390bd1 | 320 | |
ram54288 | 0:dbad57390bd1 | 321 | coap_header->options_list_ptr = (sn_coap_options_list_s *)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 322 | memset(coap_header->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 323 | |
ram54288 | 0:dbad57390bd1 | 324 | coap_header->options_list_ptr->max_age = 2; |
ram54288 | 0:dbad57390bd1 | 325 | |
ram54288 | 0:dbad57390bd1 | 326 | coap_header->options_list_ptr->location_path_len = 2; |
ram54288 | 0:dbad57390bd1 | 327 | coap_header->options_list_ptr->location_path_ptr = (uint8_t *)malloc(sizeof(coap_header->options_list_ptr->location_path_len)); |
ram54288 | 0:dbad57390bd1 | 328 | memset(coap_header->options_list_ptr->location_path_ptr, 0, sizeof(coap_header->options_list_ptr->location_path_len)); |
ram54288 | 0:dbad57390bd1 | 329 | |
ram54288 | 0:dbad57390bd1 | 330 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 331 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 332 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 333 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 334 | CHECK(observer->registered == true); |
ram54288 | 0:dbad57390bd1 | 335 | |
ram54288 | 0:dbad57390bd1 | 336 | free(nsdl->_endpoint->lifetime_ptr); |
ram54288 | 0:dbad57390bd1 | 337 | nsdl->_endpoint->lifetime_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 338 | |
ram54288 | 0:dbad57390bd1 | 339 | free(nsdl->_endpoint->location_ptr); |
ram54288 | 0:dbad57390bd1 | 340 | nsdl->_endpoint->location_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 341 | |
ram54288 | 0:dbad57390bd1 | 342 | uint8_t life1[] = {"120"}; |
ram54288 | 0:dbad57390bd1 | 343 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(life1)); |
ram54288 | 0:dbad57390bd1 | 344 | memcpy(nsdl->_endpoint->lifetime_ptr,life1,sizeof(life1)); |
ram54288 | 0:dbad57390bd1 | 345 | nsdl->_endpoint->lifetime_len = (uint8_t)sizeof(life1); |
ram54288 | 0:dbad57390bd1 | 346 | |
ram54288 | 0:dbad57390bd1 | 347 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 348 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 349 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 350 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 351 | CHECK(observer->registered == true); |
ram54288 | 0:dbad57390bd1 | 352 | |
ram54288 | 0:dbad57390bd1 | 353 | free(coap_header->options_list_ptr->location_path_ptr); |
ram54288 | 0:dbad57390bd1 | 354 | coap_header->options_list_ptr->location_path_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 355 | |
ram54288 | 0:dbad57390bd1 | 356 | free(coap_header->options_list_ptr); |
ram54288 | 0:dbad57390bd1 | 357 | coap_header->options_list_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 358 | |
ram54288 | 0:dbad57390bd1 | 359 | free(nsdl->_endpoint->lifetime_ptr); |
ram54288 | 0:dbad57390bd1 | 360 | nsdl->_endpoint->lifetime_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 361 | |
ram54288 | 0:dbad57390bd1 | 362 | uint8_t life[] = {"120"}; |
ram54288 | 0:dbad57390bd1 | 363 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(life)); |
ram54288 | 0:dbad57390bd1 | 364 | memcpy(nsdl->_endpoint->lifetime_ptr,life,sizeof(life)); |
ram54288 | 0:dbad57390bd1 | 365 | nsdl->_endpoint->lifetime_len = (uint8_t)sizeof(life); |
ram54288 | 0:dbad57390bd1 | 366 | |
ram54288 | 0:dbad57390bd1 | 367 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 368 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 369 | |
ram54288 | 0:dbad57390bd1 | 370 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 371 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 372 | CHECK(observer->registered == true); |
ram54288 | 0:dbad57390bd1 | 373 | free(nsdl->_endpoint->lifetime_ptr); |
ram54288 | 0:dbad57390bd1 | 374 | nsdl->_endpoint->lifetime_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 375 | |
ram54288 | 0:dbad57390bd1 | 376 | uint8_t big_life[] = {"4000"}; |
ram54288 | 0:dbad57390bd1 | 377 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(big_life)); |
ram54288 | 0:dbad57390bd1 | 378 | memcpy(nsdl->_endpoint->lifetime_ptr,big_life,sizeof(big_life)); |
ram54288 | 0:dbad57390bd1 | 379 | nsdl->_endpoint->lifetime_len = (uint8_t)sizeof(big_life); |
ram54288 | 0:dbad57390bd1 | 380 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 381 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 382 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 383 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 384 | CHECK(observer->registered == true); |
ram54288 | 0:dbad57390bd1 | 385 | |
ram54288 | 0:dbad57390bd1 | 386 | free(nsdl->_endpoint->lifetime_ptr); |
ram54288 | 0:dbad57390bd1 | 387 | nsdl->_endpoint->lifetime_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 388 | |
ram54288 | 0:dbad57390bd1 | 389 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 390 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 391 | |
ram54288 | 0:dbad57390bd1 | 392 | uint8_t less_life[] = {"30"}; |
ram54288 | 0:dbad57390bd1 | 393 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(less_life)); |
ram54288 | 0:dbad57390bd1 | 394 | memcpy(nsdl->_endpoint->lifetime_ptr,less_life,sizeof(less_life)); |
ram54288 | 0:dbad57390bd1 | 395 | nsdl->_endpoint->lifetime_len = (uint8_t)sizeof(less_life); |
ram54288 | 0:dbad57390bd1 | 396 | |
ram54288 | 0:dbad57390bd1 | 397 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 398 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 399 | CHECK(observer->registered == true); |
ram54288 | 0:dbad57390bd1 | 400 | |
ram54288 | 0:dbad57390bd1 | 401 | observer->data_processed = false; |
ram54288 | 0:dbad57390bd1 | 402 | observer->registered = false; |
ram54288 | 0:dbad57390bd1 | 403 | observer->unregistered = false; |
ram54288 | 0:dbad57390bd1 | 404 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 405 | |
ram54288 | 0:dbad57390bd1 | 406 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 407 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 408 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 409 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 410 | |
ram54288 | 0:dbad57390bd1 | 411 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_OPTION; |
ram54288 | 0:dbad57390bd1 | 412 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 413 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 414 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 415 | |
ram54288 | 0:dbad57390bd1 | 416 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE; |
ram54288 | 0:dbad57390bd1 | 417 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 418 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 419 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 420 | |
ram54288 | 0:dbad57390bd1 | 421 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED; |
ram54288 | 0:dbad57390bd1 | 422 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 423 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 424 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 425 | |
ram54288 | 0:dbad57390bd1 | 426 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE; |
ram54288 | 0:dbad57390bd1 | 427 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 428 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 429 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 430 | |
ram54288 | 0:dbad57390bd1 | 431 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT; |
ram54288 | 0:dbad57390bd1 | 432 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 433 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 434 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 435 | |
ram54288 | 0:dbad57390bd1 | 436 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_UNAUTHORIZED; |
ram54288 | 0:dbad57390bd1 | 437 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 438 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 439 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 440 | |
ram54288 | 0:dbad57390bd1 | 441 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_FORBIDDEN; |
ram54288 | 0:dbad57390bd1 | 442 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 443 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 444 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 445 | |
ram54288 | 0:dbad57390bd1 | 446 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_NOT_FOUND; |
ram54288 | 0:dbad57390bd1 | 447 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 448 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 449 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 450 | |
ram54288 | 0:dbad57390bd1 | 451 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 452 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 453 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 454 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 455 | |
ram54288 | 0:dbad57390bd1 | 456 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_GATEWAY; |
ram54288 | 0:dbad57390bd1 | 457 | coap_header->coap_status = COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED; |
ram54288 | 0:dbad57390bd1 | 458 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 459 | CHECK(observer->data_processed == true); |
ram54288 | 0:dbad57390bd1 | 460 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 461 | |
ram54288 | 0:dbad57390bd1 | 462 | |
ram54288 | 0:dbad57390bd1 | 463 | coap_header->msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 464 | handle->unregister_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 465 | |
ram54288 | 0:dbad57390bd1 | 466 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_DELETED; |
ram54288 | 0:dbad57390bd1 | 467 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 468 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 469 | CHECK(observer->unregistered == true); |
ram54288 | 0:dbad57390bd1 | 470 | |
ram54288 | 0:dbad57390bd1 | 471 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 472 | handle->unregister_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 473 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; |
ram54288 | 0:dbad57390bd1 | 474 | |
ram54288 | 0:dbad57390bd1 | 475 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 476 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 477 | |
ram54288 | 0:dbad57390bd1 | 478 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 479 | handle->unregister_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 480 | coap_header->coap_status = COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED; |
ram54288 | 0:dbad57390bd1 | 481 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 482 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 483 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 484 | |
ram54288 | 0:dbad57390bd1 | 485 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 486 | handle->unregister_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 487 | coap_header->coap_status = COAP_STATUS_PARSER_ERROR_IN_HEADER; |
ram54288 | 0:dbad57390bd1 | 488 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 489 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 490 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 491 | |
ram54288 | 0:dbad57390bd1 | 492 | observer->register_error = false; |
ram54288 | 0:dbad57390bd1 | 493 | handle->unregister_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 494 | coap_header->coap_status = COAP_STATUS_PARSER_ERROR_IN_HEADER; |
ram54288 | 0:dbad57390bd1 | 495 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT; |
ram54288 | 0:dbad57390bd1 | 496 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 497 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 498 | |
ram54288 | 0:dbad57390bd1 | 499 | // Receive initial bs message with error |
ram54288 | 0:dbad57390bd1 | 500 | handle->unregister_msg_id = 0; |
ram54288 | 0:dbad57390bd1 | 501 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 502 | nsdl->_bootstrap_id = 8; |
ram54288 | 0:dbad57390bd1 | 503 | handle->bootstrap_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 504 | coap_header->coap_status = COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED; |
ram54288 | 0:dbad57390bd1 | 505 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 506 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 507 | |
ram54288 | 0:dbad57390bd1 | 508 | //_update_id == msg_id |
ram54288 | 0:dbad57390bd1 | 509 | handle->update_register_msg_id = 10; |
ram54288 | 0:dbad57390bd1 | 510 | coap_header->msg_id = 10; |
ram54288 | 0:dbad57390bd1 | 511 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; |
ram54288 | 0:dbad57390bd1 | 512 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 513 | CHECK(observer->register_updated == true); |
ram54288 | 0:dbad57390bd1 | 514 | |
ram54288 | 0:dbad57390bd1 | 515 | coap_header->msg_id = 10; |
ram54288 | 0:dbad57390bd1 | 516 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_FORBIDDEN; |
ram54288 | 0:dbad57390bd1 | 517 | coap_header->coap_status = COAP_STATUS_OK; |
ram54288 | 0:dbad57390bd1 | 518 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 519 | CHECK(observer->register_error == true); |
ram54288 | 0:dbad57390bd1 | 520 | |
ram54288 | 0:dbad57390bd1 | 521 | coap_header->msg_id = 11; |
ram54288 | 0:dbad57390bd1 | 522 | CHECK( 0== nsdl->received_from_server_callback(handle,coap_header,NULL) ); |
ram54288 | 0:dbad57390bd1 | 523 | |
ram54288 | 0:dbad57390bd1 | 524 | handle->update_register_msg_id = 0; |
ram54288 | 0:dbad57390bd1 | 525 | handle->register_msg_id = 0; |
ram54288 | 0:dbad57390bd1 | 526 | handle->unregister_msg_id = 0; |
ram54288 | 0:dbad57390bd1 | 527 | coap_header->msg_id = 10; |
ram54288 | 0:dbad57390bd1 | 528 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 529 | |
ram54288 | 0:dbad57390bd1 | 530 | uint8_t object[] = {"name"}; |
ram54288 | 0:dbad57390bd1 | 531 | |
ram54288 | 0:dbad57390bd1 | 532 | coap_header->uri_path_ptr = object; |
ram54288 | 0:dbad57390bd1 | 533 | coap_header->uri_path_len = sizeof(object); |
ram54288 | 0:dbad57390bd1 | 534 | |
ram54288 | 0:dbad57390bd1 | 535 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 536 | |
ram54288 | 0:dbad57390bd1 | 537 | //Test methods that are not allowed |
ram54288 | 0:dbad57390bd1 | 538 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_GET; |
ram54288 | 0:dbad57390bd1 | 539 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 540 | |
ram54288 | 0:dbad57390bd1 | 541 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
ram54288 | 0:dbad57390bd1 | 542 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 543 | |
ram54288 | 0:dbad57390bd1 | 544 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 545 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 546 | |
ram54288 | 0:dbad57390bd1 | 547 | //Continue testing with post method |
ram54288 | 0:dbad57390bd1 | 548 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 549 | |
ram54288 | 0:dbad57390bd1 | 550 | uint8_t object_instance[] = {"name/0"}; |
ram54288 | 0:dbad57390bd1 | 551 | |
ram54288 | 0:dbad57390bd1 | 552 | coap_header->uri_path_ptr = object_instance; |
ram54288 | 0:dbad57390bd1 | 553 | coap_header->uri_path_len = sizeof(object_instance); |
ram54288 | 0:dbad57390bd1 | 554 | |
ram54288 | 0:dbad57390bd1 | 555 | coap_header->payload_ptr = (uint8_t*)malloc(1); |
ram54288 | 0:dbad57390bd1 | 556 | m2mobjectinstance_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 557 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 558 | |
ram54288 | 0:dbad57390bd1 | 559 | M2MObject *obj = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 560 | |
ram54288 | 0:dbad57390bd1 | 561 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 562 | m2mbase_stub::nsdl_resource = |
ram54288 | 0:dbad57390bd1 | 563 | (sn_nsdl_dynamic_resource_parameters_s*) malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 564 | m2mbase_stub::nsdl_resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 565 | (sn_nsdl_static_resource_parameters_s*) malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 566 | m2mbase_stub::nsdl_resource->static_resource_parameters->path = (uint8_t*)malloc(5); |
ram54288 | 0:dbad57390bd1 | 567 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[0] = 'n'; |
ram54288 | 0:dbad57390bd1 | 568 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[1] = 'a'; |
ram54288 | 0:dbad57390bd1 | 569 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[2] = 'm'; |
ram54288 | 0:dbad57390bd1 | 570 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 571 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[4] = '\0'; |
ram54288 | 0:dbad57390bd1 | 572 | m2mbase_stub::nsdl_resource->static_resource_parameters->pathlen = 5; |
ram54288 | 0:dbad57390bd1 | 573 | |
ram54288 | 0:dbad57390bd1 | 574 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 575 | |
ram54288 | 0:dbad57390bd1 | 576 | m2mobject_stub::inst = new M2MObjectInstance(*obj, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 577 | |
ram54288 | 0:dbad57390bd1 | 578 | m2mobject_stub::header = (sn_coap_hdr_s*) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 579 | memset(m2mobject_stub::header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 580 | |
ram54288 | 0:dbad57390bd1 | 581 | m2mobjectinstance_stub::header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 582 | memset(m2mobjectinstance_stub::header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 583 | m2mobjectinstance_stub::header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 584 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 585 | m2mobjectinstance_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 586 | |
ram54288 | 0:dbad57390bd1 | 587 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 588 | m2mobjectinstance_stub::header = NULL; |
ram54288 | 0:dbad57390bd1 | 589 | |
ram54288 | 0:dbad57390bd1 | 590 | m2mobjectinstance_stub::header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 591 | memset(m2mobjectinstance_stub::header, 0, sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 592 | |
ram54288 | 0:dbad57390bd1 | 593 | m2mobjectinstance_stub::header->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; |
ram54288 | 0:dbad57390bd1 | 594 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 595 | m2mobjectinstance_stub::header = NULL; |
ram54288 | 0:dbad57390bd1 | 596 | |
ram54288 | 0:dbad57390bd1 | 597 | free(coap_header->payload_ptr); |
ram54288 | 0:dbad57390bd1 | 598 | coap_header->payload_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 599 | |
ram54288 | 0:dbad57390bd1 | 600 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 601 | |
ram54288 | 0:dbad57390bd1 | 602 | delete m2mobject_stub::inst; |
ram54288 | 0:dbad57390bd1 | 603 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 604 | delete obj; |
ram54288 | 0:dbad57390bd1 | 605 | |
ram54288 | 0:dbad57390bd1 | 606 | free(coap_header->payload_ptr); |
ram54288 | 0:dbad57390bd1 | 607 | free(m2mobject_stub::header); |
ram54288 | 0:dbad57390bd1 | 608 | m2mobject_stub::header = NULL; |
ram54288 | 0:dbad57390bd1 | 609 | |
ram54288 | 0:dbad57390bd1 | 610 | uint8_t object_instance1[] = {"name/65536"}; |
ram54288 | 0:dbad57390bd1 | 611 | |
ram54288 | 0:dbad57390bd1 | 612 | coap_header->uri_path_ptr = object_instance1; |
ram54288 | 0:dbad57390bd1 | 613 | coap_header->uri_path_len = sizeof(object_instance1); |
ram54288 | 0:dbad57390bd1 | 614 | |
ram54288 | 0:dbad57390bd1 | 615 | obj = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 616 | |
ram54288 | 0:dbad57390bd1 | 617 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 618 | |
ram54288 | 0:dbad57390bd1 | 619 | m2mobject_stub::inst = new M2MObjectInstance(*obj, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 620 | |
ram54288 | 0:dbad57390bd1 | 621 | m2mobject_stub::header = (sn_coap_hdr_s*) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 622 | memset(m2mobject_stub::header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 623 | |
ram54288 | 0:dbad57390bd1 | 624 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 625 | |
ram54288 | 0:dbad57390bd1 | 626 | delete m2mobject_stub::inst; |
ram54288 | 0:dbad57390bd1 | 627 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 628 | delete obj; |
ram54288 | 0:dbad57390bd1 | 629 | |
ram54288 | 0:dbad57390bd1 | 630 | free(m2mobject_stub::header); |
ram54288 | 0:dbad57390bd1 | 631 | |
ram54288 | 0:dbad57390bd1 | 632 | uint8_t resource[] = {"name/0/resource"}; |
ram54288 | 0:dbad57390bd1 | 633 | |
ram54288 | 0:dbad57390bd1 | 634 | coap_header->uri_path_ptr = resource; |
ram54288 | 0:dbad57390bd1 | 635 | coap_header->uri_path_len = sizeof(resource); |
ram54288 | 0:dbad57390bd1 | 636 | |
ram54288 | 0:dbad57390bd1 | 637 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 638 | |
ram54288 | 0:dbad57390bd1 | 639 | // Test EMPTY ACK |
ram54288 | 0:dbad57390bd1 | 640 | coap_header->msg_code = COAP_MSG_CODE_EMPTY; |
ram54288 | 0:dbad57390bd1 | 641 | obj = new M2MObject("0", "0"); |
ram54288 | 0:dbad57390bd1 | 642 | m2mbase_stub::string_value = "0"; |
ram54288 | 0:dbad57390bd1 | 643 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 644 | m2mobject_stub::inst = new M2MObjectInstance(*obj, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 645 | |
ram54288 | 0:dbad57390bd1 | 646 | uint8_t *token = (uint8_t*) malloc(4); |
ram54288 | 0:dbad57390bd1 | 647 | token[0] = 't'; |
ram54288 | 0:dbad57390bd1 | 648 | token[1] = 'o'; |
ram54288 | 0:dbad57390bd1 | 649 | token[2] = 'k'; |
ram54288 | 0:dbad57390bd1 | 650 | token[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 651 | coap_header->token_ptr = token; |
ram54288 | 0:dbad57390bd1 | 652 | coap_header->token_len = 4; |
ram54288 | 0:dbad57390bd1 | 653 | |
ram54288 | 0:dbad57390bd1 | 654 | M2MResource res2(*m2mobject_stub::inst, "test","test",M2MResourceInstance::STRING,false, "test"); |
ram54288 | 0:dbad57390bd1 | 655 | m2mbase_stub::object_token = token; |
ram54288 | 0:dbad57390bd1 | 656 | m2mbase_stub::object_token_len = 4; |
ram54288 | 0:dbad57390bd1 | 657 | m2mobject_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 658 | res2.set_observation_token(token, 4); |
ram54288 | 0:dbad57390bd1 | 659 | |
ram54288 | 0:dbad57390bd1 | 660 | m2mobjectinstance_stub::resource_list.push_back(&res2); |
ram54288 | 0:dbad57390bd1 | 661 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 662 | |
ram54288 | 0:dbad57390bd1 | 663 | // Test RESET message |
ram54288 | 0:dbad57390bd1 | 664 | coap_header->msg_type = COAP_MSG_TYPE_RESET; |
ram54288 | 0:dbad57390bd1 | 665 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 666 | m2mobject_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 667 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 668 | m2mobject_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 669 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 670 | m2mobject_stub::base_type = M2MBase::ResourceInstance; |
ram54288 | 0:dbad57390bd1 | 671 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,NULL)); |
ram54288 | 0:dbad57390bd1 | 672 | free(token); |
ram54288 | 0:dbad57390bd1 | 673 | delete m2mobject_stub::inst; |
ram54288 | 0:dbad57390bd1 | 674 | delete obj; |
ram54288 | 0:dbad57390bd1 | 675 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 676 | |
ram54288 | 0:dbad57390bd1 | 677 | |
ram54288 | 0:dbad57390bd1 | 678 | // Bootstrap cases start from here |
ram54288 | 0:dbad57390bd1 | 679 | // handle_bootstrap_put_message() invalid object name |
ram54288 | 0:dbad57390bd1 | 680 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 681 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 682 | memset(address, 0, sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 683 | address->addr_len = 1; |
ram54288 | 0:dbad57390bd1 | 684 | address->addr_ptr = (uint8_t *)malloc(1); |
ram54288 | 0:dbad57390bd1 | 685 | address->addr_ptr[0] = 1; |
ram54288 | 0:dbad57390bd1 | 686 | address->port = 5683; |
ram54288 | 0:dbad57390bd1 | 687 | handle->oma_bs_address_len = 1; |
ram54288 | 0:dbad57390bd1 | 688 | handle->oma_bs_port = 5683; |
ram54288 | 0:dbad57390bd1 | 689 | handle->oma_bs_address_ptr = (uint8_t *)malloc(1); |
ram54288 | 0:dbad57390bd1 | 690 | handle->oma_bs_address_ptr[0] = 1; |
ram54288 | 0:dbad57390bd1 | 691 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
ram54288 | 0:dbad57390bd1 | 692 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 693 | CHECK(0== nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 694 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 695 | |
ram54288 | 0:dbad57390bd1 | 696 | // handle_bootstrap_put_message() invalid content type |
ram54288 | 0:dbad57390bd1 | 697 | obj = new M2MObject("0", "0"); |
ram54288 | 0:dbad57390bd1 | 698 | m2mbase_stub::string_value = "0"; |
ram54288 | 0:dbad57390bd1 | 699 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 700 | m2mobject_stub::inst = new M2MObjectInstance(*obj, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 701 | uint8_t security[] = {"0"}; |
ram54288 | 0:dbad57390bd1 | 702 | coap_header->uri_path_ptr = security; |
ram54288 | 0:dbad57390bd1 | 703 | coap_header->uri_path_len = sizeof(security); |
ram54288 | 0:dbad57390bd1 | 704 | M2MResource res(*m2mobject_stub::inst,"test","test",M2MResourceInstance::STRING,false,"test"); |
ram54288 | 0:dbad57390bd1 | 705 | m2mobjectinstance_stub::resource_list.push_back(&res); |
ram54288 | 0:dbad57390bd1 | 706 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 707 | m2msecurity_stub::resource = new M2MResource(*m2mobject_stub::inst,"1","type",M2MResourceInstance::STRING,false,"1"); |
ram54288 | 0:dbad57390bd1 | 708 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 709 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 710 | |
ram54288 | 0:dbad57390bd1 | 711 | // handle_bootstrap_put_message() success |
ram54288 | 0:dbad57390bd1 | 712 | coap_header->token_ptr = String::convert_integer_to_array(1,coap_header->token_len); |
ram54288 | 0:dbad57390bd1 | 713 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 714 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:dbad57390bd1 | 715 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 716 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 717 | coap_header->content_format = sn_coap_content_format_e(99); |
ram54288 | 0:dbad57390bd1 | 718 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 719 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 720 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:dbad57390bd1 | 721 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 722 | CHECK(observer->boot_error == false); |
ram54288 | 0:dbad57390bd1 | 723 | |
ram54288 | 0:dbad57390bd1 | 724 | // handle_bootstrap_put_message() TLV parsing fails |
ram54288 | 0:dbad57390bd1 | 725 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 726 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 727 | m2mtlvdeserializer_stub::is_object_bool_value = false; |
ram54288 | 0:dbad57390bd1 | 728 | m2mtlvdeserializer_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 729 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::NotAllowed; |
ram54288 | 0:dbad57390bd1 | 730 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 731 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 732 | delete m2mobject_stub::inst; |
ram54288 | 0:dbad57390bd1 | 733 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 734 | delete obj; |
ram54288 | 0:dbad57390bd1 | 735 | |
ram54288 | 0:dbad57390bd1 | 736 | // handle_bootstrap_put_message() TLV object instance |
ram54288 | 0:dbad57390bd1 | 737 | obj = new M2MObject("1", "1"); |
ram54288 | 0:dbad57390bd1 | 738 | m2mbase_stub::string_value = "1"; |
ram54288 | 0:dbad57390bd1 | 739 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 740 | m2mobject_stub::inst = new M2MObjectInstance(*obj, "name","", ""); |
ram54288 | 0:dbad57390bd1 | 741 | uint8_t server[] = {"1"}; |
ram54288 | 0:dbad57390bd1 | 742 | coap_header->uri_path_ptr = server; |
ram54288 | 0:dbad57390bd1 | 743 | coap_header->uri_path_len = 1; |
ram54288 | 0:dbad57390bd1 | 744 | |
ram54288 | 0:dbad57390bd1 | 745 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 746 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 747 | m2mtlvdeserializer_stub::is_object_bool_value = false; |
ram54288 | 0:dbad57390bd1 | 748 | m2mtlvdeserializer_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 749 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; |
ram54288 | 0:dbad57390bd1 | 750 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 751 | CHECK(observer->boot_error == false); |
ram54288 | 0:dbad57390bd1 | 752 | |
ram54288 | 0:dbad57390bd1 | 753 | // handle_bootstrap_put_message() TLV server object |
ram54288 | 0:dbad57390bd1 | 754 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 755 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 756 | m2mtlvdeserializer_stub::is_object_bool_value = true; |
ram54288 | 0:dbad57390bd1 | 757 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 758 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; |
ram54288 | 0:dbad57390bd1 | 759 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 760 | CHECK(observer->boot_error == false); |
ram54288 | 0:dbad57390bd1 | 761 | |
ram54288 | 0:dbad57390bd1 | 762 | // handle_bootstrap_put_message() TLV not resource |
ram54288 | 0:dbad57390bd1 | 763 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 764 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 765 | m2mtlvdeserializer_stub::is_object_bool_value = false; |
ram54288 | 0:dbad57390bd1 | 766 | m2mtlvdeserializer_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 767 | m2mtlvdeserializer_stub::error = M2MTLVDeserializer::None; |
ram54288 | 0:dbad57390bd1 | 768 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 769 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 770 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 771 | |
ram54288 | 0:dbad57390bd1 | 772 | // handle_bootstrap_delete() object name not match |
ram54288 | 0:dbad57390bd1 | 773 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 774 | nsdl->_bootstrap_id = 8; |
ram54288 | 0:dbad57390bd1 | 775 | handle->bootstrap_msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 776 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; |
ram54288 | 0:dbad57390bd1 | 777 | coap_header->msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 778 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 779 | coap_header->msg_id = 18; |
ram54288 | 0:dbad57390bd1 | 780 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 781 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 782 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 783 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 784 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 785 | |
ram54288 | 0:dbad57390bd1 | 786 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 787 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 788 | |
ram54288 | 0:dbad57390bd1 | 789 | // handle_bootstrap_delete() _identity_accepted false |
ram54288 | 0:dbad57390bd1 | 790 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 791 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 792 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 793 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 794 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 795 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 796 | |
ram54288 | 0:dbad57390bd1 | 797 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 798 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 799 | |
ram54288 | 0:dbad57390bd1 | 800 | // handle_bootstrap_delete() object name not match |
ram54288 | 0:dbad57390bd1 | 801 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 802 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; |
ram54288 | 0:dbad57390bd1 | 803 | coap_header->msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 804 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 805 | coap_header->msg_id = 18; |
ram54288 | 0:dbad57390bd1 | 806 | uint8_t object_name[] = {"0/0"}; |
ram54288 | 0:dbad57390bd1 | 807 | coap_header->uri_path_ptr = object_name; |
ram54288 | 0:dbad57390bd1 | 808 | coap_header->uri_path_len = 3; |
ram54288 | 0:dbad57390bd1 | 809 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 810 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 811 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 812 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 813 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 814 | |
ram54288 | 0:dbad57390bd1 | 815 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 816 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 817 | |
ram54288 | 0:dbad57390bd1 | 818 | // handle_bootstrap_delete() object name not match |
ram54288 | 0:dbad57390bd1 | 819 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 820 | coap_header->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; |
ram54288 | 0:dbad57390bd1 | 821 | coap_header->msg_id = 8; |
ram54288 | 0:dbad57390bd1 | 822 | nsdl->received_from_server_callback(handle,coap_header,NULL); |
ram54288 | 0:dbad57390bd1 | 823 | coap_header->msg_id = 18; |
ram54288 | 0:dbad57390bd1 | 824 | uint8_t invalid[] = {"0/0/1"}; |
ram54288 | 0:dbad57390bd1 | 825 | coap_header->uri_path_ptr = invalid; |
ram54288 | 0:dbad57390bd1 | 826 | coap_header->uri_path_len = 5; |
ram54288 | 0:dbad57390bd1 | 827 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 828 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 829 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 830 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 831 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 832 | |
ram54288 | 0:dbad57390bd1 | 833 | //handle_bootstrap_finished() path does not match |
ram54288 | 0:dbad57390bd1 | 834 | coap_header->uri_path_ptr = server; |
ram54288 | 0:dbad57390bd1 | 835 | coap_header->uri_path_len = 1; |
ram54288 | 0:dbad57390bd1 | 836 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 837 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 838 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 839 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 840 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 841 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 842 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 843 | |
ram54288 | 0:dbad57390bd1 | 844 | //handle_bootstrap_finished() send coap response |
ram54288 | 0:dbad57390bd1 | 845 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 846 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 847 | m2msecurity_stub::string_value = new String("coaps://"); |
ram54288 | 0:dbad57390bd1 | 848 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 849 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 850 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 851 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 852 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 853 | CHECK(nsdl->_security == NULL); |
ram54288 | 0:dbad57390bd1 | 854 | |
ram54288 | 0:dbad57390bd1 | 855 | //handle_bootstrap_finished() success no security |
ram54288 | 0:dbad57390bd1 | 856 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 857 | m2msecurity_stub::sec_mode = M2MSecurity::NoSecurity; |
ram54288 | 0:dbad57390bd1 | 858 | m2msecurity_stub::int_value = true; |
ram54288 | 0:dbad57390bd1 | 859 | m2msecurity_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 860 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 861 | observer->boot_wait = false; |
ram54288 | 0:dbad57390bd1 | 862 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 863 | coap_header->uri_path_ptr = (uint8_t*)malloc(2); |
ram54288 | 0:dbad57390bd1 | 864 | coap_header->uri_path_len = 2; |
ram54288 | 0:dbad57390bd1 | 865 | coap_header->uri_path_ptr[0] = 'b'; |
ram54288 | 0:dbad57390bd1 | 866 | coap_header->uri_path_ptr[1] = 's'; |
ram54288 | 0:dbad57390bd1 | 867 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 868 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 869 | CHECK(observer->boot_error == false); |
ram54288 | 0:dbad57390bd1 | 870 | CHECK(observer->boot_wait == true); |
ram54288 | 0:dbad57390bd1 | 871 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 872 | |
ram54288 | 0:dbad57390bd1 | 873 | //handle_bootstrap_finished() success certificate |
ram54288 | 0:dbad57390bd1 | 874 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 875 | m2msecurity_stub::sec_mode = M2MSecurity::Certificate; |
ram54288 | 0:dbad57390bd1 | 876 | m2mresourceinstance_stub::int_value = 10; |
ram54288 | 0:dbad57390bd1 | 877 | m2msecurity_stub::int_value = true; |
ram54288 | 0:dbad57390bd1 | 878 | m2msecurity_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 879 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 880 | observer->boot_wait = false; |
ram54288 | 0:dbad57390bd1 | 881 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 882 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 883 | |
ram54288 | 0:dbad57390bd1 | 884 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 885 | CHECK(observer->boot_error == false); |
ram54288 | 0:dbad57390bd1 | 886 | CHECK(observer->boot_wait == true); |
ram54288 | 0:dbad57390bd1 | 887 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 888 | |
ram54288 | 0:dbad57390bd1 | 889 | //handle_bootstrap_finished() fail, Psk not supported |
ram54288 | 0:dbad57390bd1 | 890 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 891 | m2msecurity_stub::sec_mode = M2MSecurity::Psk; |
ram54288 | 0:dbad57390bd1 | 892 | m2msecurity_stub::int_value = true; |
ram54288 | 0:dbad57390bd1 | 893 | m2msecurity_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 894 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 895 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 896 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 897 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 898 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 899 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 900 | |
ram54288 | 0:dbad57390bd1 | 901 | //handle_bootstrap_finished() fail, Bootstrap server |
ram54288 | 0:dbad57390bd1 | 902 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 903 | m2msecurity_stub::sec_mode = M2MSecurity::Certificate; |
ram54288 | 0:dbad57390bd1 | 904 | m2msecurity_stub::int_value = true; |
ram54288 | 0:dbad57390bd1 | 905 | m2msecurity_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 906 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 907 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 908 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 909 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 910 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 911 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 912 | |
ram54288 | 0:dbad57390bd1 | 913 | //handle_bootstrap_finished() fail, key size 0 |
ram54288 | 0:dbad57390bd1 | 914 | nsdl->_security = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:dbad57390bd1 | 915 | m2msecurity_stub::sec_mode = M2MSecurity::Certificate; |
ram54288 | 0:dbad57390bd1 | 916 | m2msecurity_stub::int_value = false; |
ram54288 | 0:dbad57390bd1 | 917 | m2msecurity_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 918 | m2mresourceinstance_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 919 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 920 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 921 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 922 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 923 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 924 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 925 | |
ram54288 | 0:dbad57390bd1 | 926 | //handle_bootstrap_finished() fail, _security null |
ram54288 | 0:dbad57390bd1 | 927 | m2msecurity_stub::sec_mode = M2MSecurity::Certificate; |
ram54288 | 0:dbad57390bd1 | 928 | m2msecurity_stub::int_value = false; |
ram54288 | 0:dbad57390bd1 | 929 | m2msecurity_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 930 | m2mresourceinstance_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 931 | observer->boot_error = false; |
ram54288 | 0:dbad57390bd1 | 932 | observer->boot_done = false; |
ram54288 | 0:dbad57390bd1 | 933 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 934 | CHECK(0 == nsdl->received_from_server_callback(handle,coap_header,address)); |
ram54288 | 0:dbad57390bd1 | 935 | CHECK(observer->boot_error == true); |
ram54288 | 0:dbad57390bd1 | 936 | CHECK(observer->boot_done == false); |
ram54288 | 0:dbad57390bd1 | 937 | |
ram54288 | 0:dbad57390bd1 | 938 | delete m2mobject_stub::inst; |
ram54288 | 0:dbad57390bd1 | 939 | //delete m2mbase_stub::string_value; |
ram54288 | 0:dbad57390bd1 | 940 | //m2mbase_stub::string_value = NULL; |
ram54288 | 0:dbad57390bd1 | 941 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 942 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 943 | delete obj; |
ram54288 | 0:dbad57390bd1 | 944 | delete m2msecurity_stub::string_value; |
ram54288 | 0:dbad57390bd1 | 945 | delete m2msecurity_stub::resource; |
ram54288 | 0:dbad57390bd1 | 946 | |
ram54288 | 0:dbad57390bd1 | 947 | free(m2mbase_stub::nsdl_resource->static_resource_parameters->path); |
ram54288 | 0:dbad57390bd1 | 948 | free(m2mbase_stub::nsdl_resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 949 | free(m2mbase_stub::nsdl_resource); |
ram54288 | 0:dbad57390bd1 | 950 | |
ram54288 | 0:dbad57390bd1 | 951 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 952 | free(address->addr_ptr); |
ram54288 | 0:dbad57390bd1 | 953 | free(address); |
ram54288 | 0:dbad57390bd1 | 954 | free(coap_header->token_ptr); |
ram54288 | 0:dbad57390bd1 | 955 | free(coap_header->uri_path_ptr); |
ram54288 | 0:dbad57390bd1 | 956 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 957 | free(handle->oma_bs_address_ptr); |
ram54288 | 0:dbad57390bd1 | 958 | free(handle); |
ram54288 | 0:dbad57390bd1 | 959 | } |
ram54288 | 0:dbad57390bd1 | 960 | |
ram54288 | 0:dbad57390bd1 | 961 | void Test_M2MNsdlInterface::test_resource_callback() |
ram54288 | 0:dbad57390bd1 | 962 | { |
ram54288 | 0:dbad57390bd1 | 963 | uint8_t value[] = {"name"}; |
ram54288 | 0:dbad57390bd1 | 964 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 965 | memset(coap_header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 966 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 967 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 968 | |
ram54288 | 0:dbad57390bd1 | 969 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 970 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 971 | |
ram54288 | 0:dbad57390bd1 | 972 | common_stub::coap_header->payload_ptr =(uint8_t*)malloc(1); |
ram54288 | 0:dbad57390bd1 | 973 | common_stub::coap_header->payload_len = 1; |
ram54288 | 0:dbad57390bd1 | 974 | |
ram54288 | 0:dbad57390bd1 | 975 | coap_header->uri_path_ptr = value; |
ram54288 | 0:dbad57390bd1 | 976 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 977 | |
ram54288 | 0:dbad57390bd1 | 978 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 979 | |
ram54288 | 0:dbad57390bd1 | 980 | common_stub::coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 981 | |
ram54288 | 0:dbad57390bd1 | 982 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 983 | |
ram54288 | 0:dbad57390bd1 | 984 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 985 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 986 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 987 | m2mbase_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 988 | m2mobject_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 989 | m2mbase_stub::nsdl_resource = |
ram54288 | 0:dbad57390bd1 | 990 | (sn_nsdl_dynamic_resource_parameters_s*) malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 991 | m2mbase_stub::nsdl_resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 992 | (sn_nsdl_static_resource_parameters_s*) malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 993 | m2mbase_stub::nsdl_resource->static_resource_parameters->path = (uint8_t*)malloc(5); |
ram54288 | 0:dbad57390bd1 | 994 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[0] = 'n'; |
ram54288 | 0:dbad57390bd1 | 995 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[1] = 'a'; |
ram54288 | 0:dbad57390bd1 | 996 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[2] = 'm'; |
ram54288 | 0:dbad57390bd1 | 997 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 998 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[4] = '\0'; |
ram54288 | 0:dbad57390bd1 | 999 | m2mbase_stub::nsdl_resource->static_resource_parameters->pathlen = 5; |
ram54288 | 0:dbad57390bd1 | 1000 | |
ram54288 | 0:dbad57390bd1 | 1001 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1002 | |
ram54288 | 0:dbad57390bd1 | 1003 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_COAP) ==0); |
ram54288 | 0:dbad57390bd1 | 1004 | |
ram54288 | 0:dbad57390bd1 | 1005 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
ram54288 | 0:dbad57390bd1 | 1006 | m2mobject_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1007 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_COAP) ==0); |
ram54288 | 0:dbad57390bd1 | 1008 | |
ram54288 | 0:dbad57390bd1 | 1009 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 1010 | |
ram54288 | 0:dbad57390bd1 | 1011 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_COAP) ==0); |
ram54288 | 0:dbad57390bd1 | 1012 | m2mobject_stub::base_type = M2MBase::ResourceInstance; |
ram54288 | 0:dbad57390bd1 | 1013 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_COAP) ==0); |
ram54288 | 0:dbad57390bd1 | 1014 | |
ram54288 | 0:dbad57390bd1 | 1015 | delete object; |
ram54288 | 0:dbad57390bd1 | 1016 | free(m2mbase_stub::nsdl_resource->static_resource_parameters->path); |
ram54288 | 0:dbad57390bd1 | 1017 | free(m2mbase_stub::nsdl_resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 1018 | free(m2mbase_stub::nsdl_resource); |
ram54288 | 0:dbad57390bd1 | 1019 | |
ram54288 | 0:dbad57390bd1 | 1020 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1021 | free(address); |
ram54288 | 0:dbad57390bd1 | 1022 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 1023 | } |
ram54288 | 0:dbad57390bd1 | 1024 | |
ram54288 | 0:dbad57390bd1 | 1025 | |
ram54288 | 0:dbad57390bd1 | 1026 | void Test_M2MNsdlInterface::test_resource_callback_get() |
ram54288 | 0:dbad57390bd1 | 1027 | { |
ram54288 | 0:dbad57390bd1 | 1028 | } |
ram54288 | 0:dbad57390bd1 | 1029 | |
ram54288 | 0:dbad57390bd1 | 1030 | void Test_M2MNsdlInterface::test_resource_callback_put() |
ram54288 | 0:dbad57390bd1 | 1031 | { |
ram54288 | 0:dbad57390bd1 | 1032 | uint8_t value[] = {"name/0/resource"}; |
ram54288 | 0:dbad57390bd1 | 1033 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1034 | memset(coap_header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1035 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1036 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1037 | |
ram54288 | 0:dbad57390bd1 | 1038 | coap_header->uri_path_ptr = value; |
ram54288 | 0:dbad57390bd1 | 1039 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 1040 | |
ram54288 | 0:dbad57390bd1 | 1041 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
ram54288 | 0:dbad57390bd1 | 1042 | |
ram54288 | 0:dbad57390bd1 | 1043 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1044 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 1045 | |
ram54288 | 0:dbad57390bd1 | 1046 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1047 | M2MObjectInstance* instance = new M2MObjectInstance(*object,"name","", ""); |
ram54288 | 0:dbad57390bd1 | 1048 | |
ram54288 | 0:dbad57390bd1 | 1049 | M2MResource* create_resource = new M2MResource(*instance, |
ram54288 | 0:dbad57390bd1 | 1050 | "res", |
ram54288 | 0:dbad57390bd1 | 1051 | "res", |
ram54288 | 0:dbad57390bd1 | 1052 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1053 | false, |
ram54288 | 0:dbad57390bd1 | 1054 | "res"); |
ram54288 | 0:dbad57390bd1 | 1055 | m2mobject_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1056 | m2mobject_stub::instance_list.push_back(instance); |
ram54288 | 0:dbad57390bd1 | 1057 | |
ram54288 | 0:dbad57390bd1 | 1058 | m2mobjectinstance_stub::resource_list.push_back(create_resource); |
ram54288 | 0:dbad57390bd1 | 1059 | m2mobjectinstance_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 1060 | |
ram54288 | 0:dbad57390bd1 | 1061 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1062 | |
ram54288 | 0:dbad57390bd1 | 1063 | m2mbase_stub::operation = M2MBase::PUT_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 1064 | |
ram54288 | 0:dbad57390bd1 | 1065 | coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1066 | |
ram54288 | 0:dbad57390bd1 | 1067 | uint8_t query[] = {"pmax=200&pmin=120"}; |
ram54288 | 0:dbad57390bd1 | 1068 | coap_header->options_list_ptr->uri_query_ptr = (uint8_t*)malloc(sizeof(query)); |
ram54288 | 0:dbad57390bd1 | 1069 | coap_header->options_list_ptr->uri_query_len = sizeof(query); |
ram54288 | 0:dbad57390bd1 | 1070 | |
ram54288 | 0:dbad57390bd1 | 1071 | m2mbase_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1072 | |
ram54288 | 0:dbad57390bd1 | 1073 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1074 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1075 | common_stub::coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 1076 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1077 | |
ram54288 | 0:dbad57390bd1 | 1078 | m2mobject_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1079 | m2mbase_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1080 | m2mobject_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1081 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1082 | |
ram54288 | 0:dbad57390bd1 | 1083 | m2mobject_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1084 | m2mbase_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1085 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1086 | |
ram54288 | 0:dbad57390bd1 | 1087 | m2mbase_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1088 | m2mbase_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 1089 | |
ram54288 | 0:dbad57390bd1 | 1090 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1091 | |
ram54288 | 0:dbad57390bd1 | 1092 | delete object; |
ram54288 | 0:dbad57390bd1 | 1093 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1094 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1095 | // m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1096 | delete create_resource; |
ram54288 | 0:dbad57390bd1 | 1097 | |
ram54288 | 0:dbad57390bd1 | 1098 | free(coap_header->options_list_ptr->uri_query_ptr); |
ram54288 | 0:dbad57390bd1 | 1099 | free(coap_header->options_list_ptr); |
ram54288 | 0:dbad57390bd1 | 1100 | if(common_stub::coap_header){ |
ram54288 | 0:dbad57390bd1 | 1101 | if( common_stub::coap_header->options_list_ptr){ |
ram54288 | 0:dbad57390bd1 | 1102 | free(common_stub::coap_header->options_list_ptr); |
ram54288 | 0:dbad57390bd1 | 1103 | common_stub::coap_header->options_list_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 1104 | } |
ram54288 | 0:dbad57390bd1 | 1105 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1106 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 1107 | } |
ram54288 | 0:dbad57390bd1 | 1108 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 1109 | free(address); |
ram54288 | 0:dbad57390bd1 | 1110 | |
ram54288 | 0:dbad57390bd1 | 1111 | m2mbase_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1112 | common_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1113 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1114 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1115 | } |
ram54288 | 0:dbad57390bd1 | 1116 | |
ram54288 | 0:dbad57390bd1 | 1117 | void Test_M2MNsdlInterface::test_resource_callback_post() |
ram54288 | 0:dbad57390bd1 | 1118 | { |
ram54288 | 0:dbad57390bd1 | 1119 | uint8_t value[] = {"name/0/name"}; |
ram54288 | 0:dbad57390bd1 | 1120 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1121 | memset(coap_header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1122 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1123 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1124 | |
ram54288 | 0:dbad57390bd1 | 1125 | coap_header->uri_path_ptr = value; |
ram54288 | 0:dbad57390bd1 | 1126 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 1127 | |
ram54288 | 0:dbad57390bd1 | 1128 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_POST; |
ram54288 | 0:dbad57390bd1 | 1129 | |
ram54288 | 0:dbad57390bd1 | 1130 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1131 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 1132 | m2mbase_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 1133 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1134 | M2MObjectInstance* instance = new M2MObjectInstance(*object,"name","",""); |
ram54288 | 0:dbad57390bd1 | 1135 | M2MResource* create_resource = new M2MResource(*instance, |
ram54288 | 0:dbad57390bd1 | 1136 | "name", |
ram54288 | 0:dbad57390bd1 | 1137 | "name", |
ram54288 | 0:dbad57390bd1 | 1138 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1139 | false, |
ram54288 | 0:dbad57390bd1 | 1140 | "name"); |
ram54288 | 0:dbad57390bd1 | 1141 | m2mobject_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1142 | m2mobject_stub::instance_list.push_back(instance); |
ram54288 | 0:dbad57390bd1 | 1143 | |
ram54288 | 0:dbad57390bd1 | 1144 | m2mobjectinstance_stub::resource_list.push_back(create_resource); |
ram54288 | 0:dbad57390bd1 | 1145 | m2mobjectinstance_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 1146 | |
ram54288 | 0:dbad57390bd1 | 1147 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1148 | |
ram54288 | 0:dbad57390bd1 | 1149 | m2mbase_stub::operation = M2MBase::POST_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 1150 | |
ram54288 | 0:dbad57390bd1 | 1151 | coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1152 | |
ram54288 | 0:dbad57390bd1 | 1153 | uint8_t query[] = {"pmax=200&pmin=120"}; |
ram54288 | 0:dbad57390bd1 | 1154 | coap_header->options_list_ptr->uri_query_ptr = (uint8_t*)malloc(sizeof(query)); |
ram54288 | 0:dbad57390bd1 | 1155 | coap_header->options_list_ptr->uri_query_len = sizeof(query); |
ram54288 | 0:dbad57390bd1 | 1156 | |
ram54288 | 0:dbad57390bd1 | 1157 | m2mbase_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1158 | |
ram54288 | 0:dbad57390bd1 | 1159 | m2mbase_stub::nsdl_resource = |
ram54288 | 0:dbad57390bd1 | 1160 | (sn_nsdl_dynamic_resource_parameters_s*) malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1161 | m2mbase_stub::nsdl_resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 1162 | (sn_nsdl_static_resource_parameters_s*) malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1163 | m2mbase_stub::nsdl_resource->static_resource_parameters->path = (uint8_t*)malloc(5); |
ram54288 | 0:dbad57390bd1 | 1164 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[0] = 'n'; |
ram54288 | 0:dbad57390bd1 | 1165 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[1] = 'a'; |
ram54288 | 0:dbad57390bd1 | 1166 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[2] = 'm'; |
ram54288 | 0:dbad57390bd1 | 1167 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 1168 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[4] = '\0'; |
ram54288 | 0:dbad57390bd1 | 1169 | m2mbase_stub::nsdl_resource->static_resource_parameters->pathlen = 5; |
ram54288 | 0:dbad57390bd1 | 1170 | |
ram54288 | 0:dbad57390bd1 | 1171 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1172 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1173 | common_stub::coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 1174 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1175 | |
ram54288 | 0:dbad57390bd1 | 1176 | m2mobject_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1177 | m2mbase_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1178 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1179 | |
ram54288 | 0:dbad57390bd1 | 1180 | m2mobject_stub::base_type = M2MBase::ResourceInstance; |
ram54288 | 0:dbad57390bd1 | 1181 | m2mbase_stub::base_type = M2MBase::ResourceInstance; |
ram54288 | 0:dbad57390bd1 | 1182 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1183 | |
ram54288 | 0:dbad57390bd1 | 1184 | m2mobject_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1185 | m2mbase_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1186 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1187 | |
ram54288 | 0:dbad57390bd1 | 1188 | m2mbase_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1189 | m2mbase_stub::bool_value = false; |
ram54288 | 0:dbad57390bd1 | 1190 | |
ram54288 | 0:dbad57390bd1 | 1191 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1192 | |
ram54288 | 0:dbad57390bd1 | 1193 | delete object; |
ram54288 | 0:dbad57390bd1 | 1194 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1195 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1196 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1197 | delete create_resource; |
ram54288 | 0:dbad57390bd1 | 1198 | |
ram54288 | 0:dbad57390bd1 | 1199 | free(coap_header->options_list_ptr->uri_query_ptr); |
ram54288 | 0:dbad57390bd1 | 1200 | free(coap_header->options_list_ptr); |
ram54288 | 0:dbad57390bd1 | 1201 | if(common_stub::coap_header){ |
ram54288 | 0:dbad57390bd1 | 1202 | if( common_stub::coap_header->options_list_ptr){ |
ram54288 | 0:dbad57390bd1 | 1203 | free(common_stub::coap_header->options_list_ptr); |
ram54288 | 0:dbad57390bd1 | 1204 | common_stub::coap_header->options_list_ptr = NULL; |
ram54288 | 0:dbad57390bd1 | 1205 | } |
ram54288 | 0:dbad57390bd1 | 1206 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1207 | common_stub::coap_header = NULL; |
ram54288 | 0:dbad57390bd1 | 1208 | } |
ram54288 | 0:dbad57390bd1 | 1209 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 1210 | free(address); |
ram54288 | 0:dbad57390bd1 | 1211 | free(m2mbase_stub::nsdl_resource->static_resource_parameters->path); |
ram54288 | 0:dbad57390bd1 | 1212 | free(m2mbase_stub::nsdl_resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 1213 | free(m2mbase_stub::nsdl_resource); |
ram54288 | 0:dbad57390bd1 | 1214 | |
ram54288 | 0:dbad57390bd1 | 1215 | m2mbase_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1216 | common_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1217 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1218 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1219 | } |
ram54288 | 0:dbad57390bd1 | 1220 | |
ram54288 | 0:dbad57390bd1 | 1221 | void Test_M2MNsdlInterface::test_resource_callback_delete() |
ram54288 | 0:dbad57390bd1 | 1222 | { |
ram54288 | 0:dbad57390bd1 | 1223 | uint8_t value[] = {"name/0"}; |
ram54288 | 0:dbad57390bd1 | 1224 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1225 | memset(coap_header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1226 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1227 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1228 | |
ram54288 | 0:dbad57390bd1 | 1229 | common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1230 | memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); |
ram54288 | 0:dbad57390bd1 | 1231 | |
ram54288 | 0:dbad57390bd1 | 1232 | coap_header->uri_path_ptr = value; |
ram54288 | 0:dbad57390bd1 | 1233 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 1234 | |
ram54288 | 0:dbad57390bd1 | 1235 | coap_header->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
ram54288 | 0:dbad57390bd1 | 1236 | common_stub::coap_header->msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; |
ram54288 | 0:dbad57390bd1 | 1237 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1238 | |
ram54288 | 0:dbad57390bd1 | 1239 | m2mbase_stub::nsdl_resource = |
ram54288 | 0:dbad57390bd1 | 1240 | (sn_nsdl_dynamic_resource_parameters_s*) malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1241 | m2mbase_stub::nsdl_resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 1242 | (sn_nsdl_static_resource_parameters_s*) malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1243 | |
ram54288 | 0:dbad57390bd1 | 1244 | m2mbase_stub::nsdl_resource->static_resource_parameters->path = (uint8_t*)malloc(7); |
ram54288 | 0:dbad57390bd1 | 1245 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[0] = 'n'; |
ram54288 | 0:dbad57390bd1 | 1246 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[1] = 'a'; |
ram54288 | 0:dbad57390bd1 | 1247 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[2] = 'm'; |
ram54288 | 0:dbad57390bd1 | 1248 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 1249 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[4] = '/'; |
ram54288 | 0:dbad57390bd1 | 1250 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[5] = '0'; |
ram54288 | 0:dbad57390bd1 | 1251 | m2mbase_stub::nsdl_resource->static_resource_parameters->path[6] = '\0'; |
ram54288 | 0:dbad57390bd1 | 1252 | m2mbase_stub::nsdl_resource->static_resource_parameters->pathlen = 7; |
ram54288 | 0:dbad57390bd1 | 1253 | |
ram54288 | 0:dbad57390bd1 | 1254 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1255 | |
ram54288 | 0:dbad57390bd1 | 1256 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1257 | m2mbase_stub::string_value = "name/0"; |
ram54288 | 0:dbad57390bd1 | 1258 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1259 | M2MObjectInstance* instance = new M2MObjectInstance(*object,"name", "", "name/0"); |
ram54288 | 0:dbad57390bd1 | 1260 | m2mbase_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1261 | m2mobject_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 1262 | m2mobject_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1263 | m2mobject_stub::instance_list.push_back(instance); |
ram54288 | 0:dbad57390bd1 | 1264 | m2mobject_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1265 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1266 | |
ram54288 | 0:dbad57390bd1 | 1267 | m2mbase_stub::operation = M2MBase::DELETE_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 1268 | |
ram54288 | 0:dbad57390bd1 | 1269 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1270 | |
ram54288 | 0:dbad57390bd1 | 1271 | m2mobject_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1272 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) ==0); |
ram54288 | 0:dbad57390bd1 | 1273 | |
ram54288 | 0:dbad57390bd1 | 1274 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1275 | delete object; |
ram54288 | 0:dbad57390bd1 | 1276 | free(m2mbase_stub::nsdl_resource->static_resource_parameters->path); |
ram54288 | 0:dbad57390bd1 | 1277 | free(m2mbase_stub::nsdl_resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 1278 | free(m2mbase_stub::nsdl_resource); |
ram54288 | 0:dbad57390bd1 | 1279 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1280 | free(address); |
ram54288 | 0:dbad57390bd1 | 1281 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 1282 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1283 | } |
ram54288 | 0:dbad57390bd1 | 1284 | |
ram54288 | 0:dbad57390bd1 | 1285 | /* |
ram54288 | 0:dbad57390bd1 | 1286 | void Test_M2MNsdlInterface::test_resource_callback_reset() |
ram54288 | 0:dbad57390bd1 | 1287 | { |
ram54288 | 0:dbad57390bd1 | 1288 | uint8_t value[] = {"name"}; |
ram54288 | 0:dbad57390bd1 | 1289 | sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1290 | memset(coap_header,0,sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1291 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1292 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1293 | |
ram54288 | 0:dbad57390bd1 | 1294 | coap_header->uri_path_ptr = value; |
ram54288 | 0:dbad57390bd1 | 1295 | coap_header->uri_path_len = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 1296 | |
ram54288 | 0:dbad57390bd1 | 1297 | coap_header->msg_type = COAP_MSG_TYPE_RESET; |
ram54288 | 0:dbad57390bd1 | 1298 | m2mobjectinstance_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1299 | String *name = new String("name"); |
ram54288 | 0:dbad57390bd1 | 1300 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1301 | m2mbase_stub::string_value = name; |
ram54288 | 0:dbad57390bd1 | 1302 | M2MObject *object = new M2MObject(*name); |
ram54288 | 0:dbad57390bd1 | 1303 | M2MObjectInstance* instance = new M2MObjectInstance(*name,*object); |
ram54288 | 0:dbad57390bd1 | 1304 | M2MResource* create_resource = new M2MResource(*instance, |
ram54288 | 0:dbad57390bd1 | 1305 | *name, |
ram54288 | 0:dbad57390bd1 | 1306 | *name, |
ram54288 | 0:dbad57390bd1 | 1307 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1308 | M2MResource::Dynamic,false); |
ram54288 | 0:dbad57390bd1 | 1309 | m2mobject_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1310 | m2mobject_stub::instance_list.push_back(instance); |
ram54288 | 0:dbad57390bd1 | 1311 | |
ram54288 | 0:dbad57390bd1 | 1312 | m2mobjectinstance_stub::resource_list.push_back(create_resource); |
ram54288 | 0:dbad57390bd1 | 1313 | m2mobjectinstance_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 1314 | |
ram54288 | 0:dbad57390bd1 | 1315 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1316 | // No response for RESET message |
ram54288 | 0:dbad57390bd1 | 1317 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) == 1); |
ram54288 | 0:dbad57390bd1 | 1318 | |
ram54288 | 0:dbad57390bd1 | 1319 | |
ram54288 | 0:dbad57390bd1 | 1320 | m2mobject_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1321 | // No response for RESET message |
ram54288 | 0:dbad57390bd1 | 1322 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) == 1); |
ram54288 | 0:dbad57390bd1 | 1323 | |
ram54288 | 0:dbad57390bd1 | 1324 | m2mobject_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1325 | // No response for RESET message |
ram54288 | 0:dbad57390bd1 | 1326 | CHECK(nsdl->resource_callback(NULL,coap_header,address,SN_NSDL_PROTOCOL_HTTP) == 1); |
ram54288 | 0:dbad57390bd1 | 1327 | |
ram54288 | 0:dbad57390bd1 | 1328 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1329 | delete object; |
ram54288 | 0:dbad57390bd1 | 1330 | delete name; |
ram54288 | 0:dbad57390bd1 | 1331 | delete create_resource; |
ram54288 | 0:dbad57390bd1 | 1332 | free(address); |
ram54288 | 0:dbad57390bd1 | 1333 | free(coap_header); |
ram54288 | 0:dbad57390bd1 | 1334 | m2mobject_stub::instance_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1335 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1336 | //nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1337 | } |
ram54288 | 0:dbad57390bd1 | 1338 | */ |
ram54288 | 0:dbad57390bd1 | 1339 | void Test_M2MNsdlInterface::test_process_received_data() |
ram54288 | 0:dbad57390bd1 | 1340 | { |
ram54288 | 0:dbad57390bd1 | 1341 | uint8_t *data = (uint8_t*)malloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 1342 | uint16_t data_size = sizeof(uint16_t); |
ram54288 | 0:dbad57390bd1 | 1343 | sn_nsdl_addr_s *address = (sn_nsdl_addr_s *)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1344 | |
ram54288 | 0:dbad57390bd1 | 1345 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1346 | |
ram54288 | 0:dbad57390bd1 | 1347 | CHECK(nsdl->process_received_data(data,data_size,address) == true); |
ram54288 | 0:dbad57390bd1 | 1348 | |
ram54288 | 0:dbad57390bd1 | 1349 | common_stub::int_value = -1; |
ram54288 | 0:dbad57390bd1 | 1350 | |
ram54288 | 0:dbad57390bd1 | 1351 | CHECK(nsdl->process_received_data(data,data_size,address) == false); |
ram54288 | 0:dbad57390bd1 | 1352 | |
ram54288 | 0:dbad57390bd1 | 1353 | free(address); |
ram54288 | 0:dbad57390bd1 | 1354 | free(data); |
ram54288 | 0:dbad57390bd1 | 1355 | common_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1356 | } |
ram54288 | 0:dbad57390bd1 | 1357 | |
ram54288 | 0:dbad57390bd1 | 1358 | void Test_M2MNsdlInterface::test_stop_timers() |
ram54288 | 0:dbad57390bd1 | 1359 | { |
ram54288 | 0:dbad57390bd1 | 1360 | // Check if there is no memory leak or crash |
ram54288 | 0:dbad57390bd1 | 1361 | nsdl->stop_timers(); |
ram54288 | 0:dbad57390bd1 | 1362 | } |
ram54288 | 0:dbad57390bd1 | 1363 | |
ram54288 | 0:dbad57390bd1 | 1364 | void Test_M2MNsdlInterface::test_timer_expired() |
ram54288 | 0:dbad57390bd1 | 1365 | { |
ram54288 | 0:dbad57390bd1 | 1366 | nsdl->timer_expired(M2MTimerObserver::NsdlExecution); |
ram54288 | 0:dbad57390bd1 | 1367 | CHECK(nsdl->_counter_for_nsdl == 1); |
ram54288 | 0:dbad57390bd1 | 1368 | |
ram54288 | 0:dbad57390bd1 | 1369 | if( nsdl->_endpoint == NULL){ |
ram54288 | 0:dbad57390bd1 | 1370 | nsdl->_endpoint = (sn_nsdl_ep_parameters_s*)nsdl->memory_alloc(sizeof(sn_nsdl_ep_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1371 | } |
ram54288 | 0:dbad57390bd1 | 1372 | nsdl->_endpoint->lifetime_ptr = (uint8_t*)malloc(sizeof(uint8_t)); |
ram54288 | 0:dbad57390bd1 | 1373 | |
ram54288 | 0:dbad57390bd1 | 1374 | // For checking the registration update |
ram54288 | 0:dbad57390bd1 | 1375 | nsdl->timer_expired(M2MTimerObserver::Registration); |
ram54288 | 0:dbad57390bd1 | 1376 | |
ram54288 | 0:dbad57390bd1 | 1377 | nsdl->delete_endpoint(); |
ram54288 | 0:dbad57390bd1 | 1378 | CHECK(nsdl->_endpoint == NULL); |
ram54288 | 0:dbad57390bd1 | 1379 | } |
ram54288 | 0:dbad57390bd1 | 1380 | |
ram54288 | 0:dbad57390bd1 | 1381 | void Test_M2MNsdlInterface::test_observation_to_be_sent() |
ram54288 | 0:dbad57390bd1 | 1382 | { |
ram54288 | 0:dbad57390bd1 | 1383 | Vector<uint16_t> instance_list_ids; |
ram54288 | 0:dbad57390bd1 | 1384 | m2mbase_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1385 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1386 | M2MObjectInstance* instance = new M2MObjectInstance(*object, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 1387 | M2MResource *res = new M2MResource(*instance,"res", "res", M2MResourceInstance::INTEGER,false, "res"); |
ram54288 | 0:dbad57390bd1 | 1388 | M2MResource *res2 = new M2MResource(*instance,"res2", "res2", M2MResourceInstance::INTEGER,false, "res2"); |
ram54288 | 0:dbad57390bd1 | 1389 | |
ram54288 | 0:dbad57390bd1 | 1390 | |
ram54288 | 0:dbad57390bd1 | 1391 | M2MResourceInstance* res_instance = new M2MResourceInstance(*res, |
ram54288 | 0:dbad57390bd1 | 1392 | "res", "res", |
ram54288 | 0:dbad57390bd1 | 1393 | M2MResourceInstance::INTEGER,0,"",false); |
ram54288 | 0:dbad57390bd1 | 1394 | M2MResourceInstance* res_instance_1 = new M2MResourceInstance(*res2, |
ram54288 | 0:dbad57390bd1 | 1395 | "res2", "res2", |
ram54288 | 0:dbad57390bd1 | 1396 | M2MResourceInstance::INTEGER,0,"",false); |
ram54288 | 0:dbad57390bd1 | 1397 | m2mresource_stub::list.clear(); |
ram54288 | 0:dbad57390bd1 | 1398 | m2mresource_stub::list.push_back(res_instance); |
ram54288 | 0:dbad57390bd1 | 1399 | m2mresource_stub::list.push_back(res_instance_1); |
ram54288 | 0:dbad57390bd1 | 1400 | m2mresource_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1401 | instance_list_ids.push_back(0); |
ram54288 | 0:dbad57390bd1 | 1402 | |
ram54288 | 0:dbad57390bd1 | 1403 | uint8_t value[] = {"value"}; |
ram54288 | 0:dbad57390bd1 | 1404 | m2mresourceinstance_stub::value = (uint8_t *)malloc(sizeof(value)); |
ram54288 | 0:dbad57390bd1 | 1405 | memset( m2mresourceinstance_stub::value, 0, sizeof(value)); |
ram54288 | 0:dbad57390bd1 | 1406 | memcpy(m2mresourceinstance_stub::value,value,sizeof(value)); |
ram54288 | 0:dbad57390bd1 | 1407 | m2mresourceinstance_stub::int_value = sizeof(value); |
ram54288 | 0:dbad57390bd1 | 1408 | |
ram54288 | 0:dbad57390bd1 | 1409 | m2mbase_stub::uint16_value = 321; |
ram54288 | 0:dbad57390bd1 | 1410 | m2mbase_stub::string_value = "token"; |
ram54288 | 0:dbad57390bd1 | 1411 | |
ram54288 | 0:dbad57390bd1 | 1412 | m2mresourceinstance_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1413 | |
ram54288 | 0:dbad57390bd1 | 1414 | nsdl->_nsdl_handle = (nsdl_s*)malloc(sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 1415 | memset(nsdl->_nsdl_handle,0,sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 1416 | sn_nsdl_oma_server_info_t * nsp_address = (sn_nsdl_oma_server_info_t *)malloc(sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1417 | memset(nsp_address,0,sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1418 | sn_nsdl_addr_s* address = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1419 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1420 | |
ram54288 | 0:dbad57390bd1 | 1421 | nsdl->_nsdl_handle->nsp_address_ptr = nsp_address; |
ram54288 | 0:dbad57390bd1 | 1422 | memset(nsdl->_nsdl_handle->nsp_address_ptr,0,sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1423 | nsdl->_nsdl_handle->nsp_address_ptr->omalw_address_ptr = address; |
ram54288 | 0:dbad57390bd1 | 1424 | |
ram54288 | 0:dbad57390bd1 | 1425 | //CHECK if nothing crashes |
ram54288 | 0:dbad57390bd1 | 1426 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1427 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1428 | nsdl->observation_to_be_sent(res2, 1, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1429 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1430 | |
ram54288 | 0:dbad57390bd1 | 1431 | m2mresourceinstance_stub::resource_type = M2MResource::OPAQUE; |
ram54288 | 0:dbad57390bd1 | 1432 | |
ram54288 | 0:dbad57390bd1 | 1433 | //CHECK if nothing crashes |
ram54288 | 0:dbad57390bd1 | 1434 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1435 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1436 | nsdl->observation_to_be_sent(res2, 1, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1437 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1438 | |
ram54288 | 0:dbad57390bd1 | 1439 | m2mresource_stub::list.clear(); |
ram54288 | 0:dbad57390bd1 | 1440 | m2mresource_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1441 | |
ram54288 | 0:dbad57390bd1 | 1442 | //CHECK if nothing crashes |
ram54288 | 0:dbad57390bd1 | 1443 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1444 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1445 | nsdl->observation_to_be_sent(res, 500, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1446 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1447 | |
ram54288 | 0:dbad57390bd1 | 1448 | M2MObjectInstance *object_instance = new M2MObjectInstance(*object, "name", "",""); |
ram54288 | 0:dbad57390bd1 | 1449 | m2mobject_stub::int_value = 1; |
ram54288 | 0:dbad57390bd1 | 1450 | m2mobject_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1451 | m2mobject_stub::inst = object_instance; |
ram54288 | 0:dbad57390bd1 | 1452 | m2mobjectinstance_stub::resource_list.push_back(res); |
ram54288 | 0:dbad57390bd1 | 1453 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1454 | instance_list_ids.push_back(1); |
ram54288 | 0:dbad57390bd1 | 1455 | //CHECK if nothing crashes |
ram54288 | 0:dbad57390bd1 | 1456 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1457 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1458 | nsdl->observation_to_be_sent(object, 1, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1459 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1460 | |
ram54288 | 0:dbad57390bd1 | 1461 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1462 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1463 | nsdl->observation_to_be_sent(object, 500, instance_list_ids, true); |
ram54288 | 0:dbad57390bd1 | 1464 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1465 | |
ram54288 | 0:dbad57390bd1 | 1466 | //CHECK if nothing crashes |
ram54288 | 0:dbad57390bd1 | 1467 | m2mobjectinstance_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1468 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1469 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1470 | nsdl->observation_to_be_sent(object_instance, 1, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1471 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1472 | |
ram54288 | 0:dbad57390bd1 | 1473 | common_stub::coap_header = (sn_coap_hdr_s *) malloc(sizeof(sn_coap_hdr_s)); |
ram54288 | 0:dbad57390bd1 | 1474 | common_stub::coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); |
ram54288 | 0:dbad57390bd1 | 1475 | nsdl->observation_to_be_sent(object_instance, 500, instance_list_ids); |
ram54288 | 0:dbad57390bd1 | 1476 | free(common_stub::coap_header); |
ram54288 | 0:dbad57390bd1 | 1477 | |
ram54288 | 0:dbad57390bd1 | 1478 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:dbad57390bd1 | 1479 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:dbad57390bd1 | 1480 | |
ram54288 | 0:dbad57390bd1 | 1481 | m2mbase_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1482 | m2mresourceinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1483 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1484 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1485 | m2mresource_stub::list.clear(); |
ram54288 | 0:dbad57390bd1 | 1486 | delete res; |
ram54288 | 0:dbad57390bd1 | 1487 | res = NULL; |
ram54288 | 0:dbad57390bd1 | 1488 | |
ram54288 | 0:dbad57390bd1 | 1489 | delete res2; |
ram54288 | 0:dbad57390bd1 | 1490 | res2 = NULL; |
ram54288 | 0:dbad57390bd1 | 1491 | |
ram54288 | 0:dbad57390bd1 | 1492 | delete res_instance; |
ram54288 | 0:dbad57390bd1 | 1493 | res_instance = NULL; |
ram54288 | 0:dbad57390bd1 | 1494 | |
ram54288 | 0:dbad57390bd1 | 1495 | delete res_instance_1; |
ram54288 | 0:dbad57390bd1 | 1496 | res_instance_1 = NULL; |
ram54288 | 0:dbad57390bd1 | 1497 | |
ram54288 | 0:dbad57390bd1 | 1498 | delete object_instance; |
ram54288 | 0:dbad57390bd1 | 1499 | object_instance = NULL; |
ram54288 | 0:dbad57390bd1 | 1500 | |
ram54288 | 0:dbad57390bd1 | 1501 | delete object; |
ram54288 | 0:dbad57390bd1 | 1502 | object = NULL; |
ram54288 | 0:dbad57390bd1 | 1503 | |
ram54288 | 0:dbad57390bd1 | 1504 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1505 | instance = NULL; |
ram54288 | 0:dbad57390bd1 | 1506 | |
ram54288 | 0:dbad57390bd1 | 1507 | free(nsp_address); |
ram54288 | 0:dbad57390bd1 | 1508 | free(address); |
ram54288 | 0:dbad57390bd1 | 1509 | free(nsdl->_nsdl_handle); |
ram54288 | 0:dbad57390bd1 | 1510 | } |
ram54288 | 0:dbad57390bd1 | 1511 | |
ram54288 | 0:dbad57390bd1 | 1512 | void Test_M2MNsdlInterface::test_resource_to_be_deleted() |
ram54288 | 0:dbad57390bd1 | 1513 | { |
ram54288 | 0:dbad57390bd1 | 1514 | //Checking coverage for the code |
ram54288 | 0:dbad57390bd1 | 1515 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1516 | nsdl->resource_to_be_deleted(object); |
ram54288 | 0:dbad57390bd1 | 1517 | delete object; |
ram54288 | 0:dbad57390bd1 | 1518 | } |
ram54288 | 0:dbad57390bd1 | 1519 | |
ram54288 | 0:dbad57390bd1 | 1520 | void Test_M2MNsdlInterface::test_value_updated() |
ram54288 | 0:dbad57390bd1 | 1521 | { |
ram54288 | 0:dbad57390bd1 | 1522 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1523 | M2MObjectInstance *object_instance = new M2MObjectInstance(*object, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 1524 | M2MResource *resource = new M2MResource(*object_instance, |
ram54288 | 0:dbad57390bd1 | 1525 | "resource_name", |
ram54288 | 0:dbad57390bd1 | 1526 | "resource_type", |
ram54288 | 0:dbad57390bd1 | 1527 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1528 | false, |
ram54288 | 0:dbad57390bd1 | 1529 | "resource_name"); |
ram54288 | 0:dbad57390bd1 | 1530 | |
ram54288 | 0:dbad57390bd1 | 1531 | M2MResourceInstance *resource_instance = new M2MResourceInstance(*resource, |
ram54288 | 0:dbad57390bd1 | 1532 | "resource_name", |
ram54288 | 0:dbad57390bd1 | 1533 | "resource_type", |
ram54288 | 0:dbad57390bd1 | 1534 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1535 | 0,"",false); |
ram54288 | 0:dbad57390bd1 | 1536 | |
ram54288 | 0:dbad57390bd1 | 1537 | m2mobject_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1538 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 1539 | m2mbase_stub::operation = M2MBase::GET_ALLOWED; |
ram54288 | 0:dbad57390bd1 | 1540 | nsdl->value_updated(object,"name"); |
ram54288 | 0:dbad57390bd1 | 1541 | CHECK(observer->value_update == true); |
ram54288 | 0:dbad57390bd1 | 1542 | observer->value_update = false; |
ram54288 | 0:dbad57390bd1 | 1543 | |
ram54288 | 0:dbad57390bd1 | 1544 | m2mobjectinstance_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1545 | |
ram54288 | 0:dbad57390bd1 | 1546 | nsdl->value_updated(object_instance,"name/0"); |
ram54288 | 0:dbad57390bd1 | 1547 | CHECK(observer->value_update == true); |
ram54288 | 0:dbad57390bd1 | 1548 | observer->value_update = false; |
ram54288 | 0:dbad57390bd1 | 1549 | |
ram54288 | 0:dbad57390bd1 | 1550 | common_stub::resource = (sn_nsdl_dynamic_resource_parameters_s*)malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1551 | memset(common_stub::resource,0, sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1552 | |
ram54288 | 0:dbad57390bd1 | 1553 | common_stub::resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 1554 | (sn_nsdl_static_resource_parameters_s*)malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1555 | memset(common_stub::resource->static_resource_parameters,0, sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1556 | |
ram54288 | 0:dbad57390bd1 | 1557 | common_stub::resource->static_resource_parameters->resource = (uint8_t*)malloc(2); |
ram54288 | 0:dbad57390bd1 | 1558 | memset(common_stub::resource->static_resource_parameters->resource,0, 2); |
ram54288 | 0:dbad57390bd1 | 1559 | |
ram54288 | 0:dbad57390bd1 | 1560 | common_stub::resource->static_resource_parameters->mode = SN_GRS_STATIC; |
ram54288 | 0:dbad57390bd1 | 1561 | m2mbase_stub::mode_value = M2MBase::Static; |
ram54288 | 0:dbad57390bd1 | 1562 | |
ram54288 | 0:dbad57390bd1 | 1563 | common_stub::resource->observable = false; |
ram54288 | 0:dbad57390bd1 | 1564 | m2mbase_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1565 | |
ram54288 | 0:dbad57390bd1 | 1566 | m2mresourceinstance_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1567 | uint8_t value[] = "1"; |
ram54288 | 0:dbad57390bd1 | 1568 | m2mresourceinstance_stub::value = value; |
ram54288 | 0:dbad57390bd1 | 1569 | |
ram54288 | 0:dbad57390bd1 | 1570 | m2mresourceinstance_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1571 | |
ram54288 | 0:dbad57390bd1 | 1572 | nsdl->value_updated(resource,"name/0/name"); |
ram54288 | 0:dbad57390bd1 | 1573 | CHECK(observer->value_update == true); |
ram54288 | 0:dbad57390bd1 | 1574 | observer->value_update = false; |
ram54288 | 0:dbad57390bd1 | 1575 | |
ram54288 | 0:dbad57390bd1 | 1576 | m2mresourceinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1577 | free(common_stub::resource->static_resource_parameters->resource); |
ram54288 | 0:dbad57390bd1 | 1578 | free(common_stub::resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 1579 | free(common_stub::resource); |
ram54288 | 0:dbad57390bd1 | 1580 | common_stub::resource = NULL; |
ram54288 | 0:dbad57390bd1 | 1581 | common_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1582 | |
ram54288 | 0:dbad57390bd1 | 1583 | m2mresourceinstance_stub::base_type = M2MBase::ResourceInstance; |
ram54288 | 0:dbad57390bd1 | 1584 | |
ram54288 | 0:dbad57390bd1 | 1585 | common_stub::resource = (sn_nsdl_dynamic_resource_parameters_s*)malloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1586 | memset(common_stub::resource,0, sizeof(sn_nsdl_dynamic_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1587 | |
ram54288 | 0:dbad57390bd1 | 1588 | common_stub::resource->static_resource_parameters = |
ram54288 | 0:dbad57390bd1 | 1589 | (sn_nsdl_static_resource_parameters_s*)malloc(sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1590 | memset(common_stub::resource->static_resource_parameters,0, sizeof(sn_nsdl_static_resource_parameters_s)); |
ram54288 | 0:dbad57390bd1 | 1591 | |
ram54288 | 0:dbad57390bd1 | 1592 | common_stub::resource->static_resource_parameters->resource = (uint8_t*)malloc(2); |
ram54288 | 0:dbad57390bd1 | 1593 | memset(common_stub::resource->static_resource_parameters->resource,0, 2); |
ram54288 | 0:dbad57390bd1 | 1594 | |
ram54288 | 0:dbad57390bd1 | 1595 | common_stub::resource->static_resource_parameters->mode = SN_GRS_STATIC; |
ram54288 | 0:dbad57390bd1 | 1596 | m2mbase_stub::mode_value = M2MBase::Static; |
ram54288 | 0:dbad57390bd1 | 1597 | |
ram54288 | 0:dbad57390bd1 | 1598 | m2mresourceinstance_stub::int_value = 2; |
ram54288 | 0:dbad57390bd1 | 1599 | m2mresourceinstance_stub::value = value; |
ram54288 | 0:dbad57390bd1 | 1600 | |
ram54288 | 0:dbad57390bd1 | 1601 | nsdl->value_updated(resource_instance,"name/0/name/0"); |
ram54288 | 0:dbad57390bd1 | 1602 | CHECK(observer->value_update == true); |
ram54288 | 0:dbad57390bd1 | 1603 | observer->value_update = false; |
ram54288 | 0:dbad57390bd1 | 1604 | |
ram54288 | 0:dbad57390bd1 | 1605 | m2mbase_stub::is_value_updated_function_set = true; |
ram54288 | 0:dbad57390bd1 | 1606 | nsdl->value_updated(resource_instance,"name/0/name/0"); |
ram54288 | 0:dbad57390bd1 | 1607 | CHECK(observer->value_update == false); |
ram54288 | 0:dbad57390bd1 | 1608 | observer->value_update = false; |
ram54288 | 0:dbad57390bd1 | 1609 | |
ram54288 | 0:dbad57390bd1 | 1610 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1611 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1612 | |
ram54288 | 0:dbad57390bd1 | 1613 | m2mresourceinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1614 | |
ram54288 | 0:dbad57390bd1 | 1615 | free(common_stub::resource->static_resource_parameters->resource); |
ram54288 | 0:dbad57390bd1 | 1616 | free(common_stub::resource->static_resource_parameters); |
ram54288 | 0:dbad57390bd1 | 1617 | free(common_stub::resource); |
ram54288 | 0:dbad57390bd1 | 1618 | |
ram54288 | 0:dbad57390bd1 | 1619 | common_stub::resource = NULL; |
ram54288 | 0:dbad57390bd1 | 1620 | common_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1621 | |
ram54288 | 0:dbad57390bd1 | 1622 | delete resource_instance; |
ram54288 | 0:dbad57390bd1 | 1623 | delete resource; |
ram54288 | 0:dbad57390bd1 | 1624 | delete object_instance; |
ram54288 | 0:dbad57390bd1 | 1625 | delete object; |
ram54288 | 0:dbad57390bd1 | 1626 | } |
ram54288 | 0:dbad57390bd1 | 1627 | |
ram54288 | 0:dbad57390bd1 | 1628 | |
ram54288 | 0:dbad57390bd1 | 1629 | void Test_M2MNsdlInterface::test_find_resource() |
ram54288 | 0:dbad57390bd1 | 1630 | { |
ram54288 | 0:dbad57390bd1 | 1631 | m2mbase_stub::string_value = "name"; |
ram54288 | 0:dbad57390bd1 | 1632 | m2mbase_stub::object_instance_name = "name/0"; |
ram54288 | 0:dbad57390bd1 | 1633 | m2mbase_stub::resource_name_inst = "name/0/resource_name/0"; |
ram54288 | 0:dbad57390bd1 | 1634 | m2mbase_stub::resource_name = "name/0/resource_name"; |
ram54288 | 0:dbad57390bd1 | 1635 | m2mbase_stub::find_resource = true; |
ram54288 | 0:dbad57390bd1 | 1636 | uint8_t *token = (uint8_t*) malloc(4); |
ram54288 | 0:dbad57390bd1 | 1637 | token[0] = 't'; |
ram54288 | 0:dbad57390bd1 | 1638 | token[1] = 'o'; |
ram54288 | 0:dbad57390bd1 | 1639 | token[2] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1640 | token[3] = 'e'; |
ram54288 | 0:dbad57390bd1 | 1641 | m2mbase_stub::object_token = token; |
ram54288 | 0:dbad57390bd1 | 1642 | m2mbase_stub::object_token_len = 4; |
ram54288 | 0:dbad57390bd1 | 1643 | |
ram54288 | 0:dbad57390bd1 | 1644 | uint8_t *inst_token = (uint8_t*) malloc(4); |
ram54288 | 0:dbad57390bd1 | 1645 | inst_token[0] = 't'; |
ram54288 | 0:dbad57390bd1 | 1646 | inst_token[1] = 'o'; |
ram54288 | 0:dbad57390bd1 | 1647 | inst_token[2] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1648 | inst_token[3] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1649 | m2mbase_stub::object_inst_token = inst_token; |
ram54288 | 0:dbad57390bd1 | 1650 | m2mbase_stub::object_inst_token_len = 4; |
ram54288 | 0:dbad57390bd1 | 1651 | |
ram54288 | 0:dbad57390bd1 | 1652 | uint8_t *resource_token = (uint8_t*) malloc(4); |
ram54288 | 0:dbad57390bd1 | 1653 | resource_token[0] = 't'; |
ram54288 | 0:dbad57390bd1 | 1654 | resource_token[1] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1655 | resource_token[2] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1656 | resource_token[3] = 'k'; |
ram54288 | 0:dbad57390bd1 | 1657 | m2mbase_stub::resource_token = resource_token; |
ram54288 | 0:dbad57390bd1 | 1658 | m2mbase_stub::resource_token_len = 4; |
ram54288 | 0:dbad57390bd1 | 1659 | |
ram54288 | 0:dbad57390bd1 | 1660 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1661 | M2MObjectInstance *object_instance = new M2MObjectInstance(*object,"name/0", "","name/0"); |
ram54288 | 0:dbad57390bd1 | 1662 | M2MResource *resource = new M2MResource(*object_instance, |
ram54288 | 0:dbad57390bd1 | 1663 | "resource_name", |
ram54288 | 0:dbad57390bd1 | 1664 | "resource_type", |
ram54288 | 0:dbad57390bd1 | 1665 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1666 | false, |
ram54288 | 0:dbad57390bd1 | 1667 | "resource_name"); |
ram54288 | 0:dbad57390bd1 | 1668 | |
ram54288 | 0:dbad57390bd1 | 1669 | M2MResourceInstance *resource_instance = new M2MResourceInstance(*resource, |
ram54288 | 0:dbad57390bd1 | 1670 | "0", |
ram54288 | 0:dbad57390bd1 | 1671 | "resource_type", |
ram54288 | 0:dbad57390bd1 | 1672 | M2MResourceInstance::INTEGER,0,"0",false); |
ram54288 | 0:dbad57390bd1 | 1673 | |
ram54288 | 0:dbad57390bd1 | 1674 | m2mobjectinstance_stub::base_type = M2MBase::ObjectInstance; |
ram54288 | 0:dbad57390bd1 | 1675 | m2mobject_stub::instance_list.push_back(object_instance); |
ram54288 | 0:dbad57390bd1 | 1676 | m2mobjectinstance_stub::resource_list.push_back(resource); |
ram54288 | 0:dbad57390bd1 | 1677 | m2mresource_stub::list.push_back(resource_instance); |
ram54288 | 0:dbad57390bd1 | 1678 | m2mobject_stub::base_type = M2MBase::Object; |
ram54288 | 0:dbad57390bd1 | 1679 | nsdl->_object_list.push_back(object); |
ram54288 | 0:dbad57390bd1 | 1680 | m2mresource_stub::bool_value = true; |
ram54288 | 0:dbad57390bd1 | 1681 | CHECK(nsdl->find_resource("name") == object); |
ram54288 | 0:dbad57390bd1 | 1682 | CHECK(nsdl->find_resource("name1") == NULL); |
ram54288 | 0:dbad57390bd1 | 1683 | CHECK(nsdl->find_resource("name", token, 4) == object); |
ram54288 | 0:dbad57390bd1 | 1684 | CHECK(nsdl->find_resource("name", token, 5) == NULL); |
ram54288 | 0:dbad57390bd1 | 1685 | |
ram54288 | 0:dbad57390bd1 | 1686 | m2mbase_stub::ret_counter = 0; |
ram54288 | 0:dbad57390bd1 | 1687 | CHECK(nsdl->find_resource("name/0") == object_instance); |
ram54288 | 0:dbad57390bd1 | 1688 | m2mbase_stub::ret_counter = 0; |
ram54288 | 0:dbad57390bd1 | 1689 | CHECK(nsdl->find_resource("name/0", inst_token, 4) == object_instance); |
ram54288 | 0:dbad57390bd1 | 1690 | m2mbase_stub::ret_counter = 0; |
ram54288 | 0:dbad57390bd1 | 1691 | |
ram54288 | 0:dbad57390bd1 | 1692 | CHECK(nsdl->find_resource("name/0/resource_name") == resource); |
ram54288 | 0:dbad57390bd1 | 1693 | m2mbase_stub::ret_counter = 0; |
ram54288 | 0:dbad57390bd1 | 1694 | CHECK(nsdl->find_resource("name/0/resource_name", resource_token, 4) == resource); |
ram54288 | 0:dbad57390bd1 | 1695 | |
ram54288 | 0:dbad57390bd1 | 1696 | m2mbase_stub::ret_counter = 0; |
ram54288 | 0:dbad57390bd1 | 1697 | CHECK(nsdl->find_resource("name/0/resource_name/0") == resource_instance); |
ram54288 | 0:dbad57390bd1 | 1698 | |
ram54288 | 0:dbad57390bd1 | 1699 | free(token); |
ram54288 | 0:dbad57390bd1 | 1700 | free(inst_token); |
ram54288 | 0:dbad57390bd1 | 1701 | free(resource_token); |
ram54288 | 0:dbad57390bd1 | 1702 | |
ram54288 | 0:dbad57390bd1 | 1703 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1704 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1705 | |
ram54288 | 0:dbad57390bd1 | 1706 | m2mresourceinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1707 | m2mresource_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1708 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1709 | m2mobject_stub::clear(); |
ram54288 | 0:dbad57390bd1 | 1710 | |
ram54288 | 0:dbad57390bd1 | 1711 | delete resource_instance; |
ram54288 | 0:dbad57390bd1 | 1712 | delete resource; |
ram54288 | 0:dbad57390bd1 | 1713 | delete object_instance; |
ram54288 | 0:dbad57390bd1 | 1714 | delete object; |
ram54288 | 0:dbad57390bd1 | 1715 | } |
ram54288 | 0:dbad57390bd1 | 1716 | |
ram54288 | 0:dbad57390bd1 | 1717 | void Test_M2MNsdlInterface::test_remove_object() |
ram54288 | 0:dbad57390bd1 | 1718 | { |
ram54288 | 0:dbad57390bd1 | 1719 | M2MObject *obj = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1720 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 1721 | |
ram54288 | 0:dbad57390bd1 | 1722 | nsdl->remove_object((M2MBase*)obj); |
ram54288 | 0:dbad57390bd1 | 1723 | |
ram54288 | 0:dbad57390bd1 | 1724 | CHECK(nsdl->_object_list.empty() == true); |
ram54288 | 0:dbad57390bd1 | 1725 | |
ram54288 | 0:dbad57390bd1 | 1726 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1727 | delete obj; |
ram54288 | 0:dbad57390bd1 | 1728 | } |
ram54288 | 0:dbad57390bd1 | 1729 | |
ram54288 | 0:dbad57390bd1 | 1730 | void Test_M2MNsdlInterface::test_add_object_to_list() |
ram54288 | 0:dbad57390bd1 | 1731 | { |
ram54288 | 0:dbad57390bd1 | 1732 | M2MObject *obj = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1733 | nsdl->_object_list.push_back(obj); |
ram54288 | 0:dbad57390bd1 | 1734 | |
ram54288 | 0:dbad57390bd1 | 1735 | nsdl->add_object_to_list(obj); |
ram54288 | 0:dbad57390bd1 | 1736 | CHECK(nsdl->_object_list.size() == 1); |
ram54288 | 0:dbad57390bd1 | 1737 | |
ram54288 | 0:dbad57390bd1 | 1738 | nsdl->_object_list.clear(); |
ram54288 | 0:dbad57390bd1 | 1739 | delete obj; |
ram54288 | 0:dbad57390bd1 | 1740 | } |
ram54288 | 0:dbad57390bd1 | 1741 | |
ram54288 | 0:dbad57390bd1 | 1742 | void Test_M2MNsdlInterface::test_send_delayed_response() |
ram54288 | 0:dbad57390bd1 | 1743 | { |
ram54288 | 0:dbad57390bd1 | 1744 | common_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1745 | m2mbase_stub::int_value = 0; |
ram54288 | 0:dbad57390bd1 | 1746 | |
ram54288 | 0:dbad57390bd1 | 1747 | M2MObject *object = new M2MObject("name", "name"); |
ram54288 | 0:dbad57390bd1 | 1748 | M2MObjectInstance* instance = new M2MObjectInstance(*object, "name", "", ""); |
ram54288 | 0:dbad57390bd1 | 1749 | nsdl->_nsdl_handle = (nsdl_s*)malloc(sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 1750 | memset(nsdl->_nsdl_handle,0,sizeof(nsdl_s)); |
ram54288 | 0:dbad57390bd1 | 1751 | |
ram54288 | 0:dbad57390bd1 | 1752 | sn_nsdl_oma_server_info_t * nsp_address = (sn_nsdl_oma_server_info_t *)malloc(sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1753 | memset(nsp_address,0,sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1754 | sn_nsdl_addr_s* address = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1755 | memset(address,0,sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:dbad57390bd1 | 1756 | |
ram54288 | 0:dbad57390bd1 | 1757 | M2MResource* resource = new M2MResource(*instance, |
ram54288 | 0:dbad57390bd1 | 1758 | "name", |
ram54288 | 0:dbad57390bd1 | 1759 | "name", |
ram54288 | 0:dbad57390bd1 | 1760 | M2MResourceInstance::INTEGER, |
ram54288 | 0:dbad57390bd1 | 1761 | false, |
ram54288 | 0:dbad57390bd1 | 1762 | "name"); |
ram54288 | 0:dbad57390bd1 | 1763 | |
ram54288 | 0:dbad57390bd1 | 1764 | uint8_t val[] = {"name"}; |
ram54288 | 0:dbad57390bd1 | 1765 | m2mresource_stub::delayed_token = (uint8_t*)malloc(sizeof(val)); |
ram54288 | 0:dbad57390bd1 | 1766 | memcpy(m2mresource_stub::delayed_token,val,sizeof(val)); |
ram54288 | 0:dbad57390bd1 | 1767 | m2mresource_stub::delayed_token_len = sizeof(val); |
ram54288 | 0:dbad57390bd1 | 1768 | |
ram54288 | 0:dbad57390bd1 | 1769 | m2mresourceinstance_stub::base_type = M2MBase::Resource; |
ram54288 | 0:dbad57390bd1 | 1770 | |
ram54288 | 0:dbad57390bd1 | 1771 | nsdl->_nsdl_handle->nsp_address_ptr = nsp_address; |
ram54288 | 0:dbad57390bd1 | 1772 | memset(nsdl->_nsdl_handle->nsp_address_ptr,0,sizeof(sn_nsdl_oma_server_info_t)); |
ram54288 | 0:dbad57390bd1 | 1773 | nsdl->_nsdl_handle->nsp_address_ptr->omalw_address_ptr = address; |
ram54288 | 0:dbad57390bd1 | 1774 | |
ram54288 | 0:dbad57390bd1 | 1775 | nsdl->send_delayed_response(resource); |
ram54288 | 0:dbad57390bd1 | 1776 | |
ram54288 | 0:dbad57390bd1 | 1777 | free(nsp_address); |
ram54288 | 0:dbad57390bd1 | 1778 | free(address); |
ram54288 | 0:dbad57390bd1 | 1779 | free(nsdl->_nsdl_handle); |
ram54288 | 0:dbad57390bd1 | 1780 | |
ram54288 | 0:dbad57390bd1 | 1781 | delete object; |
ram54288 | 0:dbad57390bd1 | 1782 | delete instance; |
ram54288 | 0:dbad57390bd1 | 1783 | delete resource; |
ram54288 | 0:dbad57390bd1 | 1784 | free(m2mresource_stub::delayed_token); |
ram54288 | 0:dbad57390bd1 | 1785 | m2mresource_stub::delayed_token = NULL; |
ram54288 | 0:dbad57390bd1 | 1786 | m2mresource_stub::delayed_token_len = 0; |
ram54288 | 0:dbad57390bd1 | 1787 | } |
ram54288 | 0:dbad57390bd1 | 1788 | |
ram54288 | 0:dbad57390bd1 | 1789 | void Test_M2MNsdlInterface::test_get_nsdl_handle() |
ram54288 | 0:dbad57390bd1 | 1790 | { |
ram54288 | 0:dbad57390bd1 | 1791 | CHECK(nsdl->get_nsdl_handle() == nsdl->_nsdl_handle); |
ram54288 | 0:dbad57390bd1 | 1792 | } |
ram54288 | 0:dbad57390bd1 | 1793 | |
ram54288 | 0:dbad57390bd1 | 1794 | void Test_M2MNsdlInterface::test_endpoint_name() |
ram54288 | 0:dbad57390bd1 | 1795 | { |
ram54288 | 0:dbad57390bd1 | 1796 | String endpoint = "test"; |
ram54288 | 0:dbad57390bd1 | 1797 | nsdl->_endpoint_name = endpoint; |
ram54288 | 0:dbad57390bd1 | 1798 | CHECK(nsdl->endpoint_name() == endpoint); |
ram54288 | 0:dbad57390bd1 | 1799 | } |