A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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_m2msecurity.h"
ram54288 0:a7a43371b306 18 #include "m2mobject_stub.h"
ram54288 0:a7a43371b306 19 #include "m2mobjectinstance_stub.h"
ram54288 0:a7a43371b306 20 #include "m2mresource_stub.h"
ram54288 0:a7a43371b306 21 #include "m2mresourceinstance_stub.h"
ram54288 0:a7a43371b306 22 #include "m2mbase_stub.h"
ram54288 0:a7a43371b306 23 #include "nsdlaccesshelper_stub.h"
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25 Test_M2MSecurity::Test_M2MSecurity()
ram54288 0:a7a43371b306 26 {
ram54288 0:a7a43371b306 27 M2MObject* obj = new M2MObject("name", "name");
ram54288 0:a7a43371b306 28 m2mobject_stub::inst = new M2MObjectInstance(*obj,"name","type", "name");
ram54288 0:a7a43371b306 29 m2mresource_stub::bool_value = true;
ram54288 0:a7a43371b306 30 m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 31 "name",
ram54288 0:a7a43371b306 32 "type",
ram54288 0:a7a43371b306 33 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 34 false,
ram54288 0:a7a43371b306 35 "name");
ram54288 0:a7a43371b306 36 security = new M2MSecurity(M2MSecurity::Bootstrap);
ram54288 0:a7a43371b306 37
ram54288 0:a7a43371b306 38 delete m2mobjectinstance_stub::create_resource;
ram54288 0:a7a43371b306 39 m2mobjectinstance_stub::create_resource = NULL;
ram54288 0:a7a43371b306 40
ram54288 0:a7a43371b306 41 delete obj;
ram54288 0:a7a43371b306 42 }
ram54288 0:a7a43371b306 43
ram54288 0:a7a43371b306 44 Test_M2MSecurity::~Test_M2MSecurity()
ram54288 0:a7a43371b306 45 {
ram54288 0:a7a43371b306 46 delete m2mobject_stub::inst;
ram54288 0:a7a43371b306 47 m2mobject_stub::inst = NULL;
ram54288 0:a7a43371b306 48 m2mobject_stub::clear();
ram54288 0:a7a43371b306 49 m2mobjectinstance_stub::clear();
ram54288 0:a7a43371b306 50 m2mresource_stub::clear();
ram54288 0:a7a43371b306 51 m2mbase_stub::clear();
ram54288 0:a7a43371b306 52 delete security;
ram54288 0:a7a43371b306 53 }
ram54288 0:a7a43371b306 54
ram54288 0:a7a43371b306 55 void Test_M2MSecurity::test_create_resource_int()
ram54288 0:a7a43371b306 56 {
ram54288 0:a7a43371b306 57 m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 58 "name",
ram54288 0:a7a43371b306 59 "type",
ram54288 0:a7a43371b306 60 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 61 false,
ram54288 0:a7a43371b306 62 "name");
ram54288 0:a7a43371b306 63
ram54288 0:a7a43371b306 64 CHECK(security->create_resource(M2MSecurity::M2MServerUri,10) == NULL);
ram54288 0:a7a43371b306 65 CHECK(security->create_resource(M2MSecurity::BootstrapServer,10) == NULL);
ram54288 0:a7a43371b306 66 CHECK(security->create_resource(M2MSecurity::SecurityMode,10) == NULL);
ram54288 0:a7a43371b306 67 CHECK(security->create_resource(M2MSecurity::PublicKey,10) == NULL);
ram54288 0:a7a43371b306 68 CHECK(security->create_resource(M2MSecurity::ServerPublicKey,10) == NULL);
ram54288 0:a7a43371b306 69 CHECK(security->create_resource(M2MSecurity::Secretkey,10) == NULL);
ram54288 0:a7a43371b306 70 CHECK(security->create_resource(M2MSecurity::SMSBindingKey,10) == NULL);
ram54288 0:a7a43371b306 71 CHECK(security->create_resource(M2MSecurity::SMSBindingSecretKey,10) == NULL);
ram54288 0:a7a43371b306 72
ram54288 0:a7a43371b306 73 CHECK(security->create_resource(M2MSecurity::M2MServerSMSNumber,10) != NULL);
ram54288 0:a7a43371b306 74 CHECK(security->create_resource(M2MSecurity::ShortServerID,10) != NULL);
ram54288 0:a7a43371b306 75 CHECK(security->create_resource(M2MSecurity::ClientHoldOffTime,10) != NULL);
ram54288 0:a7a43371b306 76 CHECK(security->create_resource(M2MSecurity::SMSSecurityMode,10) != NULL);
ram54288 0:a7a43371b306 77
ram54288 0:a7a43371b306 78 delete m2mobjectinstance_stub::create_resource;
ram54288 0:a7a43371b306 79 m2mobjectinstance_stub::create_resource = NULL;
ram54288 0:a7a43371b306 80 }
ram54288 0:a7a43371b306 81
ram54288 0:a7a43371b306 82 void Test_M2MSecurity::test_delete_resource()
ram54288 0:a7a43371b306 83 {
ram54288 0:a7a43371b306 84 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 85 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 86 "name",
ram54288 0:a7a43371b306 87 "type",
ram54288 0:a7a43371b306 88 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 89 false,
ram54288 0:a7a43371b306 90 "name");
ram54288 0:a7a43371b306 91
ram54288 0:a7a43371b306 92 CHECK(security->delete_resource(M2MSecurity::SMSBindingSecretKey) == false);
ram54288 0:a7a43371b306 93 CHECK(security->delete_resource(M2MSecurity::SMSBindingKey) == false);
ram54288 0:a7a43371b306 94 CHECK(security->delete_resource(M2MSecurity::M2MServerUri) == false);
ram54288 0:a7a43371b306 95 CHECK(security->delete_resource(M2MSecurity::Secretkey) == false);
ram54288 0:a7a43371b306 96 CHECK(security->delete_resource(M2MSecurity::ServerPublicKey) == false);
ram54288 0:a7a43371b306 97 CHECK(security->delete_resource(M2MSecurity::BootstrapServer) == false);
ram54288 0:a7a43371b306 98 CHECK(security->delete_resource(M2MSecurity::PublicKey) == false);
ram54288 0:a7a43371b306 99 CHECK(security->delete_resource(M2MSecurity::SecurityMode) == false);
ram54288 0:a7a43371b306 100
ram54288 0:a7a43371b306 101 m2mobjectinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 102
ram54288 0:a7a43371b306 103 CHECK(security->delete_resource(M2MSecurity::M2MServerSMSNumber) == true);
ram54288 0:a7a43371b306 104 CHECK(security->delete_resource(M2MSecurity::ShortServerID) == true);
ram54288 0:a7a43371b306 105 CHECK(security->delete_resource(M2MSecurity::ClientHoldOffTime) == true);
ram54288 0:a7a43371b306 106 CHECK(security->delete_resource(M2MSecurity::SMSSecurityMode) == true);
ram54288 0:a7a43371b306 107
ram54288 0:a7a43371b306 108 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 109 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 110 }
ram54288 0:a7a43371b306 111
ram54288 0:a7a43371b306 112 void Test_M2MSecurity::test_set_resource_value_string()
ram54288 0:a7a43371b306 113 {
ram54288 0:a7a43371b306 114 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 115 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 116 "name",
ram54288 0:a7a43371b306 117 "type",
ram54288 0:a7a43371b306 118 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 119 false,
ram54288 0:a7a43371b306 120 "name");
ram54288 0:a7a43371b306 121
ram54288 0:a7a43371b306 122 CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,"test") == true);
ram54288 0:a7a43371b306 123
ram54288 0:a7a43371b306 124 CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,"test") == false);
ram54288 0:a7a43371b306 125 CHECK(security->set_resource_value(M2MSecurity::ShortServerID,"test") == false);
ram54288 0:a7a43371b306 126 CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,"test") == false);
ram54288 0:a7a43371b306 127 CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,"test") == false);
ram54288 0:a7a43371b306 128 CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,"test") == false);
ram54288 0:a7a43371b306 129 CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,"test") == false);
ram54288 0:a7a43371b306 130 CHECK(security->set_resource_value(M2MSecurity::Secretkey,"test") == false);
ram54288 0:a7a43371b306 131 CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,"test") == false);
ram54288 0:a7a43371b306 132 CHECK(security->set_resource_value(M2MSecurity::PublicKey,"test") == false);
ram54288 0:a7a43371b306 133 CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,"test") == false);
ram54288 0:a7a43371b306 134 CHECK(security->set_resource_value(M2MSecurity::SecurityMode,"test") == false);
ram54288 0:a7a43371b306 135
ram54288 0:a7a43371b306 136 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 137 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 138 }
ram54288 0:a7a43371b306 139
ram54288 0:a7a43371b306 140 void Test_M2MSecurity::test_set_resource_value_int()
ram54288 0:a7a43371b306 141 {
ram54288 0:a7a43371b306 142 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 143 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 144 "name",
ram54288 0:a7a43371b306 145 "type",
ram54288 0:a7a43371b306 146 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 147 false,
ram54288 0:a7a43371b306 148 "name");
ram54288 0:a7a43371b306 149
ram54288 0:a7a43371b306 150 CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,10) == false);
ram54288 0:a7a43371b306 151 CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,10) == false);
ram54288 0:a7a43371b306 152 CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,10) == false);
ram54288 0:a7a43371b306 153 CHECK(security->set_resource_value(M2MSecurity::Secretkey,10) == false);
ram54288 0:a7a43371b306 154 CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,10) == false);
ram54288 0:a7a43371b306 155 CHECK(security->set_resource_value(M2MSecurity::PublicKey,10) == false);
ram54288 0:a7a43371b306 156 CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,10) == false);
ram54288 0:a7a43371b306 157
ram54288 0:a7a43371b306 158 CHECK(security->set_resource_value(M2MSecurity::SecurityMode,10) == true);
ram54288 0:a7a43371b306 159 CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,10) == true);
ram54288 0:a7a43371b306 160 CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,10) == true);
ram54288 0:a7a43371b306 161 CHECK(security->set_resource_value(M2MSecurity::ShortServerID,10) == true);
ram54288 0:a7a43371b306 162 CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,10) == true);
ram54288 0:a7a43371b306 163
ram54288 0:a7a43371b306 164 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 165 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 166 }
ram54288 0:a7a43371b306 167
ram54288 0:a7a43371b306 168 void Test_M2MSecurity::test_set_resource_value_buffer()
ram54288 0:a7a43371b306 169 {
ram54288 0:a7a43371b306 170 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 171
ram54288 0:a7a43371b306 172 uint8_t value[] = {"value"};
ram54288 0:a7a43371b306 173 uint16_t length = (uint16_t)sizeof(value);
ram54288 0:a7a43371b306 174
ram54288 0:a7a43371b306 175 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 176 "name",
ram54288 0:a7a43371b306 177 "type",
ram54288 0:a7a43371b306 178 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 179 false,
ram54288 0:a7a43371b306 180 "name");
ram54288 0:a7a43371b306 181
ram54288 0:a7a43371b306 182 CHECK(security->set_resource_value(M2MSecurity::Secretkey,value,length) == true);
ram54288 0:a7a43371b306 183 CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,value,length) == true);
ram54288 0:a7a43371b306 184 CHECK(security->set_resource_value(M2MSecurity::PublicKey,value,length) == true);
ram54288 0:a7a43371b306 185
ram54288 0:a7a43371b306 186 CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,value,length) == false);
ram54288 0:a7a43371b306 187 CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,value,length) == false);
ram54288 0:a7a43371b306 188 CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,value,length) == false);
ram54288 0:a7a43371b306 189 CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,value,length) == false);
ram54288 0:a7a43371b306 190
ram54288 0:a7a43371b306 191 CHECK(security->set_resource_value(M2MSecurity::SecurityMode,value,length) == false);
ram54288 0:a7a43371b306 192 CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,value,length) == false);
ram54288 0:a7a43371b306 193 CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,value,length) == false);
ram54288 0:a7a43371b306 194 CHECK(security->set_resource_value(M2MSecurity::ShortServerID,value,length) == false);
ram54288 0:a7a43371b306 195 CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,value,length) == false);
ram54288 0:a7a43371b306 196
ram54288 0:a7a43371b306 197 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 198 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 199 }
ram54288 0:a7a43371b306 200
ram54288 0:a7a43371b306 201 void Test_M2MSecurity::test_resource_value_int()
ram54288 0:a7a43371b306 202 {
ram54288 0:a7a43371b306 203 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 204
ram54288 0:a7a43371b306 205 uint8_t value[] = {"10"};
ram54288 0:a7a43371b306 206 //m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value));
ram54288 0:a7a43371b306 207 uint8_t size = 0;
ram54288 0:a7a43371b306 208 m2mresourceinstance_stub::value = String::convert_integer_to_array(10,size);
ram54288 0:a7a43371b306 209 /*memset(m2mresourceinstance_stub::value,0,(uint32_t)size);
ram54288 0:a7a43371b306 210 memcpy(m2mresourceinstance_stub::value, 10, size);*/
ram54288 0:a7a43371b306 211 m2mresourceinstance_stub::int_value = (uint16_t)size;
ram54288 0:a7a43371b306 212
ram54288 0:a7a43371b306 213 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 214 "name",
ram54288 0:a7a43371b306 215 "type",
ram54288 0:a7a43371b306 216 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 217 false,
ram54288 0:a7a43371b306 218 "name");
ram54288 0:a7a43371b306 219
ram54288 0:a7a43371b306 220 CHECK(security->resource_value_int(M2MSecurity::SecurityMode) == 10);
ram54288 0:a7a43371b306 221 CHECK(security->resource_value_int(M2MSecurity::SMSSecurityMode) == 10);
ram54288 0:a7a43371b306 222 CHECK(security->resource_value_int(M2MSecurity::M2MServerSMSNumber) == 10);
ram54288 0:a7a43371b306 223 CHECK(security->resource_value_int(M2MSecurity::ShortServerID) == 10);
ram54288 0:a7a43371b306 224 CHECK(security->resource_value_int(M2MSecurity::ClientHoldOffTime) == 10);
ram54288 0:a7a43371b306 225 CHECK(security->resource_value_int(M2MSecurity::BootstrapServer) == 0);
ram54288 0:a7a43371b306 226 CHECK(security->resource_value_int(M2MSecurity::PublicKey) == 0);
ram54288 0:a7a43371b306 227 CHECK(security->resource_value_int(M2MSecurity::ServerPublicKey) == 0);
ram54288 0:a7a43371b306 228 CHECK(security->resource_value_int(M2MSecurity::Secretkey) == 0);
ram54288 0:a7a43371b306 229 CHECK(security->resource_value_int(M2MSecurity::SMSBindingSecretKey) == 0);
ram54288 0:a7a43371b306 230 CHECK(security->resource_value_int(M2MSecurity::SMSBindingKey) == 0);
ram54288 0:a7a43371b306 231 CHECK(security->resource_value_int(M2MSecurity::M2MServerUri) == 0);
ram54288 0:a7a43371b306 232
ram54288 0:a7a43371b306 233 security->clear_resources();
ram54288 0:a7a43371b306 234 CHECK(security->resource_value_int(M2MSecurity::SecurityMode) == 0);
ram54288 0:a7a43371b306 235 CHECK(security->resource_value_int(M2MSecurity::SMSSecurityMode) == 0);
ram54288 0:a7a43371b306 236 CHECK(security->resource_value_int(M2MSecurity::M2MServerSMSNumber) == 0);
ram54288 0:a7a43371b306 237 CHECK(security->resource_value_int(M2MSecurity::ShortServerID) == 0);
ram54288 0:a7a43371b306 238 CHECK(security->resource_value_int(M2MSecurity::ClientHoldOffTime) == 0);
ram54288 0:a7a43371b306 239 CHECK(security->resource_value_int(M2MSecurity::BootstrapServer) == 0);
ram54288 0:a7a43371b306 240 CHECK(security->resource_value_int(M2MSecurity::PublicKey) == 0);
ram54288 0:a7a43371b306 241 CHECK(security->resource_value_int(M2MSecurity::ServerPublicKey) == 0);
ram54288 0:a7a43371b306 242 CHECK(security->resource_value_int(M2MSecurity::Secretkey) == 0);
ram54288 0:a7a43371b306 243 CHECK(security->resource_value_int(M2MSecurity::SMSBindingSecretKey) == 0);
ram54288 0:a7a43371b306 244 CHECK(security->resource_value_int(M2MSecurity::SMSBindingKey) == 0);
ram54288 0:a7a43371b306 245 CHECK(security->resource_value_int(M2MSecurity::M2MServerUri) == 0);
ram54288 0:a7a43371b306 246
ram54288 0:a7a43371b306 247 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 248 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 249
ram54288 0:a7a43371b306 250 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 251 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 252 }
ram54288 0:a7a43371b306 253
ram54288 0:a7a43371b306 254 void Test_M2MSecurity::test_resource_value_string()
ram54288 0:a7a43371b306 255 {
ram54288 0:a7a43371b306 256 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 257 String test = "string";
ram54288 0:a7a43371b306 258 uint8_t value[] = {"string"};
ram54288 0:a7a43371b306 259 m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value));
ram54288 0:a7a43371b306 260 memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value));
ram54288 0:a7a43371b306 261 memcpy(m2mresourceinstance_stub::value,value,sizeof(value));
ram54288 0:a7a43371b306 262 m2mresourceinstance_stub::int_value = (uint16_t)sizeof(value);
ram54288 0:a7a43371b306 263
ram54288 0:a7a43371b306 264 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 265 "name",
ram54288 0:a7a43371b306 266 "type",
ram54288 0:a7a43371b306 267 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 268 false,
ram54288 0:a7a43371b306 269 "name");
ram54288 0:a7a43371b306 270
ram54288 0:a7a43371b306 271 CHECK(security->resource_value_string(M2MSecurity::M2MServerUri) == test);
ram54288 0:a7a43371b306 272
ram54288 0:a7a43371b306 273 CHECK(security->resource_value_string(M2MSecurity::SMSBindingKey) == "");
ram54288 0:a7a43371b306 274 CHECK(security->resource_value_string(M2MSecurity::SMSBindingSecretKey) == "");
ram54288 0:a7a43371b306 275 CHECK(security->resource_value_string(M2MSecurity::Secretkey) == "");
ram54288 0:a7a43371b306 276 CHECK(security->resource_value_string(M2MSecurity::ServerPublicKey) == "");
ram54288 0:a7a43371b306 277 CHECK(security->resource_value_string(M2MSecurity::PublicKey) == "");
ram54288 0:a7a43371b306 278 CHECK(security->resource_value_string(M2MSecurity::BootstrapServer) == "");
ram54288 0:a7a43371b306 279 CHECK(security->resource_value_string(M2MSecurity::ClientHoldOffTime) == "");
ram54288 0:a7a43371b306 280 CHECK(security->resource_value_string(M2MSecurity::ShortServerID) == "");
ram54288 0:a7a43371b306 281 CHECK(security->resource_value_string(M2MSecurity::M2MServerSMSNumber) == "");
ram54288 0:a7a43371b306 282 CHECK(security->resource_value_string(M2MSecurity::SMSSecurityMode) == "");
ram54288 0:a7a43371b306 283 CHECK(security->resource_value_string(M2MSecurity::SecurityMode) == "");
ram54288 0:a7a43371b306 284
ram54288 0:a7a43371b306 285 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 286 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 287
ram54288 0:a7a43371b306 288 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 289 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 290 }
ram54288 0:a7a43371b306 291
ram54288 0:a7a43371b306 292 void Test_M2MSecurity::test_resource_value_buffer()
ram54288 0:a7a43371b306 293 {
ram54288 0:a7a43371b306 294 m2mresourceinstance_stub::bool_value = true;
ram54288 0:a7a43371b306 295
ram54288 0:a7a43371b306 296 uint8_t value[] = {"buffer"};
ram54288 0:a7a43371b306 297 uint8_t *out_value = NULL;
ram54288 0:a7a43371b306 298
ram54288 0:a7a43371b306 299 m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value));
ram54288 0:a7a43371b306 300 memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value));
ram54288 0:a7a43371b306 301 memcpy(m2mresourceinstance_stub::value,value,sizeof(value));
ram54288 0:a7a43371b306 302 m2mresourceinstance_stub::int_value = (uint16_t)sizeof(value);
ram54288 0:a7a43371b306 303
ram54288 0:a7a43371b306 304 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 305 "name",
ram54288 0:a7a43371b306 306 "type",
ram54288 0:a7a43371b306 307 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 308 false,
ram54288 0:a7a43371b306 309 "name");
ram54288 0:a7a43371b306 310
ram54288 0:a7a43371b306 311 CHECK(security->resource_value_buffer(M2MSecurity::Secretkey,out_value) != 0);
ram54288 0:a7a43371b306 312 CHECK(security->resource_value_buffer(M2MSecurity::ServerPublicKey,out_value) != 0);
ram54288 0:a7a43371b306 313 CHECK(security->resource_value_buffer(M2MSecurity::PublicKey,out_value) != 0);
ram54288 0:a7a43371b306 314
ram54288 0:a7a43371b306 315 CHECK(security->resource_value_buffer(M2MSecurity::M2MServerUri,out_value) == 0);
ram54288 0:a7a43371b306 316
ram54288 0:a7a43371b306 317 CHECK(security->resource_value_buffer(M2MSecurity::SMSBindingKey,out_value) == 0);
ram54288 0:a7a43371b306 318 CHECK(security->resource_value_buffer(M2MSecurity::SMSBindingSecretKey,out_value) == 0);
ram54288 0:a7a43371b306 319 CHECK(security->resource_value_buffer(M2MSecurity::BootstrapServer,out_value) == 0);
ram54288 0:a7a43371b306 320 CHECK(security->resource_value_buffer(M2MSecurity::ClientHoldOffTime,out_value) == 0);
ram54288 0:a7a43371b306 321 CHECK(security->resource_value_buffer(M2MSecurity::ShortServerID,out_value) == 0);
ram54288 0:a7a43371b306 322 CHECK(security->resource_value_buffer(M2MSecurity::M2MServerSMSNumber,out_value) == 0);
ram54288 0:a7a43371b306 323 CHECK(security->resource_value_buffer(M2MSecurity::SMSSecurityMode,out_value) == 0);
ram54288 0:a7a43371b306 324 CHECK(security->resource_value_buffer(M2MSecurity::SecurityMode,out_value) == 0);
ram54288 0:a7a43371b306 325
ram54288 0:a7a43371b306 326 const uint8_t *outvalue = NULL;
ram54288 0:a7a43371b306 327 CHECK(security->resource_value_buffer(M2MSecurity::Secretkey,outvalue) != 0);
ram54288 0:a7a43371b306 328 CHECK(security->resource_value_buffer(M2MSecurity::ServerPublicKey,outvalue) != 0);
ram54288 0:a7a43371b306 329 CHECK(security->resource_value_buffer(M2MSecurity::PublicKey,outvalue) != 0);
ram54288 0:a7a43371b306 330
ram54288 0:a7a43371b306 331 free(out_value);
ram54288 0:a7a43371b306 332 out_value = NULL;
ram54288 0:a7a43371b306 333
ram54288 0:a7a43371b306 334 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 335 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 336
ram54288 0:a7a43371b306 337 free(m2mresourceinstance_stub::value);
ram54288 0:a7a43371b306 338 m2mresourceinstance_stub::value = NULL;
ram54288 0:a7a43371b306 339 }
ram54288 0:a7a43371b306 340
ram54288 0:a7a43371b306 341 void Test_M2MSecurity::test_is_resource_present()
ram54288 0:a7a43371b306 342 {
ram54288 0:a7a43371b306 343 m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 344 "name",
ram54288 0:a7a43371b306 345 "type",
ram54288 0:a7a43371b306 346 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 347 false,
ram54288 0:a7a43371b306 348 "name");
ram54288 0:a7a43371b306 349
ram54288 0:a7a43371b306 350 CHECK(security->is_resource_present(M2MSecurity::M2MServerUri) == true);
ram54288 0:a7a43371b306 351
ram54288 0:a7a43371b306 352 delete m2mobjectinstance_stub::resource;
ram54288 0:a7a43371b306 353 m2mobjectinstance_stub::resource = NULL;
ram54288 0:a7a43371b306 354
ram54288 0:a7a43371b306 355 CHECK(security->is_resource_present(M2MSecurity::ClientHoldOffTime) == false);
ram54288 0:a7a43371b306 356 }
ram54288 0:a7a43371b306 357
ram54288 0:a7a43371b306 358 void Test_M2MSecurity::test_total_resource_count()
ram54288 0:a7a43371b306 359 {
ram54288 0:a7a43371b306 360 M2MResource *res = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 361 "name",
ram54288 0:a7a43371b306 362 "type",
ram54288 0:a7a43371b306 363 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 364 false,
ram54288 0:a7a43371b306 365 "name");
ram54288 0:a7a43371b306 366
ram54288 0:a7a43371b306 367 m2mobjectinstance_stub::resource_list.push_back(res);
ram54288 0:a7a43371b306 368 M2MResource *res2 = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 369 "name",
ram54288 0:a7a43371b306 370 "type",
ram54288 0:a7a43371b306 371 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 372 false,
ram54288 0:a7a43371b306 373 "name");
ram54288 0:a7a43371b306 374
ram54288 0:a7a43371b306 375 m2mobjectinstance_stub::resource_list.push_back(res2);
ram54288 0:a7a43371b306 376
ram54288 0:a7a43371b306 377 CHECK(security->total_resource_count() == 2);
ram54288 0:a7a43371b306 378
ram54288 0:a7a43371b306 379 m2mobjectinstance_stub::resource_list.clear();
ram54288 0:a7a43371b306 380
ram54288 0:a7a43371b306 381 delete res2;
ram54288 0:a7a43371b306 382 delete res;
ram54288 0:a7a43371b306 383 }
ram54288 0:a7a43371b306 384
ram54288 0:a7a43371b306 385 void Test_M2MSecurity::test_m2m_server_constructor()
ram54288 0:a7a43371b306 386 {
ram54288 0:a7a43371b306 387 m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst,
ram54288 0:a7a43371b306 388 "name",
ram54288 0:a7a43371b306 389 "type",
ram54288 0:a7a43371b306 390 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 391 false,
ram54288 0:a7a43371b306 392 "name");
ram54288 0:a7a43371b306 393
ram54288 0:a7a43371b306 394 M2MSecurity* sec = new M2MSecurity(M2MSecurity::M2MServer);
ram54288 0:a7a43371b306 395 CHECK(M2MSecurity::M2MServer == sec->server_type());
ram54288 0:a7a43371b306 396
ram54288 0:a7a43371b306 397 delete sec;
ram54288 0:a7a43371b306 398 delete m2mobjectinstance_stub::create_resource;
ram54288 0:a7a43371b306 399 m2mobjectinstance_stub::create_resource = NULL;
ram54288 0:a7a43371b306 400 }
ram54288 0:a7a43371b306 401
ram54288 0:a7a43371b306 402 void Test_M2MSecurity::test_server_type()
ram54288 0:a7a43371b306 403 {
ram54288 0:a7a43371b306 404 CHECK(M2MSecurity::Bootstrap ==security->server_type());
ram54288 0:a7a43371b306 405 }