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 | |
Michael Spang | e00eac3 | 2021-06-21 17:25:47 -0400 | [diff] [blame] | 25 | #include <app/AppBuildConfig.h> |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 26 | #include <app/MessageDef/CommandDataElement.h> |
| 27 | #include <app/MessageDef/CommandList.h> |
| 28 | #include <app/MessageDef/InvokeCommand.h> |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 29 | #include <app/MessageDef/ReadRequest.h> |
| 30 | #include <app/MessageDef/ReportData.h> |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 31 | #include <app/MessageDef/SubscribeRequest.h> |
| 32 | #include <app/MessageDef/SubscribeResponse.h> |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 33 | #include <app/MessageDef/TimedRequest.h> |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 34 | #include <app/MessageDef/WriteRequest.h> |
| 35 | #include <app/MessageDef/WriteResponse.h> |
Kevin Schoedel | 15669b6 | 2021-07-15 17:52:20 -0400 | [diff] [blame] | 36 | #include <core/CHIPError.h> |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 37 | #include <core/CHIPTLVDebug.hpp> |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 38 | #include <support/CHIPMem.h> |
Andrei Litvin | 05faf7d | 2020-11-30 21:01:07 -0500 | [diff] [blame] | 39 | #include <support/UnitTestRegistration.h> |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 40 | #include <system/TLVPacketBufferBackingStore.h> |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 41 | |
| 42 | #include <nlunit-test.h> |
| 43 | |
| 44 | namespace { |
| 45 | |
| 46 | using namespace chip::app; |
| 47 | |
| 48 | void TLVPrettyPrinter(const char * aFormat, ...) |
| 49 | { |
| 50 | va_list args; |
| 51 | |
| 52 | va_start(args, aFormat); |
| 53 | |
| 54 | vprintf(aFormat, args); |
| 55 | |
| 56 | va_end(args); |
| 57 | } |
| 58 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 59 | CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 60 | { |
| 61 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 62 | chip::System::PacketBufferTLVReader reader; |
| 63 | reader.Init(aMsgBuf.Retain()); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 64 | err = reader.Next(); |
| 65 | chip::TLV::Debug::Dump(reader, TLVPrettyPrinter); |
| 66 | |
| 67 | if (CHIP_NO_ERROR != err) |
| 68 | { |
Kevin Schoedel | 0fe17ec | 2021-08-05 08:52:07 -0400 | [diff] [blame^] | 69 | ChipLogProgress(DataManagement, "DebugPrettyPrint fails with err %" CHIP_ERROR_FORMAT, err.Format()); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | return err; |
| 73 | } |
| 74 | |
| 75 | void BuildAttributePath(nlTestSuite * apSuite, AttributePath::Builder & aAttributePathBuilder) |
| 76 | { |
| 77 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 78 | aAttributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 79 | err = aAttributePathBuilder.GetError(); |
| 80 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 81 | } |
| 82 | |
| 83 | void ParseAttributePath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 84 | { |
| 85 | AttributePath::Parser attributePathParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 86 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 87 | chip::NodeId nodeId = 1; |
| 88 | chip::EndpointId endpointId = 2; |
| 89 | chip::ClusterId clusterId = 3; |
Song Guo | f88fe0a | 2021-06-29 04:19:12 +0800 | [diff] [blame] | 90 | chip::AttributeId fieldId = 4; |
yunhanw-google | ebb7396 | 2021-04-16 16:02:17 -0700 | [diff] [blame] | 91 | chip::ListIndex listIndex = 5; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 92 | |
| 93 | err = attributePathParser.Init(aReader); |
| 94 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 95 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 96 | err = attributePathParser.CheckSchemaValidity(); |
| 97 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 98 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 99 | err = attributePathParser.GetNodeId(&nodeId); |
| 100 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); |
| 101 | |
| 102 | err = attributePathParser.GetEndpointId(&endpointId); |
| 103 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); |
| 104 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 105 | err = attributePathParser.GetClusterId(&clusterId); |
| 106 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 107 | |
| 108 | err = attributePathParser.GetFieldId(&fieldId); |
| 109 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && fieldId == 4); |
| 110 | |
| 111 | err = attributePathParser.GetListIndex(&listIndex); |
| 112 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && listIndex == 5); |
| 113 | } |
| 114 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 115 | void BuildAttributePathList(nlTestSuite * apSuite, AttributePathList::Builder & aAttributePathListBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 116 | { |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 117 | AttributePath::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePathBuilder(); |
| 118 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
| 119 | BuildAttributePath(apSuite, attributePathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 120 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 121 | aAttributePathListBuilder.EndOfAttributePathList(); |
| 122 | NL_TEST_ASSERT(apSuite, aAttributePathListBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 126 | { |
| 127 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 128 | AttributePathList::Parser attributePathListParser; |
| 129 | AttributePath::Parser attributePathParser; |
| 130 | |
| 131 | err = attributePathListParser.Init(aReader); |
| 132 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 133 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 134 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 135 | err = attributePathListParser.CheckSchemaValidity(); |
| 136 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 137 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void BuildEventPath(nlTestSuite * apSuite, EventPath::Builder & aEventPathBuilder) |
| 141 | { |
| 142 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 143 | aEventPathBuilder.NodeId(1).EndpointId(2).ClusterId(3).EventId(4).EndOfEventPath(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 144 | err = aEventPathBuilder.GetError(); |
| 145 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 146 | } |
| 147 | |
| 148 | void ParseEventPath(nlTestSuite * apSuite, EventPath::Parser & aEventPathParser) |
| 149 | { |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 150 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 151 | chip::NodeId nodeId = 1; |
| 152 | chip::EndpointId endpointId = 2; |
| 153 | chip::ClusterId clusterId = 3; |
| 154 | chip::EventId eventId = 4; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 155 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 156 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 157 | err = aEventPathParser.CheckSchemaValidity(); |
| 158 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 159 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 160 | err = aEventPathParser.GetNodeId(&nodeId); |
| 161 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); |
| 162 | |
| 163 | err = aEventPathParser.GetEndpointId(&endpointId); |
| 164 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); |
| 165 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 166 | err = aEventPathParser.GetClusterId(&clusterId); |
| 167 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 168 | |
| 169 | err = aEventPathParser.GetEventId(&eventId); |
| 170 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && eventId == 4); |
| 171 | } |
| 172 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 173 | void BuildEventPathList(nlTestSuite * apSuite, EventPathList::Builder & aEventPathListBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 174 | { |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 175 | EventPath::Builder eventPathBuilder = aEventPathListBuilder.CreateEventPathBuilder(); |
| 176 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 177 | BuildEventPath(apSuite, eventPathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 178 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 179 | aEventPathListBuilder.EndOfEventPathList(); |
| 180 | NL_TEST_ASSERT(apSuite, aEventPathListBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void ParseEventPathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 184 | { |
| 185 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 186 | EventPathList::Parser eventPathListParser; |
| 187 | |
| 188 | err = eventPathListParser.Init(aReader); |
| 189 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 190 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 191 | err = eventPathListParser.CheckSchemaValidity(); |
| 192 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 193 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void BuildCommandPath(nlTestSuite * apSuite, CommandPath::Builder & aCommandPathBuilder) |
| 197 | { |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 198 | aCommandPathBuilder.EndpointId(1).ClusterId(3).CommandId(4).EndOfCommandPath(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 199 | NL_TEST_ASSERT(apSuite, aCommandPathBuilder.GetError() == CHIP_NO_ERROR); |
| 200 | } |
| 201 | |
| 202 | void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 203 | { |
| 204 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 205 | CommandPath::Parser commandPathParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 206 | chip::EndpointId endpointId = 0; |
| 207 | chip::ClusterId clusterId = 0; |
| 208 | chip::CommandId commandId = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 209 | |
| 210 | err = commandPathParser.Init(aReader); |
| 211 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 212 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 213 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 214 | err = commandPathParser.CheckSchemaValidity(); |
| 215 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 216 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 217 | err = commandPathParser.GetEndpointId(&endpointId); |
| 218 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 1); |
| 219 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 220 | err = commandPathParser.GetClusterId(&clusterId); |
| 221 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 222 | |
| 223 | err = commandPathParser.GetCommandId(&commandId); |
| 224 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && commandId == 4); |
| 225 | } |
| 226 | |
| 227 | void BuildEventDataElement(nlTestSuite * apSuite, EventDataElement::Builder & aEventDataElementBuilder) |
| 228 | { |
| 229 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 230 | |
| 231 | EventPath::Builder eventPathBuilder = aEventDataElementBuilder.CreateEventPathBuilder(); |
| 232 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 233 | BuildEventPath(apSuite, eventPathBuilder); |
| 234 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 235 | aEventDataElementBuilder.PriorityLevel(2) |
| 236 | .Number(3) |
| 237 | .UTCTimestamp(4) |
| 238 | .SystemTimestamp(5) |
| 239 | .DeltaUTCTimestamp(6) |
| 240 | .DeltaSystemTimestamp(7); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 241 | err = aEventDataElementBuilder.GetError(); |
| 242 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 243 | // Construct test event data |
| 244 | { |
| 245 | chip::TLV::TLVWriter * pWriter = aEventDataElementBuilder.GetWriter(); |
| 246 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 247 | err = |
| 248 | pWriter->StartContainer(chip::TLV::ContextTag(EventDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, dummyType); |
| 249 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 250 | |
| 251 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 252 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 253 | |
| 254 | err = pWriter->EndContainer(dummyType); |
| 255 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 256 | } |
| 257 | |
| 258 | aEventDataElementBuilder.EndOfEventDataElement(); |
| 259 | } |
| 260 | |
| 261 | void ParseEventDataElement(nlTestSuite * apSuite, EventDataElement::Parser & aEventDataElementParser) |
| 262 | { |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 263 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 264 | uint8_t importanceLevel = 0; |
| 265 | uint64_t number = 0; |
| 266 | uint64_t uTCTimestamp = 0; |
| 267 | uint64_t systemTimestamp = 0; |
| 268 | uint64_t deltaUTCTimestamp = 0; |
| 269 | uint64_t deltaSystemTimestamp = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 270 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 271 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 272 | err = aEventDataElementParser.CheckSchemaValidity(); |
| 273 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 274 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 275 | { |
| 276 | { |
| 277 | EventPath::Parser eventPath; |
| 278 | err = aEventDataElementParser.GetEventPath(&eventPath); |
| 279 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 280 | } |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 281 | err = aEventDataElementParser.GetPriorityLevel(&importanceLevel); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 282 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && importanceLevel == 2); |
| 283 | err = aEventDataElementParser.GetNumber(&number); |
| 284 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && number == 3); |
| 285 | err = aEventDataElementParser.GetUTCTimestamp(&uTCTimestamp); |
| 286 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && uTCTimestamp == 4); |
| 287 | err = aEventDataElementParser.GetSystemTimestamp(&systemTimestamp); |
| 288 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && systemTimestamp == 5); |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 289 | err = aEventDataElementParser.GetDeltaUTCTimestamp(&deltaUTCTimestamp); |
| 290 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaUTCTimestamp == 6); |
| 291 | err = aEventDataElementParser.GetDeltaSystemTimestamp(&deltaSystemTimestamp); |
| 292 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaSystemTimestamp == 7); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 293 | |
| 294 | { |
| 295 | chip::TLV::TLVReader reader; |
| 296 | bool val = false; |
| 297 | chip::TLV::TLVType container; |
| 298 | aEventDataElementParser.GetData(&reader); |
| 299 | err = reader.EnterContainer(container); |
| 300 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 301 | |
| 302 | err = reader.Next(); |
| 303 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 304 | |
| 305 | err = reader.Get(val); |
| 306 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 307 | |
| 308 | err = reader.ExitContainer(container); |
| 309 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | void BuildEventList(nlTestSuite * apSuite, EventList::Builder & aEventListBuilder) |
| 315 | { |
| 316 | EventDataElement::Builder eventDataElementBuilder = aEventListBuilder.CreateEventBuilder(); |
| 317 | NL_TEST_ASSERT(apSuite, eventDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 318 | BuildEventDataElement(apSuite, eventDataElementBuilder); |
| 319 | |
| 320 | aEventListBuilder.EndOfEventList(); |
| 321 | NL_TEST_ASSERT(apSuite, aEventListBuilder.GetError() == CHIP_NO_ERROR); |
| 322 | } |
| 323 | |
| 324 | void ParseEventList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 325 | { |
| 326 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 327 | EventList::Parser eventListParser; |
| 328 | |
| 329 | err = eventListParser.Init(aReader); |
| 330 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 331 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 332 | err = eventListParser.CheckSchemaValidity(); |
| 333 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 334 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void BuildStatusElement(nlTestSuite * apSuite, StatusElement::Builder & aStatusElementBuilder) |
| 338 | { |
| 339 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 340 | |
yunhanw-google | ea6dbf6 | 2021-04-02 08:10:20 -0700 | [diff] [blame] | 341 | aStatusElementBuilder.EncodeStatusElement(chip::Protocols::SecureChannel::GeneralStatusCode::kFailure, 2, 3) |
| 342 | .EndOfStatusElement(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 343 | err = aStatusElementBuilder.GetError(); |
| 344 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 345 | } |
| 346 | |
| 347 | void ParseStatusElement(nlTestSuite * apSuite, StatusElement::Parser & aStatusElementParser) |
| 348 | { |
| 349 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 350 | StatusElement::Parser StatusElementParser; |
| 351 | |
yunhanw-google | ea6dbf6 | 2021-04-02 08:10:20 -0700 | [diff] [blame] | 352 | chip::Protocols::SecureChannel::GeneralStatusCode generalCode = chip::Protocols::SecureChannel::GeneralStatusCode::kFailure; |
| 353 | uint32_t protocolId = 0; |
| 354 | uint16_t protocolCode = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 355 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 356 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 357 | err = aStatusElementParser.CheckSchemaValidity(); |
| 358 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 359 | #endif |
yunhanw-google | ea6dbf6 | 2021-04-02 08:10:20 -0700 | [diff] [blame] | 360 | err = aStatusElementParser.DecodeStatusElement(&generalCode, &protocolId, &protocolCode); |
| 361 | NL_TEST_ASSERT(apSuite, |
| 362 | err == CHIP_NO_ERROR && |
| 363 | static_cast<uint16_t>(generalCode) == |
| 364 | static_cast<uint16_t>(chip::Protocols::SecureChannel::GeneralStatusCode::kFailure) && |
| 365 | protocolId == 2 && protocolCode == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void BuildAttributeStatusElement(nlTestSuite * apSuite, AttributeStatusElement::Builder & aAttributeStatusElementBuilder) |
| 369 | { |
| 370 | AttributePath::Builder attributePathBuilder = aAttributeStatusElementBuilder.CreateAttributePathBuilder(); |
| 371 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
| 372 | BuildAttributePath(apSuite, attributePathBuilder); |
| 373 | |
| 374 | StatusElement::Builder statusElementBuilder = aAttributeStatusElementBuilder.CreateStatusElementBuilder(); |
| 375 | NL_TEST_ASSERT(apSuite, statusElementBuilder.GetError() == CHIP_NO_ERROR); |
| 376 | BuildStatusElement(apSuite, statusElementBuilder); |
| 377 | |
| 378 | aAttributeStatusElementBuilder.EndOfAttributeStatusElement(); |
| 379 | NL_TEST_ASSERT(apSuite, aAttributeStatusElementBuilder.GetError() == CHIP_NO_ERROR); |
| 380 | } |
| 381 | |
| 382 | void ParseAttributeStatusElement(nlTestSuite * apSuite, AttributeStatusElement::Parser & aAttributeStatusElementParser) |
| 383 | { |
| 384 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 385 | AttributePath::Parser attributePathParser; |
| 386 | StatusElement::Parser statusElementParser; |
| 387 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 388 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 389 | err = aAttributeStatusElementParser.CheckSchemaValidity(); |
| 390 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 391 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 392 | err = aAttributeStatusElementParser.GetAttributePath(&attributePathParser); |
| 393 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 394 | |
| 395 | err = aAttributeStatusElementParser.GetStatusElement(&statusElementParser); |
| 396 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 397 | } |
| 398 | |
| 399 | void BuildAttributeStatusList(nlTestSuite * apSuite, AttributeStatusList::Builder & aAttributeStatusListBuilder) |
| 400 | { |
| 401 | AttributeStatusElement::Builder aAttributeStatusElementBuilder = aAttributeStatusListBuilder.CreateAttributeStatusBuilder(); |
| 402 | NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); |
| 403 | BuildAttributeStatusElement(apSuite, aAttributeStatusElementBuilder); |
| 404 | |
| 405 | aAttributeStatusListBuilder.EndOfAttributeStatusList(); |
| 406 | NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); |
| 407 | } |
| 408 | |
| 409 | void ParseAttributeStatusList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 410 | { |
| 411 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 412 | AttributeStatusList::Parser attributeStatusParser; |
| 413 | |
| 414 | err = attributeStatusParser.Init(aReader); |
| 415 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 416 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 417 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 418 | err = attributeStatusParser.CheckSchemaValidity(); |
| 419 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 420 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void BuildAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Builder & aAttributeDataElementBuilder) |
| 424 | { |
| 425 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 426 | |
| 427 | AttributePath::Builder attributePathBuilder = aAttributeDataElementBuilder.CreateAttributePathBuilder(); |
| 428 | NL_TEST_ASSERT(apSuite, aAttributeDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 429 | BuildAttributePath(apSuite, attributePathBuilder); |
| 430 | |
| 431 | aAttributeDataElementBuilder.DataVersion(2); |
| 432 | err = aAttributeDataElementBuilder.GetError(); |
| 433 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 434 | |
| 435 | // Construct attribute data |
| 436 | { |
| 437 | chip::TLV::TLVWriter * pWriter = aAttributeDataElementBuilder.GetWriter(); |
| 438 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 439 | err = pWriter->StartContainer(chip::TLV::ContextTag(AttributeDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, |
| 440 | dummyType); |
| 441 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 442 | |
| 443 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 444 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 445 | |
| 446 | err = pWriter->EndContainer(dummyType); |
| 447 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 448 | } |
| 449 | |
| 450 | aAttributeDataElementBuilder.MoreClusterData(true); |
| 451 | err = aAttributeDataElementBuilder.GetError(); |
| 452 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 453 | |
| 454 | aAttributeDataElementBuilder.EndOfAttributeDataElement(); |
| 455 | NL_TEST_ASSERT(apSuite, aAttributeDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 456 | } |
| 457 | |
| 458 | void ParseAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Parser & aAttributeDataElementParser) |
| 459 | { |
| 460 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 461 | AttributePath::Parser attributePathParser; |
| 462 | StatusElement::Parser statusElementParser; |
| 463 | chip::DataVersion version = 0; |
| 464 | bool moreClusterDataFlag = false; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 465 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 466 | err = aAttributeDataElementParser.CheckSchemaValidity(); |
| 467 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 468 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 469 | err = aAttributeDataElementParser.GetAttributePath(&attributePathParser); |
| 470 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 471 | |
| 472 | err = aAttributeDataElementParser.GetDataVersion(&version); |
| 473 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && version == 2); |
| 474 | |
| 475 | { |
| 476 | chip::TLV::TLVReader reader; |
| 477 | bool val = false; |
| 478 | chip::TLV::TLVType container; |
| 479 | aAttributeDataElementParser.GetData(&reader); |
| 480 | err = reader.EnterContainer(container); |
| 481 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 482 | |
| 483 | err = reader.Next(); |
| 484 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 485 | |
| 486 | err = reader.Get(val); |
| 487 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 488 | |
| 489 | err = reader.ExitContainer(container); |
| 490 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 491 | } |
| 492 | |
| 493 | err = aAttributeDataElementParser.GetMoreClusterDataFlag(&moreClusterDataFlag); |
| 494 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreClusterDataFlag); |
| 495 | } |
| 496 | |
| 497 | void BuildAttributeDataList(nlTestSuite * apSuite, AttributeDataList::Builder & aAttributeDataListBuilder) |
| 498 | { |
| 499 | AttributeDataElement::Builder attributeDataElementBuilder = aAttributeDataListBuilder.CreateAttributeDataElementBuilder(); |
| 500 | NL_TEST_ASSERT(apSuite, aAttributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 501 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder); |
| 502 | |
| 503 | aAttributeDataListBuilder.EndOfAttributeDataList(); |
| 504 | NL_TEST_ASSERT(apSuite, aAttributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 505 | } |
| 506 | |
| 507 | void ParseAttributeDataList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 508 | { |
| 509 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 510 | AttributeDataList::Parser attributeDataListParser; |
| 511 | |
| 512 | err = attributeDataListParser.Init(aReader); |
| 513 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 514 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 515 | err = attributeDataListParser.CheckSchemaValidity(); |
| 516 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 517 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 518 | } |
| 519 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 520 | void BuildAttributeDataVersionList(nlTestSuite * apSuite, AttributeDataVersionList::Builder & aAttributeDataVersionListBuilder) |
| 521 | { |
| 522 | aAttributeDataVersionListBuilder.AddVersion(1); |
| 523 | |
| 524 | aAttributeDataVersionListBuilder.EndOfAttributeDataVersionList(); |
| 525 | NL_TEST_ASSERT(apSuite, aAttributeDataVersionListBuilder.GetError() == CHIP_NO_ERROR); |
| 526 | } |
| 527 | |
| 528 | void ParseAttributeDataVersionList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 529 | { |
| 530 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 531 | chip::DataVersion version; |
| 532 | AttributeDataVersionList::Parser attributeDataVersionListParser; |
| 533 | |
| 534 | err = attributeDataVersionListParser.Init(aReader); |
| 535 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 536 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 537 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 538 | err = attributeDataVersionListParser.CheckSchemaValidity(); |
| 539 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 540 | #endif |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 541 | attributeDataVersionListParser.GetVersion(&version); |
| 542 | } |
| 543 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 544 | void BuildCommandDataElement(nlTestSuite * apSuite, CommandDataElement::Builder & aCommandDataElementBuilder) |
| 545 | { |
| 546 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 547 | |
| 548 | CommandPath::Builder commandPathBuilder = aCommandDataElementBuilder.CreateCommandPathBuilder(); |
| 549 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 550 | BuildCommandPath(apSuite, commandPathBuilder); |
| 551 | |
| 552 | // Construct command data |
| 553 | { |
| 554 | chip::TLV::TLVWriter * pWriter = aCommandDataElementBuilder.GetWriter(); |
| 555 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
| 556 | err = pWriter->StartContainer(chip::TLV::ContextTag(CommandDataElement::kCsTag_Data), chip::TLV::kTLVType_Structure, |
| 557 | dummyType); |
| 558 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 559 | |
| 560 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 561 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 562 | |
| 563 | err = pWriter->EndContainer(dummyType); |
| 564 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 565 | } |
| 566 | |
| 567 | aCommandDataElementBuilder.EndOfCommandDataElement(); |
| 568 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 569 | } |
| 570 | |
| 571 | void ParseCommandDataElement(nlTestSuite * apSuite, CommandDataElement::Parser & aCommandDataElementParser) |
| 572 | { |
| 573 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 574 | CommandPath::Parser commandPathParser; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 575 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 576 | err = aCommandDataElementParser.CheckSchemaValidity(); |
| 577 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 578 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 579 | err = aCommandDataElementParser.GetCommandPath(&commandPathParser); |
| 580 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 581 | |
| 582 | { |
| 583 | chip::TLV::TLVReader reader; |
| 584 | bool val = false; |
| 585 | chip::TLV::TLVType container; |
| 586 | aCommandDataElementParser.GetData(&reader); |
| 587 | err = reader.EnterContainer(container); |
| 588 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 589 | |
| 590 | err = reader.Next(); |
| 591 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 592 | |
| 593 | err = reader.Get(val); |
| 594 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 595 | |
| 596 | err = reader.ExitContainer(container); |
| 597 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 598 | } |
| 599 | } |
| 600 | |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 601 | void BuildCommandDataElementWithStatusCode(nlTestSuite * apSuite, CommandDataElement::Builder & aCommandDataElementBuilder) |
| 602 | { |
| 603 | CommandPath::Builder commandPathBuilder = aCommandDataElementBuilder.CreateCommandPathBuilder(); |
| 604 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 605 | BuildCommandPath(apSuite, commandPathBuilder); |
| 606 | |
| 607 | StatusElement::Builder statusElementBuilder = aCommandDataElementBuilder.CreateStatusElementBuilder(); |
| 608 | NL_TEST_ASSERT(apSuite, statusElementBuilder.GetError() == CHIP_NO_ERROR); |
| 609 | BuildStatusElement(apSuite, statusElementBuilder); |
| 610 | |
| 611 | aCommandDataElementBuilder.EndOfCommandDataElement(); |
| 612 | NL_TEST_ASSERT(apSuite, aCommandDataElementBuilder.GetError() == CHIP_NO_ERROR); |
| 613 | } |
| 614 | |
| 615 | void ParseCommandDataElementWithStatusCode(nlTestSuite * apSuite, CommandDataElement::Parser & aCommandDataElementParser) |
| 616 | { |
| 617 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 618 | CommandPath::Parser commandPathParser; |
| 619 | StatusElement::Parser statusElementParser; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 620 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 621 | err = aCommandDataElementParser.CheckSchemaValidity(); |
| 622 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 623 | #endif |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 624 | err = aCommandDataElementParser.GetCommandPath(&commandPathParser); |
| 625 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 626 | |
| 627 | err = aCommandDataElementParser.GetStatusElement(&statusElementParser); |
| 628 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 629 | } |
| 630 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 631 | void BuildCommandList(nlTestSuite * apSuite, CommandList::Builder & aCommandListBuilder) |
| 632 | { |
| 633 | CommandDataElement::Builder commandDataElementBuilder = aCommandListBuilder.CreateCommandDataElementBuilder(); |
| 634 | NL_TEST_ASSERT(apSuite, aCommandListBuilder.GetError() == CHIP_NO_ERROR); |
| 635 | BuildCommandDataElement(apSuite, commandDataElementBuilder); |
| 636 | |
| 637 | aCommandListBuilder.EndOfCommandList(); |
| 638 | NL_TEST_ASSERT(apSuite, aCommandListBuilder.GetError() == CHIP_NO_ERROR); |
| 639 | } |
| 640 | |
| 641 | void ParseCommandList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 642 | { |
| 643 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 644 | CommandList::Parser commandListParser; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 645 | err = commandListParser.Init(aReader); |
| 646 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 647 | |
| 648 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 649 | err = commandListParser.CheckSchemaValidity(); |
| 650 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 651 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void BuildReportData(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 655 | { |
| 656 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 657 | ReportData::Builder reportDataBuilder; |
| 658 | |
| 659 | err = reportDataBuilder.Init(&aWriter); |
| 660 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 661 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 662 | reportDataBuilder.SuppressResponse(true).SubscriptionId(2); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 663 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 664 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 665 | AttributeDataList::Builder attributeDataList = reportDataBuilder.CreateAttributeDataListBuilder(); |
| 666 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 667 | BuildAttributeDataList(apSuite, attributeDataList); |
| 668 | |
| 669 | EventList::Builder eventList = reportDataBuilder.CreateEventDataListBuilder(); |
| 670 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 671 | BuildEventList(apSuite, eventList); |
| 672 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 673 | reportDataBuilder.MoreChunkedMessages(true); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 674 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 675 | |
| 676 | reportDataBuilder.EndOfReportData(); |
| 677 | NL_TEST_ASSERT(apSuite, reportDataBuilder.GetError() == CHIP_NO_ERROR); |
| 678 | } |
| 679 | |
| 680 | void ParseReportData(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 681 | { |
| 682 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 683 | ReportData::Parser reportDataParser; |
| 684 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 685 | bool suppressResponse = false; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 686 | uint64_t subscriptionId = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 687 | AttributeDataList::Parser attributeDataListParser; |
| 688 | EventList::Parser eventListParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 689 | bool moreChunkedMessages = false; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 690 | reportDataParser.Init(aReader); |
| 691 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 692 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 693 | err = reportDataParser.CheckSchemaValidity(); |
| 694 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 695 | #endif |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 696 | err = reportDataParser.GetSuppressResponse(&suppressResponse); |
| 697 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 698 | |
| 699 | err = reportDataParser.GetSubscriptionId(&subscriptionId); |
| 700 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && subscriptionId == 2); |
| 701 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 702 | err = reportDataParser.GetAttributeDataList(&attributeDataListParser); |
| 703 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 704 | |
| 705 | err = reportDataParser.GetEventDataList(&eventListParser); |
| 706 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 707 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 708 | err = reportDataParser.GetMoreChunkedMessages(&moreChunkedMessages); |
| 709 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | void BuildInvokeCommand(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 713 | { |
| 714 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 715 | InvokeCommand::Builder invokeCommandBuilder; |
| 716 | |
| 717 | err = invokeCommandBuilder.Init(&aWriter); |
| 718 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 719 | |
| 720 | CommandList::Builder commandList = invokeCommandBuilder.CreateCommandListBuilder(); |
| 721 | NL_TEST_ASSERT(apSuite, invokeCommandBuilder.GetError() == CHIP_NO_ERROR); |
| 722 | BuildCommandList(apSuite, commandList); |
| 723 | |
| 724 | invokeCommandBuilder.EndOfInvokeCommand(); |
| 725 | NL_TEST_ASSERT(apSuite, invokeCommandBuilder.GetError() == CHIP_NO_ERROR); |
| 726 | } |
| 727 | |
| 728 | void ParseInvokeCommand(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 729 | { |
| 730 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 731 | |
| 732 | InvokeCommand::Parser invokeCommandParser; |
| 733 | CommandList::Parser commandListParser; |
| 734 | |
| 735 | err = invokeCommandParser.Init(aReader); |
| 736 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 737 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 738 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 739 | err = invokeCommandParser.CheckSchemaValidity(); |
| 740 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 741 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 742 | err = invokeCommandParser.GetCommandList(&commandListParser); |
| 743 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 744 | } |
| 745 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 746 | void BuildReadRequest(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 747 | { |
| 748 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 749 | ReadRequest::Builder readRequestBuilder; |
| 750 | |
| 751 | err = readRequestBuilder.Init(&aWriter); |
| 752 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 753 | |
| 754 | AttributePathList::Builder attributePathList = readRequestBuilder.CreateAttributePathListBuilder(); |
| 755 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 756 | BuildAttributePathList(apSuite, attributePathList); |
| 757 | |
| 758 | EventPathList::Builder eventPathList = readRequestBuilder.CreateEventPathListBuilder(); |
| 759 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 760 | BuildEventPathList(apSuite, eventPathList); |
| 761 | |
| 762 | AttributeDataVersionList::Builder attributeDataVersionList = readRequestBuilder.CreateAttributeDataVersionListBuilder(); |
| 763 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 764 | BuildAttributeDataVersionList(apSuite, attributeDataVersionList); |
| 765 | |
| 766 | readRequestBuilder.EventNumber(1); |
| 767 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 768 | |
| 769 | readRequestBuilder.EndOfReadRequest(); |
| 770 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 771 | } |
| 772 | |
| 773 | void ParseReadRequest(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 774 | { |
| 775 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 776 | |
| 777 | ReadRequest::Parser readRequestParser; |
| 778 | AttributePathList::Parser attributePathListParser; |
| 779 | EventPathList::Parser eventPathListParser; |
| 780 | AttributeDataVersionList::Parser attributeDataVersionListParser; |
| 781 | uint64_t eventNumber; |
| 782 | |
| 783 | err = readRequestParser.Init(aReader); |
| 784 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 785 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 786 | err = readRequestParser.CheckSchemaValidity(); |
| 787 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 788 | #endif |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 789 | err = readRequestParser.GetAttributePathList(&attributePathListParser); |
| 790 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 791 | |
| 792 | err = readRequestParser.GetEventPathList(&eventPathListParser); |
| 793 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 794 | |
| 795 | err = readRequestParser.GetAttributeDataVersionList(&attributeDataVersionListParser); |
| 796 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 797 | |
| 798 | err = readRequestParser.GetEventNumber(&eventNumber); |
| 799 | NL_TEST_ASSERT(apSuite, eventNumber == 1 && err == CHIP_NO_ERROR); |
| 800 | } |
| 801 | |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 802 | void BuildWriteRequest(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 803 | { |
| 804 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 805 | WriteRequest::Builder writeRequestBuilder; |
| 806 | |
| 807 | err = writeRequestBuilder.Init(&aWriter); |
| 808 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 809 | |
| 810 | writeRequestBuilder.SuppressResponse(true); |
| 811 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 812 | |
| 813 | AttributeDataList::Builder attributeDataList = writeRequestBuilder.CreateAttributeDataListBuilder(); |
| 814 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 815 | BuildAttributeDataList(apSuite, attributeDataList); |
| 816 | |
| 817 | AttributeDataVersionList::Builder attributeDataVersionList = writeRequestBuilder.CreateAttributeDataVersionListBuilder(); |
| 818 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 819 | BuildAttributeDataVersionList(apSuite, attributeDataVersionList); |
| 820 | |
| 821 | writeRequestBuilder.MoreChunkedMessages(true); |
| 822 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 823 | |
| 824 | writeRequestBuilder.EndOfWriteRequest(); |
| 825 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 826 | } |
| 827 | |
| 828 | void ParseWriteRequest(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 829 | { |
| 830 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 831 | |
| 832 | WriteRequest::Parser writeRequestParser; |
| 833 | bool suppressResponse = false; |
| 834 | AttributeDataList::Parser attributeDataList; |
| 835 | AttributeDataVersionList::Parser attributeDataVersionList; |
| 836 | bool moreChunkedMessages = false; |
| 837 | |
| 838 | err = writeRequestParser.Init(aReader); |
| 839 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 840 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 841 | err = writeRequestParser.CheckSchemaValidity(); |
| 842 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 843 | #endif |
| 844 | err = writeRequestParser.GetSuppressResponse(&suppressResponse); |
| 845 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); |
| 846 | |
| 847 | err = writeRequestParser.GetAttributeDataList(&attributeDataList); |
| 848 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 849 | |
| 850 | err = writeRequestParser.GetAttributeDataVersionList(&attributeDataVersionList); |
| 851 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 852 | |
| 853 | err = writeRequestParser.GetMoreChunkedMessages(&moreChunkedMessages); |
| 854 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); |
| 855 | } |
| 856 | |
| 857 | void BuildWriteResponse(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 858 | { |
| 859 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 860 | WriteResponse::Builder writeResponseBuilder; |
| 861 | |
| 862 | err = writeResponseBuilder.Init(&aWriter); |
| 863 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 864 | |
yunhanw-google | 79b3354 | 2021-04-16 16:02:25 -0700 | [diff] [blame] | 865 | AttributeStatusList::Builder attributeStatusList = writeResponseBuilder.CreateAttributeStatusListBuilder(); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 866 | NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 79b3354 | 2021-04-16 16:02:25 -0700 | [diff] [blame] | 867 | BuildAttributeStatusList(apSuite, attributeStatusList); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 868 | |
| 869 | writeResponseBuilder.EndOfWriteResponse(); |
| 870 | NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 871 | } |
| 872 | |
| 873 | void ParseWriteResponse(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 874 | { |
| 875 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 876 | |
| 877 | WriteResponse::Parser writeResponseParser; |
yunhanw-google | 79b3354 | 2021-04-16 16:02:25 -0700 | [diff] [blame] | 878 | AttributeStatusList::Parser attributeStatusListParser; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 879 | err = writeResponseParser.Init(aReader); |
| 880 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 881 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 882 | err = writeResponseParser.CheckSchemaValidity(); |
| 883 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 884 | #endif |
yunhanw-google | 79b3354 | 2021-04-16 16:02:25 -0700 | [diff] [blame] | 885 | err = writeResponseParser.GetAttributeStatusList(&attributeStatusListParser); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 886 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 887 | } |
| 888 | |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 889 | void BuildSubscribeRequest(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 890 | { |
| 891 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 892 | SubscribeRequest::Builder subscribeRequestBuilder; |
| 893 | |
| 894 | err = subscribeRequestBuilder.Init(&aWriter); |
| 895 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 896 | |
| 897 | AttributePathList::Builder attributePathList = subscribeRequestBuilder.CreateAttributePathListBuilder(); |
| 898 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 899 | BuildAttributePathList(apSuite, attributePathList); |
| 900 | |
| 901 | EventPathList::Builder eventPathList = subscribeRequestBuilder.CreateEventPathListBuilder(); |
| 902 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 903 | BuildEventPathList(apSuite, eventPathList); |
| 904 | |
| 905 | AttributeDataVersionList::Builder attributeDataVersionList = subscribeRequestBuilder.CreateAttributeDataVersionListBuilder(); |
| 906 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 907 | BuildAttributeDataVersionList(apSuite, attributeDataVersionList); |
| 908 | |
| 909 | subscribeRequestBuilder.EventNumber(1); |
| 910 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 911 | |
yunhanw-google | 4a1c7cf | 2021-07-16 10:06:41 -0700 | [diff] [blame] | 912 | subscribeRequestBuilder.MinIntervalSeconds(2); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 913 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 914 | |
yunhanw-google | 4a1c7cf | 2021-07-16 10:06:41 -0700 | [diff] [blame] | 915 | subscribeRequestBuilder.MaxIntervalSeconds(3); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 916 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 917 | |
| 918 | subscribeRequestBuilder.KeepExistingSubscriptions(true); |
| 919 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 920 | |
| 921 | subscribeRequestBuilder.IsProxy(true); |
| 922 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 923 | |
| 924 | subscribeRequestBuilder.EndOfSubscribeRequest(); |
| 925 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 926 | } |
| 927 | |
| 928 | void ParseSubscribeRequest(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 929 | { |
| 930 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 931 | |
| 932 | SubscribeRequest::Parser subscribeRequestParser; |
| 933 | AttributePathList::Parser attributePathListParser; |
| 934 | EventPathList::Parser eventPathListParser; |
| 935 | AttributeDataVersionList::Parser attributeDataVersionListParser; |
| 936 | uint64_t eventNumber = 0; |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 937 | uint16_t minIntervalSeconds = 0; |
| 938 | uint16_t maxIntervalSeconds = 0; |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 939 | bool keepExistingSubscription = false; |
| 940 | bool isProxy = false; |
| 941 | |
| 942 | err = subscribeRequestParser.Init(aReader); |
| 943 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 944 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 945 | err = subscribeRequestParser.CheckSchemaValidity(); |
| 946 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 947 | #endif |
| 948 | err = subscribeRequestParser.GetAttributePathList(&attributePathListParser); |
| 949 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 950 | |
| 951 | err = subscribeRequestParser.GetEventPathList(&eventPathListParser); |
| 952 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 953 | |
| 954 | err = subscribeRequestParser.GetAttributeDataVersionList(&attributeDataVersionListParser); |
| 955 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 956 | |
| 957 | err = subscribeRequestParser.GetEventNumber(&eventNumber); |
| 958 | NL_TEST_ASSERT(apSuite, eventNumber == 1 && err == CHIP_NO_ERROR); |
| 959 | |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 960 | err = subscribeRequestParser.GetMinIntervalSeconds(&minIntervalSeconds); |
yunhanw-google | 4a1c7cf | 2021-07-16 10:06:41 -0700 | [diff] [blame] | 961 | NL_TEST_ASSERT(apSuite, minIntervalSeconds == 2 && err == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 962 | |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 963 | err = subscribeRequestParser.GetMaxIntervalSeconds(&maxIntervalSeconds); |
yunhanw-google | 4a1c7cf | 2021-07-16 10:06:41 -0700 | [diff] [blame] | 964 | NL_TEST_ASSERT(apSuite, maxIntervalSeconds == 3 && err == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 965 | |
| 966 | err = subscribeRequestParser.GetKeepExistingSubscriptions(&keepExistingSubscription); |
| 967 | NL_TEST_ASSERT(apSuite, keepExistingSubscription && err == CHIP_NO_ERROR); |
| 968 | |
| 969 | err = subscribeRequestParser.GetIsProxy(&isProxy); |
| 970 | NL_TEST_ASSERT(apSuite, isProxy && err == CHIP_NO_ERROR); |
| 971 | } |
| 972 | |
| 973 | void BuildSubscribeResponse(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 974 | { |
| 975 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 976 | SubscribeResponse::Builder subscribeResponseBuilder; |
| 977 | |
| 978 | err = subscribeResponseBuilder.Init(&aWriter); |
| 979 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 980 | |
| 981 | subscribeResponseBuilder.SubscriptionId(1); |
| 982 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 983 | |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 984 | subscribeResponseBuilder.FinalSyncIntervalSeconds(1); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 985 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 986 | |
| 987 | subscribeResponseBuilder.EndOfSubscribeResponse(); |
| 988 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 989 | } |
| 990 | |
| 991 | void ParseSubscribeResponse(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 992 | { |
| 993 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 994 | |
| 995 | SubscribeResponse::Parser subscribeResponseParser; |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 996 | uint64_t subscriptionId = 0; |
| 997 | uint16_t finalSyncIntervalSeconds = 0; |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 998 | |
| 999 | err = subscribeResponseParser.Init(aReader); |
| 1000 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1001 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1002 | err = subscribeResponseParser.CheckSchemaValidity(); |
| 1003 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1004 | #endif |
| 1005 | err = subscribeResponseParser.GetSubscriptionId(&subscriptionId); |
| 1006 | NL_TEST_ASSERT(apSuite, subscriptionId == 1 && err == CHIP_NO_ERROR); |
| 1007 | |
yunhanw-google | 0889e23 | 2021-07-13 10:00:30 -0700 | [diff] [blame] | 1008 | err = subscribeResponseParser.GetFinalSyncIntervalSeconds(&finalSyncIntervalSeconds); |
| 1009 | NL_TEST_ASSERT(apSuite, finalSyncIntervalSeconds == 1 && err == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1012 | void BuildTimedRequest(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 1013 | { |
| 1014 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1015 | TimedRequest::Builder timedRequestBuilder; |
| 1016 | |
| 1017 | err = timedRequestBuilder.Init(&aWriter); |
| 1018 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1019 | |
| 1020 | timedRequestBuilder.TimeoutMs(1); |
| 1021 | NL_TEST_ASSERT(apSuite, timedRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1022 | } |
| 1023 | |
| 1024 | void ParseTimedRequest(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 1025 | { |
| 1026 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1027 | |
| 1028 | TimedRequest::Parser timedRequestarser; |
| 1029 | uint16_t timeout = 0; |
| 1030 | |
| 1031 | err = timedRequestarser.Init(aReader); |
| 1032 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1033 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1034 | err = timedRequestarser.CheckSchemaValidity(); |
| 1035 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1036 | #endif |
| 1037 | err = timedRequestarser.GetTimeoutMs(&timeout); |
| 1038 | NL_TEST_ASSERT(apSuite, timeout == 1 && err == CHIP_NO_ERROR); |
| 1039 | } |
| 1040 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1041 | void AttributePathTest(nlTestSuite * apSuite, void * apContext) |
| 1042 | { |
| 1043 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1044 | AttributePath::Builder attributePathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1045 | chip::System::PacketBufferTLVWriter writer; |
| 1046 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1047 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1048 | attributePathBuilder.Init(&writer); |
| 1049 | BuildAttributePath(apSuite, attributePathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1050 | chip::System::PacketBufferHandle buf; |
| 1051 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1052 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1053 | |
| 1054 | DebugPrettyPrint(buf); |
| 1055 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1056 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1057 | err = reader.Next(); |
| 1058 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1059 | |
| 1060 | ParseAttributePath(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | void AttributePathListTest(nlTestSuite * apSuite, void * apContext) |
| 1064 | { |
| 1065 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1066 | chip::System::PacketBufferTLVWriter writer; |
| 1067 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1068 | AttributePathList::Builder attributePathListBuilder; |
| 1069 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1070 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1071 | |
| 1072 | err = attributePathListBuilder.Init(&writer); |
| 1073 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1074 | |
| 1075 | BuildAttributePathList(apSuite, attributePathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1076 | chip::System::PacketBufferHandle buf; |
| 1077 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1078 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1079 | |
| 1080 | DebugPrettyPrint(buf); |
| 1081 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1082 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1083 | err = reader.Next(); |
| 1084 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1085 | ParseAttributePathList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | void EventPathTest(nlTestSuite * apSuite, void * apContext) |
| 1089 | { |
| 1090 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1091 | EventPath::Parser eventPathParser; |
| 1092 | EventPath::Builder eventPathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1093 | chip::System::PacketBufferTLVWriter writer; |
| 1094 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1095 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1096 | eventPathBuilder.Init(&writer); |
| 1097 | BuildEventPath(apSuite, eventPathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1098 | chip::System::PacketBufferHandle buf; |
| 1099 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1100 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1101 | |
| 1102 | DebugPrettyPrint(buf); |
| 1103 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1104 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1105 | err = reader.Next(); |
| 1106 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1107 | |
| 1108 | eventPathParser.Init(reader); |
| 1109 | ParseEventPath(apSuite, eventPathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | void EventPathListTest(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; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1117 | EventPathList::Builder eventPathListBuilder; |
| 1118 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1119 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1120 | |
| 1121 | err = eventPathListBuilder.Init(&writer); |
| 1122 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1123 | |
| 1124 | BuildEventPathList(apSuite, eventPathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1125 | chip::System::PacketBufferHandle buf; |
| 1126 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1127 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1128 | |
| 1129 | DebugPrettyPrint(buf); |
| 1130 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1131 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1132 | err = reader.Next(); |
| 1133 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1134 | ParseEventPathList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | void CommandPathTest(nlTestSuite * apSuite, void * apContext) |
| 1138 | { |
| 1139 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1140 | chip::System::PacketBufferTLVWriter writer; |
| 1141 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1142 | CommandPath::Builder commandPathBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1143 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1144 | err = commandPathBuilder.Init(&writer); |
| 1145 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1146 | |
| 1147 | BuildCommandPath(apSuite, commandPathBuilder); |
| 1148 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1149 | chip::System::PacketBufferHandle buf; |
| 1150 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1151 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1152 | |
| 1153 | DebugPrettyPrint(buf); |
| 1154 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1155 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1156 | err = reader.Next(); |
| 1157 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1158 | |
| 1159 | ParseCommandPath(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | void EventDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 1163 | { |
| 1164 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1165 | EventDataElement::Builder eventDataElementBuilder; |
| 1166 | EventDataElement::Parser eventDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1167 | chip::System::PacketBufferTLVWriter writer; |
| 1168 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1169 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1170 | eventDataElementBuilder.Init(&writer); |
| 1171 | BuildEventDataElement(apSuite, eventDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1172 | chip::System::PacketBufferHandle buf; |
| 1173 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1174 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1175 | |
| 1176 | DebugPrettyPrint(buf); |
| 1177 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1178 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1179 | err = reader.Next(); |
| 1180 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1181 | |
| 1182 | eventDataElementParser.Init(reader); |
| 1183 | ParseEventDataElement(apSuite, eventDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void EventListTest(nlTestSuite * apSuite, void * apContext) |
| 1187 | { |
| 1188 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1189 | chip::System::PacketBufferTLVWriter writer; |
| 1190 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1191 | EventList::Builder eventListBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1192 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1193 | eventListBuilder.Init(&writer); |
| 1194 | BuildEventList(apSuite, eventListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1195 | chip::System::PacketBufferHandle buf; |
| 1196 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1197 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1198 | |
| 1199 | DebugPrettyPrint(buf); |
| 1200 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1201 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1202 | err = reader.Next(); |
| 1203 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1204 | ParseEventList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | void StatusElementTest(nlTestSuite * apSuite, void * apContext) |
| 1208 | { |
| 1209 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1210 | StatusElement::Builder statusElementBuilder; |
| 1211 | StatusElement::Parser statusElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1212 | chip::System::PacketBufferTLVWriter writer; |
| 1213 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1214 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1215 | statusElementBuilder.Init(&writer); |
| 1216 | BuildStatusElement(apSuite, statusElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1217 | chip::System::PacketBufferHandle buf; |
| 1218 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1219 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1220 | |
| 1221 | DebugPrettyPrint(buf); |
| 1222 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1223 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1224 | err = reader.Next(); |
| 1225 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1226 | |
| 1227 | statusElementParser.Init(reader); |
| 1228 | ParseStatusElement(apSuite, statusElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | void AttributeStatusElementTest(nlTestSuite * apSuite, void * apContext) |
| 1232 | { |
| 1233 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1234 | AttributeStatusElement::Builder attributeStatusElementBuilder; |
| 1235 | AttributeStatusElement::Parser attributeStatusElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1236 | chip::System::PacketBufferTLVWriter writer; |
| 1237 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1238 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1239 | attributeStatusElementBuilder.Init(&writer); |
| 1240 | BuildAttributeStatusElement(apSuite, attributeStatusElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1241 | chip::System::PacketBufferHandle buf; |
| 1242 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1243 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1244 | |
| 1245 | DebugPrettyPrint(buf); |
| 1246 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1247 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1248 | err = reader.Next(); |
| 1249 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1250 | |
| 1251 | attributeStatusElementParser.Init(reader); |
| 1252 | ParseAttributeStatusElement(apSuite, attributeStatusElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | void AttributeStatusListTest(nlTestSuite * apSuite, void * apContext) |
| 1256 | { |
| 1257 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1258 | chip::System::PacketBufferTLVWriter writer; |
| 1259 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1260 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1261 | AttributeStatusList::Builder attributeStatusListBuilder; |
| 1262 | err = attributeStatusListBuilder.Init(&writer); |
| 1263 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1264 | BuildAttributeStatusList(apSuite, attributeStatusListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1265 | chip::System::PacketBufferHandle buf; |
| 1266 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1267 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1268 | |
| 1269 | DebugPrettyPrint(buf); |
| 1270 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1271 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1272 | err = reader.Next(); |
| 1273 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1274 | ParseAttributeStatusList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | void AttributeDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 1278 | { |
| 1279 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1280 | AttributeDataElement::Builder attributeDataElementBuilder; |
| 1281 | AttributeDataElement::Parser attributeDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1282 | chip::System::PacketBufferTLVWriter writer; |
| 1283 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1284 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1285 | attributeDataElementBuilder.Init(&writer); |
| 1286 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1287 | chip::System::PacketBufferHandle buf; |
| 1288 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1289 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1290 | |
| 1291 | DebugPrettyPrint(buf); |
| 1292 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1293 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1294 | err = reader.Next(); |
| 1295 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1296 | |
| 1297 | attributeDataElementParser.Init(reader); |
| 1298 | ParseAttributeDataElement(apSuite, attributeDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void AttributeDataListTest(nlTestSuite * apSuite, void * apContext) |
| 1302 | { |
| 1303 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1304 | chip::System::PacketBufferTLVWriter writer; |
| 1305 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1306 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1307 | AttributeDataList::Builder attributeDataListBuilder; |
| 1308 | attributeDataListBuilder.Init(&writer); |
| 1309 | BuildAttributeDataList(apSuite, attributeDataListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1310 | chip::System::PacketBufferHandle buf; |
| 1311 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1312 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1313 | |
| 1314 | DebugPrettyPrint(buf); |
| 1315 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1316 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1317 | err = reader.Next(); |
| 1318 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1319 | ParseAttributeDataList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1322 | void AttributeDataVersionListTest(nlTestSuite * apSuite, void * apContext) |
| 1323 | { |
| 1324 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1325 | chip::System::PacketBufferTLVWriter writer; |
| 1326 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1327 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1328 | AttributeDataVersionList::Builder attributeDataVersionListBuilder; |
| 1329 | attributeDataVersionListBuilder.Init(&writer); |
| 1330 | BuildAttributeDataVersionList(apSuite, attributeDataVersionListBuilder); |
| 1331 | chip::System::PacketBufferHandle buf; |
| 1332 | err = writer.Finalize(&buf); |
| 1333 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1334 | |
| 1335 | DebugPrettyPrint(buf); |
| 1336 | |
| 1337 | reader.Init(std::move(buf)); |
| 1338 | err = reader.Next(); |
| 1339 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1340 | ParseAttributeDataVersionList(apSuite, reader); |
| 1341 | } |
| 1342 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1343 | void CommandDataElementTest(nlTestSuite * apSuite, void * apContext) |
| 1344 | { |
| 1345 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1346 | CommandDataElement::Builder commandDataElementBuilder; |
| 1347 | CommandDataElement::Parser commandDataElementParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1348 | chip::System::PacketBufferTLVWriter writer; |
| 1349 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1350 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1351 | commandDataElementBuilder.Init(&writer); |
| 1352 | BuildCommandDataElement(apSuite, commandDataElementBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1353 | chip::System::PacketBufferHandle buf; |
| 1354 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1355 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1356 | |
| 1357 | DebugPrettyPrint(buf); |
| 1358 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1359 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1360 | err = reader.Next(); |
| 1361 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1362 | |
| 1363 | commandDataElementParser.Init(reader); |
| 1364 | ParseCommandDataElement(apSuite, commandDataElementParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1367 | void CommandDataElementWithStatusCodeTest(nlTestSuite * apSuite, void * apContext) |
| 1368 | { |
| 1369 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1370 | CommandDataElement::Builder commandDataElementBuilder; |
| 1371 | CommandDataElement::Parser commandDataElementParser; |
| 1372 | chip::System::PacketBufferTLVWriter writer; |
| 1373 | chip::System::PacketBufferTLVReader reader; |
| 1374 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1375 | commandDataElementBuilder.Init(&writer); |
| 1376 | BuildCommandDataElementWithStatusCode(apSuite, commandDataElementBuilder); |
| 1377 | chip::System::PacketBufferHandle buf; |
| 1378 | err = writer.Finalize(&buf); |
| 1379 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1380 | |
| 1381 | DebugPrettyPrint(buf); |
| 1382 | |
| 1383 | reader.Init(std::move(buf)); |
| 1384 | err = reader.Next(); |
| 1385 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1386 | |
| 1387 | commandDataElementParser.Init(reader); |
| 1388 | ParseCommandDataElementWithStatusCode(apSuite, commandDataElementParser); |
| 1389 | } |
| 1390 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1391 | void CommandListTest(nlTestSuite * apSuite, void * apContext) |
| 1392 | { |
| 1393 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1394 | chip::System::PacketBufferTLVWriter writer; |
| 1395 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1396 | CommandList::Builder commandListBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1397 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1398 | commandListBuilder.Init(&writer); |
| 1399 | BuildCommandList(apSuite, commandListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1400 | chip::System::PacketBufferHandle buf; |
| 1401 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1402 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1403 | |
| 1404 | DebugPrettyPrint(buf); |
| 1405 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1406 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1407 | err = reader.Next(); |
| 1408 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1409 | ParseCommandList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | void ReportDataTest(nlTestSuite * apSuite, void * apContext) |
| 1413 | { |
| 1414 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1415 | chip::System::PacketBufferTLVWriter writer; |
| 1416 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1417 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1418 | BuildReportData(apSuite, writer); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1419 | chip::System::PacketBufferHandle buf; |
| 1420 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1421 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1422 | |
| 1423 | DebugPrettyPrint(buf); |
| 1424 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1425 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1426 | err = reader.Next(); |
| 1427 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1428 | ParseReportData(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | void InvokeCommandTest(nlTestSuite * apSuite, void * apContext) |
| 1432 | { |
| 1433 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1434 | chip::System::PacketBufferTLVWriter writer; |
| 1435 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1436 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1437 | BuildInvokeCommand(apSuite, writer); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1438 | chip::System::PacketBufferHandle buf; |
| 1439 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1440 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1441 | |
| 1442 | DebugPrettyPrint(buf); |
| 1443 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1444 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1445 | err = reader.Next(); |
| 1446 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1447 | ParseInvokeCommand(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1450 | void ReadRequestTest(nlTestSuite * apSuite, void * apContext) |
| 1451 | { |
| 1452 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1453 | chip::System::PacketBufferTLVWriter writer; |
| 1454 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1455 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1456 | BuildReadRequest(apSuite, writer); |
| 1457 | chip::System::PacketBufferHandle buf; |
| 1458 | err = writer.Finalize(&buf); |
| 1459 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1460 | |
| 1461 | DebugPrettyPrint(buf); |
| 1462 | |
| 1463 | reader.Init(std::move(buf)); |
| 1464 | err = reader.Next(); |
| 1465 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1466 | ParseReadRequest(apSuite, reader); |
| 1467 | } |
| 1468 | |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1469 | void WriteRequestTest(nlTestSuite * apSuite, void * apContext) |
| 1470 | { |
| 1471 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1472 | chip::System::PacketBufferTLVWriter writer; |
| 1473 | chip::System::PacketBufferTLVReader reader; |
| 1474 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1475 | BuildWriteRequest(apSuite, writer); |
| 1476 | chip::System::PacketBufferHandle buf; |
| 1477 | err = writer.Finalize(&buf); |
| 1478 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1479 | |
| 1480 | DebugPrettyPrint(buf); |
| 1481 | |
| 1482 | reader.Init(std::move(buf)); |
| 1483 | err = reader.Next(); |
| 1484 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1485 | ParseWriteRequest(apSuite, reader); |
| 1486 | } |
| 1487 | |
| 1488 | void WriteResponseTest(nlTestSuite * apSuite, void * apContext) |
| 1489 | { |
| 1490 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1491 | chip::System::PacketBufferTLVWriter writer; |
| 1492 | chip::System::PacketBufferTLVReader reader; |
| 1493 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1494 | BuildWriteResponse(apSuite, writer); |
| 1495 | chip::System::PacketBufferHandle buf; |
| 1496 | err = writer.Finalize(&buf); |
| 1497 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1498 | |
| 1499 | DebugPrettyPrint(buf); |
| 1500 | |
| 1501 | reader.Init(std::move(buf)); |
| 1502 | err = reader.Next(); |
| 1503 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1504 | ParseWriteResponse(apSuite, reader); |
| 1505 | } |
| 1506 | |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1507 | void SubscribeRequestTest(nlTestSuite * apSuite, void * apContext) |
| 1508 | { |
| 1509 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1510 | chip::System::PacketBufferTLVWriter writer; |
| 1511 | chip::System::PacketBufferTLVReader reader; |
| 1512 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1513 | BuildSubscribeRequest(apSuite, writer); |
| 1514 | chip::System::PacketBufferHandle buf; |
| 1515 | err = writer.Finalize(&buf); |
| 1516 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1517 | |
| 1518 | DebugPrettyPrint(buf); |
| 1519 | |
| 1520 | reader.Init(std::move(buf)); |
| 1521 | err = reader.Next(); |
| 1522 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1523 | ParseSubscribeRequest(apSuite, reader); |
| 1524 | } |
| 1525 | |
| 1526 | void SubscribeResponseTest(nlTestSuite * apSuite, void * apContext) |
| 1527 | { |
| 1528 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1529 | chip::System::PacketBufferTLVWriter writer; |
| 1530 | chip::System::PacketBufferTLVReader reader; |
| 1531 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1532 | BuildSubscribeResponse(apSuite, writer); |
| 1533 | chip::System::PacketBufferHandle buf; |
| 1534 | err = writer.Finalize(&buf); |
| 1535 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1536 | |
| 1537 | DebugPrettyPrint(buf); |
| 1538 | |
| 1539 | reader.Init(std::move(buf)); |
| 1540 | err = reader.Next(); |
| 1541 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1542 | ParseSubscribeResponse(apSuite, reader); |
| 1543 | } |
| 1544 | |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1545 | void TimedRequestTest(nlTestSuite * apSuite, void * apContext) |
| 1546 | { |
| 1547 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1548 | chip::System::PacketBufferTLVWriter writer; |
| 1549 | chip::System::PacketBufferTLVReader reader; |
| 1550 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1551 | BuildTimedRequest(apSuite, writer); |
| 1552 | chip::System::PacketBufferHandle buf; |
| 1553 | err = writer.Finalize(&buf); |
| 1554 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1555 | |
| 1556 | DebugPrettyPrint(buf); |
| 1557 | |
| 1558 | reader.Init(std::move(buf)); |
| 1559 | err = reader.Next(); |
| 1560 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1561 | ParseTimedRequest(apSuite, reader); |
| 1562 | } |
| 1563 | |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 1564 | void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) |
| 1565 | { |
| 1566 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1567 | size_t NumDataElement = 0; |
| 1568 | chip::System::PacketBufferTLVWriter writer; |
| 1569 | chip::System::PacketBufferTLVReader reader; |
| 1570 | AttributeDataList::Parser attributeDataListParser; |
| 1571 | chip::TLV::TLVWriter checkpoint; |
| 1572 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1573 | AttributeDataList::Builder attributeDataListBuilder; |
| 1574 | attributeDataListBuilder.Init(&writer); |
| 1575 | |
| 1576 | // encode one attribute element |
| 1577 | AttributeDataElement::Builder attributeDataElementBuilder1 = attributeDataListBuilder.CreateAttributeDataElementBuilder(); |
| 1578 | NL_TEST_ASSERT(apSuite, attributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 1579 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder1); |
| 1580 | // checkpoint |
| 1581 | attributeDataListBuilder.Checkpoint(checkpoint); |
| 1582 | // encode another attribute element |
| 1583 | AttributeDataElement::Builder attributeDataElementBuilder2 = attributeDataListBuilder.CreateAttributeDataElementBuilder(); |
| 1584 | NL_TEST_ASSERT(apSuite, attributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 1585 | BuildAttributeDataElement(apSuite, attributeDataElementBuilder2); |
| 1586 | // rollback to previous checkpoint |
| 1587 | attributeDataListBuilder.Rollback(checkpoint); |
| 1588 | |
| 1589 | attributeDataListBuilder.EndOfAttributeDataList(); |
| 1590 | NL_TEST_ASSERT(apSuite, attributeDataListBuilder.GetError() == CHIP_NO_ERROR); |
| 1591 | |
| 1592 | chip::System::PacketBufferHandle buf; |
| 1593 | err = writer.Finalize(&buf); |
| 1594 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1595 | |
| 1596 | DebugPrettyPrint(buf); |
| 1597 | |
| 1598 | reader.Init(std::move(buf)); |
| 1599 | err = reader.Next(); |
| 1600 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1601 | |
| 1602 | err = attributeDataListParser.Init(reader); |
| 1603 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 1604 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1605 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1606 | err = attributeDataListParser.CheckSchemaValidity(); |
| 1607 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1608 | #endif |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 1609 | while (CHIP_NO_ERROR == (err = attributeDataListParser.Next())) |
| 1610 | { |
| 1611 | ++NumDataElement; |
| 1612 | } |
| 1613 | |
| 1614 | NL_TEST_ASSERT(apSuite, NumDataElement == 1); |
| 1615 | } |
| 1616 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1617 | /** |
| 1618 | * Test Suite. It lists all the test functions. |
| 1619 | */ |
| 1620 | |
| 1621 | // clang-format off |
| 1622 | const nlTest sTests[] = |
| 1623 | { |
| 1624 | NL_TEST_DEF("AttributePathTest", AttributePathTest), |
| 1625 | NL_TEST_DEF("AttributePathListTest", AttributePathListTest), |
| 1626 | NL_TEST_DEF("EventPathTest", EventPathTest), |
| 1627 | NL_TEST_DEF("EventPathListTest", EventPathListTest), |
| 1628 | NL_TEST_DEF("CommandPathTest", CommandPathTest), |
| 1629 | NL_TEST_DEF("EventDataElementTest", EventDataElementTest), |
| 1630 | NL_TEST_DEF("EventListTest", EventListTest), |
| 1631 | NL_TEST_DEF("StatusElementTest", StatusElementTest), |
| 1632 | NL_TEST_DEF("AttributeStatusElementTest", AttributeStatusElementTest), |
| 1633 | NL_TEST_DEF("AttributeStatusListTest", AttributeStatusListTest), |
| 1634 | NL_TEST_DEF("AttributeDataElementTest", AttributeDataElementTest), |
| 1635 | NL_TEST_DEF("AttributeDataListTest", AttributeDataListTest), |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1636 | NL_TEST_DEF("AttributeDataVersionListTest", AttributeDataVersionListTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1637 | NL_TEST_DEF("CommandDataElementTest", CommandDataElementTest), |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1638 | NL_TEST_DEF("CommandDataElementWithStatusCodeTest", CommandDataElementWithStatusCodeTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1639 | NL_TEST_DEF("CommandListTest", CommandListTest), |
| 1640 | NL_TEST_DEF("ReportDataTest", ReportDataTest), |
| 1641 | NL_TEST_DEF("InvokeCommandTest", InvokeCommandTest), |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1642 | NL_TEST_DEF("ReadRequestTest", ReadRequestTest), |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1643 | NL_TEST_DEF("WriteRequestTest", WriteRequestTest), |
| 1644 | NL_TEST_DEF("WriteResponseTest", WriteResponseTest), |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1645 | NL_TEST_DEF("SubscribeRequestTest", SubscribeRequestTest), |
| 1646 | NL_TEST_DEF("SubscribeResponseTest", SubscribeResponseTest), |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1647 | NL_TEST_DEF("TimedRequestTest", TimedRequestTest), |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 1648 | NL_TEST_DEF("CheckPointRollbackTest", CheckPointRollbackTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1649 | NL_TEST_SENTINEL() |
| 1650 | }; |
| 1651 | // clang-format on |
| 1652 | } // namespace |
| 1653 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1654 | /** |
| 1655 | * Set up the test suite. |
| 1656 | */ |
| 1657 | static int TestSetup(void * inContext) |
| 1658 | { |
| 1659 | CHIP_ERROR error = chip::Platform::MemoryInit(); |
| 1660 | if (error != CHIP_NO_ERROR) |
| 1661 | return FAILURE; |
| 1662 | return SUCCESS; |
| 1663 | } |
| 1664 | |
| 1665 | /** |
| 1666 | * Tear down the test suite. |
| 1667 | */ |
| 1668 | static int TestTeardown(void * inContext) |
| 1669 | { |
| 1670 | chip::Platform::MemoryShutdown(); |
| 1671 | return SUCCESS; |
| 1672 | } |
| 1673 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1674 | int TestMessageDef() |
| 1675 | { |
| 1676 | // clang-format off |
| 1677 | nlTestSuite theSuite = |
| 1678 | { |
| 1679 | "MessageDef", |
| 1680 | &sTests[0], |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1681 | TestSetup, |
| 1682 | TestTeardown, |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1683 | }; |
| 1684 | // clang-format on |
| 1685 | |
| 1686 | nlTestRunner(&theSuite, nullptr); |
| 1687 | |
| 1688 | return (nlTestRunnerStats(&theSuite)); |
| 1689 | } |
| 1690 | |
| 1691 | CHIP_REGISTER_TEST_SUITE(TestMessageDef) |