yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 3 | * Copyright (c) 2020-2021 Project CHIP Authors |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * @file |
| 21 | * This file implements a test for CHIP Interaction Model Message Def |
| 22 | * |
| 23 | */ |
| 24 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 25 | #include <app/MessageDef/CommandDataElement.h> |
| 26 | #include <app/MessageDef/CommandList.h> |
| 27 | #include <app/MessageDef/InvokeCommand.h> |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 28 | #include <app/MessageDef/ReadRequest.h> |
| 29 | #include <app/MessageDef/ReportData.h> |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 30 | #include <core/CHIPTLVDebug.hpp> |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 31 | #include <support/CHIPMem.h> |
Andrei Litvin | 05faf7d | 2020-11-30 21:01:07 -0500 | [diff] [blame] | 32 | #include <support/UnitTestRegistration.h> |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 33 | #include <system/TLVPacketBufferBackingStore.h> |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 34 | |
| 35 | #include <nlunit-test.h> |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | using namespace chip::app; |
| 40 | |
| 41 | void TLVPrettyPrinter(const char * aFormat, ...) |
| 42 | { |
| 43 | va_list args; |
| 44 | |
| 45 | va_start(args, aFormat); |
| 46 | |
| 47 | vprintf(aFormat, args); |
| 48 | |
| 49 | va_end(args); |
| 50 | } |
| 51 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 52 | CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 53 | { |
| 54 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 55 | chip::System::PacketBufferTLVReader reader; |
| 56 | reader.Init(aMsgBuf.Retain()); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 57 | err = reader.Next(); |
| 58 | chip::TLV::Debug::Dump(reader, TLVPrettyPrinter); |
| 59 | |
| 60 | if (CHIP_NO_ERROR != err) |
| 61 | { |
| 62 | ChipLogProgress(DataManagement, "DebugPrettyPrint fails with err %d", err); |
| 63 | } |
| 64 | |
| 65 | return err; |
| 66 | } |
| 67 | |
| 68 | void BuildAttributePath(nlTestSuite * apSuite, AttributePath::Builder & aAttributePathBuilder) |
| 69 | { |
| 70 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 71 | aAttributePathBuilder.NodeId(1).EndpointId(2).NamespacedClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); |
| 72 | err = aAttributePathBuilder.GetError(); |
| 73 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 74 | } |
| 75 | |
| 76 | void ParseAttributePath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 77 | { |
| 78 | AttributePath::Parser attributePathParser; |
| 79 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 80 | chip::NodeId nodeId = 1; |
| 81 | chip::EndpointId endpointId = 2; |
| 82 | chip::ClusterId namespacedClusterId = 3; |
| 83 | uint8_t fieldId = 4; |
| 84 | uint16_t listIndex = 5; |
| 85 | |
| 86 | err = attributePathParser.Init(aReader); |
| 87 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 88 | |
| 89 | err = attributePathParser.CheckSchemaValidity(); |
| 90 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 91 | |
| 92 | err = attributePathParser.GetNodeId(&nodeId); |
| 93 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); |
| 94 | |
| 95 | err = attributePathParser.GetEndpointId(&endpointId); |
| 96 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); |
| 97 | |
| 98 | err = attributePathParser.GetNamespacedClusterId(&namespacedClusterId); |
| 99 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && namespacedClusterId == 3); |
| 100 | |
| 101 | err = attributePathParser.GetFieldId(&fieldId); |
| 102 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && fieldId == 4); |
| 103 | |
| 104 | err = attributePathParser.GetListIndex(&listIndex); |
| 105 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && listIndex == 5); |
| 106 | } |
| 107 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 108 | void BuildAttributePathList(nlTestSuite * apSuite, AttributePathList::Builder & aAttributePathListBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 109 | { |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 110 | AttributePath::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePathBuilder(); |
| 111 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
| 112 | BuildAttributePath(apSuite, attributePathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 113 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 114 | aAttributePathListBuilder.EndOfAttributePathList(); |
| 115 | NL_TEST_ASSERT(apSuite, aAttributePathListBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 119 | { |
| 120 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 121 | AttributePathList::Parser attributePathListParser; |
| 122 | AttributePath::Parser attributePathParser; |
| 123 | |
| 124 | err = attributePathListParser.Init(aReader); |
| 125 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 126 | |
| 127 | err = attributePathListParser.CheckSchemaValidity(); |
| 128 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 129 | } |
| 130 | |
| 131 | void BuildEventPath(nlTestSuite * apSuite, EventPath::Builder & aEventPathBuilder) |
| 132 | { |
| 133 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 134 | aEventPathBuilder.NodeId(1).EndpointId(2).NamespacedClusterId(3).EventId(4).EndOfEventPath(); |
| 135 | err = aEventPathBuilder.GetError(); |
| 136 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 137 | } |
| 138 | |
| 139 | void ParseEventPath(nlTestSuite * apSuite, EventPath::Parser & aEventPathParser) |
| 140 | { |
| 141 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 142 | chip::NodeId nodeId = 1; |
| 143 | chip::EndpointId endpointId = 2; |
| 144 | chip::ClusterId namespacedClusterId = 3; |
| 145 | chip::EventId eventId = 4; |
| 146 | |
| 147 | err = aEventPathParser.CheckSchemaValidity(); |
| 148 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 149 | |
| 150 | err = aEventPathParser.GetNodeId(&nodeId); |
| 151 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); |
| 152 | |
| 153 | err = aEventPathParser.GetEndpointId(&endpointId); |
| 154 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); |
| 155 | |
| 156 | err = aEventPathParser.GetNamespacedClusterId(&namespacedClusterId); |
| 157 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && namespacedClusterId == 3); |
| 158 | |
| 159 | err = aEventPathParser.GetEventId(&eventId); |
| 160 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && eventId == 4); |
| 161 | } |
| 162 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 163 | void BuildEventPathList(nlTestSuite * apSuite, EventPathList::Builder & aEventPathListBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 164 | { |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 165 | EventPath::Builder eventPathBuilder = aEventPathListBuilder.CreateEventPathBuilder(); |
| 166 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 167 | BuildEventPath(apSuite, eventPathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 168 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 169 | aEventPathListBuilder.EndOfEventPathList(); |
| 170 | NL_TEST_ASSERT(apSuite, aEventPathListBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void ParseEventPathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 174 | { |
| 175 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 176 | EventPathList::Parser eventPathListParser; |
| 177 | |
| 178 | err = eventPathListParser.Init(aReader); |
| 179 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 180 | |
| 181 | err = eventPathListParser.CheckSchemaValidity(); |
| 182 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 183 | } |
| 184 | |
| 185 | void BuildCommandPath(nlTestSuite * apSuite, CommandPath::Builder & aCommandPathBuilder) |
| 186 | { |
| 187 | aCommandPathBuilder.EndpointId(1).NamespacedClusterId(3).CommandId(4).EndOfCommandPath(); |
| 188 | NL_TEST_ASSERT(apSuite, aCommandPathBuilder.GetError() == CHIP_NO_ERROR); |
| 189 | } |
| 190 | |
| 191 | void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 192 | { |
| 193 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 194 | CommandPath::Parser commandPathParser; |
| 195 | chip::EndpointId endpointId = 0; |
| 196 | chip::ClusterId namespacedClusterId = 0; |
| 197 | chip::CommandId commandId = 0; |
| 198 | |
| 199 | err = commandPathParser.Init(aReader); |
| 200 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 201 | |
| 202 | err = commandPathParser.CheckSchemaValidity(); |
| 203 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 204 | |
| 205 | err = commandPathParser.GetEndpointId(&endpointId); |
| 206 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 1); |
| 207 | |
| 208 | err = commandPathParser.GetNamespacedClusterId(&namespacedClusterId); |
| 209 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && namespacedClusterId == 3); |
| 210 | |
| 211 | err = commandPathParser.GetCommandId(&commandId); |
| 212 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && commandId == 4); |
| 213 | } |
| 214 | |
| 215 | void BuildEventDataElement(nlTestSuite * apSuite, EventDataElement::Builder & aEventDataElementBuilder) |
| 216 | { |
| 217 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 218 | |
| 219 | EventPath::Builder eventPathBuilder = aEventDataElementBuilder.CreateEventPathBuilder(); |
| 220 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 221 | BuildEventPath(apSuite, eventPathBuilder); |
| 222 | |
| 223 | aEventDataElementBuilder.ImportanceLevel(2).Number(3).UTCTimestamp(4).SystemTimestamp(5).DeltaUTCTime(6).DeltaSystemTime(7); |
| 224 | err = aEventDataElementBuilder.GetError(); |
| 225 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 226 | // Construct test event data |
| 227 | { |
| 228 | chip::TLV::TLVWriter * pWriter = aEventDataElementBuilder.GetWriter(); |
| 229 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 230 | err = |
| 231 | pWriter->StartContainer(chip::TLV::ContextTag(EventDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, dummyType); |
| 232 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 233 | |
| 234 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 235 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 236 | |
| 237 | err = pWriter->EndContainer(dummyType); |
| 238 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 239 | } |
| 240 | |
| 241 | aEventDataElementBuilder.EndOfEventDataElement(); |
| 242 | } |
| 243 | |
| 244 | void ParseEventDataElement(nlTestSuite * apSuite, EventDataElement::Parser & aEventDataElementParser) |
| 245 | { |
| 246 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 247 | uint8_t importanceLevel = 0; |
| 248 | uint64_t number = 0; |
| 249 | uint64_t uTCTimestamp = 0; |
| 250 | uint64_t systemTimestamp = 0; |
| 251 | uint64_t deltaUTCTime = 0; |
| 252 | uint64_t deltaSystemTime = 0; |
| 253 | |
| 254 | err = aEventDataElementParser.CheckSchemaValidity(); |
| 255 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 256 | |
| 257 | { |
| 258 | { |
| 259 | EventPath::Parser eventPath; |
| 260 | err = aEventDataElementParser.GetEventPath(&eventPath); |
| 261 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 262 | } |
| 263 | err = aEventDataElementParser.GetImportanceLevel(&importanceLevel); |
| 264 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && importanceLevel == 2); |
| 265 | err = aEventDataElementParser.GetNumber(&number); |
| 266 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && number == 3); |
| 267 | err = aEventDataElementParser.GetUTCTimestamp(&uTCTimestamp); |
| 268 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && uTCTimestamp == 4); |
| 269 | err = aEventDataElementParser.GetSystemTimestamp(&systemTimestamp); |
| 270 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && systemTimestamp == 5); |
| 271 | err = aEventDataElementParser.GetDeltaUTCTime(&deltaUTCTime); |
| 272 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaUTCTime == 6); |
| 273 | err = aEventDataElementParser.GetDeltaSystemTime(&deltaSystemTime); |
| 274 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaSystemTime == 7); |
| 275 | |
| 276 | { |
| 277 | chip::TLV::TLVReader reader; |
| 278 | bool val = false; |
| 279 | chip::TLV::TLVType container; |
| 280 | aEventDataElementParser.GetData(&reader); |
| 281 | err = reader.EnterContainer(container); |
| 282 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 283 | |
| 284 | err = reader.Next(); |
| 285 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 286 | |
| 287 | err = reader.Get(val); |
| 288 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 289 | |
| 290 | err = reader.ExitContainer(container); |
| 291 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void BuildEventList(nlTestSuite * apSuite, EventList::Builder & aEventListBuilder) |
| 297 | { |
| 298 | EventDataElement::Builder eventDataElementBuilder = aEventListBuilder.CreateEventBuilder(); |
| 299 | NL_TEST_ASSERT(apSuite, eventDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 300 | BuildEventDataElement(apSuite, eventDataElementBuilder); |
| 301 | |
| 302 | aEventListBuilder.EndOfEventList(); |
| 303 | NL_TEST_ASSERT(apSuite, aEventListBuilder.GetError() == CHIP_NO_ERROR); |
| 304 | } |
| 305 | |
| 306 | void ParseEventList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 307 | { |
| 308 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 309 | EventList::Parser eventListParser; |
| 310 | |
| 311 | err = eventListParser.Init(aReader); |
| 312 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 313 | |
| 314 | err = eventListParser.CheckSchemaValidity(); |
| 315 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 316 | } |
| 317 | |
| 318 | void BuildStatusElement(nlTestSuite * apSuite, StatusElement::Builder & aStatusElementBuilder) |
| 319 | { |
| 320 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 321 | |
| 322 | aStatusElementBuilder.EncodeStatusElement(1, 2, 3, 4).EndOfStatusElement(); |
| 323 | err = aStatusElementBuilder.GetError(); |
| 324 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 325 | } |
| 326 | |
| 327 | void ParseStatusElement(nlTestSuite * apSuite, StatusElement::Parser & aStatusElementParser) |
| 328 | { |
| 329 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 330 | StatusElement::Parser StatusElementParser; |
| 331 | |
| 332 | uint16_t generalCode = 0; |
| 333 | uint32_t protocolId = 0; |
| 334 | uint16_t protocolCode = 0; |
| 335 | chip::ClusterId namespacedClusterId = 0; |
| 336 | |
| 337 | err = aStatusElementParser.CheckSchemaValidity(); |
| 338 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 339 | |
| 340 | err = aStatusElementParser.DecodeStatusElement(&generalCode, &protocolId, &protocolCode, &namespacedClusterId); |
| 341 | NL_TEST_ASSERT(apSuite, |
| 342 | err == CHIP_NO_ERROR && generalCode == 1 && protocolId == 2 && protocolCode == 3 && namespacedClusterId == 4); |
| 343 | } |
| 344 | |
| 345 | void BuildAttributeStatusElement(nlTestSuite * apSuite, AttributeStatusElement::Builder & aAttributeStatusElementBuilder) |
| 346 | { |
| 347 | AttributePath::Builder attributePathBuilder = aAttributeStatusElementBuilder.CreateAttributePathBuilder(); |
| 348 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
| 349 | BuildAttributePath(apSuite, attributePathBuilder); |
| 350 | |
| 351 | StatusElement::Builder statusElementBuilder = aAttributeStatusElementBuilder.CreateStatusElementBuilder(); |
| 352 | NL_TEST_ASSERT(apSuite, statusElementBuilder.GetError() == CHIP_NO_ERROR); |
| 353 | BuildStatusElement(apSuite, statusElementBuilder); |
| 354 | |
| 355 | aAttributeStatusElementBuilder.EndOfAttributeStatusElement(); |
| 356 | NL_TEST_ASSERT(apSuite, aAttributeStatusElementBuilder.GetError() == CHIP_NO_ERROR); |
| 357 | } |
| 358 | |
| 359 | void ParseAttributeStatusElement(nlTestSuite * apSuite, AttributeStatusElement::Parser & aAttributeStatusElementParser) |
| 360 | { |
| 361 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 362 | AttributePath::Parser attributePathParser; |
| 363 | StatusElement::Parser statusElementParser; |
| 364 | |
| 365 | err = aAttributeStatusElementParser.CheckSchemaValidity(); |
| 366 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 367 | |
| 368 | err = aAttributeStatusElementParser.GetAttributePath(&attributePathParser); |
| 369 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 370 | |
| 371 | err = aAttributeStatusElementParser.GetStatusElement(&statusElementParser); |
| 372 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 373 | } |
| 374 | |
| 375 | void BuildAttributeStatusList(nlTestSuite * apSuite, AttributeStatusList::Builder & aAttributeStatusListBuilder) |
| 376 | { |
| 377 | AttributeStatusElement::Builder aAttributeStatusElementBuilder = aAttributeStatusListBuilder.CreateAttributeStatusBuilder(); |
| 378 | NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); |
| 379 | BuildAttributeStatusElement(apSuite, aAttributeStatusElementBuilder); |
| 380 | |
| 381 | aAttributeStatusListBuilder.EndOfAttributeStatusList(); |
| 382 | NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); |
| 383 | } |
| 384 | |
| 385 | void ParseAttributeStatusList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 386 | { |
| 387 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 388 | AttributeStatusList::Parser attributeStatusParser; |
| 389 | |
| 390 | err = attributeStatusParser.Init(aReader); |
| 391 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 392 | |
| 393 | err = attributeStatusParser.CheckSchemaValidity(); |
| 394 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 395 | } |
| 396 | |
| 397 | void BuildAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Builder & aAttributeDataElementBuilder) |
| 398 | { |
| 399 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 400 | |
| 401 | AttributePath::Builder attributePathBuilder = aAttributeDataElementBuilder.CreateAttributePathBuilder(); |
| 402 | NL_TEST_ASSERT(apSuite, aAttributeDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 403 | BuildAttributePath(apSuite, attributePathBuilder); |
| 404 | |
| 405 | aAttributeDataElementBuilder.DataVersion(2); |
| 406 | err = aAttributeDataElementBuilder.GetError(); |
| 407 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 408 | |
| 409 | // Construct attribute data |
| 410 | { |
| 411 | chip::TLV::TLVWriter * pWriter = aAttributeDataElementBuilder.GetWriter(); |
| 412 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 413 | err = pWriter->StartContainer(chip::TLV::ContextTag(AttributeDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, |
| 414 | dummyType); |
| 415 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 416 | |
| 417 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 418 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 419 | |
| 420 | err = pWriter->EndContainer(dummyType); |
| 421 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 422 | } |
| 423 | |
| 424 | aAttributeDataElementBuilder.MoreClusterData(true); |
| 425 | err = aAttributeDataElementBuilder.GetError(); |
| 426 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 427 | |
| 428 | aAttributeDataElementBuilder.EndOfAttributeDataElement(); |
| 429 | NL_TEST_ASSERT(apSuite, aAttributeDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 430 | } |
| 431 | |
| 432 | void ParseAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Parser & aAttributeDataElementParser) |
| 433 | { |
| 434 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 435 | AttributePath::Parser attributePathParser; |
| 436 | StatusElement::Parser statusElementParser; |
| 437 | chip::DataVersion version = 0; |
| 438 | bool moreClusterDataFlag = false; |
| 439 | |
| 440 | err = aAttributeDataElementParser.CheckSchemaValidity(); |
| 441 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 442 | |
| 443 | err = aAttributeDataElementParser.GetAttributePath(&attributePathParser); |
| 444 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 445 | |
| 446 | err = aAttributeDataElementParser.GetDataVersion(&version); |
| 447 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && version == 2); |
| 448 | |
| 449 | { |
| 450 | chip::TLV::TLVReader reader; |
| 451 | bool val = false; |
| 452 | chip::TLV::TLVType container; |
| 453 | aAttributeDataElementParser.GetData(&reader); |
| 454 | err = reader.EnterContainer(container); |
| 455 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 456 | |
| 457 | err = reader.Next(); |
| 458 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 459 | |
| 460 | err = reader.Get(val); |
| 461 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 462 | |
| 463 | err = reader.ExitContainer(container); |
| 464 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 465 | } |
| 466 | |
| 467 | err = aAttributeDataElementParser.GetMoreClusterDataFlag(&moreClusterDataFlag); |
| 468 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreClusterDataFlag); |
| 469 | } |
| 470 | |
| 471 | void BuildAttributeDataList(nlTestSuite * apSuite, AttributeDataList::Builder & aAttributeDataListBuilder) |
| 472 | { |
| 473 | AttributeDataElement::Builder attributeDataElementBuilder = aAttributeDataListBuilder.CreateAttributeDataElementBuilder(); |
| 474 | NL_TEST_ASSERT(apSuite, aAttributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 475 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder); |
| 476 | |
| 477 | aAttributeDataListBuilder.EndOfAttributeDataList(); |
| 478 | NL_TEST_ASSERT(apSuite, aAttributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 479 | } |
| 480 | |
| 481 | void ParseAttributeDataList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 482 | { |
| 483 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 484 | AttributeDataList::Parser attributeDataListParser; |
| 485 | |
| 486 | err = attributeDataListParser.Init(aReader); |
| 487 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 488 | |
| 489 | err = attributeDataListParser.CheckSchemaValidity(); |
| 490 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 491 | } |
| 492 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 493 | void BuildAttributeDataVersionList(nlTestSuite * apSuite, AttributeDataVersionList::Builder & aAttributeDataVersionListBuilder) |
| 494 | { |
| 495 | aAttributeDataVersionListBuilder.AddVersion(1); |
| 496 | |
| 497 | aAttributeDataVersionListBuilder.EndOfAttributeDataVersionList(); |
| 498 | NL_TEST_ASSERT(apSuite, aAttributeDataVersionListBuilder.GetError() == CHIP_NO_ERROR); |
| 499 | } |
| 500 | |
| 501 | void ParseAttributeDataVersionList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 502 | { |
| 503 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 504 | chip::DataVersion version; |
| 505 | AttributeDataVersionList::Parser attributeDataVersionListParser; |
| 506 | |
| 507 | err = attributeDataVersionListParser.Init(aReader); |
| 508 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 509 | |
| 510 | err = attributeDataVersionListParser.CheckSchemaValidity(); |
| 511 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 512 | |
| 513 | attributeDataVersionListParser.GetVersion(&version); |
| 514 | } |
| 515 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 516 | void BuildCommandDataElement(nlTestSuite * apSuite, CommandDataElement::Builder & aCommandDataElementBuilder) |
| 517 | { |
| 518 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 519 | |
| 520 | CommandPath::Builder commandPathBuilder = aCommandDataElementBuilder.CreateCommandPathBuilder(); |
| 521 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 522 | BuildCommandPath(apSuite, commandPathBuilder); |
| 523 | |
| 524 | // Construct command data |
| 525 | { |
| 526 | chip::TLV::TLVWriter * pWriter = aCommandDataElementBuilder.GetWriter(); |
| 527 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 528 | err = pWriter->StartContainer(chip::TLV::ContextTag(CommandDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, |
| 529 | dummyType); |
| 530 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 531 | |
| 532 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 533 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 534 | |
| 535 | err = pWriter->EndContainer(dummyType); |
| 536 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 537 | } |
| 538 | |
| 539 | aCommandDataElementBuilder.EndOfCommandDataElement(); |
| 540 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 541 | } |
| 542 | |
| 543 | void ParseCommandDataElement(nlTestSuite * apSuite, CommandDataElement::Parser & aCommandDataElementParser) |
| 544 | { |
| 545 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 546 | CommandPath::Parser commandPathParser; |
| 547 | |
| 548 | err = aCommandDataElementParser.CheckSchemaValidity(); |
| 549 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 550 | |
| 551 | err = aCommandDataElementParser.GetCommandPath(&commandPathParser); |
| 552 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 553 | |
| 554 | { |
| 555 | chip::TLV::TLVReader reader; |
| 556 | bool val = false; |
| 557 | chip::TLV::TLVType container; |
| 558 | aCommandDataElementParser.GetData(&reader); |
| 559 | err = reader.EnterContainer(container); |
| 560 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 561 | |
| 562 | err = reader.Next(); |
| 563 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 564 | |
| 565 | err = reader.Get(val); |
| 566 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 567 | |
| 568 | err = reader.ExitContainer(container); |
| 569 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void BuildCommandList(nlTestSuite * apSuite, CommandList::Builder & aCommandListBuilder) |
| 574 | { |
| 575 | CommandDataElement::Builder commandDataElementBuilder = aCommandListBuilder.CreateCommandDataElementBuilder(); |
| 576 | NL_TEST_ASSERT(apSuite, aCommandListBuilder.GetError() == CHIP_NO_ERROR); |
| 577 | BuildCommandDataElement(apSuite, commandDataElementBuilder); |
| 578 | |
| 579 | aCommandListBuilder.EndOfCommandList(); |
| 580 | NL_TEST_ASSERT(apSuite, aCommandListBuilder.GetError() == CHIP_NO_ERROR); |
| 581 | } |
| 582 | |
| 583 | void ParseCommandList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 584 | { |
| 585 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 586 | CommandList::Parser commandListParser; |
| 587 | commandListParser.Init(aReader); |
| 588 | err = commandListParser.CheckSchemaValidity(); |
| 589 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 590 | } |
| 591 | |
| 592 | void BuildReportData(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 593 | { |
| 594 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 595 | ReportData::Builder reportDataBuilder; |
| 596 | |
| 597 | err = reportDataBuilder.Init(&aWriter); |
| 598 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 599 | |
| 600 | reportDataBuilder.RequestResponse(1).SubscriptionId(2); |
| 601 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 602 | |
| 603 | AttributeStatusList::Builder attributeStatusList = reportDataBuilder.CreateAttributeStatusListBuilder(); |
| 604 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 605 | BuildAttributeStatusList(apSuite, attributeStatusList); |
| 606 | |
| 607 | AttributeDataList::Builder attributeDataList = reportDataBuilder.CreateAttributeDataListBuilder(); |
| 608 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 609 | BuildAttributeDataList(apSuite, attributeDataList); |
| 610 | |
| 611 | EventList::Builder eventList = reportDataBuilder.CreateEventDataListBuilder(); |
| 612 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 613 | BuildEventList(apSuite, eventList); |
| 614 | |
| 615 | reportDataBuilder.IsLastReport(6); |
| 616 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 617 | |
| 618 | reportDataBuilder.EndOfReportData(); |
| 619 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 620 | } |
| 621 | |
| 622 | void ParseReportData(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 623 | { |
| 624 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 625 | ReportData::Parser reportDataParser; |
| 626 | |
| 627 | bool requestResponse = false; |
| 628 | uint64_t subscriptionId = 0; |
| 629 | AttributeStatusList::Parser attributeStatusListParser; |
| 630 | AttributeDataList::Parser attributeDataListParser; |
| 631 | EventList::Parser eventListParser; |
| 632 | bool isLastReport = false; |
| 633 | reportDataParser.Init(aReader); |
| 634 | |
| 635 | err = reportDataParser.CheckSchemaValidity(); |
| 636 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 637 | |
| 638 | err = reportDataParser.GetRequestResponse(&requestResponse); |
| 639 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && requestResponse); |
| 640 | |
| 641 | err = reportDataParser.GetSubscriptionId(&subscriptionId); |
| 642 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && subscriptionId == 2); |
| 643 | |
| 644 | err = reportDataParser.GetAttributeStatusList(&attributeStatusListParser); |
| 645 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 646 | |
| 647 | err = reportDataParser.GetAttributeDataList(&attributeDataListParser); |
| 648 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 649 | |
| 650 | err = reportDataParser.GetEventDataList(&eventListParser); |
| 651 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 652 | |
| 653 | err = reportDataParser.GetIsLastReport(&isLastReport); |
| 654 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isLastReport); |
| 655 | } |
| 656 | |
| 657 | void BuildInvokeCommand(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 658 | { |
| 659 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 660 | InvokeCommand::Builder invokeCommandBuilder; |
| 661 | |
| 662 | err = invokeCommandBuilder.Init(&aWriter); |
| 663 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 664 | |
| 665 | CommandList::Builder commandList = invokeCommandBuilder.CreateCommandListBuilder(); |
| 666 | NL_TEST_ASSERT(apSuite, invokeCommandBuilder.GetError() == CHIP_NO_ERROR); |
| 667 | BuildCommandList(apSuite, commandList); |
| 668 | |
| 669 | invokeCommandBuilder.EndOfInvokeCommand(); |
| 670 | NL_TEST_ASSERT(apSuite, invokeCommandBuilder.GetError() == CHIP_NO_ERROR); |
| 671 | } |
| 672 | |
| 673 | void ParseInvokeCommand(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 674 | { |
| 675 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 676 | |
| 677 | InvokeCommand::Parser invokeCommandParser; |
| 678 | CommandList::Parser commandListParser; |
| 679 | |
| 680 | err = invokeCommandParser.Init(aReader); |
| 681 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 682 | |
| 683 | err = invokeCommandParser.CheckSchemaValidity(); |
| 684 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 685 | |
| 686 | err = invokeCommandParser.GetCommandList(&commandListParser); |
| 687 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 688 | } |
| 689 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 690 | void BuildReadRequest(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 691 | { |
| 692 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 693 | ReadRequest::Builder readRequestBuilder; |
| 694 | |
| 695 | err = readRequestBuilder.Init(&aWriter); |
| 696 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 697 | |
| 698 | AttributePathList::Builder attributePathList = readRequestBuilder.CreateAttributePathListBuilder(); |
| 699 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 700 | BuildAttributePathList(apSuite, attributePathList); |
| 701 | |
| 702 | EventPathList::Builder eventPathList = readRequestBuilder.CreateEventPathListBuilder(); |
| 703 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 704 | BuildEventPathList(apSuite, eventPathList); |
| 705 | |
| 706 | AttributeDataVersionList::Builder attributeDataVersionList = readRequestBuilder.CreateAttributeDataVersionListBuilder(); |
| 707 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 708 | BuildAttributeDataVersionList(apSuite, attributeDataVersionList); |
| 709 | |
| 710 | readRequestBuilder.EventNumber(1); |
| 711 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 712 | |
| 713 | readRequestBuilder.EndOfReadRequest(); |
| 714 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 715 | } |
| 716 | |
| 717 | void ParseReadRequest(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 718 | { |
| 719 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 720 | |
| 721 | ReadRequest::Parser readRequestParser; |
| 722 | AttributePathList::Parser attributePathListParser; |
| 723 | EventPathList::Parser eventPathListParser; |
| 724 | AttributeDataVersionList::Parser attributeDataVersionListParser; |
| 725 | uint64_t eventNumber; |
| 726 | |
| 727 | err = readRequestParser.Init(aReader); |
| 728 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 729 | |
| 730 | err = readRequestParser.CheckSchemaValidity(); |
| 731 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 732 | |
| 733 | err = readRequestParser.GetAttributePathList(&attributePathListParser); |
| 734 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 735 | |
| 736 | err = readRequestParser.GetEventPathList(&eventPathListParser); |
| 737 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 738 | |
| 739 | err = readRequestParser.GetAttributeDataVersionList(&attributeDataVersionListParser); |
| 740 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 741 | |
| 742 | err = readRequestParser.GetEventNumber(&eventNumber); |
| 743 | NL_TEST_ASSERT(apSuite, eventNumber == 1 && err == CHIP_NO_ERROR); |
| 744 | } |
| 745 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 746 | void AttributePathTest(nlTestSuite * apSuite, void * apContext) |
| 747 | { |
| 748 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 749 | AttributePath::Builder attributePathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 750 | chip::System::PacketBufferTLVWriter writer; |
| 751 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 752 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 753 | attributePathBuilder.Init(&writer); |
| 754 | BuildAttributePath(apSuite, attributePathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 755 | chip::System::PacketBufferHandle buf; |
| 756 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 757 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 758 | |
| 759 | DebugPrettyPrint(buf); |
| 760 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 761 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 762 | err = reader.Next(); |
| 763 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 764 | |
| 765 | ParseAttributePath(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | void AttributePathListTest(nlTestSuite * apSuite, void * apContext) |
| 769 | { |
| 770 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 771 | chip::System::PacketBufferTLVWriter writer; |
| 772 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 773 | AttributePathList::Builder attributePathListBuilder; |
| 774 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 775 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 776 | |
| 777 | err = attributePathListBuilder.Init(&writer); |
| 778 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 779 | |
| 780 | BuildAttributePathList(apSuite, attributePathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 781 | chip::System::PacketBufferHandle buf; |
| 782 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 783 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 784 | |
| 785 | DebugPrettyPrint(buf); |
| 786 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 787 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 788 | err = reader.Next(); |
| 789 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 790 | ParseAttributePathList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | void EventPathTest(nlTestSuite * apSuite, void * apContext) |
| 794 | { |
| 795 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 796 | EventPath::Parser eventPathParser; |
| 797 | EventPath::Builder eventPathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 798 | chip::System::PacketBufferTLVWriter writer; |
| 799 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 800 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 801 | eventPathBuilder.Init(&writer); |
| 802 | BuildEventPath(apSuite, eventPathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 803 | chip::System::PacketBufferHandle buf; |
| 804 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 805 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 806 | |
| 807 | DebugPrettyPrint(buf); |
| 808 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 809 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 810 | err = reader.Next(); |
| 811 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 812 | |
| 813 | eventPathParser.Init(reader); |
| 814 | ParseEventPath(apSuite, eventPathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | void EventPathListTest(nlTestSuite * apSuite, void * apContext) |
| 818 | { |
| 819 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 820 | chip::System::PacketBufferTLVWriter writer; |
| 821 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 822 | EventPathList::Builder eventPathListBuilder; |
| 823 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 824 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 825 | |
| 826 | err = eventPathListBuilder.Init(&writer); |
| 827 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 828 | |
| 829 | BuildEventPathList(apSuite, eventPathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 830 | chip::System::PacketBufferHandle buf; |
| 831 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 832 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 833 | |
| 834 | DebugPrettyPrint(buf); |
| 835 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 836 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 837 | err = reader.Next(); |
| 838 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 839 | ParseEventPathList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | void CommandPathTest(nlTestSuite * apSuite, void * apContext) |
| 843 | { |
| 844 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 845 | chip::System::PacketBufferTLVWriter writer; |
| 846 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 847 | CommandPath::Builder commandPathBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 848 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 849 | err = commandPathBuilder.Init(&writer); |
| 850 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 851 | |
| 852 | BuildCommandPath(apSuite, commandPathBuilder); |
| 853 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 854 | chip::System::PacketBufferHandle buf; |
| 855 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 856 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 857 | |
| 858 | DebugPrettyPrint(buf); |
| 859 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 860 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 861 | err = reader.Next(); |
| 862 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 863 | |
| 864 | ParseCommandPath(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void EventDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 868 | { |
| 869 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 870 | EventDataElement::Builder eventDataElementBuilder; |
| 871 | EventDataElement::Parser eventDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 872 | chip::System::PacketBufferTLVWriter writer; |
| 873 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 874 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 875 | eventDataElementBuilder.Init(&writer); |
| 876 | BuildEventDataElement(apSuite, eventDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 877 | chip::System::PacketBufferHandle buf; |
| 878 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 879 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 880 | |
| 881 | DebugPrettyPrint(buf); |
| 882 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 883 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 884 | err = reader.Next(); |
| 885 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 886 | |
| 887 | eventDataElementParser.Init(reader); |
| 888 | ParseEventDataElement(apSuite, eventDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | void EventListTest(nlTestSuite * apSuite, void * apContext) |
| 892 | { |
| 893 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 894 | chip::System::PacketBufferTLVWriter writer; |
| 895 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 896 | EventList::Builder eventListBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 897 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 898 | eventListBuilder.Init(&writer); |
| 899 | BuildEventList(apSuite, eventListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 900 | chip::System::PacketBufferHandle buf; |
| 901 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 902 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 903 | |
| 904 | DebugPrettyPrint(buf); |
| 905 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 906 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 907 | err = reader.Next(); |
| 908 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 909 | ParseEventList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | void StatusElementTest(nlTestSuite * apSuite, void * apContext) |
| 913 | { |
| 914 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 915 | StatusElement::Builder statusElementBuilder; |
| 916 | StatusElement::Parser statusElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 917 | chip::System::PacketBufferTLVWriter writer; |
| 918 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 919 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 920 | statusElementBuilder.Init(&writer); |
| 921 | BuildStatusElement(apSuite, statusElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 922 | chip::System::PacketBufferHandle buf; |
| 923 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 924 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 925 | |
| 926 | DebugPrettyPrint(buf); |
| 927 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 928 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 929 | err = reader.Next(); |
| 930 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 931 | |
| 932 | statusElementParser.Init(reader); |
| 933 | ParseStatusElement(apSuite, statusElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | void AttributeStatusElementTest(nlTestSuite * apSuite, void * apContext) |
| 937 | { |
| 938 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 939 | AttributeStatusElement::Builder attributeStatusElementBuilder; |
| 940 | AttributeStatusElement::Parser attributeStatusElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 941 | chip::System::PacketBufferTLVWriter writer; |
| 942 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 943 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 944 | attributeStatusElementBuilder.Init(&writer); |
| 945 | BuildAttributeStatusElement(apSuite, attributeStatusElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 946 | chip::System::PacketBufferHandle buf; |
| 947 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 948 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 949 | |
| 950 | DebugPrettyPrint(buf); |
| 951 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 952 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 953 | err = reader.Next(); |
| 954 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 955 | |
| 956 | attributeStatusElementParser.Init(reader); |
| 957 | ParseAttributeStatusElement(apSuite, attributeStatusElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | void AttributeStatusListTest(nlTestSuite * apSuite, void * apContext) |
| 961 | { |
| 962 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 963 | chip::System::PacketBufferTLVWriter writer; |
| 964 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 965 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 966 | AttributeStatusList::Builder attributeStatusListBuilder; |
| 967 | err = attributeStatusListBuilder.Init(&writer); |
| 968 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 969 | BuildAttributeStatusList(apSuite, attributeStatusListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 970 | chip::System::PacketBufferHandle buf; |
| 971 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 972 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 973 | |
| 974 | DebugPrettyPrint(buf); |
| 975 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 976 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 977 | err = reader.Next(); |
| 978 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 979 | ParseAttributeStatusList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | void AttributeDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 983 | { |
| 984 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 985 | AttributeDataElement::Builder attributeDataElementBuilder; |
| 986 | AttributeDataElement::Parser attributeDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 987 | chip::System::PacketBufferTLVWriter writer; |
| 988 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 989 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 990 | attributeDataElementBuilder.Init(&writer); |
| 991 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 992 | chip::System::PacketBufferHandle buf; |
| 993 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 994 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 995 | |
| 996 | DebugPrettyPrint(buf); |
| 997 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 998 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 999 | err = reader.Next(); |
| 1000 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1001 | |
| 1002 | attributeDataElementParser.Init(reader); |
| 1003 | ParseAttributeDataElement(apSuite, attributeDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | void AttributeDataListTest(nlTestSuite * apSuite, void * apContext) |
| 1007 | { |
| 1008 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1009 | chip::System::PacketBufferTLVWriter writer; |
| 1010 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1011 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1012 | AttributeDataList::Builder attributeDataListBuilder; |
| 1013 | attributeDataListBuilder.Init(&writer); |
| 1014 | BuildAttributeDataList(apSuite, attributeDataListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1015 | chip::System::PacketBufferHandle buf; |
| 1016 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1017 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1018 | |
| 1019 | DebugPrettyPrint(buf); |
| 1020 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1021 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1022 | err = reader.Next(); |
| 1023 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1024 | ParseAttributeDataList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1027 | void AttributeDataVersionListTest(nlTestSuite * apSuite, void * apContext) |
| 1028 | { |
| 1029 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1030 | chip::System::PacketBufferTLVWriter writer; |
| 1031 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1032 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1033 | AttributeDataVersionList::Builder attributeDataVersionListBuilder; |
| 1034 | attributeDataVersionListBuilder.Init(&writer); |
| 1035 | BuildAttributeDataVersionList(apSuite, attributeDataVersionListBuilder); |
| 1036 | chip::System::PacketBufferHandle buf; |
| 1037 | err = writer.Finalize(&buf); |
| 1038 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1039 | |
| 1040 | DebugPrettyPrint(buf); |
| 1041 | |
| 1042 | reader.Init(std::move(buf)); |
| 1043 | err = reader.Next(); |
| 1044 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1045 | ParseAttributeDataVersionList(apSuite, reader); |
| 1046 | } |
| 1047 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1048 | void CommandDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 1049 | { |
| 1050 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1051 | CommandDataElement::Builder commandDataElementBuilder; |
| 1052 | CommandDataElement::Parser commandDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1053 | chip::System::PacketBufferTLVWriter writer; |
| 1054 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1055 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1056 | commandDataElementBuilder.Init(&writer); |
| 1057 | BuildCommandDataElement(apSuite, commandDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1058 | chip::System::PacketBufferHandle buf; |
| 1059 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1060 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1061 | |
| 1062 | DebugPrettyPrint(buf); |
| 1063 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1064 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1065 | err = reader.Next(); |
| 1066 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1067 | |
| 1068 | commandDataElementParser.Init(reader); |
| 1069 | ParseCommandDataElement(apSuite, commandDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | void CommandListTest(nlTestSuite * apSuite, void * apContext) |
| 1073 | { |
| 1074 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1075 | chip::System::PacketBufferTLVWriter writer; |
| 1076 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1077 | CommandList::Builder commandListBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1078 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1079 | commandListBuilder.Init(&writer); |
| 1080 | BuildCommandList(apSuite, commandListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1081 | chip::System::PacketBufferHandle buf; |
| 1082 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1083 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1084 | |
| 1085 | DebugPrettyPrint(buf); |
| 1086 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1087 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1088 | err = reader.Next(); |
| 1089 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1090 | ParseCommandList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | void ReportDataTest(nlTestSuite * apSuite, void * apContext) |
| 1094 | { |
| 1095 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1096 | chip::System::PacketBufferTLVWriter writer; |
| 1097 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1098 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1099 | BuildReportData(apSuite, writer); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1100 | chip::System::PacketBufferHandle buf; |
| 1101 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1102 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1103 | |
| 1104 | DebugPrettyPrint(buf); |
| 1105 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1106 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1107 | err = reader.Next(); |
| 1108 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1109 | ParseReportData(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | void InvokeCommandTest(nlTestSuite * apSuite, void * apContext) |
| 1113 | { |
| 1114 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1115 | chip::System::PacketBufferTLVWriter writer; |
| 1116 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1117 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1118 | BuildInvokeCommand(apSuite, writer); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1119 | chip::System::PacketBufferHandle buf; |
| 1120 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1121 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1122 | |
| 1123 | DebugPrettyPrint(buf); |
| 1124 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1125 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1126 | err = reader.Next(); |
| 1127 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1128 | ParseInvokeCommand(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1131 | void ReadRequestTest(nlTestSuite * apSuite, void * apContext) |
| 1132 | { |
| 1133 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1134 | chip::System::PacketBufferTLVWriter writer; |
| 1135 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1136 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1137 | BuildReadRequest(apSuite, writer); |
| 1138 | chip::System::PacketBufferHandle buf; |
| 1139 | err = writer.Finalize(&buf); |
| 1140 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1141 | |
| 1142 | DebugPrettyPrint(buf); |
| 1143 | |
| 1144 | reader.Init(std::move(buf)); |
| 1145 | err = reader.Next(); |
| 1146 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1147 | ParseReadRequest(apSuite, reader); |
| 1148 | } |
| 1149 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1150 | /** |
| 1151 | * Test Suite. It lists all the test functions. |
| 1152 | */ |
| 1153 | |
| 1154 | // clang-format off |
| 1155 | const nlTest sTests[] = |
| 1156 | { |
| 1157 | NL_TEST_DEF("AttributePathTest", AttributePathTest), |
| 1158 | NL_TEST_DEF("AttributePathListTest", AttributePathListTest), |
| 1159 | NL_TEST_DEF("EventPathTest", EventPathTest), |
| 1160 | NL_TEST_DEF("EventPathListTest", EventPathListTest), |
| 1161 | NL_TEST_DEF("CommandPathTest", CommandPathTest), |
| 1162 | NL_TEST_DEF("EventDataElementTest", EventDataElementTest), |
| 1163 | NL_TEST_DEF("EventListTest", EventListTest), |
| 1164 | NL_TEST_DEF("StatusElementTest", StatusElementTest), |
| 1165 | NL_TEST_DEF("AttributeStatusElementTest", AttributeStatusElementTest), |
| 1166 | NL_TEST_DEF("AttributeStatusListTest", AttributeStatusListTest), |
| 1167 | NL_TEST_DEF("AttributeDataElementTest", AttributeDataElementTest), |
| 1168 | NL_TEST_DEF("AttributeDataListTest", AttributeDataListTest), |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1169 | NL_TEST_DEF("AttributeDataVersionListTest", AttributeDataVersionListTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1170 | NL_TEST_DEF("CommandDataElementTest", CommandDataElementTest), |
| 1171 | NL_TEST_DEF("CommandListTest", CommandListTest), |
| 1172 | NL_TEST_DEF("ReportDataTest", ReportDataTest), |
| 1173 | NL_TEST_DEF("InvokeCommandTest", InvokeCommandTest), |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1174 | NL_TEST_DEF("ReadRequestTest", ReadRequestTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1175 | NL_TEST_SENTINEL() |
| 1176 | }; |
| 1177 | // clang-format on |
| 1178 | } // namespace |
| 1179 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1180 | /** |
| 1181 | * Set up the test suite. |
| 1182 | */ |
| 1183 | static int TestSetup(void * inContext) |
| 1184 | { |
| 1185 | CHIP_ERROR error = chip::Platform::MemoryInit(); |
| 1186 | if (error != CHIP_NO_ERROR) |
| 1187 | return FAILURE; |
| 1188 | return SUCCESS; |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * Tear down the test suite. |
| 1193 | */ |
| 1194 | static int TestTeardown(void * inContext) |
| 1195 | { |
| 1196 | chip::Platform::MemoryShutdown(); |
| 1197 | return SUCCESS; |
| 1198 | } |
| 1199 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1200 | int TestMessageDef() |
| 1201 | { |
| 1202 | // clang-format off |
| 1203 | nlTestSuite theSuite = |
| 1204 | { |
| 1205 | "MessageDef", |
| 1206 | &sTests[0], |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1207 | TestSetup, |
| 1208 | TestTeardown, |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1209 | }; |
| 1210 | // clang-format on |
| 1211 | |
| 1212 | nlTestRunner(&theSuite, nullptr); |
| 1213 | |
| 1214 | return (nlTestRunnerStats(&theSuite)); |
| 1215 | } |
| 1216 | |
| 1217 | CHIP_REGISTER_TEST_SUITE(TestMessageDef) |