Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/m2minterfaceimpl/test_m2minterfaceimpl.cpp@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | #include "CppUTest/TestHarness.h" |
ram54288 | 0:a7a43371b306 | 17 | #include "test_m2minterfaceimpl.h" |
ram54288 | 0:a7a43371b306 | 18 | #include "m2minterfaceobserver.h" |
ram54288 | 0:a7a43371b306 | 19 | #include "m2mconnectionhandler_stub.h" |
ram54288 | 0:a7a43371b306 | 20 | #include "m2msecurity_stub.h" |
ram54288 | 0:a7a43371b306 | 21 | #include "m2mnsdlinterface_stub.h" |
ram54288 | 0:a7a43371b306 | 22 | #include "m2mobject_stub.h" |
ram54288 | 0:a7a43371b306 | 23 | #include "m2mobjectinstance_stub.h" |
ram54288 | 0:a7a43371b306 | 24 | #include "m2mbase.h" |
ram54288 | 0:a7a43371b306 | 25 | |
ram54288 | 0:a7a43371b306 | 26 | entropy_cb ent_cb; |
ram54288 | 0:a7a43371b306 | 27 | |
ram54288 | 0:a7a43371b306 | 28 | class TestObserver : public M2MInterfaceObserver { |
ram54288 | 0:a7a43371b306 | 29 | |
ram54288 | 0:a7a43371b306 | 30 | public: |
ram54288 | 0:a7a43371b306 | 31 | TestObserver() : val_updated(false), error_occured(false), |
ram54288 | 0:a7a43371b306 | 32 | registered(false), unregistered(false), bootstrapped(false) |
ram54288 | 0:a7a43371b306 | 33 | { |
ram54288 | 0:a7a43371b306 | 34 | } |
ram54288 | 0:a7a43371b306 | 35 | |
ram54288 | 0:a7a43371b306 | 36 | virtual ~TestObserver(){} |
ram54288 | 0:a7a43371b306 | 37 | void bootstrap_done(M2MSecurity */*server_object*/){ |
ram54288 | 0:a7a43371b306 | 38 | bootstrapped = true; |
ram54288 | 0:a7a43371b306 | 39 | } |
ram54288 | 0:a7a43371b306 | 40 | |
ram54288 | 0:a7a43371b306 | 41 | void object_registered(M2MSecurity */*security_object*/, |
ram54288 | 0:a7a43371b306 | 42 | const M2MServer &/*server_object*/) { |
ram54288 | 0:a7a43371b306 | 43 | registered = true; |
ram54288 | 0:a7a43371b306 | 44 | } |
ram54288 | 0:a7a43371b306 | 45 | |
ram54288 | 0:a7a43371b306 | 46 | void object_unregistered(M2MSecurity */*server_object*/){ |
ram54288 | 0:a7a43371b306 | 47 | unregistered = true; |
ram54288 | 0:a7a43371b306 | 48 | } |
ram54288 | 0:a7a43371b306 | 49 | |
ram54288 | 0:a7a43371b306 | 50 | void registration_updated(M2MSecurity */*security_object*/, |
ram54288 | 0:a7a43371b306 | 51 | const M2MServer &/*server_object*/){ |
ram54288 | 0:a7a43371b306 | 52 | registered = true; |
ram54288 | 0:a7a43371b306 | 53 | } |
ram54288 | 0:a7a43371b306 | 54 | |
ram54288 | 0:a7a43371b306 | 55 | void error(M2MInterface::Error /*error*/){ |
ram54288 | 0:a7a43371b306 | 56 | error_occured = true; |
ram54288 | 0:a7a43371b306 | 57 | } |
ram54288 | 0:a7a43371b306 | 58 | |
ram54288 | 0:a7a43371b306 | 59 | void value_updated(M2MBase *, M2MBase::BaseType ){ |
ram54288 | 0:a7a43371b306 | 60 | val_updated = true; |
ram54288 | 0:a7a43371b306 | 61 | } |
ram54288 | 0:a7a43371b306 | 62 | |
ram54288 | 0:a7a43371b306 | 63 | bool val_updated; |
ram54288 | 0:a7a43371b306 | 64 | bool error_occured; |
ram54288 | 0:a7a43371b306 | 65 | bool registered; |
ram54288 | 0:a7a43371b306 | 66 | bool unregistered; |
ram54288 | 0:a7a43371b306 | 67 | bool bootstrapped; |
ram54288 | 0:a7a43371b306 | 68 | }; |
ram54288 | 0:a7a43371b306 | 69 | |
ram54288 | 0:a7a43371b306 | 70 | class M2MBaseTest : public M2MBase |
ram54288 | 0:a7a43371b306 | 71 | { |
ram54288 | 0:a7a43371b306 | 72 | public: |
ram54288 | 0:a7a43371b306 | 73 | M2MBaseTest() : M2MBase("a", M2MBase::Static, "type","a",false){} |
ram54288 | 0:a7a43371b306 | 74 | }; |
ram54288 | 0:a7a43371b306 | 75 | |
ram54288 | 0:a7a43371b306 | 76 | Test_M2MInterfaceImpl::Test_M2MInterfaceImpl() |
ram54288 | 0:a7a43371b306 | 77 | { |
ram54288 | 0:a7a43371b306 | 78 | observer = new TestObserver(); |
ram54288 | 0:a7a43371b306 | 79 | impl = new M2MInterfaceImpl(*observer, |
ram54288 | 0:a7a43371b306 | 80 | "endpoint_name", |
ram54288 | 0:a7a43371b306 | 81 | "endpoint_type", |
ram54288 | 0:a7a43371b306 | 82 | 120, |
ram54288 | 0:a7a43371b306 | 83 | 8000, |
ram54288 | 0:a7a43371b306 | 84 | "domain"); |
ram54288 | 0:a7a43371b306 | 85 | } |
ram54288 | 0:a7a43371b306 | 86 | |
ram54288 | 0:a7a43371b306 | 87 | Test_M2MInterfaceImpl:: ~Test_M2MInterfaceImpl() |
ram54288 | 0:a7a43371b306 | 88 | { |
ram54288 | 0:a7a43371b306 | 89 | delete observer; |
ram54288 | 0:a7a43371b306 | 90 | delete impl; |
ram54288 | 0:a7a43371b306 | 91 | } |
ram54288 | 0:a7a43371b306 | 92 | |
ram54288 | 0:a7a43371b306 | 93 | void Test_M2MInterfaceImpl::test_constructor() |
ram54288 | 0:a7a43371b306 | 94 | { |
ram54288 | 0:a7a43371b306 | 95 | TestObserver obs; |
ram54288 | 0:a7a43371b306 | 96 | |
ram54288 | 0:a7a43371b306 | 97 | M2MInterfaceImpl* obj = new M2MInterfaceImpl(obs, |
ram54288 | 0:a7a43371b306 | 98 | "endpoint_name", |
ram54288 | 0:a7a43371b306 | 99 | "endpoint_type", |
ram54288 | 0:a7a43371b306 | 100 | 120, |
ram54288 | 0:a7a43371b306 | 101 | 8000, |
ram54288 | 0:a7a43371b306 | 102 | "domain", |
ram54288 | 0:a7a43371b306 | 103 | M2MInterface::TCP); |
ram54288 | 0:a7a43371b306 | 104 | CHECK(obj->_current_state == 0); |
ram54288 | 0:a7a43371b306 | 105 | //TODO: Check rest of variables |
ram54288 | 0:a7a43371b306 | 106 | delete obj; |
ram54288 | 0:a7a43371b306 | 107 | obj = new M2MInterfaceImpl(obs, |
ram54288 | 0:a7a43371b306 | 108 | "endpoint_name", |
ram54288 | 0:a7a43371b306 | 109 | "endpoint_type", |
ram54288 | 0:a7a43371b306 | 110 | 120, |
ram54288 | 0:a7a43371b306 | 111 | 8000, |
ram54288 | 0:a7a43371b306 | 112 | "domain", |
ram54288 | 0:a7a43371b306 | 113 | M2MInterface::TCP_QUEUE); |
ram54288 | 0:a7a43371b306 | 114 | delete obj; |
ram54288 | 0:a7a43371b306 | 115 | } |
ram54288 | 0:a7a43371b306 | 116 | |
ram54288 | 0:a7a43371b306 | 117 | void Test_M2MInterfaceImpl::test_bootstrap() |
ram54288 | 0:a7a43371b306 | 118 | { |
ram54288 | 0:a7a43371b306 | 119 | M2MSecurity *sec = new M2MSecurity(M2MSecurity::Bootstrap); |
ram54288 | 0:a7a43371b306 | 120 | m2msecurity_stub::int_value = 2; |
ram54288 | 0:a7a43371b306 | 121 | String *val = new String("coaps://[2001:12:12:23::23:FF]:5685"); |
ram54288 | 0:a7a43371b306 | 122 | |
ram54288 | 0:a7a43371b306 | 123 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 124 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 125 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 126 | |
ram54288 | 0:a7a43371b306 | 127 | |
ram54288 | 0:a7a43371b306 | 128 | impl->bootstrap(NULL); |
ram54288 | 0:a7a43371b306 | 129 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 130 | |
ram54288 | 0:a7a43371b306 | 131 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 132 | |
ram54288 | 0:a7a43371b306 | 133 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 134 | |
ram54288 | 0:a7a43371b306 | 135 | delete val; |
ram54288 | 0:a7a43371b306 | 136 | |
ram54288 | 0:a7a43371b306 | 137 | val = new String("coaps://[10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 138 | |
ram54288 | 0:a7a43371b306 | 139 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 140 | |
ram54288 | 0:a7a43371b306 | 141 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 142 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 143 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 144 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 145 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 146 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 147 | |
ram54288 | 0:a7a43371b306 | 148 | delete val; |
ram54288 | 0:a7a43371b306 | 149 | |
ram54288 | 0:a7a43371b306 | 150 | val = new String("coaps://10.45.3.83]:5685"); |
ram54288 | 0:a7a43371b306 | 151 | |
ram54288 | 0:a7a43371b306 | 152 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 153 | |
ram54288 | 0:a7a43371b306 | 154 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 155 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 156 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 157 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 158 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 159 | |
ram54288 | 0:a7a43371b306 | 160 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 161 | |
ram54288 | 0:a7a43371b306 | 162 | delete val; |
ram54288 | 0:a7a43371b306 | 163 | |
ram54288 | 0:a7a43371b306 | 164 | val = new String("coap://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 165 | |
ram54288 | 0:a7a43371b306 | 166 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 167 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 168 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 169 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 170 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 171 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 172 | |
ram54288 | 0:a7a43371b306 | 173 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 174 | |
ram54288 | 0:a7a43371b306 | 175 | delete val; |
ram54288 | 0:a7a43371b306 | 176 | |
ram54288 | 0:a7a43371b306 | 177 | val = new String("coap://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 178 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 179 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 180 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 181 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 182 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 183 | |
ram54288 | 0:a7a43371b306 | 184 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 185 | |
ram54288 | 0:a7a43371b306 | 186 | delete val; |
ram54288 | 0:a7a43371b306 | 187 | |
ram54288 | 0:a7a43371b306 | 188 | val = new String("coap://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 189 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 190 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 191 | |
ram54288 | 0:a7a43371b306 | 192 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 193 | |
ram54288 | 0:a7a43371b306 | 194 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 195 | |
ram54288 | 0:a7a43371b306 | 196 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 197 | m2mconnectionhandler_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 198 | |
ram54288 | 0:a7a43371b306 | 199 | // Ignore the event. |
ram54288 | 0:a7a43371b306 | 200 | impl->_current_state = M2MInterfaceImpl::STATE_WAITING; |
ram54288 | 0:a7a43371b306 | 201 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 202 | |
ram54288 | 0:a7a43371b306 | 203 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 204 | |
ram54288 | 0:a7a43371b306 | 205 | impl->bootstrap(sec); |
ram54288 | 0:a7a43371b306 | 206 | |
ram54288 | 0:a7a43371b306 | 207 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 208 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 209 | |
ram54288 | 0:a7a43371b306 | 210 | delete val; |
ram54288 | 0:a7a43371b306 | 211 | val = NULL; |
ram54288 | 0:a7a43371b306 | 212 | |
ram54288 | 0:a7a43371b306 | 213 | delete sec; |
ram54288 | 0:a7a43371b306 | 214 | } |
ram54288 | 0:a7a43371b306 | 215 | |
ram54288 | 0:a7a43371b306 | 216 | void Test_M2MInterfaceImpl::test_cancel_bootstrap() |
ram54288 | 0:a7a43371b306 | 217 | { |
ram54288 | 0:a7a43371b306 | 218 | // Check for coverage, currently no implementation |
ram54288 | 0:a7a43371b306 | 219 | impl->cancel_bootstrap(); |
ram54288 | 0:a7a43371b306 | 220 | } |
ram54288 | 0:a7a43371b306 | 221 | |
ram54288 | 0:a7a43371b306 | 222 | void Test_M2MInterfaceImpl::test_register_object() |
ram54288 | 0:a7a43371b306 | 223 | { |
ram54288 | 0:a7a43371b306 | 224 | M2MSecurity *sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 225 | m2msecurity_stub::int_value = 2; |
ram54288 | 0:a7a43371b306 | 226 | |
ram54288 | 0:a7a43371b306 | 227 | M2MObject *object = new M2MObject("test", "test"); |
ram54288 | 0:a7a43371b306 | 228 | M2MObjectInstance *ins = object->create_object_instance(); |
ram54288 | 0:a7a43371b306 | 229 | ins->create_dynamic_resource("test","type",M2MResourceInstance::STRING,false,false); |
ram54288 | 0:a7a43371b306 | 230 | |
ram54288 | 0:a7a43371b306 | 231 | M2MObjectList list; |
ram54288 | 0:a7a43371b306 | 232 | list.push_back(object); |
ram54288 | 0:a7a43371b306 | 233 | |
ram54288 | 0:a7a43371b306 | 234 | String *val = new String("coaps://[2001:12:12:23::23:FF]:5685"); |
ram54288 | 0:a7a43371b306 | 235 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 236 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 237 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 238 | |
ram54288 | 0:a7a43371b306 | 239 | impl->register_object(NULL,list); |
ram54288 | 0:a7a43371b306 | 240 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 241 | |
ram54288 | 0:a7a43371b306 | 242 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 243 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER); |
ram54288 | 0:a7a43371b306 | 244 | |
ram54288 | 0:a7a43371b306 | 245 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 246 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 247 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER); |
ram54288 | 0:a7a43371b306 | 248 | |
ram54288 | 0:a7a43371b306 | 249 | delete val; |
ram54288 | 0:a7a43371b306 | 250 | val = new String("coaps://[10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 251 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 252 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 253 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 254 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 255 | |
ram54288 | 0:a7a43371b306 | 256 | delete impl->_security; |
ram54288 | 0:a7a43371b306 | 257 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 258 | sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 259 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 260 | |
ram54288 | 0:a7a43371b306 | 261 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 262 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 263 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 264 | delete val; |
ram54288 | 0:a7a43371b306 | 265 | val = new String("coaps://10.45.3.83]:5685"); |
ram54288 | 0:a7a43371b306 | 266 | |
ram54288 | 0:a7a43371b306 | 267 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 268 | |
ram54288 | 0:a7a43371b306 | 269 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 270 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 271 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 272 | |
ram54288 | 0:a7a43371b306 | 273 | delete impl->_security; |
ram54288 | 0:a7a43371b306 | 274 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 275 | sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 276 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 277 | |
ram54288 | 0:a7a43371b306 | 278 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 279 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 280 | |
ram54288 | 0:a7a43371b306 | 281 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 282 | delete val; |
ram54288 | 0:a7a43371b306 | 283 | val = new String("coaps://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 284 | delete impl->_security; |
ram54288 | 0:a7a43371b306 | 285 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 286 | sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 287 | |
ram54288 | 0:a7a43371b306 | 288 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 289 | |
ram54288 | 0:a7a43371b306 | 290 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 291 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 292 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 293 | |
ram54288 | 0:a7a43371b306 | 294 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 295 | |
ram54288 | 0:a7a43371b306 | 296 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER); |
ram54288 | 0:a7a43371b306 | 297 | |
ram54288 | 0:a7a43371b306 | 298 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 299 | delete val; |
ram54288 | 0:a7a43371b306 | 300 | val = new String("coap://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 301 | delete impl->_security; |
ram54288 | 0:a7a43371b306 | 302 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 303 | sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 304 | |
ram54288 | 0:a7a43371b306 | 305 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 306 | |
ram54288 | 0:a7a43371b306 | 307 | m2msecurity_stub::string_value = val; |
ram54288 | 0:a7a43371b306 | 308 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 309 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 310 | |
ram54288 | 0:a7a43371b306 | 311 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 312 | |
ram54288 | 0:a7a43371b306 | 313 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER); |
ram54288 | 0:a7a43371b306 | 314 | |
ram54288 | 0:a7a43371b306 | 315 | delete val; |
ram54288 | 0:a7a43371b306 | 316 | val = new String("coap://10.45.3.83:5685"); |
ram54288 | 0:a7a43371b306 | 317 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 318 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER); |
ram54288 | 0:a7a43371b306 | 319 | |
ram54288 | 0:a7a43371b306 | 320 | |
ram54288 | 0:a7a43371b306 | 321 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 322 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 323 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 324 | |
ram54288 | 0:a7a43371b306 | 325 | delete impl->_security; |
ram54288 | 0:a7a43371b306 | 326 | impl->_security = NULL; |
ram54288 | 0:a7a43371b306 | 327 | sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 328 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 329 | |
ram54288 | 0:a7a43371b306 | 330 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 331 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 332 | |
ram54288 | 0:a7a43371b306 | 333 | impl->_current_state = M2MInterfaceImpl::STATE_BOOTSTRAP; |
ram54288 | 0:a7a43371b306 | 334 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 335 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 336 | |
ram54288 | 0:a7a43371b306 | 337 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 338 | |
ram54288 | 0:a7a43371b306 | 339 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 340 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 341 | |
ram54288 | 0:a7a43371b306 | 342 | impl->_current_state = M2MInterfaceImpl::STATE_BOOTSTRAP; |
ram54288 | 0:a7a43371b306 | 343 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 344 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 345 | |
ram54288 | 0:a7a43371b306 | 346 | impl->register_object(sec,list); |
ram54288 | 0:a7a43371b306 | 347 | |
ram54288 | 0:a7a43371b306 | 348 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 349 | |
ram54288 | 0:a7a43371b306 | 350 | |
ram54288 | 0:a7a43371b306 | 351 | delete val; |
ram54288 | 0:a7a43371b306 | 352 | val = NULL; |
ram54288 | 0:a7a43371b306 | 353 | |
ram54288 | 0:a7a43371b306 | 354 | list.clear(); |
ram54288 | 0:a7a43371b306 | 355 | delete object; |
ram54288 | 0:a7a43371b306 | 356 | delete sec; |
ram54288 | 0:a7a43371b306 | 357 | } |
ram54288 | 0:a7a43371b306 | 358 | |
ram54288 | 0:a7a43371b306 | 359 | void Test_M2MInterfaceImpl::test_update_registration() |
ram54288 | 0:a7a43371b306 | 360 | { |
ram54288 | 0:a7a43371b306 | 361 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 362 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 363 | impl->update_registration(NULL,120); |
ram54288 | 0:a7a43371b306 | 364 | |
ram54288 | 0:a7a43371b306 | 365 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_UPDATE_REGISTRATION); |
ram54288 | 0:a7a43371b306 | 366 | |
ram54288 | 0:a7a43371b306 | 367 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 368 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 369 | impl->update_registration(NULL,120); |
ram54288 | 0:a7a43371b306 | 370 | |
ram54288 | 0:a7a43371b306 | 371 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_UPDATE_REGISTRATION); |
ram54288 | 0:a7a43371b306 | 372 | |
ram54288 | 0:a7a43371b306 | 373 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 374 | impl->update_registration(NULL,120); |
ram54288 | 0:a7a43371b306 | 375 | |
ram54288 | 0:a7a43371b306 | 376 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 377 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 378 | |
ram54288 | 0:a7a43371b306 | 379 | impl->_current_state = M2MInterfaceImpl::STATE_BOOTSTRAP; |
ram54288 | 0:a7a43371b306 | 380 | impl->update_registration(NULL,120); |
ram54288 | 0:a7a43371b306 | 381 | |
ram54288 | 0:a7a43371b306 | 382 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP); |
ram54288 | 0:a7a43371b306 | 383 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 384 | |
ram54288 | 0:a7a43371b306 | 385 | impl->update_registration(NULL,30); |
ram54288 | 0:a7a43371b306 | 386 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 387 | |
ram54288 | 0:a7a43371b306 | 388 | impl->update_registration(NULL,120); |
ram54288 | 0:a7a43371b306 | 389 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 390 | |
ram54288 | 0:a7a43371b306 | 391 | |
ram54288 | 0:a7a43371b306 | 392 | M2MObject *object = new M2MObject("test", "test"); |
ram54288 | 0:a7a43371b306 | 393 | M2MObjectInstance *ins = object->create_object_instance(); |
ram54288 | 0:a7a43371b306 | 394 | ins->create_dynamic_resource("test","type",M2MResourceInstance::STRING,false,false); |
ram54288 | 0:a7a43371b306 | 395 | |
ram54288 | 0:a7a43371b306 | 396 | M2MObjectList list; |
ram54288 | 0:a7a43371b306 | 397 | list.push_back(object); |
ram54288 | 0:a7a43371b306 | 398 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 399 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 400 | impl->update_registration(NULL, list); |
ram54288 | 0:a7a43371b306 | 401 | |
ram54288 | 0:a7a43371b306 | 402 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_UPDATE_REGISTRATION); |
ram54288 | 0:a7a43371b306 | 403 | list.clear(); |
ram54288 | 0:a7a43371b306 | 404 | |
ram54288 | 0:a7a43371b306 | 405 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 406 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 407 | impl->update_registration(NULL, list); |
ram54288 | 0:a7a43371b306 | 408 | |
ram54288 | 0:a7a43371b306 | 409 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_UPDATE_REGISTRATION); |
ram54288 | 0:a7a43371b306 | 410 | delete object; |
ram54288 | 0:a7a43371b306 | 411 | |
ram54288 | 0:a7a43371b306 | 412 | } |
ram54288 | 0:a7a43371b306 | 413 | |
ram54288 | 0:a7a43371b306 | 414 | void Test_M2MInterfaceImpl::test_unregister_object() |
ram54288 | 0:a7a43371b306 | 415 | { |
ram54288 | 0:a7a43371b306 | 416 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 417 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 418 | |
ram54288 | 0:a7a43371b306 | 419 | impl->unregister_object(NULL); |
ram54288 | 0:a7a43371b306 | 420 | |
ram54288 | 0:a7a43371b306 | 421 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 422 | |
ram54288 | 0:a7a43371b306 | 423 | impl->_current_state = M2MInterfaceImpl::STATE_REGISTERED; |
ram54288 | 0:a7a43371b306 | 424 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 425 | |
ram54288 | 0:a7a43371b306 | 426 | impl->unregister_object(NULL); |
ram54288 | 0:a7a43371b306 | 427 | |
ram54288 | 0:a7a43371b306 | 428 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 429 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 430 | |
ram54288 | 0:a7a43371b306 | 431 | impl->_current_state = M2MInterfaceImpl::STATE_IDLE; |
ram54288 | 0:a7a43371b306 | 432 | |
ram54288 | 0:a7a43371b306 | 433 | impl->unregister_object(NULL); |
ram54288 | 0:a7a43371b306 | 434 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 435 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 436 | } |
ram54288 | 0:a7a43371b306 | 437 | |
ram54288 | 0:a7a43371b306 | 438 | void Test_M2MInterfaceImpl::test_set_queue_sleep_handler() |
ram54288 | 0:a7a43371b306 | 439 | { |
ram54288 | 0:a7a43371b306 | 440 | callback_handler cb(this,&Test_M2MInterfaceImpl::test_callback_handler); |
ram54288 | 0:a7a43371b306 | 441 | impl->set_queue_sleep_handler(cb); |
ram54288 | 0:a7a43371b306 | 442 | CHECK(impl->_callback_handler != NULL); |
ram54288 | 0:a7a43371b306 | 443 | |
ram54288 | 0:a7a43371b306 | 444 | callback_handler cb1(NULL); |
ram54288 | 0:a7a43371b306 | 445 | impl->set_queue_sleep_handler(cb1); |
ram54288 | 0:a7a43371b306 | 446 | CHECK(impl->_callback_handler == NULL); |
ram54288 | 0:a7a43371b306 | 447 | } |
ram54288 | 0:a7a43371b306 | 448 | |
ram54288 | 0:a7a43371b306 | 449 | |
ram54288 | 0:a7a43371b306 | 450 | void Test_M2MInterfaceImpl::test_set_random_number_callback() |
ram54288 | 0:a7a43371b306 | 451 | { |
ram54288 | 0:a7a43371b306 | 452 | random_number_cb cb(&test_random_callback); |
ram54288 | 0:a7a43371b306 | 453 | impl->set_random_number_callback(cb); |
ram54288 | 0:a7a43371b306 | 454 | } |
ram54288 | 0:a7a43371b306 | 455 | |
ram54288 | 0:a7a43371b306 | 456 | void Test_M2MInterfaceImpl::test_set_entropy_callback() |
ram54288 | 0:a7a43371b306 | 457 | { |
ram54288 | 0:a7a43371b306 | 458 | impl->set_entropy_callback(ent_cb); |
ram54288 | 0:a7a43371b306 | 459 | } |
ram54288 | 0:a7a43371b306 | 460 | |
ram54288 | 0:a7a43371b306 | 461 | void Test_M2MInterfaceImpl::test_set_platform_network_handler() |
ram54288 | 0:a7a43371b306 | 462 | { |
ram54288 | 0:a7a43371b306 | 463 | void *test = NULL; |
ram54288 | 0:a7a43371b306 | 464 | impl->set_platform_network_handler(test); |
ram54288 | 0:a7a43371b306 | 465 | } |
ram54288 | 0:a7a43371b306 | 466 | |
ram54288 | 0:a7a43371b306 | 467 | void Test_M2MInterfaceImpl::test_coap_message_ready() |
ram54288 | 0:a7a43371b306 | 468 | { |
ram54288 | 0:a7a43371b306 | 469 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 470 | uint8_t *data_ptr = (uint8_t *)malloc(sizeof(uint8_t)); |
ram54288 | 0:a7a43371b306 | 471 | uint16_t data_len = sizeof(uint8_t); |
ram54288 | 0:a7a43371b306 | 472 | sn_nsdl_addr_s *address_ptr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); |
ram54288 | 0:a7a43371b306 | 473 | |
ram54288 | 0:a7a43371b306 | 474 | impl->coap_message_ready(data_ptr,data_len,address_ptr); |
ram54288 | 0:a7a43371b306 | 475 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 476 | |
ram54288 | 0:a7a43371b306 | 477 | impl->_current_state = M2MInterfaceImpl::STATE_WAITING; |
ram54288 | 0:a7a43371b306 | 478 | impl->coap_message_ready(data_ptr,data_len,address_ptr); |
ram54288 | 0:a7a43371b306 | 479 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 480 | |
ram54288 | 0:a7a43371b306 | 481 | m2mconnectionhandler_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 482 | impl->coap_message_ready(data_ptr,data_len,address_ptr); |
ram54288 | 0:a7a43371b306 | 483 | |
ram54288 | 0:a7a43371b306 | 484 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 485 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 486 | |
ram54288 | 0:a7a43371b306 | 487 | free(address_ptr); |
ram54288 | 0:a7a43371b306 | 488 | free(data_ptr); |
ram54288 | 0:a7a43371b306 | 489 | } |
ram54288 | 0:a7a43371b306 | 490 | |
ram54288 | 0:a7a43371b306 | 491 | void Test_M2MInterfaceImpl::test_client_registered() |
ram54288 | 0:a7a43371b306 | 492 | { |
ram54288 | 0:a7a43371b306 | 493 | impl->client_registered(NULL); |
ram54288 | 0:a7a43371b306 | 494 | |
ram54288 | 0:a7a43371b306 | 495 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTERED); |
ram54288 | 0:a7a43371b306 | 496 | CHECK(observer->registered == true); |
ram54288 | 0:a7a43371b306 | 497 | } |
ram54288 | 0:a7a43371b306 | 498 | |
ram54288 | 0:a7a43371b306 | 499 | void Test_M2MInterfaceImpl::test_registration_updated() |
ram54288 | 0:a7a43371b306 | 500 | { |
ram54288 | 0:a7a43371b306 | 501 | M2MServer *server = NULL; |
ram54288 | 0:a7a43371b306 | 502 | impl->registration_updated(*server); |
ram54288 | 0:a7a43371b306 | 503 | |
ram54288 | 0:a7a43371b306 | 504 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTERED); |
ram54288 | 0:a7a43371b306 | 505 | CHECK(observer->registered == true); |
ram54288 | 0:a7a43371b306 | 506 | } |
ram54288 | 0:a7a43371b306 | 507 | |
ram54288 | 0:a7a43371b306 | 508 | void Test_M2MInterfaceImpl::test_registration_error() |
ram54288 | 0:a7a43371b306 | 509 | { |
ram54288 | 0:a7a43371b306 | 510 | impl->registration_error(1); |
ram54288 | 0:a7a43371b306 | 511 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 512 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 513 | |
ram54288 | 0:a7a43371b306 | 514 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 515 | impl->registration_error(1, true); |
ram54288 | 0:a7a43371b306 | 516 | CHECK(observer->error_occured == false); |
ram54288 | 0:a7a43371b306 | 517 | } |
ram54288 | 0:a7a43371b306 | 518 | |
ram54288 | 0:a7a43371b306 | 519 | void Test_M2MInterfaceImpl::test_client_unregistered() |
ram54288 | 0:a7a43371b306 | 520 | { |
ram54288 | 0:a7a43371b306 | 521 | impl->client_unregistered(); |
ram54288 | 0:a7a43371b306 | 522 | |
ram54288 | 0:a7a43371b306 | 523 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 524 | CHECK(observer->unregistered == true); |
ram54288 | 0:a7a43371b306 | 525 | } |
ram54288 | 0:a7a43371b306 | 526 | |
ram54288 | 0:a7a43371b306 | 527 | void Test_M2MInterfaceImpl::test_bootstrap_wait() |
ram54288 | 0:a7a43371b306 | 528 | { |
ram54288 | 0:a7a43371b306 | 529 | M2MSecurity *sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 530 | impl->bootstrap_wait(sec); |
ram54288 | 0:a7a43371b306 | 531 | |
ram54288 | 0:a7a43371b306 | 532 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP_WAIT); |
ram54288 | 0:a7a43371b306 | 533 | CHECK(impl->_security == sec); |
ram54288 | 0:a7a43371b306 | 534 | CHECK(observer->bootstrapped == false); |
ram54288 | 0:a7a43371b306 | 535 | |
ram54288 | 0:a7a43371b306 | 536 | delete sec; |
ram54288 | 0:a7a43371b306 | 537 | } |
ram54288 | 0:a7a43371b306 | 538 | |
ram54288 | 0:a7a43371b306 | 539 | |
ram54288 | 0:a7a43371b306 | 540 | void Test_M2MInterfaceImpl::test_bootstrap_done() |
ram54288 | 0:a7a43371b306 | 541 | { |
ram54288 | 0:a7a43371b306 | 542 | M2MSecurity *sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a7a43371b306 | 543 | impl->bootstrap_done(sec); |
ram54288 | 0:a7a43371b306 | 544 | |
ram54288 | 0:a7a43371b306 | 545 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAPPED); |
ram54288 | 0:a7a43371b306 | 546 | CHECK(observer->bootstrapped == true); |
ram54288 | 0:a7a43371b306 | 547 | |
ram54288 | 0:a7a43371b306 | 548 | delete sec; |
ram54288 | 0:a7a43371b306 | 549 | } |
ram54288 | 0:a7a43371b306 | 550 | |
ram54288 | 0:a7a43371b306 | 551 | void Test_M2MInterfaceImpl::test_bootstrap_error() |
ram54288 | 0:a7a43371b306 | 552 | { |
ram54288 | 0:a7a43371b306 | 553 | impl->bootstrap_error(); |
ram54288 | 0:a7a43371b306 | 554 | |
ram54288 | 0:a7a43371b306 | 555 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 556 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 557 | } |
ram54288 | 0:a7a43371b306 | 558 | |
ram54288 | 0:a7a43371b306 | 559 | void Test_M2MInterfaceImpl::test_coap_data_processed() |
ram54288 | 0:a7a43371b306 | 560 | { |
ram54288 | 0:a7a43371b306 | 561 | impl->coap_data_processed(); |
ram54288 | 0:a7a43371b306 | 562 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 563 | } |
ram54288 | 0:a7a43371b306 | 564 | |
ram54288 | 0:a7a43371b306 | 565 | void Test_M2MInterfaceImpl::test_value_updated() |
ram54288 | 0:a7a43371b306 | 566 | { |
ram54288 | 0:a7a43371b306 | 567 | impl->value_updated(NULL); |
ram54288 | 0:a7a43371b306 | 568 | CHECK(observer->val_updated == false); |
ram54288 | 0:a7a43371b306 | 569 | |
ram54288 | 0:a7a43371b306 | 570 | M2MBaseTest b; |
ram54288 | 0:a7a43371b306 | 571 | impl->value_updated(&b); |
ram54288 | 0:a7a43371b306 | 572 | CHECK(observer->val_updated == true); |
ram54288 | 0:a7a43371b306 | 573 | } |
ram54288 | 0:a7a43371b306 | 574 | |
ram54288 | 0:a7a43371b306 | 575 | void Test_M2MInterfaceImpl::test_data_available() |
ram54288 | 0:a7a43371b306 | 576 | { |
ram54288 | 0:a7a43371b306 | 577 | uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t)); |
ram54288 | 0:a7a43371b306 | 578 | uint16_t data_size = sizeof(uint8_t); |
ram54288 | 0:a7a43371b306 | 579 | M2MConnectionObserver::SocketAddress *address = (M2MConnectionObserver::SocketAddress*) |
ram54288 | 0:a7a43371b306 | 580 | malloc(sizeof(M2MConnectionObserver::SocketAddress)); |
ram54288 | 0:a7a43371b306 | 581 | |
ram54288 | 0:a7a43371b306 | 582 | address->_stack = M2MInterface::LwIP_IPv4; |
ram54288 | 0:a7a43371b306 | 583 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 584 | |
ram54288 | 0:a7a43371b306 | 585 | impl->data_available(data,data_size,*address); |
ram54288 | 0:a7a43371b306 | 586 | |
ram54288 | 0:a7a43371b306 | 587 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 588 | |
ram54288 | 0:a7a43371b306 | 589 | address->_stack = M2MInterface::LwIP_IPv6; |
ram54288 | 0:a7a43371b306 | 590 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 591 | |
ram54288 | 0:a7a43371b306 | 592 | impl->data_available(data,data_size,*address); |
ram54288 | 0:a7a43371b306 | 593 | |
ram54288 | 0:a7a43371b306 | 594 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 595 | |
ram54288 | 0:a7a43371b306 | 596 | address->_stack = M2MInterface::LwIP_IPv4; |
ram54288 | 0:a7a43371b306 | 597 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 598 | |
ram54288 | 0:a7a43371b306 | 599 | impl->data_available(data,data_size,*address); |
ram54288 | 0:a7a43371b306 | 600 | |
ram54288 | 0:a7a43371b306 | 601 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 602 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 603 | |
ram54288 | 0:a7a43371b306 | 604 | free(data); |
ram54288 | 0:a7a43371b306 | 605 | free(address); |
ram54288 | 0:a7a43371b306 | 606 | } |
ram54288 | 0:a7a43371b306 | 607 | |
ram54288 | 0:a7a43371b306 | 608 | void Test_M2MInterfaceImpl::test_socket_error() |
ram54288 | 0:a7a43371b306 | 609 | { |
ram54288 | 0:a7a43371b306 | 610 | for (int i = 0; i <= MBED_CLIENT_RECONNECTION_COUNT; i++) { |
ram54288 | 0:a7a43371b306 | 611 | impl->socket_error(M2MConnectionHandler::SSL_CONNECTION_ERROR); |
ram54288 | 0:a7a43371b306 | 612 | impl->_retry_timer_expired = true; |
ram54288 | 0:a7a43371b306 | 613 | } |
ram54288 | 0:a7a43371b306 | 614 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 615 | |
ram54288 | 0:a7a43371b306 | 616 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 617 | impl->socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, false); |
ram54288 | 0:a7a43371b306 | 618 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 619 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 620 | |
ram54288 | 0:a7a43371b306 | 621 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 622 | impl->socket_error(M2MConnectionHandler::DNS_RESOLVING_ERROR, false); |
ram54288 | 0:a7a43371b306 | 623 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 624 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 625 | |
ram54288 | 0:a7a43371b306 | 626 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 627 | impl->socket_error(M2MConnectionHandler::SOCKET_SEND_ERROR, false); |
ram54288 | 0:a7a43371b306 | 628 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 629 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 630 | |
ram54288 | 0:a7a43371b306 | 631 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 632 | impl->socket_error(M2MConnectionHandler::SSL_HANDSHAKE_ERROR, false); |
ram54288 | 0:a7a43371b306 | 633 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 634 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 635 | |
ram54288 | 0:a7a43371b306 | 636 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 637 | impl->socket_error(M2MConnectionHandler::SOCKET_ABORT, false); |
ram54288 | 0:a7a43371b306 | 638 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 639 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 640 | |
ram54288 | 0:a7a43371b306 | 641 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 642 | impl->socket_error(M2MConnectionHandler::ERROR_NONE, false); |
ram54288 | 0:a7a43371b306 | 643 | CHECK(observer->error_occured == false); |
ram54288 | 0:a7a43371b306 | 644 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 645 | } |
ram54288 | 0:a7a43371b306 | 646 | |
ram54288 | 0:a7a43371b306 | 647 | void Test_M2MInterfaceImpl::test_address_ready() |
ram54288 | 0:a7a43371b306 | 648 | { |
ram54288 | 0:a7a43371b306 | 649 | M2MConnectionObserver::SocketAddress *address = |
ram54288 | 0:a7a43371b306 | 650 | (M2MConnectionObserver::SocketAddress*) malloc(sizeof(M2MConnectionObserver::SocketAddress)); |
ram54288 | 0:a7a43371b306 | 651 | M2MConnectionObserver::ServerType server_type = M2MConnectionObserver::Bootstrap; |
ram54288 | 0:a7a43371b306 | 652 | uint16_t server_port = 5685; |
ram54288 | 0:a7a43371b306 | 653 | |
ram54288 | 0:a7a43371b306 | 654 | address->_stack = M2MInterface::LwIP_IPv6; |
ram54288 | 0:a7a43371b306 | 655 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 656 | |
ram54288 | 0:a7a43371b306 | 657 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 658 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP_RESOURCE_CREATED); |
ram54288 | 0:a7a43371b306 | 659 | |
ram54288 | 0:a7a43371b306 | 660 | address->_stack = M2MInterface::LwIP_IPv4; |
ram54288 | 0:a7a43371b306 | 661 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 662 | |
ram54288 | 0:a7a43371b306 | 663 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 664 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP_RESOURCE_CREATED); |
ram54288 | 0:a7a43371b306 | 665 | |
ram54288 | 0:a7a43371b306 | 666 | |
ram54288 | 0:a7a43371b306 | 667 | address->_stack = M2MInterface::LwIP_IPv6; |
ram54288 | 0:a7a43371b306 | 668 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 669 | |
ram54288 | 0:a7a43371b306 | 670 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 671 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 672 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 673 | |
ram54288 | 0:a7a43371b306 | 674 | // Test for Address resolving for LWM2M server |
ram54288 | 0:a7a43371b306 | 675 | server_type = M2MConnectionObserver::LWM2MServer; |
ram54288 | 0:a7a43371b306 | 676 | |
ram54288 | 0:a7a43371b306 | 677 | address->_stack = M2MInterface::LwIP_IPv4; |
ram54288 | 0:a7a43371b306 | 678 | m2mnsdlinterface_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 679 | |
ram54288 | 0:a7a43371b306 | 680 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 681 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER_ADDRESS_RESOLVED); |
ram54288 | 0:a7a43371b306 | 682 | |
ram54288 | 0:a7a43371b306 | 683 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 684 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER_ADDRESS_RESOLVED); |
ram54288 | 0:a7a43371b306 | 685 | |
ram54288 | 0:a7a43371b306 | 686 | address->_stack = M2MInterface::LwIP_IPv6; |
ram54288 | 0:a7a43371b306 | 687 | m2mnsdlinterface_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 688 | |
ram54288 | 0:a7a43371b306 | 689 | impl->address_ready(*address,server_type,server_port); |
ram54288 | 0:a7a43371b306 | 690 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE); |
ram54288 | 0:a7a43371b306 | 691 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 692 | |
ram54288 | 0:a7a43371b306 | 693 | free(address); |
ram54288 | 0:a7a43371b306 | 694 | } |
ram54288 | 0:a7a43371b306 | 695 | |
ram54288 | 0:a7a43371b306 | 696 | void Test_M2MInterfaceImpl::test_data_sent() |
ram54288 | 0:a7a43371b306 | 697 | { |
ram54288 | 0:a7a43371b306 | 698 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 699 | |
ram54288 | 0:a7a43371b306 | 700 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 701 | |
ram54288 | 0:a7a43371b306 | 702 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 703 | |
ram54288 | 0:a7a43371b306 | 704 | m2mconnectionhandler_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 705 | |
ram54288 | 0:a7a43371b306 | 706 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 707 | |
ram54288 | 0:a7a43371b306 | 708 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 709 | CHECK(observer->error_occured == false); |
ram54288 | 0:a7a43371b306 | 710 | |
ram54288 | 0:a7a43371b306 | 711 | impl->_callback_handler = callback_handler(this, &Test_M2MInterfaceImpl::test_callback_handler); |
ram54288 | 0:a7a43371b306 | 712 | |
ram54288 | 0:a7a43371b306 | 713 | m2mconnectionhandler_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 714 | |
ram54288 | 0:a7a43371b306 | 715 | impl->_binding_mode = M2MInterface::UDP_QUEUE; |
ram54288 | 0:a7a43371b306 | 716 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 717 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 718 | |
ram54288 | 0:a7a43371b306 | 719 | impl->_binding_mode = M2MInterface::TCP_QUEUE; |
ram54288 | 0:a7a43371b306 | 720 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 721 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 722 | |
ram54288 | 0:a7a43371b306 | 723 | impl->_binding_mode = M2MInterface::SMS_QUEUE; |
ram54288 | 0:a7a43371b306 | 724 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 725 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 726 | |
ram54288 | 0:a7a43371b306 | 727 | impl->_binding_mode = M2MInterface::UDP_SMS_QUEUE; |
ram54288 | 0:a7a43371b306 | 728 | impl->data_sent(); |
ram54288 | 0:a7a43371b306 | 729 | CHECK(impl->_current_state == M2MInterfaceImpl::STATE_WAITING); |
ram54288 | 0:a7a43371b306 | 730 | } |
ram54288 | 0:a7a43371b306 | 731 | |
ram54288 | 0:a7a43371b306 | 732 | void Test_M2MInterfaceImpl::test_timer_expired() |
ram54288 | 0:a7a43371b306 | 733 | { |
ram54288 | 0:a7a43371b306 | 734 | visited = false; |
ram54288 | 0:a7a43371b306 | 735 | impl->_callback_handler = NULL; |
ram54288 | 0:a7a43371b306 | 736 | impl->timer_expired(M2MTimerObserver::QueueSleep); |
ram54288 | 0:a7a43371b306 | 737 | CHECK(visited == false); |
ram54288 | 0:a7a43371b306 | 738 | |
ram54288 | 0:a7a43371b306 | 739 | impl->_callback_handler = callback_handler(this, &Test_M2MInterfaceImpl::test_callback_handler); |
ram54288 | 0:a7a43371b306 | 740 | |
ram54288 | 0:a7a43371b306 | 741 | visited = false; |
ram54288 | 0:a7a43371b306 | 742 | impl->timer_expired(M2MTimerObserver::QueueSleep); |
ram54288 | 0:a7a43371b306 | 743 | CHECK(visited == true); |
ram54288 | 0:a7a43371b306 | 744 | visited = false; |
ram54288 | 0:a7a43371b306 | 745 | |
ram54288 | 0:a7a43371b306 | 746 | impl->_bootstrapped = true; |
ram54288 | 0:a7a43371b306 | 747 | impl->timer_expired(M2MTimerObserver::RetryTimer); |
ram54288 | 0:a7a43371b306 | 748 | CHECK(impl->_retry_timer_expired == true); |
ram54288 | 0:a7a43371b306 | 749 | |
ram54288 | 0:a7a43371b306 | 750 | impl->_bootstrapped = false; |
ram54288 | 0:a7a43371b306 | 751 | impl->timer_expired(M2MTimerObserver::RetryTimer); |
ram54288 | 0:a7a43371b306 | 752 | CHECK(impl->_retry_timer_expired == true); |
ram54288 | 0:a7a43371b306 | 753 | |
ram54288 | 0:a7a43371b306 | 754 | observer->error_occured = false; |
ram54288 | 0:a7a43371b306 | 755 | impl->timer_expired(M2MTimerObserver::BootstrapTimer); |
ram54288 | 0:a7a43371b306 | 756 | CHECK(observer->error_occured == true); |
ram54288 | 0:a7a43371b306 | 757 | } |
ram54288 | 0:a7a43371b306 | 758 | |
ram54288 | 0:a7a43371b306 | 759 | void Test_M2MInterfaceImpl::test_callback_handler() |
ram54288 | 0:a7a43371b306 | 760 | { |
ram54288 | 0:a7a43371b306 | 761 | visited = true; |
ram54288 | 0:a7a43371b306 | 762 | } |
ram54288 | 0:a7a43371b306 | 763 | |
ram54288 | 0:a7a43371b306 | 764 | uint32_t test_random_callback(void) |
ram54288 | 0:a7a43371b306 | 765 | { |
ram54288 | 0:a7a43371b306 | 766 | return 1; |
ram54288 | 0:a7a43371b306 | 767 | } |