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