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