Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/m2mfirmware/test_m2mfirmware.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_m2mfirmware.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_M2MFirmware::Test_M2MFirmware() |
ram54288 | 0:a7a43371b306 | 26 | { |
ram54288 | 0:a7a43371b306 | 27 | M2MObject* obj = new M2MObject("name", "name"); |
ram54288 | 0:a7a43371b306 | 28 | m2mobject_stub::inst = new M2MObjectInstance(*obj, |
ram54288 | 0:a7a43371b306 | 29 | "name","",""); |
ram54288 | 0:a7a43371b306 | 30 | m2mobjectinstance_stub::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 | |
ram54288 | 0:a7a43371b306 | 37 | m2mobjectinstance_stub::create_resource_instance= new M2MResourceInstance(*m2mobjectinstance_stub::resource, |
ram54288 | 0:a7a43371b306 | 38 | "name", |
ram54288 | 0:a7a43371b306 | 39 | "type", |
ram54288 | 0:a7a43371b306 | 40 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 41 | 0, |
ram54288 | 0:a7a43371b306 | 42 | "name", |
ram54288 | 0:a7a43371b306 | 43 | false); |
ram54288 | 0:a7a43371b306 | 44 | m2mresource_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 45 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 46 | "name", |
ram54288 | 0:a7a43371b306 | 47 | "type", |
ram54288 | 0:a7a43371b306 | 48 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 49 | false, |
ram54288 | 0:a7a43371b306 | 50 | "name"); |
ram54288 | 0:a7a43371b306 | 51 | firmware = M2MFirmware::get_instance(); |
ram54288 | 0:a7a43371b306 | 52 | |
ram54288 | 0:a7a43371b306 | 53 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a7a43371b306 | 54 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a7a43371b306 | 55 | |
ram54288 | 0:a7a43371b306 | 56 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 57 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 58 | |
ram54288 | 0:a7a43371b306 | 59 | delete m2mobjectinstance_stub::create_resource_instance; |
ram54288 | 0:a7a43371b306 | 60 | m2mobjectinstance_stub::create_resource_instance = NULL; |
ram54288 | 0:a7a43371b306 | 61 | delete obj; |
ram54288 | 0:a7a43371b306 | 62 | } |
ram54288 | 0:a7a43371b306 | 63 | |
ram54288 | 0:a7a43371b306 | 64 | Test_M2MFirmware::~Test_M2MFirmware() |
ram54288 | 0:a7a43371b306 | 65 | { |
ram54288 | 0:a7a43371b306 | 66 | delete m2mobject_stub::inst; |
ram54288 | 0:a7a43371b306 | 67 | m2mobject_stub::inst = NULL; |
ram54288 | 0:a7a43371b306 | 68 | |
ram54288 | 0:a7a43371b306 | 69 | M2MFirmware::delete_instance(); |
ram54288 | 0:a7a43371b306 | 70 | firmware = NULL; |
ram54288 | 0:a7a43371b306 | 71 | } |
ram54288 | 0:a7a43371b306 | 72 | |
ram54288 | 0:a7a43371b306 | 73 | void Test_M2MFirmware::test_create_resource_string() |
ram54288 | 0:a7a43371b306 | 74 | { |
ram54288 | 0:a7a43371b306 | 75 | CHECK(firmware->create_resource(M2MFirmware::Package, "test") == NULL); |
ram54288 | 0:a7a43371b306 | 76 | CHECK(firmware->create_resource(M2MFirmware::Update, "test") == NULL); |
ram54288 | 0:a7a43371b306 | 77 | CHECK(firmware->create_resource(M2MFirmware::State, "test") == NULL); |
ram54288 | 0:a7a43371b306 | 78 | |
ram54288 | 0:a7a43371b306 | 79 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 80 | "name", |
ram54288 | 0:a7a43371b306 | 81 | "type", |
ram54288 | 0:a7a43371b306 | 82 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 83 | false, |
ram54288 | 0:a7a43371b306 | 84 | "name"); |
ram54288 | 0:a7a43371b306 | 85 | CHECK(firmware->create_resource(M2MFirmware::PackageName,"test") != NULL); |
ram54288 | 0:a7a43371b306 | 86 | CHECK(M2MBase::GET_ALLOWED == m2mbase_stub::operation); |
ram54288 | 0:a7a43371b306 | 87 | CHECK(firmware->create_resource(M2MFirmware::PackageName,"") != NULL); |
ram54288 | 0:a7a43371b306 | 88 | |
ram54288 | 0:a7a43371b306 | 89 | // Check size limit |
ram54288 | 0:a7a43371b306 | 90 | String test = ""; |
ram54288 | 0:a7a43371b306 | 91 | for (int i = 0; i <= 255; i++) { |
ram54288 | 0:a7a43371b306 | 92 | test.append("a", 1); |
ram54288 | 0:a7a43371b306 | 93 | } |
ram54288 | 0:a7a43371b306 | 94 | // 255 + null-termination |
ram54288 | 0:a7a43371b306 | 95 | CHECK(firmware->create_resource(M2MFirmware::PackageVersion,test) == NULL); |
ram54288 | 0:a7a43371b306 | 96 | |
ram54288 | 0:a7a43371b306 | 97 | test = ""; |
ram54288 | 0:a7a43371b306 | 98 | for (int i = 0; i <= 254; i++) { |
ram54288 | 0:a7a43371b306 | 99 | test.append("a", 1); |
ram54288 | 0:a7a43371b306 | 100 | } |
ram54288 | 0:a7a43371b306 | 101 | // 254 + null-termination |
ram54288 | 0:a7a43371b306 | 102 | CHECK(firmware->create_resource(M2MFirmware::PackageVersion,test) != NULL); |
ram54288 | 0:a7a43371b306 | 103 | CHECK(M2MBase::GET_ALLOWED == m2mbase_stub::operation); |
ram54288 | 0:a7a43371b306 | 104 | |
ram54288 | 0:a7a43371b306 | 105 | |
ram54288 | 0:a7a43371b306 | 106 | CHECK(firmware->create_resource(M2MFirmware::Package,"test") == NULL); |
ram54288 | 0:a7a43371b306 | 107 | CHECK(firmware->create_resource(M2MFirmware::Update,"test") == NULL); |
ram54288 | 0:a7a43371b306 | 108 | CHECK(firmware->create_resource(M2MFirmware::State,"test") == NULL); |
ram54288 | 0:a7a43371b306 | 109 | CHECK(firmware->create_resource(M2MFirmware::UpdateSupportedObjects,"test") == NULL); |
ram54288 | 0:a7a43371b306 | 110 | CHECK(firmware->create_resource(M2MFirmware::UpdateResult,"test") == NULL); |
ram54288 | 0:a7a43371b306 | 111 | |
ram54288 | 0:a7a43371b306 | 112 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a7a43371b306 | 113 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a7a43371b306 | 114 | } |
ram54288 | 0:a7a43371b306 | 115 | |
ram54288 | 0:a7a43371b306 | 116 | void Test_M2MFirmware::test_create_resource_int() |
ram54288 | 0:a7a43371b306 | 117 | { |
ram54288 | 0:a7a43371b306 | 118 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 119 | "name", |
ram54288 | 0:a7a43371b306 | 120 | "type", |
ram54288 | 0:a7a43371b306 | 121 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 122 | false, |
ram54288 | 0:a7a43371b306 | 123 | "name"); |
ram54288 | 0:a7a43371b306 | 124 | |
ram54288 | 0:a7a43371b306 | 125 | CHECK(firmware->create_resource(M2MFirmware::PackageVersion,10) == NULL); |
ram54288 | 0:a7a43371b306 | 126 | CHECK(firmware->create_resource(M2MFirmware::PackageName,10) == NULL); |
ram54288 | 0:a7a43371b306 | 127 | CHECK(firmware->create_resource(M2MFirmware::Package,10) == NULL); |
ram54288 | 0:a7a43371b306 | 128 | CHECK(firmware->create_resource(M2MFirmware::Update,10) == NULL); |
ram54288 | 0:a7a43371b306 | 129 | |
ram54288 | 0:a7a43371b306 | 130 | m2mbase_stub::void_value = malloc(20); |
ram54288 | 0:a7a43371b306 | 131 | |
ram54288 | 0:a7a43371b306 | 132 | CHECK(firmware->create_resource(M2MFirmware::UpdateSupportedObjects,false) != NULL); |
ram54288 | 0:a7a43371b306 | 133 | CHECK(firmware->create_resource(M2MFirmware::UpdateSupportedObjects,true) != NULL); |
ram54288 | 0:a7a43371b306 | 134 | CHECK(firmware->create_resource(M2MFirmware::UpdateSupportedObjects,5) == NULL); |
ram54288 | 0:a7a43371b306 | 135 | CHECK(M2MBase::GET_PUT_ALLOWED == m2mbase_stub::operation); |
ram54288 | 0:a7a43371b306 | 136 | |
ram54288 | 0:a7a43371b306 | 137 | CHECK(firmware->create_resource(M2MFirmware::Update,10) == NULL); |
ram54288 | 0:a7a43371b306 | 138 | |
ram54288 | 0:a7a43371b306 | 139 | free(m2mbase_stub::void_value); |
ram54288 | 0:a7a43371b306 | 140 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a7a43371b306 | 141 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a7a43371b306 | 142 | } |
ram54288 | 0:a7a43371b306 | 143 | |
ram54288 | 0:a7a43371b306 | 144 | |
ram54288 | 0:a7a43371b306 | 145 | void Test_M2MFirmware::test_delete_resource() |
ram54288 | 0:a7a43371b306 | 146 | { |
ram54288 | 0:a7a43371b306 | 147 | m2mobjectinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 148 | |
ram54288 | 0:a7a43371b306 | 149 | CHECK(firmware->delete_resource(M2MFirmware::PackageName) == true); |
ram54288 | 0:a7a43371b306 | 150 | CHECK(firmware->delete_resource(M2MFirmware::PackageVersion) == true); |
ram54288 | 0:a7a43371b306 | 151 | CHECK(firmware->delete_resource(M2MFirmware::UpdateSupportedObjects) == true); |
ram54288 | 0:a7a43371b306 | 152 | |
ram54288 | 0:a7a43371b306 | 153 | CHECK(firmware->delete_resource(M2MFirmware::Package) == false); |
ram54288 | 0:a7a43371b306 | 154 | CHECK(firmware->delete_resource(M2MFirmware::PackageUri) == false); |
ram54288 | 0:a7a43371b306 | 155 | CHECK(firmware->delete_resource(M2MFirmware::State) == false); |
ram54288 | 0:a7a43371b306 | 156 | CHECK(firmware->delete_resource(M2MFirmware::UpdateResult) == false); |
ram54288 | 0:a7a43371b306 | 157 | CHECK(firmware->delete_resource(M2MFirmware::Update) == false); |
ram54288 | 0:a7a43371b306 | 158 | } |
ram54288 | 0:a7a43371b306 | 159 | |
ram54288 | 0:a7a43371b306 | 160 | void Test_M2MFirmware::test_set_resource_value_string() |
ram54288 | 0:a7a43371b306 | 161 | { |
ram54288 | 0:a7a43371b306 | 162 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a7a43371b306 | 163 | m2mbase_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 164 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 165 | |
ram54288 | 0:a7a43371b306 | 166 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 167 | "name", |
ram54288 | 0:a7a43371b306 | 168 | "type", |
ram54288 | 0:a7a43371b306 | 169 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 170 | false, |
ram54288 | 0:a7a43371b306 | 171 | "name"); |
ram54288 | 0:a7a43371b306 | 172 | m2mresource_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 173 | |
ram54288 | 0:a7a43371b306 | 174 | m2mbase_stub::void_value = malloc(20); |
ram54288 | 0:a7a43371b306 | 175 | |
ram54288 | 0:a7a43371b306 | 176 | CHECK(firmware->set_resource_value(M2MFirmware::PackageName,"test") == true); |
ram54288 | 0:a7a43371b306 | 177 | CHECK(firmware->set_resource_value(M2MFirmware::PackageVersion,"test") == true); |
ram54288 | 0:a7a43371b306 | 178 | CHECK(firmware->set_resource_value(M2MFirmware::PackageUri,"test") == true); |
ram54288 | 0:a7a43371b306 | 179 | CHECK(firmware->set_resource_value(M2MFirmware::PackageUri,"") == true); |
ram54288 | 0:a7a43371b306 | 180 | |
ram54288 | 0:a7a43371b306 | 181 | // Check size limit |
ram54288 | 0:a7a43371b306 | 182 | String test = ""; |
ram54288 | 0:a7a43371b306 | 183 | for (int i = 0; i <= 255; i++) { |
ram54288 | 0:a7a43371b306 | 184 | test.append("a", 1); |
ram54288 | 0:a7a43371b306 | 185 | } |
ram54288 | 0:a7a43371b306 | 186 | CHECK(firmware->set_resource_value(M2MFirmware::PackageUri,test) == false); |
ram54288 | 0:a7a43371b306 | 187 | |
ram54288 | 0:a7a43371b306 | 188 | CHECK(firmware->set_resource_value(M2MFirmware::Package,"test") == false); |
ram54288 | 0:a7a43371b306 | 189 | CHECK(firmware->set_resource_value(M2MFirmware::State,"test") == false); |
ram54288 | 0:a7a43371b306 | 190 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateResult,"test") == false); |
ram54288 | 0:a7a43371b306 | 191 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateSupportedObjects,"test") == false); |
ram54288 | 0:a7a43371b306 | 192 | CHECK(firmware->set_resource_value(M2MFirmware::Update,"test") == false); |
ram54288 | 0:a7a43371b306 | 193 | |
ram54288 | 0:a7a43371b306 | 194 | free(m2mbase_stub::void_value); |
ram54288 | 0:a7a43371b306 | 195 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 196 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 197 | } |
ram54288 | 0:a7a43371b306 | 198 | |
ram54288 | 0:a7a43371b306 | 199 | void Test_M2MFirmware::test_set_resource_value_int() |
ram54288 | 0:a7a43371b306 | 200 | { |
ram54288 | 0:a7a43371b306 | 201 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 202 | |
ram54288 | 0:a7a43371b306 | 203 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 204 | "name", |
ram54288 | 0:a7a43371b306 | 205 | "type", |
ram54288 | 0:a7a43371b306 | 206 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 207 | false, |
ram54288 | 0:a7a43371b306 | 208 | "name"); |
ram54288 | 0:a7a43371b306 | 209 | m2mresource_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 210 | |
ram54288 | 0:a7a43371b306 | 211 | m2mbase_stub::void_value = malloc(20); |
ram54288 | 0:a7a43371b306 | 212 | |
ram54288 | 0:a7a43371b306 | 213 | CHECK(firmware->set_resource_value(M2MFirmware::PackageName,10) == false); |
ram54288 | 0:a7a43371b306 | 214 | CHECK(firmware->set_resource_value(M2MFirmware::PackageVersion,10) == false); |
ram54288 | 0:a7a43371b306 | 215 | CHECK(firmware->set_resource_value(M2MFirmware::PackageUri,10) == false); |
ram54288 | 0:a7a43371b306 | 216 | |
ram54288 | 0:a7a43371b306 | 217 | CHECK(firmware->set_resource_value(M2MFirmware::Package,10) == false); |
ram54288 | 0:a7a43371b306 | 218 | CHECK(firmware->set_resource_value(M2MFirmware::State,2) == true); |
ram54288 | 0:a7a43371b306 | 219 | CHECK(firmware->set_resource_value(M2MFirmware::State,1) == true); |
ram54288 | 0:a7a43371b306 | 220 | CHECK(firmware->set_resource_value(M2MFirmware::State,3) == true); |
ram54288 | 0:a7a43371b306 | 221 | CHECK(firmware->set_resource_value(M2MFirmware::State,4) == false); |
ram54288 | 0:a7a43371b306 | 222 | CHECK(firmware->set_resource_value(M2MFirmware::State,0) == true); |
ram54288 | 0:a7a43371b306 | 223 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateResult,2) == true); |
ram54288 | 0:a7a43371b306 | 224 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateResult,20) == false); |
ram54288 | 0:a7a43371b306 | 225 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateSupportedObjects,true) == true); |
ram54288 | 0:a7a43371b306 | 226 | CHECK(firmware->set_resource_value(M2MFirmware::Update,10) == false); |
ram54288 | 0:a7a43371b306 | 227 | CHECK(firmware->check_value_range(M2MFirmware::Update,10) == false); |
ram54288 | 0:a7a43371b306 | 228 | |
ram54288 | 0:a7a43371b306 | 229 | free(m2mbase_stub::void_value); |
ram54288 | 0:a7a43371b306 | 230 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 231 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 232 | } |
ram54288 | 0:a7a43371b306 | 233 | |
ram54288 | 0:a7a43371b306 | 234 | |
ram54288 | 0:a7a43371b306 | 235 | void Test_M2MFirmware::test_resource_value_int() |
ram54288 | 0:a7a43371b306 | 236 | { |
ram54288 | 0:a7a43371b306 | 237 | uint8_t value[] = {"10"}; |
ram54288 | 0:a7a43371b306 | 238 | uint8_t* ptr = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 239 | m2mresourceinstance_stub::value = ptr; |
ram54288 | 0:a7a43371b306 | 240 | memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 241 | memcpy(m2mresourceinstance_stub::value, value,sizeof(value)); |
ram54288 | 0:a7a43371b306 | 242 | m2mresourceinstance_stub::int_value = (uint32_t)sizeof(value); |
ram54288 | 0:a7a43371b306 | 243 | |
ram54288 | 0:a7a43371b306 | 244 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 245 | "name", |
ram54288 | 0:a7a43371b306 | 246 | "type", |
ram54288 | 0:a7a43371b306 | 247 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 248 | false, |
ram54288 | 0:a7a43371b306 | 249 | "name"); |
ram54288 | 0:a7a43371b306 | 250 | |
ram54288 | 0:a7a43371b306 | 251 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 252 | m2mresource_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 253 | m2mbase_stub::void_value = malloc(20); |
ram54288 | 0:a7a43371b306 | 254 | |
ram54288 | 0:a7a43371b306 | 255 | CHECK(firmware->resource_value_int(M2MFirmware::State) == 10); |
ram54288 | 0:a7a43371b306 | 256 | CHECK(firmware->resource_value_int(M2MFirmware::UpdateResult) == 10); |
ram54288 | 0:a7a43371b306 | 257 | CHECK(firmware->resource_value_int(M2MFirmware::UpdateSupportedObjects) == 10); |
ram54288 | 0:a7a43371b306 | 258 | CHECK(firmware->resource_value_int(M2MFirmware::PackageName) == -1); |
ram54288 | 0:a7a43371b306 | 259 | CHECK(firmware->resource_value_int(M2MFirmware::Package) == -1); |
ram54288 | 0:a7a43371b306 | 260 | CHECK(firmware->resource_value_int(M2MFirmware::PackageUri) == -1); |
ram54288 | 0:a7a43371b306 | 261 | CHECK(firmware->resource_value_int(M2MFirmware::PackageVersion) == -1); |
ram54288 | 0:a7a43371b306 | 262 | CHECK(firmware->resource_value_int(M2MFirmware::Update) == -1); |
ram54288 | 0:a7a43371b306 | 263 | |
ram54288 | 0:a7a43371b306 | 264 | free(m2mbase_stub::void_value); |
ram54288 | 0:a7a43371b306 | 265 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 266 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 267 | |
ram54288 | 0:a7a43371b306 | 268 | free(ptr); |
ram54288 | 0:a7a43371b306 | 269 | } |
ram54288 | 0:a7a43371b306 | 270 | |
ram54288 | 0:a7a43371b306 | 271 | void Test_M2MFirmware::test_resource_value_string() |
ram54288 | 0:a7a43371b306 | 272 | { |
ram54288 | 0:a7a43371b306 | 273 | String test = "string"; |
ram54288 | 0:a7a43371b306 | 274 | uint8_t value[] = {"string"}; |
ram54288 | 0:a7a43371b306 | 275 | m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 276 | memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 277 | memcpy(m2mresourceinstance_stub::value,value,sizeof(value)); |
ram54288 | 0:a7a43371b306 | 278 | m2mresourceinstance_stub::int_value = (uint32_t)sizeof(value); |
ram54288 | 0:a7a43371b306 | 279 | |
ram54288 | 0:a7a43371b306 | 280 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 281 | "name", |
ram54288 | 0:a7a43371b306 | 282 | "type", |
ram54288 | 0:a7a43371b306 | 283 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 284 | false, |
ram54288 | 0:a7a43371b306 | 285 | "name"); |
ram54288 | 0:a7a43371b306 | 286 | |
ram54288 | 0:a7a43371b306 | 287 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 288 | m2mresource_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 289 | m2mbase_stub::void_value = malloc(20); |
ram54288 | 0:a7a43371b306 | 290 | |
ram54288 | 0:a7a43371b306 | 291 | CHECK(firmware->resource_value_string(M2MFirmware::PackageUri) == test); |
ram54288 | 0:a7a43371b306 | 292 | CHECK(firmware->resource_value_string(M2MFirmware::PackageName) == test); |
ram54288 | 0:a7a43371b306 | 293 | CHECK(firmware->resource_value_string(M2MFirmware::PackageVersion) == test); |
ram54288 | 0:a7a43371b306 | 294 | CHECK(firmware->resource_value_string(M2MFirmware::Package) == ""); |
ram54288 | 0:a7a43371b306 | 295 | CHECK(firmware->resource_value_string(M2MFirmware::Update) == ""); |
ram54288 | 0:a7a43371b306 | 296 | CHECK(firmware->resource_value_string(M2MFirmware::UpdateResult) == ""); |
ram54288 | 0:a7a43371b306 | 297 | CHECK(firmware->resource_value_string(M2MFirmware::UpdateSupportedObjects) == ""); |
ram54288 | 0:a7a43371b306 | 298 | CHECK(firmware->resource_value_string(M2MFirmware::State) == ""); |
ram54288 | 0:a7a43371b306 | 299 | |
ram54288 | 0:a7a43371b306 | 300 | free(m2mbase_stub::void_value); |
ram54288 | 0:a7a43371b306 | 301 | |
ram54288 | 0:a7a43371b306 | 302 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 303 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 304 | |
ram54288 | 0:a7a43371b306 | 305 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a7a43371b306 | 306 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a7a43371b306 | 307 | } |
ram54288 | 0:a7a43371b306 | 308 | |
ram54288 | 0:a7a43371b306 | 309 | void Test_M2MFirmware::test_is_resource_present() |
ram54288 | 0:a7a43371b306 | 310 | { |
ram54288 | 0:a7a43371b306 | 311 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 312 | "name", |
ram54288 | 0:a7a43371b306 | 313 | "type", |
ram54288 | 0:a7a43371b306 | 314 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 315 | false, |
ram54288 | 0:a7a43371b306 | 316 | "name"); |
ram54288 | 0:a7a43371b306 | 317 | m2mresource_stub::bool_value = false; |
ram54288 | 0:a7a43371b306 | 318 | CHECK(firmware->is_resource_present(M2MFirmware::PackageUri) == true); |
ram54288 | 0:a7a43371b306 | 319 | |
ram54288 | 0:a7a43371b306 | 320 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 321 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 322 | |
ram54288 | 0:a7a43371b306 | 323 | CHECK(firmware->is_resource_present(M2MFirmware::PackageName) == false); |
ram54288 | 0:a7a43371b306 | 324 | CHECK(firmware->is_resource_present(M2MFirmware::PackageVersion) == false); |
ram54288 | 0:a7a43371b306 | 325 | } |
ram54288 | 0:a7a43371b306 | 326 | |
ram54288 | 0:a7a43371b306 | 327 | void Test_M2MFirmware::test_per_resource_count() |
ram54288 | 0:a7a43371b306 | 328 | { |
ram54288 | 0:a7a43371b306 | 329 | m2mobjectinstance_stub::int_value = 1; |
ram54288 | 0:a7a43371b306 | 330 | CHECK(firmware->per_resource_count(M2MFirmware::Package) == 1); |
ram54288 | 0:a7a43371b306 | 331 | |
ram54288 | 0:a7a43371b306 | 332 | m2mobjectinstance_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 333 | |
ram54288 | 0:a7a43371b306 | 334 | CHECK(firmware->per_resource_count(M2MFirmware::PackageVersion) == 0); |
ram54288 | 0:a7a43371b306 | 335 | } |
ram54288 | 0:a7a43371b306 | 336 | |
ram54288 | 0:a7a43371b306 | 337 | |
ram54288 | 0:a7a43371b306 | 338 | |
ram54288 | 0:a7a43371b306 | 339 | void Test_M2MFirmware::test_total_resource_count() |
ram54288 | 0:a7a43371b306 | 340 | { |
ram54288 | 0:a7a43371b306 | 341 | M2MResource res(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 342 | "name", |
ram54288 | 0:a7a43371b306 | 343 | "type", |
ram54288 | 0:a7a43371b306 | 344 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 345 | false, |
ram54288 | 0:a7a43371b306 | 346 | "name"); |
ram54288 | 0:a7a43371b306 | 347 | |
ram54288 | 0:a7a43371b306 | 348 | m2mobjectinstance_stub::resource_list.push_back(&res); |
ram54288 | 0:a7a43371b306 | 349 | M2MResource res2(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 350 | "name", |
ram54288 | 0:a7a43371b306 | 351 | "type", |
ram54288 | 0:a7a43371b306 | 352 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 353 | false, |
ram54288 | 0:a7a43371b306 | 354 | "name"); |
ram54288 | 0:a7a43371b306 | 355 | |
ram54288 | 0:a7a43371b306 | 356 | m2mobjectinstance_stub::resource_list.push_back(&res2); |
ram54288 | 0:a7a43371b306 | 357 | |
ram54288 | 0:a7a43371b306 | 358 | CHECK(firmware->total_resource_count() == 2); |
ram54288 | 0:a7a43371b306 | 359 | |
ram54288 | 0:a7a43371b306 | 360 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:a7a43371b306 | 361 | } |
ram54288 | 0:a7a43371b306 | 362 | |
ram54288 | 0:a7a43371b306 | 363 | void Test_M2MFirmware::test_resource_value_buffer() |
ram54288 | 0:a7a43371b306 | 364 | { |
ram54288 | 0:a7a43371b306 | 365 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 366 | |
ram54288 | 0:a7a43371b306 | 367 | uint8_t value[] = {"buffer"}; |
ram54288 | 0:a7a43371b306 | 368 | uint8_t *out_value = NULL; |
ram54288 | 0:a7a43371b306 | 369 | |
ram54288 | 0:a7a43371b306 | 370 | m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 371 | memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value)); |
ram54288 | 0:a7a43371b306 | 372 | memcpy(m2mresourceinstance_stub::value,value,sizeof(value)); |
ram54288 | 0:a7a43371b306 | 373 | m2mresourceinstance_stub::int_value = (uint16_t)sizeof(value); |
ram54288 | 0:a7a43371b306 | 374 | |
ram54288 | 0:a7a43371b306 | 375 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 376 | "name", |
ram54288 | 0:a7a43371b306 | 377 | "type", |
ram54288 | 0:a7a43371b306 | 378 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 379 | false, |
ram54288 | 0:a7a43371b306 | 380 | "name"); |
ram54288 | 0:a7a43371b306 | 381 | |
ram54288 | 0:a7a43371b306 | 382 | CHECK(firmware->resource_value_buffer(M2MFirmware::Package,out_value) != 0); |
ram54288 | 0:a7a43371b306 | 383 | |
ram54288 | 0:a7a43371b306 | 384 | CHECK(firmware->resource_value_buffer(M2MFirmware::PackageName,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 385 | CHECK(firmware->resource_value_buffer(M2MFirmware::PackageUri,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 386 | CHECK(firmware->resource_value_buffer(M2MFirmware::PackageVersion,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 387 | CHECK(firmware->resource_value_buffer(M2MFirmware::Update,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 388 | CHECK(firmware->resource_value_buffer(M2MFirmware::State,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 389 | CHECK(firmware->resource_value_buffer(M2MFirmware::UpdateResult,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 390 | CHECK(firmware->resource_value_buffer(M2MFirmware::UpdateSupportedObjects,out_value) == 0); |
ram54288 | 0:a7a43371b306 | 391 | |
ram54288 | 0:a7a43371b306 | 392 | |
ram54288 | 0:a7a43371b306 | 393 | free(out_value); |
ram54288 | 0:a7a43371b306 | 394 | out_value = NULL; |
ram54288 | 0:a7a43371b306 | 395 | |
ram54288 | 0:a7a43371b306 | 396 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 397 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 398 | |
ram54288 | 0:a7a43371b306 | 399 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a7a43371b306 | 400 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a7a43371b306 | 401 | } |
ram54288 | 0:a7a43371b306 | 402 | |
ram54288 | 0:a7a43371b306 | 403 | void Test_M2MFirmware::test_set_resource_value_buffer() |
ram54288 | 0:a7a43371b306 | 404 | { |
ram54288 | 0:a7a43371b306 | 405 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a7a43371b306 | 406 | |
ram54288 | 0:a7a43371b306 | 407 | uint8_t value[] = {"value"}; |
ram54288 | 0:a7a43371b306 | 408 | uint16_t length = (uint16_t)sizeof(value); |
ram54288 | 0:a7a43371b306 | 409 | |
ram54288 | 0:a7a43371b306 | 410 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a7a43371b306 | 411 | "name", |
ram54288 | 0:a7a43371b306 | 412 | "type", |
ram54288 | 0:a7a43371b306 | 413 | M2MResourceInstance::STRING, |
ram54288 | 0:a7a43371b306 | 414 | false, |
ram54288 | 0:a7a43371b306 | 415 | "name"); |
ram54288 | 0:a7a43371b306 | 416 | |
ram54288 | 0:a7a43371b306 | 417 | CHECK(firmware->set_resource_value(M2MFirmware::Package,value,length) == true); |
ram54288 | 0:a7a43371b306 | 418 | CHECK(firmware->set_resource_value(M2MFirmware::PackageName,value,length) == false); |
ram54288 | 0:a7a43371b306 | 419 | CHECK(firmware->set_resource_value(M2MFirmware::PackageUri,value,length) == false); |
ram54288 | 0:a7a43371b306 | 420 | CHECK(firmware->set_resource_value(M2MFirmware::PackageVersion,value,length) == false); |
ram54288 | 0:a7a43371b306 | 421 | CHECK(firmware->set_resource_value(M2MFirmware::State,value,length) == false); |
ram54288 | 0:a7a43371b306 | 422 | CHECK(firmware->set_resource_value(M2MFirmware::Update,value,length) == false); |
ram54288 | 0:a7a43371b306 | 423 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateResult,value,length) == false); |
ram54288 | 0:a7a43371b306 | 424 | CHECK(firmware->set_resource_value(M2MFirmware::UpdateSupportedObjects,value,length) == false); |
ram54288 | 0:a7a43371b306 | 425 | |
ram54288 | 0:a7a43371b306 | 426 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a7a43371b306 | 427 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a7a43371b306 | 428 | } |
ram54288 | 0:a7a43371b306 | 429 | |
ram54288 | 0:a7a43371b306 | 430 | void Test_M2MFirmware::test_resource_name() |
ram54288 | 0:a7a43371b306 | 431 | { |
ram54288 | 0:a7a43371b306 | 432 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::Package), "0"); |
ram54288 | 0:a7a43371b306 | 433 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::PackageUri), "1"); |
ram54288 | 0:a7a43371b306 | 434 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::Update), "2"); |
ram54288 | 0:a7a43371b306 | 435 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::State), "3"); |
ram54288 | 0:a7a43371b306 | 436 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::UpdateSupportedObjects), "4"); |
ram54288 | 0:a7a43371b306 | 437 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::UpdateResult), "5"); |
ram54288 | 0:a7a43371b306 | 438 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::PackageName), "6"); |
ram54288 | 0:a7a43371b306 | 439 | STRCMP_EQUAL(firmware->resource_name(M2MFirmware::PackageVersion), "7"); |
ram54288 | 0:a7a43371b306 | 440 | } |