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 | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 26 | #include <app/MessageDef/EventFilterIBs.h> |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 27 | #include <app/MessageDef/EventStatusIB.h> |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 28 | #include <app/MessageDef/InvokeRequestMessage.h> |
| 29 | #include <app/MessageDef/InvokeResponseMessage.h> |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 30 | #include <app/MessageDef/ReadRequestMessage.h> |
| 31 | #include <app/MessageDef/ReportDataMessage.h> |
| 32 | #include <app/MessageDef/SubscribeRequestMessage.h> |
| 33 | #include <app/MessageDef/SubscribeResponseMessage.h> |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 34 | #include <app/MessageDef/TimedRequestMessage.h> |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 35 | #include <app/MessageDef/WriteRequestMessage.h> |
| 36 | #include <app/MessageDef/WriteResponseMessage.h> |
Zang MingJie | 53dd583 | 2021-09-03 03:05:16 +0800 | [diff] [blame] | 37 | #include <lib/core/CHIPError.h> |
| 38 | #include <lib/core/CHIPTLVDebug.hpp> |
| 39 | #include <lib/support/CHIPMem.h> |
Justin Wood | 0e14979 | 2022-01-06 21:52:51 +0100 | [diff] [blame] | 40 | #include <lib/support/EnforceFormat.h> |
Zang MingJie | 53dd583 | 2021-09-03 03:05:16 +0800 | [diff] [blame] | 41 | #include <lib/support/UnitTestRegistration.h> |
Justin Wood | 0e14979 | 2022-01-06 21:52:51 +0100 | [diff] [blame] | 42 | #include <lib/support/logging/Constants.h> |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 43 | #include <system/TLVPacketBufferBackingStore.h> |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 44 | |
| 45 | #include <nlunit-test.h> |
| 46 | |
| 47 | namespace { |
| 48 | |
| 49 | using namespace chip::app; |
| 50 | |
Justin Wood | 0e14979 | 2022-01-06 21:52:51 +0100 | [diff] [blame] | 51 | void ENFORCE_FORMAT(1, 2) TLVPrettyPrinter(const char * aFormat, ...) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 52 | { |
| 53 | va_list args; |
| 54 | |
| 55 | va_start(args, aFormat); |
| 56 | |
| 57 | vprintf(aFormat, args); |
| 58 | |
| 59 | va_end(args); |
| 60 | } |
| 61 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 62 | CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 63 | { |
| 64 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 65 | chip::System::PacketBufferTLVReader reader; |
| 66 | reader.Init(aMsgBuf.Retain()); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 67 | err = reader.Next(); |
| 68 | chip::TLV::Debug::Dump(reader, TLVPrettyPrinter); |
| 69 | |
| 70 | if (CHIP_NO_ERROR != err) |
| 71 | { |
Kevin Schoedel | 0fe17ec | 2021-08-05 08:52:07 -0400 | [diff] [blame] | 72 | ChipLogProgress(DataManagement, "DebugPrettyPrint fails with err %" CHIP_ERROR_FORMAT, err.Format()); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | return err; |
| 76 | } |
| 77 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 78 | void BuildStatusIB(nlTestSuite * apSuite, StatusIB::Builder & aStatusIBBuilder) |
| 79 | { |
| 80 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 81 | |
| 82 | StatusIB statusIB; |
| 83 | statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; |
| 84 | aStatusIBBuilder.EncodeStatusIB(statusIB); |
| 85 | err = aStatusIBBuilder.GetError(); |
| 86 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 87 | } |
| 88 | |
| 89 | void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) |
| 90 | { |
| 91 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 92 | StatusIB::Parser StatusIBParser; |
| 93 | StatusIB statusIB; |
| 94 | |
| 95 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 96 | err = aStatusIBParser.CheckSchemaValidity(); |
| 97 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 98 | #endif |
| 99 | err = aStatusIBParser.DecodeStatusIB(statusIB); |
| 100 | NL_TEST_ASSERT(apSuite, |
| 101 | err == CHIP_NO_ERROR && statusIB.mStatus == chip::Protocols::InteractionModel::Status::InvalidSubscription && |
| 102 | !statusIB.mClusterStatus.HasValue()); |
| 103 | } |
| 104 | |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 105 | void BuildClusterPathIB(nlTestSuite * apSuite, ClusterPathIB::Builder & aClusterPathBuilder) |
| 106 | { |
| 107 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 108 | aClusterPathBuilder.Node(1).Endpoint(2).Cluster(3).EndOfClusterPathIB(); |
| 109 | err = aClusterPathBuilder.GetError(); |
| 110 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 111 | } |
| 112 | |
| 113 | void ParseClusterPathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 114 | { |
| 115 | ClusterPathIB::Parser clusterPathParser; |
| 116 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 117 | chip::NodeId node = 0; |
| 118 | chip::EndpointId endpoint = 0; |
| 119 | chip::ClusterId cluster = 0; |
| 120 | |
| 121 | err = clusterPathParser.Init(aReader); |
| 122 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 123 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 124 | err = clusterPathParser.CheckSchemaValidity(); |
| 125 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 126 | #endif |
| 127 | |
| 128 | err = clusterPathParser.GetNode(&node); |
| 129 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); |
| 130 | |
| 131 | err = clusterPathParser.GetEndpoint(&endpoint); |
| 132 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); |
| 133 | |
| 134 | err = clusterPathParser.GetCluster(&cluster); |
| 135 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); |
| 136 | } |
| 137 | |
| 138 | void BuildDataVersionFilterIB(nlTestSuite * apSuite, DataVersionFilterIB::Builder & aDataVersionFilterIBBuilder) |
| 139 | { |
yunhanw-google | 4584707 | 2021-12-08 14:14:10 -0800 | [diff] [blame] | 140 | ClusterPathIB::Builder & clusterPathBuilder = aDataVersionFilterIBBuilder.CreatePath(); |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 141 | NL_TEST_ASSERT(apSuite, clusterPathBuilder.GetError() == CHIP_NO_ERROR); |
| 142 | BuildClusterPathIB(apSuite, clusterPathBuilder); |
| 143 | aDataVersionFilterIBBuilder.DataVersion(2).EndOfDataVersionFilterIB(); |
| 144 | NL_TEST_ASSERT(apSuite, aDataVersionFilterIBBuilder.GetError() == CHIP_NO_ERROR); |
| 145 | } |
| 146 | |
| 147 | void ParseDataVersionFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 148 | { |
| 149 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 150 | DataVersionFilterIB::Parser dataVersionFilterIBParser; |
| 151 | ClusterPathIB::Parser clusterPath; |
| 152 | chip::DataVersion dataVersion = 2; |
| 153 | |
| 154 | err = dataVersionFilterIBParser.Init(aReader); |
| 155 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 156 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 157 | err = dataVersionFilterIBParser.CheckSchemaValidity(); |
| 158 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 159 | #endif |
| 160 | |
| 161 | err = dataVersionFilterIBParser.GetPath(&clusterPath); |
| 162 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 163 | |
| 164 | err = dataVersionFilterIBParser.GetDataVersion(&dataVersion); |
| 165 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && dataVersion == 2); |
| 166 | } |
| 167 | |
| 168 | void BuildDataVersionFilterIBs(nlTestSuite * apSuite, DataVersionFilterIBs::Builder & aDataVersionFilterIBsBuilder) |
| 169 | { |
| 170 | DataVersionFilterIB::Builder & dataVersionFilterIBBuilder = aDataVersionFilterIBsBuilder.CreateDataVersionFilter(); |
| 171 | NL_TEST_ASSERT(apSuite, aDataVersionFilterIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 172 | BuildDataVersionFilterIB(apSuite, dataVersionFilterIBBuilder); |
| 173 | aDataVersionFilterIBsBuilder.EndOfDataVersionFilterIBs(); |
| 174 | NL_TEST_ASSERT(apSuite, aDataVersionFilterIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 175 | } |
| 176 | |
| 177 | void ParseDataVersionFilterIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 178 | { |
| 179 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 180 | DataVersionFilterIBs::Parser dataVersionFilterIBsParser; |
| 181 | |
| 182 | err = dataVersionFilterIBsParser.Init(aReader); |
| 183 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 184 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 185 | err = dataVersionFilterIBsParser.CheckSchemaValidity(); |
| 186 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 187 | #endif |
| 188 | } |
| 189 | |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 190 | void BuildEventFilterIB(nlTestSuite * apSuite, EventFilterIB::Builder & aEventFilterIBBuilder) |
| 191 | { |
| 192 | aEventFilterIBBuilder.Node(1).EventMin(2).EndOfEventFilterIB(); |
| 193 | NL_TEST_ASSERT(apSuite, aEventFilterIBBuilder.GetError() == CHIP_NO_ERROR); |
| 194 | } |
| 195 | |
| 196 | void ParseEventFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 197 | { |
| 198 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 199 | EventFilterIB::Parser eventFilterIBParser; |
| 200 | chip::NodeId node = 1; |
| 201 | uint64_t eventMin = 2; |
| 202 | |
| 203 | err = eventFilterIBParser.Init(aReader); |
| 204 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 205 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 206 | err = eventFilterIBParser.CheckSchemaValidity(); |
| 207 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 208 | #endif |
| 209 | err = eventFilterIBParser.GetNode(&node); |
| 210 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); |
| 211 | |
| 212 | err = eventFilterIBParser.GetEventMin(&eventMin); |
| 213 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && eventMin == 2); |
| 214 | } |
| 215 | |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 216 | void BuildEventFilters(nlTestSuite * apSuite, EventFilterIBs::Builder & aEventFiltersBuilder) |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 217 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 218 | EventFilterIB::Builder & eventFilterBuilder = aEventFiltersBuilder.CreateEventFilter(); |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 219 | NL_TEST_ASSERT(apSuite, aEventFiltersBuilder.GetError() == CHIP_NO_ERROR); |
| 220 | BuildEventFilterIB(apSuite, eventFilterBuilder); |
| 221 | aEventFiltersBuilder.EndOfEventFilters(); |
| 222 | NL_TEST_ASSERT(apSuite, aEventFiltersBuilder.GetError() == CHIP_NO_ERROR); |
| 223 | } |
| 224 | |
| 225 | void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 226 | { |
| 227 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 228 | EventFilterIBs::Parser eventFiltersParser; |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 229 | |
| 230 | err = eventFiltersParser.Init(aReader); |
| 231 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 232 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 233 | err = eventFiltersParser.CheckSchemaValidity(); |
| 234 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 235 | #endif |
| 236 | } |
| 237 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 238 | void BuildAttributePathIB(nlTestSuite * apSuite, AttributePathIB::Builder & aAttributePathBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 239 | { |
| 240 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 241 | aAttributePathBuilder.EnableTagCompression(false) |
| 242 | .Node(1) |
| 243 | .Endpoint(2) |
| 244 | .Cluster(3) |
| 245 | .Attribute(4) |
| 246 | .ListIndex(5) |
| 247 | .EndOfAttributePathIB(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 248 | err = aAttributePathBuilder.GetError(); |
| 249 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 250 | } |
| 251 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 252 | void ParseAttributePathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 253 | { |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 254 | AttributePathIB::Parser attributePathParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 255 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 256 | bool enableTagCompression = true; |
| 257 | chip::NodeId node = 1; |
| 258 | chip::EndpointId endpoint = 2; |
| 259 | chip::ClusterId cluster = 3; |
| 260 | chip::AttributeId attribute = 4; |
yunhanw-google | ebb7396 | 2021-04-16 16:02:17 -0700 | [diff] [blame] | 261 | chip::ListIndex listIndex = 5; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 262 | |
| 263 | err = attributePathParser.Init(aReader); |
| 264 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 265 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 266 | err = attributePathParser.CheckSchemaValidity(); |
| 267 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 268 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 269 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 270 | err = attributePathParser.GetEnableTagCompression(&enableTagCompression); |
| 271 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && enableTagCompression == false); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 272 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 273 | err = attributePathParser.GetNode(&node); |
| 274 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 275 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 276 | err = attributePathParser.GetEndpoint(&endpoint); |
| 277 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); |
| 278 | |
| 279 | err = attributePathParser.GetCluster(&cluster); |
| 280 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); |
| 281 | |
| 282 | err = attributePathParser.GetAttribute(&attribute); |
| 283 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && attribute == 4); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 284 | |
| 285 | err = attributePathParser.GetListIndex(&listIndex); |
| 286 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && listIndex == 5); |
| 287 | } |
| 288 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 289 | void BuildAttributePathList(nlTestSuite * apSuite, AttributePathIBs::Builder & aAttributePathListBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 290 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 291 | AttributePathIB::Builder & attributePathBuilder = aAttributePathListBuilder.CreatePath(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 292 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 293 | BuildAttributePathIB(apSuite, attributePathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 294 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 295 | aAttributePathListBuilder.EndOfAttributePathIBs(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 296 | NL_TEST_ASSERT(apSuite, aAttributePathListBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 300 | { |
| 301 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 302 | AttributePathIBs::Parser attributePathListParser; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 303 | AttributePathIB::Parser attributePathParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 304 | |
| 305 | err = attributePathListParser.Init(aReader); |
| 306 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 307 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 308 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 309 | err = attributePathListParser.CheckSchemaValidity(); |
| 310 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 311 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 312 | } |
| 313 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 314 | void BuildEventPath(nlTestSuite * apSuite, EventPathIB::Builder & aEventPathBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 315 | { |
| 316 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 317 | aEventPathBuilder.Node(1).Endpoint(2).Cluster(3).Event(4).IsUrgent(true).EndOfEventPathIB(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 318 | err = aEventPathBuilder.GetError(); |
| 319 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 320 | } |
| 321 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 322 | void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 323 | { |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 324 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 325 | chip::NodeId node = 1; |
| 326 | chip::EndpointId endpoint = 2; |
| 327 | chip::ClusterId cluster = 3; |
| 328 | chip::EventId event = 4; |
| 329 | bool isUrgent = false; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 330 | |
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 = aEventPathParser.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 | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 335 | err = aEventPathParser.GetNode(&node); |
| 336 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 337 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 338 | err = aEventPathParser.GetEndpoint(&endpoint); |
| 339 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 340 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 341 | err = aEventPathParser.GetCluster(&cluster); |
| 342 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 343 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 344 | err = aEventPathParser.GetEvent(&event); |
| 345 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && event == 4); |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 346 | |
| 347 | err = aEventPathParser.GetIsUrgent(&isUrgent); |
| 348 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isUrgent == true); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 349 | } |
| 350 | |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 351 | void BuildEventPaths(nlTestSuite * apSuite, EventPathIBs::Builder & aEventPathsBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 352 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 353 | EventPathIB::Builder & eventPathBuilder = aEventPathsBuilder.CreatePath(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 354 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 355 | BuildEventPath(apSuite, eventPathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 356 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 357 | aEventPathsBuilder.EndOfEventPaths(); |
| 358 | NL_TEST_ASSERT(apSuite, aEventPathsBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 359 | } |
| 360 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 361 | void ParseEventPaths(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 362 | { |
| 363 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 364 | EventPathIBs::Parser eventPathListParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 365 | |
| 366 | err = eventPathListParser.Init(aReader); |
| 367 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 368 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 369 | err = eventPathListParser.CheckSchemaValidity(); |
| 370 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 371 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 372 | } |
| 373 | |
yunhanw-google | 8c2638c | 2021-10-20 16:33:42 -0700 | [diff] [blame] | 374 | void BuildCommandPath(nlTestSuite * apSuite, CommandPathIB::Builder & aCommandPathBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 375 | { |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 376 | aCommandPathBuilder.EndpointId(1).ClusterId(3).CommandId(4).EndOfCommandPathIB(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 377 | NL_TEST_ASSERT(apSuite, aCommandPathBuilder.GetError() == CHIP_NO_ERROR); |
| 378 | } |
| 379 | |
| 380 | void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 381 | { |
| 382 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 8c2638c | 2021-10-20 16:33:42 -0700 | [diff] [blame] | 383 | CommandPathIB::Parser commandPathParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 384 | chip::EndpointId endpointId = 0; |
| 385 | chip::ClusterId clusterId = 0; |
| 386 | chip::CommandId commandId = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 387 | |
| 388 | err = commandPathParser.Init(aReader); |
| 389 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 390 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 391 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 392 | err = commandPathParser.CheckSchemaValidity(); |
| 393 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 394 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 395 | err = commandPathParser.GetEndpointId(&endpointId); |
| 396 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 1); |
| 397 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 398 | err = commandPathParser.GetClusterId(&clusterId); |
| 399 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 400 | |
| 401 | err = commandPathParser.GetCommandId(&commandId); |
| 402 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && commandId == 4); |
| 403 | } |
| 404 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 405 | void BuildEventDataIB(nlTestSuite * apSuite, EventDataIB::Builder & aEventDataIBBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 406 | { |
| 407 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 408 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 409 | EventPathIB::Builder & eventPathBuilder = aEventDataIBBuilder.CreatePath(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 410 | NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); |
| 411 | BuildEventPath(apSuite, eventPathBuilder); |
| 412 | |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 413 | aEventDataIBBuilder.EventNumber(2).Priority(3).EpochTimestamp(4).SystemTimestamp(5).DeltaEpochTimestamp(6).DeltaSystemTimestamp( |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 414 | 7); |
| 415 | err = aEventDataIBBuilder.GetError(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 416 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 417 | // Construct test event data |
| 418 | { |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 419 | chip::TLV::TLVWriter * pWriter = aEventDataIBBuilder.GetWriter(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 420 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 421 | err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), |
| 422 | chip::TLV::kTLVType_Structure, dummyType); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 423 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 424 | |
| 425 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 426 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 427 | |
| 428 | err = pWriter->EndContainer(dummyType); |
| 429 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 430 | } |
| 431 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 432 | aEventDataIBBuilder.EndOfEventDataIB(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 433 | } |
| 434 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 435 | void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 436 | { |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 437 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 438 | uint8_t priorityLevel = 0; |
| 439 | chip::EventNumber number = 0; |
| 440 | uint64_t EpochTimestamp = 0; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 441 | uint64_t systemTimestamp = 0; |
| 442 | uint64_t deltaUTCTimestamp = 0; |
| 443 | uint64_t deltaSystemTimestamp = 0; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 444 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 445 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 446 | err = aEventDataIBParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 447 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 448 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 449 | { |
| 450 | { |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 451 | EventPathIB::Parser eventPath; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 452 | err = aEventDataIBParser.GetPath(&eventPath); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 453 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 454 | } |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 455 | err = aEventDataIBParser.GetEventNumber(&number); |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 456 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && number == 2); |
| 457 | err = aEventDataIBParser.GetPriority(&priorityLevel); |
| 458 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && priorityLevel == 3); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 459 | err = aEventDataIBParser.GetEpochTimestamp(&EpochTimestamp); |
| 460 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && EpochTimestamp == 4); |
| 461 | err = aEventDataIBParser.GetSystemTimestamp(&systemTimestamp); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 462 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && systemTimestamp == 5); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 463 | err = aEventDataIBParser.GetDeltaEpochTimestamp(&deltaUTCTimestamp); |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 464 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaUTCTimestamp == 6); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 465 | err = aEventDataIBParser.GetDeltaSystemTimestamp(&deltaSystemTimestamp); |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 466 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaSystemTimestamp == 7); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 467 | |
| 468 | { |
| 469 | chip::TLV::TLVReader reader; |
| 470 | bool val = false; |
| 471 | chip::TLV::TLVType container; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 472 | aEventDataIBParser.GetData(&reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 473 | err = reader.EnterContainer(container); |
| 474 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 475 | |
| 476 | err = reader.Next(); |
| 477 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 478 | |
| 479 | err = reader.Get(val); |
| 480 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 481 | |
| 482 | err = reader.ExitContainer(container); |
| 483 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 488 | void BuildEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Builder & aEventStatusIBBuilder) |
| 489 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 490 | EventPathIB::Builder & eventPathBuilder = aEventStatusIBBuilder.CreatePath(); |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 491 | NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); |
| 492 | BuildEventPath(apSuite, eventPathBuilder); |
| 493 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 494 | StatusIB::Builder & statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 495 | NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); |
| 496 | BuildStatusIB(apSuite, statusIBBuilder); |
| 497 | |
| 498 | aEventStatusIBBuilder.EndOfEventStatusIB(); |
| 499 | NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); |
| 500 | } |
| 501 | |
| 502 | void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventStatusIBParser) |
| 503 | { |
| 504 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 505 | EventPathIB::Parser eventPathParser; |
| 506 | StatusIB::Parser statusParser; |
| 507 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 508 | err = aEventStatusIBParser.CheckSchemaValidity(); |
| 509 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 510 | #endif |
| 511 | err = aEventStatusIBParser.GetPath(&eventPathParser); |
| 512 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 513 | |
| 514 | err = aEventStatusIBParser.GetErrorStatus(&statusParser); |
| 515 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 516 | } |
| 517 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 518 | void BuildEventReportIB(nlTestSuite * apSuite, EventReportIB::Builder & aEventReportIBBuilder) |
| 519 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 520 | EventDataIB::Builder & eventDataIBBuilder = aEventReportIBBuilder.CreateEventData(); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 521 | NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); |
| 522 | BuildEventDataIB(apSuite, eventDataIBBuilder); |
| 523 | |
| 524 | aEventReportIBBuilder.EndOfEventReportIB(); |
| 525 | NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); |
| 526 | } |
| 527 | |
| 528 | void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventReportIBParser) |
| 529 | { |
| 530 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 531 | EventStatusIB::Parser eventStatusParser; |
| 532 | EventDataIB::Parser eventDataParser; |
| 533 | |
| 534 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 535 | err = aEventReportIBParser.CheckSchemaValidity(); |
| 536 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 537 | #endif |
yunhanw-google | f3d6b7c | 2021-11-17 13:42:38 -0800 | [diff] [blame] | 538 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 539 | err = aEventReportIBParser.GetEventData(&eventDataParser); |
| 540 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 541 | } |
| 542 | |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 543 | void BuildEventReports(nlTestSuite * apSuite, EventReportIBs::Builder & aEventReportsBuilder) |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 544 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 545 | EventReportIB::Builder & eventReportIBBuilder = aEventReportsBuilder.CreateEventReport(); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 546 | NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); |
| 547 | BuildEventReportIB(apSuite, eventReportIBBuilder); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 548 | aEventReportsBuilder.EndOfEventReports(); |
| 549 | NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); |
| 550 | } |
| 551 | |
| 552 | void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 553 | { |
| 554 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 555 | EventReportIBs::Parser eventReportsParser; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 556 | |
| 557 | err = eventReportsParser.Init(aReader); |
| 558 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 559 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 560 | err = eventReportsParser.CheckSchemaValidity(); |
| 561 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 562 | #endif |
| 563 | } |
| 564 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 565 | void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & aAttributeStatusIBBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 566 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 567 | AttributePathIB::Builder & attributePathBuilder = aAttributeStatusIBBuilder.CreatePath(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 568 | NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 569 | BuildAttributePathIB(apSuite, attributePathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 570 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 571 | StatusIB::Builder & statusIBBuilder = aAttributeStatusIBBuilder.CreateErrorStatus(); |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 572 | NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); |
| 573 | BuildStatusIB(apSuite, statusIBBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 574 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 575 | aAttributeStatusIBBuilder.EndOfAttributeStatusIB(); |
| 576 | NL_TEST_ASSERT(apSuite, aAttributeStatusIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 577 | } |
| 578 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 579 | void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & aAttributeStatusIBParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 580 | { |
| 581 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 582 | AttributePathIB::Parser attributePathParser; |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 583 | StatusIB::Parser StatusIBParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 584 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 585 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 586 | err = aAttributeStatusIBParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 587 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 588 | #endif |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 589 | err = aAttributeStatusIBParser.GetPath(&attributePathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 590 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 591 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 592 | err = aAttributeStatusIBParser.GetErrorStatus(&StatusIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 593 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 594 | } |
| 595 | |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 596 | void BuildAttributeStatuses(nlTestSuite * apSuite, AttributeStatusIBs::Builder & aAttributeStatusesBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 597 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 598 | AttributeStatusIB::Builder & aAttributeStatusIBBuilder = aAttributeStatusesBuilder.CreateAttributeStatus(); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 599 | NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 600 | BuildAttributeStatusIB(apSuite, aAttributeStatusIBBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 601 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 602 | aAttributeStatusesBuilder.EndOfAttributeStatuses(); |
| 603 | NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 604 | } |
| 605 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 606 | void ParseAttributeStatuses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 607 | { |
| 608 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 609 | AttributeStatusIBs::Parser attributeStatusParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 610 | |
| 611 | err = attributeStatusParser.Init(aReader); |
| 612 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 613 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 614 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 615 | err = attributeStatusParser.CheckSchemaValidity(); |
| 616 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 617 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 618 | } |
| 619 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 620 | void BuildAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Builder & aAttributeDataIBBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 621 | { |
| 622 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 623 | |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 624 | aAttributeDataIBBuilder.DataVersion(2); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 625 | AttributePathIB::Builder & attributePathBuilder = aAttributeDataIBBuilder.CreatePath(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 626 | NL_TEST_ASSERT(apSuite, aAttributeDataIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 627 | BuildAttributePathIB(apSuite, attributePathBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 628 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 629 | // Construct attribute data |
| 630 | { |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 631 | chip::TLV::TLVWriter * pWriter = aAttributeDataIBBuilder.GetWriter(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 632 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 633 | err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(AttributeDataIB::Tag::kData)), |
| 634 | chip::TLV::kTLVType_Structure, dummyType); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 635 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 636 | |
| 637 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 638 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 639 | |
| 640 | err = pWriter->EndContainer(dummyType); |
| 641 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 642 | } |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 643 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 644 | err = aAttributeDataIBBuilder.GetError(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 645 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 646 | aAttributeDataIBBuilder.EndOfAttributeDataIB(); |
| 647 | NL_TEST_ASSERT(apSuite, aAttributeDataIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 648 | } |
| 649 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 650 | void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttributeDataIBParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 651 | { |
| 652 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 653 | AttributePathIB::Parser attributePathParser; |
yunhanw-google | 0edb9f9 | 2022-02-11 00:50:59 -0800 | [diff] [blame] | 654 | chip::DataVersion version = 0; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 655 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 656 | err = aAttributeDataIBParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 657 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 658 | #endif |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 659 | err = aAttributeDataIBParser.GetPath(&attributePathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 660 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 661 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 662 | err = aAttributeDataIBParser.GetDataVersion(&version); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 663 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && version == 2); |
| 664 | |
| 665 | { |
| 666 | chip::TLV::TLVReader reader; |
| 667 | bool val = false; |
| 668 | chip::TLV::TLVType container; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 669 | aAttributeDataIBParser.GetData(&reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 670 | err = reader.EnterContainer(container); |
| 671 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 672 | |
| 673 | err = reader.Next(); |
| 674 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 675 | |
| 676 | err = reader.Get(val); |
| 677 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 678 | |
| 679 | err = reader.ExitContainer(container); |
| 680 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 681 | } |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 682 | } |
| 683 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 684 | void BuildAttributeDataIBs(nlTestSuite * apSuite, AttributeDataIBs::Builder & aAttributeDataIBsBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 685 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 686 | AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 687 | NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 688 | BuildAttributeDataIB(apSuite, attributeDataIBBuilder); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 689 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 690 | aAttributeDataIBsBuilder.EndOfAttributeDataIBs(); |
| 691 | NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 692 | } |
| 693 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 694 | void ParseAttributeDataIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 695 | { |
| 696 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 697 | AttributeDataIBs::Parser AttributeDataIBsParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 698 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 699 | err = AttributeDataIBsParser.Init(aReader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 700 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 701 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 702 | err = AttributeDataIBsParser.CheckSchemaValidity(); |
| 703 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 704 | #endif |
| 705 | } |
| 706 | |
| 707 | void BuildAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Builder & aAttributeReportIBBuilder) |
| 708 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 709 | AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeReportIBBuilder.CreateAttributeData(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 710 | NL_TEST_ASSERT(apSuite, aAttributeReportIBBuilder.GetError() == CHIP_NO_ERROR); |
| 711 | BuildAttributeDataIB(apSuite, attributeDataIBBuilder); |
| 712 | |
| 713 | aAttributeReportIBBuilder.EndOfAttributeReportIB(); |
| 714 | NL_TEST_ASSERT(apSuite, aAttributeReportIBBuilder.GetError() == CHIP_NO_ERROR); |
| 715 | } |
| 716 | |
| 717 | void ParseAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Parser & aAttributeReportIBParser) |
| 718 | { |
| 719 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 720 | AttributeStatusIB::Parser attributeStatusParser; |
| 721 | AttributeDataIB::Parser attributeDataParser; |
| 722 | |
| 723 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 724 | err = aAttributeReportIBParser.CheckSchemaValidity(); |
| 725 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 726 | #endif |
| 727 | err = aAttributeReportIBParser.GetAttributeData(&attributeDataParser); |
| 728 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 729 | } |
| 730 | |
| 731 | void BuildAttributeReportIBs(nlTestSuite * apSuite, AttributeReportIBs::Builder & aAttributeReportIBsBuilder) |
| 732 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 733 | AttributeReportIB::Builder & attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 734 | NL_TEST_ASSERT(apSuite, aAttributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 735 | BuildAttributeReportIB(apSuite, attributeReportIBBuilder); |
| 736 | |
| 737 | aAttributeReportIBsBuilder.EndOfAttributeReportIBs(); |
| 738 | NL_TEST_ASSERT(apSuite, aAttributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 739 | } |
| 740 | |
| 741 | void ParseAttributeReportIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 742 | { |
| 743 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 744 | AttributeReportIBs::Parser attributeReportIBsParser; |
| 745 | |
| 746 | err = attributeReportIBsParser.Init(aReader); |
| 747 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 748 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 749 | err = attributeReportIBsParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 750 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 751 | #endif |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 752 | } |
| 753 | |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 754 | void BuildCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Builder & aCommandDataIBBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 755 | { |
| 756 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 757 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 758 | CommandPathIB::Builder & commandPathBuilder = aCommandDataIBBuilder.CreatePath(); |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 759 | NL_TEST_ASSERT(apSuite, aCommandDataIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 760 | BuildCommandPath(apSuite, commandPathBuilder); |
| 761 | |
| 762 | // Construct command data |
| 763 | { |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 764 | chip::TLV::TLVWriter * pWriter = aCommandDataIBBuilder.GetWriter(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 765 | chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; |
yunhanw-google | 731ae5a | 2022-06-01 23:02:05 -0700 | [diff] [blame] | 766 | err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kFields)), |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 767 | chip::TLV::kTLVType_Structure, dummyType); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 768 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 769 | |
| 770 | err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); |
| 771 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 772 | |
| 773 | err = pWriter->EndContainer(dummyType); |
| 774 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 775 | } |
| 776 | |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 777 | aCommandDataIBBuilder.EndOfCommandDataIB(); |
| 778 | NL_TEST_ASSERT(apSuite, aCommandDataIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 779 | } |
| 780 | |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 781 | void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandDataIBParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 782 | { |
| 783 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 8c2638c | 2021-10-20 16:33:42 -0700 | [diff] [blame] | 784 | CommandPathIB::Parser commandPathParser; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 785 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 786 | err = aCommandDataIBParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 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 | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 789 | err = aCommandDataIBParser.GetPath(&commandPathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 790 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 791 | |
| 792 | { |
| 793 | chip::TLV::TLVReader reader; |
| 794 | bool val = false; |
| 795 | chip::TLV::TLVType container; |
yunhanw-google | 731ae5a | 2022-06-01 23:02:05 -0700 | [diff] [blame] | 796 | aCommandDataIBParser.GetFields(&reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 797 | err = reader.EnterContainer(container); |
| 798 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 799 | |
| 800 | err = reader.Next(); |
| 801 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 802 | |
| 803 | err = reader.Get(val); |
| 804 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); |
| 805 | |
| 806 | err = reader.ExitContainer(container); |
| 807 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 808 | } |
| 809 | } |
| 810 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 811 | void BuildCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Builder & aCommandStatusIBBuilder) |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 812 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 813 | CommandPathIB::Builder & commandPathBuilder = aCommandStatusIBBuilder.CreatePath(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 814 | NL_TEST_ASSERT(apSuite, aCommandStatusIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 815 | BuildCommandPath(apSuite, commandPathBuilder); |
| 816 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 817 | StatusIB::Builder & statusIBBuilder = aCommandStatusIBBuilder.CreateErrorStatus(); |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 818 | NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); |
| 819 | BuildStatusIB(apSuite, statusIBBuilder); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 820 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 821 | aCommandStatusIBBuilder.EndOfCommandStatusIB(); |
| 822 | NL_TEST_ASSERT(apSuite, aCommandStatusIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 823 | } |
| 824 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 825 | void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aCommandStatusIBParser) |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 826 | { |
| 827 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 8c2638c | 2021-10-20 16:33:42 -0700 | [diff] [blame] | 828 | CommandPathIB::Parser commandPathParser; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 829 | StatusIB::Parser statusParser; |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 830 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 831 | err = aCommandStatusIBParser.CheckSchemaValidity(); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 832 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 833 | #endif |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 834 | err = aCommandStatusIBParser.GetPath(&commandPathParser); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 835 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 836 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 837 | err = aCommandStatusIBParser.GetErrorStatus(&statusParser); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 838 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 839 | } |
| 840 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 841 | void BuildWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 842 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 843 | CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 844 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 845 | BuildCommandDataIB(apSuite, commandDataBuilder); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 846 | CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 847 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 848 | BuildCommandStatusIB(apSuite, commandStatusBuilder); |
| 849 | aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); |
| 850 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 851 | } |
| 852 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 853 | void BuildInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) |
| 854 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 855 | CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 856 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 857 | BuildCommandDataIB(apSuite, commandDataBuilder); |
| 858 | aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); |
| 859 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 860 | } |
| 861 | |
| 862 | void BuildInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) |
| 863 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 864 | CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 865 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 866 | BuildCommandStatusIB(apSuite, commandStatusBuilder); |
| 867 | aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); |
| 868 | NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); |
| 869 | } |
| 870 | |
| 871 | void ParseInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 872 | { |
| 873 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 874 | CommandDataIB::Parser commandDataParser; |
| 875 | CommandStatusIB::Parser statusIBParser; |
| 876 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 877 | err = aInvokeResponseIBParser.CheckSchemaValidity(); |
| 878 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 879 | #endif |
| 880 | err = aInvokeResponseIBParser.GetCommand(&commandDataParser); |
| 881 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 882 | } |
| 883 | |
| 884 | void ParseInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) |
| 885 | { |
| 886 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 887 | CommandDataIB::Parser commandDataParser; |
| 888 | CommandStatusIB::Parser statusIBParser; |
| 889 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 890 | err = aInvokeResponseIBParser.CheckSchemaValidity(); |
| 891 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 892 | #endif |
| 893 | err = aInvokeResponseIBParser.GetStatus(&statusIBParser); |
| 894 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 895 | } |
| 896 | |
| 897 | void ParseWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) |
| 898 | { |
| 899 | CommandDataIB::Parser commandDataParser; |
| 900 | CommandStatusIB::Parser statusIBParser; |
| 901 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 902 | CHIP_ERROR err = aInvokeResponseIBParser.CheckSchemaValidity(); |
| 903 | NL_TEST_ASSERT(apSuite, err != CHIP_NO_ERROR); |
| 904 | #endif |
| 905 | } |
| 906 | |
| 907 | void BuildInvokeRequests(nlTestSuite * apSuite, InvokeRequests::Builder & aInvokeRequestsBuilder) |
| 908 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 909 | CommandDataIB::Builder & aCommandDataIBBuilder = aInvokeRequestsBuilder.CreateCommandData(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 910 | NL_TEST_ASSERT(apSuite, aInvokeRequestsBuilder.GetError() == CHIP_NO_ERROR); |
| 911 | BuildCommandDataIB(apSuite, aCommandDataIBBuilder); |
| 912 | |
| 913 | aInvokeRequestsBuilder.EndOfInvokeRequests(); |
| 914 | NL_TEST_ASSERT(apSuite, aInvokeRequestsBuilder.GetError() == CHIP_NO_ERROR); |
| 915 | } |
| 916 | |
| 917 | void ParseInvokeRequests(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 918 | { |
| 919 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 920 | InvokeRequests::Parser invokeRequestsParser; |
| 921 | err = invokeRequestsParser.Init(aReader); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 922 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 923 | |
| 924 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 925 | err = invokeRequestsParser.CheckSchemaValidity(); |
| 926 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 927 | #endif |
| 928 | } |
| 929 | |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 930 | void BuildInvokeResponses(nlTestSuite * apSuite, InvokeResponseIBs::Builder & aInvokeResponsesBuilder) |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 931 | { |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 932 | InvokeResponseIB::Builder & invokeResponseIBBuilder = aInvokeResponsesBuilder.CreateInvokeResponse(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 933 | NL_TEST_ASSERT(apSuite, aInvokeResponsesBuilder.GetError() == CHIP_NO_ERROR); |
| 934 | BuildInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBBuilder); |
| 935 | |
| 936 | aInvokeResponsesBuilder.EndOfInvokeResponses(); |
| 937 | NL_TEST_ASSERT(apSuite, aInvokeResponsesBuilder.GetError() == CHIP_NO_ERROR); |
| 938 | } |
| 939 | |
| 940 | void ParseInvokeResponses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 941 | { |
| 942 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 943 | InvokeResponseIBs::Parser invokeResponsesParser; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 944 | err = invokeResponsesParser.Init(aReader); |
| 945 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 946 | |
| 947 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 948 | err = invokeResponsesParser.CheckSchemaValidity(); |
| 949 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 950 | #endif |
| 951 | } |
| 952 | |
| 953 | void BuildInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 954 | { |
| 955 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 956 | InvokeRequestMessage::Builder invokeRequestMessageBuilder; |
| 957 | err = invokeRequestMessageBuilder.Init(&aWriter); |
| 958 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 959 | invokeRequestMessageBuilder.SuppressResponse(true); |
| 960 | invokeRequestMessageBuilder.TimedRequest(true); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 961 | InvokeRequests::Builder & invokeRequestsBuilder = invokeRequestMessageBuilder.CreateInvokeRequests(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 962 | NL_TEST_ASSERT(apSuite, invokeRequestsBuilder.GetError() == CHIP_NO_ERROR); |
| 963 | |
| 964 | BuildInvokeRequests(apSuite, invokeRequestsBuilder); |
| 965 | |
| 966 | invokeRequestMessageBuilder.EndOfInvokeRequestMessage(); |
| 967 | NL_TEST_ASSERT(apSuite, invokeRequestMessageBuilder.GetError() == CHIP_NO_ERROR); |
| 968 | } |
| 969 | |
| 970 | void ParseInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 971 | { |
| 972 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 973 | InvokeRequestMessage::Parser invokeRequestMessageParser; |
| 974 | err = invokeRequestMessageParser.Init(aReader); |
| 975 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 976 | |
| 977 | bool suppressResponse = false; |
| 978 | bool timedRequest = false; |
| 979 | invokeRequestMessageParser.GetSuppressResponse(&suppressResponse); |
| 980 | invokeRequestMessageParser.GetTimedRequest(&timedRequest); |
| 981 | NL_TEST_ASSERT(apSuite, suppressResponse == true); |
| 982 | NL_TEST_ASSERT(apSuite, timedRequest == true); |
| 983 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 984 | err = invokeRequestMessageParser.CheckSchemaValidity(); |
| 985 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 986 | #endif |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 987 | NL_TEST_ASSERT(apSuite, invokeRequestMessageParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | void BuildInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
| 991 | { |
| 992 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 993 | InvokeResponseMessage::Builder invokeResponseMessageBuilder; |
| 994 | err = invokeResponseMessageBuilder.Init(&aWriter); |
| 995 | |
| 996 | invokeResponseMessageBuilder.SuppressResponse(true); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 997 | InvokeResponseIBs::Builder & invokeResponsesBuilder = invokeResponseMessageBuilder.CreateInvokeResponses(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 998 | NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); |
| 999 | |
| 1000 | BuildInvokeResponses(apSuite, invokeResponsesBuilder); |
| 1001 | |
| 1002 | invokeResponseMessageBuilder.EndOfInvokeResponseMessage(); |
| 1003 | NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); |
| 1004 | } |
| 1005 | |
| 1006 | void ParseInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
| 1007 | { |
| 1008 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1009 | InvokeResponseMessage::Parser invokeResponseMessageParser; |
| 1010 | err = invokeResponseMessageParser.Init(aReader); |
| 1011 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1012 | |
| 1013 | bool suppressResponse = false; |
| 1014 | invokeResponseMessageParser.GetSuppressResponse(&suppressResponse); |
| 1015 | NL_TEST_ASSERT(apSuite, suppressResponse == true); |
| 1016 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1017 | err = invokeResponseMessageParser.CheckSchemaValidity(); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1018 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1019 | #endif |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1020 | NL_TEST_ASSERT(apSuite, invokeResponseMessageParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1023 | void BuildReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1024 | { |
| 1025 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1026 | ReportDataMessage::Builder reportDataMessageBuilder; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1027 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1028 | err = reportDataMessageBuilder.Init(&aWriter); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1029 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1030 | |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 1031 | reportDataMessageBuilder.SubscriptionId(2); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1032 | NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1033 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1034 | AttributeReportIBs::Builder & attributeReportIBs = reportDataMessageBuilder.CreateAttributeReportIBs(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1035 | NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1036 | BuildAttributeReportIBs(apSuite, attributeReportIBs); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1037 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1038 | EventReportIBs::Builder & eventReportIBs = reportDataMessageBuilder.CreateEventReports(); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1039 | NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1040 | BuildEventReports(apSuite, eventReportIBs); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1041 | |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 1042 | reportDataMessageBuilder.MoreChunkedMessages(true).SuppressResponse(true); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1043 | NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1044 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1045 | reportDataMessageBuilder.EndOfReportDataMessage(); |
| 1046 | NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1049 | void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1050 | { |
| 1051 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1052 | ReportDataMessage::Parser reportDataParser; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1053 | |
Song GUO | 6e22467 | 2022-05-14 05:58:58 +0800 | [diff] [blame] | 1054 | bool suppressResponse = false; |
| 1055 | chip::SubscriptionId subscriptionId = 0; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1056 | AttributeReportIBs::Parser attributeReportIBsParser; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1057 | EventReportIBs::Parser eventReportsParser; |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 1058 | bool moreChunkedMessages = false; |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1059 | reportDataParser.Init(aReader); |
| 1060 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1061 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1062 | err = reportDataParser.CheckSchemaValidity(); |
| 1063 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1064 | #endif |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 1065 | err = reportDataParser.GetSuppressResponse(&suppressResponse); |
| 1066 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1067 | |
| 1068 | err = reportDataParser.GetSubscriptionId(&subscriptionId); |
| 1069 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && subscriptionId == 2); |
| 1070 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1071 | err = reportDataParser.GetAttributeReportIBs(&attributeReportIBsParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1072 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1073 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1074 | err = reportDataParser.GetEventReports(&eventReportsParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1075 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1076 | |
yunhanw-google | df5569f | 2021-02-25 11:14:18 -0800 | [diff] [blame] | 1077 | err = reportDataParser.GetMoreChunkedMessages(&moreChunkedMessages); |
| 1078 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1079 | NL_TEST_ASSERT(apSuite, reportDataParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1082 | void BuildReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1083 | { |
| 1084 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1085 | ReadRequestMessage::Builder readRequestBuilder; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1086 | |
| 1087 | err = readRequestBuilder.Init(&aWriter); |
| 1088 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1089 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1090 | AttributePathIBs::Builder & attributePathIBs = readRequestBuilder.CreateAttributeRequests(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1091 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1092 | BuildAttributePathList(apSuite, attributePathIBs); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1093 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1094 | EventPathIBs::Builder & eventPathList = readRequestBuilder.CreateEventRequests(); |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1095 | |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1096 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1097 | BuildEventPaths(apSuite, eventPathList); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1098 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1099 | EventFilterIBs::Builder & eventFilters = readRequestBuilder.CreateEventFilters(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1100 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1101 | BuildEventFilters(apSuite, eventFilters); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1102 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1103 | readRequestBuilder.IsFabricFiltered(true); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1104 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1105 | |
yunhanw-google | 57a2df3 | 2022-04-14 11:04:47 -0700 | [diff] [blame] | 1106 | DataVersionFilterIBs::Builder & dataVersionFilters = readRequestBuilder.CreateDataVersionFilters(); |
| 1107 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1108 | BuildDataVersionFilterIBs(apSuite, dataVersionFilters); |
| 1109 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1110 | readRequestBuilder.EndOfReadRequestMessage(); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1111 | NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1112 | } |
| 1113 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1114 | void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1115 | { |
| 1116 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1117 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1118 | ReadRequestMessage::Parser readRequestParser; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1119 | AttributePathIBs::Parser attributePathListParser; |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1120 | DataVersionFilterIBs::Parser dataVersionFilterIBsParser; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1121 | EventPathIBs::Parser eventPathListParser; |
| 1122 | EventFilterIBs::Parser eventFiltersParser; |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1123 | bool isFabricFiltered = false; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1124 | |
| 1125 | err = readRequestParser.Init(aReader); |
| 1126 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1127 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1128 | err = readRequestParser.CheckSchemaValidity(); |
| 1129 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 1130 | #endif |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1131 | err = readRequestParser.GetAttributeRequests(&attributePathListParser); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1132 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1133 | |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1134 | err = readRequestParser.GetDataVersionFilters(&dataVersionFilterIBsParser); |
| 1135 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1136 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1137 | err = readRequestParser.GetEventRequests(&eventPathListParser); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1138 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1139 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1140 | err = readRequestParser.GetEventFilters(&eventFiltersParser); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1141 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1142 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1143 | err = readRequestParser.GetIsFabricFiltered(&isFabricFiltered); |
| 1144 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isFabricFiltered); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1145 | NL_TEST_ASSERT(apSuite, readRequestParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1148 | void BuildWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1149 | { |
| 1150 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1151 | WriteRequestMessage::Builder writeRequestBuilder; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1152 | |
| 1153 | err = writeRequestBuilder.Init(&aWriter); |
| 1154 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1155 | |
| 1156 | writeRequestBuilder.SuppressResponse(true); |
| 1157 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1158 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1159 | writeRequestBuilder.TimedRequest(true); |
| 1160 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1161 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1162 | AttributeDataIBs::Builder & attributeDataIBs = writeRequestBuilder.CreateWriteRequests(); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1163 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1164 | BuildAttributeDataIBs(apSuite, attributeDataIBs); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1165 | |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1166 | writeRequestBuilder.MoreChunkedMessages(true); |
| 1167 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1168 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1169 | writeRequestBuilder.EndOfWriteRequestMessage(); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1170 | NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1171 | } |
| 1172 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1173 | void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1174 | { |
| 1175 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1176 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1177 | WriteRequestMessage::Parser writeRequestParser; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1178 | bool suppressResponse = false; |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1179 | bool timeRequest = false; |
| 1180 | AttributeDataIBs::Parser writeRequests; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1181 | bool moreChunkedMessages = false; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1182 | |
| 1183 | err = writeRequestParser.Init(aReader); |
| 1184 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1185 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1186 | err = writeRequestParser.CheckSchemaValidity(); |
| 1187 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1188 | #endif |
| 1189 | err = writeRequestParser.GetSuppressResponse(&suppressResponse); |
| 1190 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); |
| 1191 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1192 | err = writeRequestParser.GetTimedRequest(&timeRequest); |
| 1193 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && timeRequest); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1194 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1195 | err = writeRequestParser.GetWriteRequests(&writeRequests); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1196 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1197 | |
| 1198 | err = writeRequestParser.GetMoreChunkedMessages(&moreChunkedMessages); |
| 1199 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1202 | void BuildWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1203 | { |
| 1204 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1205 | WriteResponseMessage::Builder writeResponseBuilder; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1206 | |
| 1207 | err = writeResponseBuilder.Init(&aWriter); |
| 1208 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1209 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1210 | AttributeStatusIBs::Builder & attributeStatuses = writeResponseBuilder.CreateWriteResponses(); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1211 | NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1212 | BuildAttributeStatuses(apSuite, attributeStatuses); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1213 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1214 | writeResponseBuilder.EndOfWriteResponseMessage(); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1215 | NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 1216 | } |
| 1217 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1218 | void ParseWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1219 | { |
| 1220 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1221 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1222 | WriteResponseMessage::Parser writeResponseParser; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1223 | AttributeStatusIBs::Parser attributeStatusesParser; |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1224 | err = writeResponseParser.Init(aReader); |
| 1225 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1226 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1227 | err = writeResponseParser.CheckSchemaValidity(); |
| 1228 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1229 | #endif |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1230 | err = writeResponseParser.GetWriteResponses(&attributeStatusesParser); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1231 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1232 | NL_TEST_ASSERT(apSuite, writeResponseParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1235 | void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1236 | { |
| 1237 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1238 | SubscribeRequestMessage::Builder subscribeRequestBuilder; |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1239 | |
| 1240 | err = subscribeRequestBuilder.Init(&aWriter); |
| 1241 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1242 | |
yunhanw-google | 51db97b | 2021-12-03 08:36:41 -0800 | [diff] [blame] | 1243 | subscribeRequestBuilder.KeepSubscriptions(true); |
| 1244 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1245 | |
| 1246 | subscribeRequestBuilder.MinIntervalFloorSeconds(2); |
| 1247 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1248 | |
| 1249 | subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); |
| 1250 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1251 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1252 | AttributePathIBs::Builder & attributePathIBs = subscribeRequestBuilder.CreateAttributeRequests(); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1253 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1254 | BuildAttributePathList(apSuite, attributePathIBs); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1255 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1256 | EventPathIBs::Builder & eventPathList = subscribeRequestBuilder.CreateEventRequests(); |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1257 | |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1258 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1259 | BuildEventPaths(apSuite, eventPathList); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1260 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 1261 | EventFilterIBs::Builder & eventFilters = subscribeRequestBuilder.CreateEventFilters(); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1262 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1263 | BuildEventFilters(apSuite, eventFilters); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1264 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1265 | subscribeRequestBuilder.IsFabricFiltered(true); |
| 1266 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1267 | |
yunhanw-google | 57a2df3 | 2022-04-14 11:04:47 -0700 | [diff] [blame] | 1268 | DataVersionFilterIBs::Builder & dataVersionFilters = subscribeRequestBuilder.CreateDataVersionFilters(); |
| 1269 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1270 | BuildDataVersionFilterIBs(apSuite, dataVersionFilters); |
| 1271 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1272 | subscribeRequestBuilder.EndOfSubscribeRequestMessage(); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1273 | NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); |
| 1274 | } |
| 1275 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1276 | void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1277 | { |
| 1278 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1279 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1280 | SubscribeRequestMessage::Parser subscribeRequestParser; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1281 | AttributePathIBs::Parser attributePathListParser; |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1282 | DataVersionFilterIBs::Parser dataVersionFilterIBsParser; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1283 | EventPathIBs::Parser eventPathListParser; |
| 1284 | EventFilterIBs::Parser eventFiltersParser; |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1285 | uint16_t MinIntervalFloorSeconds = 0; |
| 1286 | uint16_t MaxIntervalCeilingSeconds = 0; |
| 1287 | bool keepExistingSubscription = false; |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1288 | bool isFabricFiltered = false; |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1289 | |
| 1290 | err = subscribeRequestParser.Init(aReader); |
| 1291 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1292 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1293 | err = subscribeRequestParser.CheckSchemaValidity(); |
| 1294 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1295 | #endif |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1296 | err = subscribeRequestParser.GetAttributeRequests(&attributePathListParser); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1297 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1298 | |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1299 | err = subscribeRequestParser.GetDataVersionFilters(&dataVersionFilterIBsParser); |
| 1300 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1301 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1302 | err = subscribeRequestParser.GetEventRequests(&eventPathListParser); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1303 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1304 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1305 | err = subscribeRequestParser.GetEventFilters(&eventFiltersParser); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1306 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1307 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1308 | err = subscribeRequestParser.GetMinIntervalFloorSeconds(&MinIntervalFloorSeconds); |
| 1309 | NL_TEST_ASSERT(apSuite, MinIntervalFloorSeconds == 2 && err == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1310 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1311 | err = subscribeRequestParser.GetMaxIntervalCeilingSeconds(&MaxIntervalCeilingSeconds); |
| 1312 | NL_TEST_ASSERT(apSuite, MaxIntervalCeilingSeconds == 3 && err == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1313 | |
yunhanw-google | 6a9cd5f | 2021-10-12 17:44:25 -0700 | [diff] [blame] | 1314 | err = subscribeRequestParser.GetKeepSubscriptions(&keepExistingSubscription); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1315 | NL_TEST_ASSERT(apSuite, keepExistingSubscription && err == CHIP_NO_ERROR); |
| 1316 | |
yunhanw-google | 494fb9b | 2021-11-17 12:01:02 -0800 | [diff] [blame] | 1317 | err = subscribeRequestParser.GetIsFabricFiltered(&isFabricFiltered); |
| 1318 | NL_TEST_ASSERT(apSuite, isFabricFiltered && err == CHIP_NO_ERROR); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1319 | NL_TEST_ASSERT(apSuite, subscribeRequestParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1322 | void BuildSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1323 | { |
| 1324 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1325 | SubscribeResponseMessage::Builder subscribeResponseBuilder; |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1326 | |
| 1327 | err = subscribeResponseBuilder.Init(&aWriter); |
| 1328 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1329 | |
| 1330 | subscribeResponseBuilder.SubscriptionId(1); |
| 1331 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 1332 | |
yunhanw-google | ec5f5dc | 2021-09-13 16:47:42 -0700 | [diff] [blame] | 1333 | subscribeResponseBuilder.MinIntervalFloorSeconds(1); |
| 1334 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 1335 | |
| 1336 | subscribeResponseBuilder.MaxIntervalCeilingSeconds(2); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1337 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 1338 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1339 | subscribeResponseBuilder.EndOfSubscribeResponseMessage(); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1340 | NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); |
| 1341 | } |
| 1342 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1343 | void ParseSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1344 | { |
| 1345 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1346 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 1347 | SubscribeResponseMessage::Parser subscribeResponseParser; |
Song GUO | 6e22467 | 2022-05-14 05:58:58 +0800 | [diff] [blame] | 1348 | chip::SubscriptionId subscriptionId = 0; |
| 1349 | uint16_t minIntervalFloorSeconds = 0; |
| 1350 | uint16_t maxIntervalCeilingSeconds = 0; |
| 1351 | err = subscribeResponseParser.Init(aReader); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1352 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1353 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
| 1354 | err = subscribeResponseParser.CheckSchemaValidity(); |
| 1355 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1356 | #endif |
| 1357 | err = subscribeResponseParser.GetSubscriptionId(&subscriptionId); |
| 1358 | NL_TEST_ASSERT(apSuite, subscriptionId == 1 && err == CHIP_NO_ERROR); |
| 1359 | |
yunhanw-google | ec5f5dc | 2021-09-13 16:47:42 -0700 | [diff] [blame] | 1360 | err = subscribeResponseParser.GetMinIntervalFloorSeconds(&minIntervalFloorSeconds); |
| 1361 | NL_TEST_ASSERT(apSuite, minIntervalFloorSeconds == 1 && err == CHIP_NO_ERROR); |
| 1362 | |
| 1363 | err = subscribeResponseParser.GetMaxIntervalCeilingSeconds(&maxIntervalCeilingSeconds); |
| 1364 | NL_TEST_ASSERT(apSuite, maxIntervalCeilingSeconds == 2 && err == CHIP_NO_ERROR); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1365 | |
| 1366 | NL_TEST_ASSERT(apSuite, subscribeResponseParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 1369 | void BuildTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1370 | { |
| 1371 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 1372 | TimedRequestMessage::Builder TimedRequestMessageBuilder; |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1373 | |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 1374 | err = TimedRequestMessageBuilder.Init(&aWriter); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1375 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1376 | |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 1377 | TimedRequestMessageBuilder.TimeoutMs(1); |
| 1378 | NL_TEST_ASSERT(apSuite, TimedRequestMessageBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 1381 | void ParseTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1382 | { |
| 1383 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1384 | |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1385 | TimedRequestMessage::Parser timedRequestMessageParser; |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1386 | uint16_t timeout = 0; |
| 1387 | |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1388 | err = timedRequestMessageParser.Init(aReader); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1389 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1390 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1391 | err = timedRequestMessageParser.CheckSchemaValidity(); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1392 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1393 | #endif |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1394 | err = timedRequestMessageParser.GetTimeoutMs(&timeout); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1395 | NL_TEST_ASSERT(apSuite, timeout == 1 && err == CHIP_NO_ERROR); |
yunhanw-google | 4394fcb | 2022-02-17 17:36:41 -0800 | [diff] [blame] | 1396 | |
| 1397 | NL_TEST_ASSERT(apSuite, timedRequestMessageParser.ExitContainer() == CHIP_NO_ERROR); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1400 | void DataVersionFilterIBTest(nlTestSuite * apSuite, void * apContext) |
| 1401 | { |
| 1402 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1403 | DataVersionFilterIB::Builder dataVersionFilterIBBuilder; |
| 1404 | chip::System::PacketBufferTLVWriter writer; |
| 1405 | chip::System::PacketBufferTLVReader reader; |
| 1406 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1407 | dataVersionFilterIBBuilder.Init(&writer); |
| 1408 | BuildDataVersionFilterIB(apSuite, dataVersionFilterIBBuilder); |
| 1409 | chip::System::PacketBufferHandle buf; |
| 1410 | err = writer.Finalize(&buf); |
| 1411 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1412 | |
| 1413 | DebugPrettyPrint(buf); |
| 1414 | |
| 1415 | reader.Init(std::move(buf)); |
| 1416 | err = reader.Next(); |
| 1417 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1418 | ParseDataVersionFilterIB(apSuite, reader); |
| 1419 | } |
| 1420 | |
| 1421 | void DataVersionFilterIBsTest(nlTestSuite * apSuite, void * apContext) |
| 1422 | { |
| 1423 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1424 | chip::System::PacketBufferTLVWriter writer; |
| 1425 | chip::System::PacketBufferTLVReader reader; |
| 1426 | DataVersionFilterIBs::Builder dataVersionFilterIBsBuilder; |
| 1427 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1428 | |
| 1429 | err = dataVersionFilterIBsBuilder.Init(&writer); |
| 1430 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1431 | |
| 1432 | BuildDataVersionFilterIBs(apSuite, dataVersionFilterIBsBuilder); |
| 1433 | chip::System::PacketBufferHandle buf; |
| 1434 | err = writer.Finalize(&buf); |
| 1435 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1436 | |
| 1437 | DebugPrettyPrint(buf); |
| 1438 | |
| 1439 | reader.Init(std::move(buf)); |
| 1440 | err = reader.Next(); |
| 1441 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1442 | ParseDataVersionFilterIBs(apSuite, reader); |
| 1443 | } |
| 1444 | |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 1445 | void EventFilterTest(nlTestSuite * apSuite, void * apContext) |
| 1446 | { |
| 1447 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1448 | EventFilterIB::Builder eventFilterBuilder; |
| 1449 | chip::System::PacketBufferTLVWriter writer; |
| 1450 | chip::System::PacketBufferTLVReader reader; |
| 1451 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1452 | eventFilterBuilder.Init(&writer); |
| 1453 | BuildEventFilterIB(apSuite, eventFilterBuilder); |
| 1454 | chip::System::PacketBufferHandle buf; |
| 1455 | err = writer.Finalize(&buf); |
| 1456 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1457 | |
| 1458 | DebugPrettyPrint(buf); |
| 1459 | |
| 1460 | reader.Init(std::move(buf)); |
| 1461 | err = reader.Next(); |
| 1462 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 1463 | ParseEventFilterIB(apSuite, reader); |
| 1464 | } |
| 1465 | |
| 1466 | void EventFiltersTest(nlTestSuite * apSuite, void * apContext) |
| 1467 | { |
| 1468 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1469 | chip::System::PacketBufferTLVWriter writer; |
| 1470 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1471 | EventFilterIBs::Builder eventFiltersBuilder; |
| 1472 | EventFilterIBs::Parser eventFiltersParser; |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 1473 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1474 | |
| 1475 | err = eventFiltersBuilder.Init(&writer); |
| 1476 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1477 | |
| 1478 | BuildEventFilters(apSuite, eventFiltersBuilder); |
| 1479 | chip::System::PacketBufferHandle buf; |
| 1480 | err = writer.Finalize(&buf); |
| 1481 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1482 | |
| 1483 | DebugPrettyPrint(buf); |
| 1484 | |
| 1485 | reader.Init(std::move(buf)); |
| 1486 | err = reader.Next(); |
| 1487 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1488 | ParseEventFilters(apSuite, reader); |
| 1489 | } |
| 1490 | |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 1491 | void ClusterPathIBTest(nlTestSuite * apSuite, void * apContext) |
| 1492 | { |
| 1493 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1494 | ClusterPathIB::Builder clusterPathBuilder; |
| 1495 | chip::System::PacketBufferTLVWriter writer; |
| 1496 | chip::System::PacketBufferTLVReader reader; |
| 1497 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1498 | clusterPathBuilder.Init(&writer); |
| 1499 | BuildClusterPathIB(apSuite, clusterPathBuilder); |
| 1500 | chip::System::PacketBufferHandle buf; |
| 1501 | err = writer.Finalize(&buf); |
| 1502 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1503 | |
| 1504 | DebugPrettyPrint(buf); |
| 1505 | |
| 1506 | reader.Init(std::move(buf)); |
| 1507 | err = reader.Next(); |
| 1508 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1509 | |
| 1510 | ParseClusterPathIB(apSuite, reader); |
| 1511 | } |
| 1512 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1513 | void AttributePathTest(nlTestSuite * apSuite, void * apContext) |
| 1514 | { |
| 1515 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1516 | AttributePathIB::Builder attributePathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1517 | chip::System::PacketBufferTLVWriter writer; |
| 1518 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1519 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1520 | attributePathBuilder.Init(&writer); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1521 | BuildAttributePathIB(apSuite, attributePathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1522 | chip::System::PacketBufferHandle buf; |
| 1523 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1524 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1525 | |
| 1526 | DebugPrettyPrint(buf); |
| 1527 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1528 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1529 | err = reader.Next(); |
| 1530 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1531 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1532 | ParseAttributePathIB(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | void AttributePathListTest(nlTestSuite * apSuite, void * apContext) |
| 1536 | { |
| 1537 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1538 | chip::System::PacketBufferTLVWriter writer; |
| 1539 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1540 | AttributePathIBs::Builder attributePathListBuilder; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1541 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1542 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1543 | |
| 1544 | err = attributePathListBuilder.Init(&writer); |
| 1545 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1546 | |
| 1547 | BuildAttributePathList(apSuite, attributePathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1548 | chip::System::PacketBufferHandle buf; |
| 1549 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1550 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1551 | |
| 1552 | DebugPrettyPrint(buf); |
| 1553 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1554 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1555 | err = reader.Next(); |
| 1556 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1557 | ParseAttributePathList(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | void EventPathTest(nlTestSuite * apSuite, void * apContext) |
| 1561 | { |
| 1562 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1563 | EventPathIB::Parser eventPathParser; |
| 1564 | EventPathIB::Builder eventPathBuilder; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1565 | chip::System::PacketBufferTLVWriter writer; |
| 1566 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1567 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1568 | eventPathBuilder.Init(&writer); |
| 1569 | BuildEventPath(apSuite, eventPathBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1570 | chip::System::PacketBufferHandle buf; |
| 1571 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1572 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1573 | |
| 1574 | DebugPrettyPrint(buf); |
| 1575 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1576 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1577 | err = reader.Next(); |
| 1578 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1579 | |
| 1580 | eventPathParser.Init(reader); |
| 1581 | ParseEventPath(apSuite, eventPathParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1584 | void EventPathsTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1585 | { |
| 1586 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1587 | chip::System::PacketBufferTLVWriter writer; |
| 1588 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1589 | EventPathIBs::Builder eventPathListBuilder; |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1590 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1591 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 1592 | |
| 1593 | err = eventPathListBuilder.Init(&writer); |
| 1594 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1595 | |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1596 | BuildEventPaths(apSuite, eventPathListBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1597 | chip::System::PacketBufferHandle buf; |
| 1598 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1599 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1600 | |
| 1601 | DebugPrettyPrint(buf); |
| 1602 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1603 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1604 | err = reader.Next(); |
| 1605 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 1606 | ParseEventPaths(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1607 | } |
| 1608 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1609 | void CommandPathIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1610 | { |
| 1611 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1612 | chip::System::PacketBufferTLVWriter writer; |
| 1613 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | 8c2638c | 2021-10-20 16:33:42 -0700 | [diff] [blame] | 1614 | CommandPathIB::Builder commandPathBuilder; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1615 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1616 | err = commandPathBuilder.Init(&writer); |
| 1617 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1618 | |
| 1619 | BuildCommandPath(apSuite, commandPathBuilder); |
| 1620 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1621 | chip::System::PacketBufferHandle buf; |
| 1622 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1623 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1624 | |
| 1625 | DebugPrettyPrint(buf); |
| 1626 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1627 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1628 | err = reader.Next(); |
| 1629 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1630 | |
| 1631 | ParseCommandPath(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1632 | } |
| 1633 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1634 | void EventDataIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1635 | { |
| 1636 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1637 | EventDataIB::Builder eventDataIBBuilder; |
| 1638 | EventDataIB::Parser eventDataIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1639 | chip::System::PacketBufferTLVWriter writer; |
| 1640 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1641 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1642 | eventDataIBBuilder.Init(&writer); |
| 1643 | BuildEventDataIB(apSuite, eventDataIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1644 | chip::System::PacketBufferHandle buf; |
| 1645 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1646 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1647 | |
| 1648 | DebugPrettyPrint(buf); |
| 1649 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1650 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1651 | err = reader.Next(); |
| 1652 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1653 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1654 | eventDataIBParser.Init(reader); |
| 1655 | ParseEventDataIB(apSuite, eventDataIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1658 | void EventReportIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1659 | { |
| 1660 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1661 | EventReportIB::Builder eventReportIBBuilder; |
| 1662 | EventReportIB::Parser eventReportIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1663 | chip::System::PacketBufferTLVWriter writer; |
| 1664 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1665 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1666 | eventReportIBBuilder.Init(&writer); |
| 1667 | BuildEventReportIB(apSuite, eventReportIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1668 | chip::System::PacketBufferHandle buf; |
| 1669 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1670 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1671 | |
| 1672 | DebugPrettyPrint(buf); |
| 1673 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1674 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1675 | err = reader.Next(); |
| 1676 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1677 | |
| 1678 | eventReportIBParser.Init(reader); |
| 1679 | ParseEventReportIB(apSuite, eventReportIBParser); |
| 1680 | } |
| 1681 | |
| 1682 | void EventReportsTest(nlTestSuite * apSuite, void * apContext) |
| 1683 | { |
| 1684 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1685 | chip::System::PacketBufferTLVWriter writer; |
| 1686 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1687 | EventReportIBs::Builder eventReportsBuilder; |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 1688 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1689 | eventReportsBuilder.Init(&writer); |
| 1690 | BuildEventReports(apSuite, eventReportsBuilder); |
| 1691 | chip::System::PacketBufferHandle buf; |
| 1692 | err = writer.Finalize(&buf); |
| 1693 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1694 | |
| 1695 | DebugPrettyPrint(buf); |
| 1696 | |
| 1697 | reader.Init(std::move(buf)); |
| 1698 | err = reader.Next(); |
| 1699 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1700 | ParseEventReports(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
yunhanw-google | 588d4c9 | 2022-05-11 23:50:15 -0700 | [diff] [blame] | 1703 | void EmptyEventReportsTest(nlTestSuite * apSuite, void * apContext) |
| 1704 | { |
| 1705 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1706 | chip::System::PacketBufferTLVWriter writer; |
| 1707 | chip::System::PacketBufferTLVReader reader; |
| 1708 | EventReportIBs::Builder eventReportsBuilder; |
| 1709 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1710 | eventReportsBuilder.Init(&writer); |
| 1711 | eventReportsBuilder.EndOfEventReports(); |
| 1712 | NL_TEST_ASSERT(apSuite, eventReportsBuilder.GetError() == CHIP_NO_ERROR); |
| 1713 | chip::System::PacketBufferHandle buf; |
| 1714 | err = writer.Finalize(&buf); |
| 1715 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1716 | |
| 1717 | DebugPrettyPrint(buf); |
| 1718 | |
| 1719 | reader.Init(std::move(buf)); |
| 1720 | err = reader.Next(); |
| 1721 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1722 | ParseEventReports(apSuite, reader); |
| 1723 | } |
| 1724 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1725 | void AttributeReportIBTest(nlTestSuite * apSuite, void * apContext) |
| 1726 | { |
| 1727 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1728 | AttributeReportIB::Builder attributeReportIBBuilder; |
| 1729 | AttributeReportIB::Parser attributeReportIBParser; |
| 1730 | chip::System::PacketBufferTLVWriter writer; |
| 1731 | chip::System::PacketBufferTLVReader reader; |
| 1732 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1733 | attributeReportIBBuilder.Init(&writer); |
| 1734 | BuildAttributeReportIB(apSuite, attributeReportIBBuilder); |
| 1735 | chip::System::PacketBufferHandle buf; |
| 1736 | err = writer.Finalize(&buf); |
| 1737 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1738 | |
| 1739 | DebugPrettyPrint(buf); |
| 1740 | |
| 1741 | reader.Init(std::move(buf)); |
| 1742 | err = reader.Next(); |
| 1743 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1744 | |
| 1745 | attributeReportIBParser.Init(reader); |
| 1746 | ParseAttributeReportIB(apSuite, attributeReportIBParser); |
| 1747 | } |
| 1748 | |
| 1749 | void AttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) |
| 1750 | { |
| 1751 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1752 | chip::System::PacketBufferTLVWriter writer; |
| 1753 | chip::System::PacketBufferTLVReader reader; |
| 1754 | AttributeReportIBs::Builder attributeReportIBsBuilder; |
| 1755 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1756 | attributeReportIBsBuilder.Init(&writer); |
| 1757 | BuildAttributeReportIBs(apSuite, attributeReportIBsBuilder); |
| 1758 | chip::System::PacketBufferHandle buf; |
| 1759 | err = writer.Finalize(&buf); |
| 1760 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1761 | |
| 1762 | DebugPrettyPrint(buf); |
| 1763 | |
| 1764 | reader.Init(std::move(buf)); |
| 1765 | err = reader.Next(); |
| 1766 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1767 | ParseAttributeReportIBs(apSuite, reader); |
| 1768 | } |
| 1769 | |
yunhanw-google | 588d4c9 | 2022-05-11 23:50:15 -0700 | [diff] [blame] | 1770 | void EmptyAttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) |
| 1771 | { |
| 1772 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1773 | chip::System::PacketBufferTLVWriter writer; |
| 1774 | chip::System::PacketBufferTLVReader reader; |
| 1775 | AttributeReportIBs::Builder attributeReportIBsBuilder; |
| 1776 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1777 | attributeReportIBsBuilder.Init(&writer); |
| 1778 | attributeReportIBsBuilder.EndOfAttributeReportIBs(); |
| 1779 | NL_TEST_ASSERT(apSuite, attributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 1780 | chip::System::PacketBufferHandle buf; |
| 1781 | err = writer.Finalize(&buf); |
| 1782 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1783 | |
| 1784 | DebugPrettyPrint(buf); |
| 1785 | |
| 1786 | reader.Init(std::move(buf)); |
| 1787 | err = reader.Next(); |
| 1788 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1789 | ParseAttributeReportIBs(apSuite, reader); |
| 1790 | } |
| 1791 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1792 | void StatusIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1793 | { |
| 1794 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1795 | StatusIB::Builder statusIBBuilder; |
| 1796 | StatusIB::Parser StatusIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1797 | chip::System::PacketBufferTLVWriter writer; |
| 1798 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1799 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1800 | statusIBBuilder.Init(&writer); |
| 1801 | BuildStatusIB(apSuite, statusIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1802 | chip::System::PacketBufferHandle buf; |
| 1803 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1804 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1805 | |
| 1806 | DebugPrettyPrint(buf); |
| 1807 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1808 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1809 | err = reader.Next(); |
| 1810 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1811 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1812 | StatusIBParser.Init(reader); |
| 1813 | ParseStatusIB(apSuite, StatusIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1814 | } |
| 1815 | |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 1816 | void EventStatusIBTest(nlTestSuite * apSuite, void * apContext) |
| 1817 | { |
| 1818 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 1819 | EventStatusIB::Builder eventStatusIBBuilder; |
| 1820 | EventStatusIB::Parser eventStatusIBParser; |
| 1821 | chip::System::PacketBufferTLVWriter writer; |
| 1822 | chip::System::PacketBufferTLVReader reader; |
| 1823 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 1824 | eventStatusIBBuilder.Init(&writer); |
| 1825 | BuildEventStatusIB(apSuite, eventStatusIBBuilder); |
| 1826 | chip::System::PacketBufferHandle buf; |
| 1827 | err = writer.Finalize(&buf); |
| 1828 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1829 | |
| 1830 | DebugPrettyPrint(buf); |
| 1831 | |
| 1832 | reader.Init(std::move(buf)); |
| 1833 | err = reader.Next(); |
| 1834 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1835 | |
| 1836 | eventStatusIBParser.Init(reader); |
| 1837 | ParseEventStatusIB(apSuite, eventStatusIBParser); |
| 1838 | } |
| 1839 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1840 | void AttributeStatusIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1841 | { |
| 1842 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1843 | AttributeStatusIB::Builder attributeStatusIBBuilder; |
| 1844 | AttributeStatusIB::Parser attributeStatusIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1845 | chip::System::PacketBufferTLVWriter writer; |
| 1846 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1847 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1848 | attributeStatusIBBuilder.Init(&writer); |
| 1849 | BuildAttributeStatusIB(apSuite, attributeStatusIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1850 | chip::System::PacketBufferHandle buf; |
| 1851 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1852 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1853 | |
| 1854 | DebugPrettyPrint(buf); |
| 1855 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1856 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1857 | err = reader.Next(); |
| 1858 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1859 | |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 1860 | attributeStatusIBParser.Init(reader); |
| 1861 | ParseAttributeStatusIB(apSuite, attributeStatusIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1862 | } |
| 1863 | |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1864 | void AttributeStatusesTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1865 | { |
| 1866 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1867 | chip::System::PacketBufferTLVWriter writer; |
| 1868 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1869 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 1870 | AttributeStatusIBs::Builder attributeStatusesBuilder; |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1871 | err = attributeStatusesBuilder.Init(&writer); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1872 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1873 | BuildAttributeStatuses(apSuite, attributeStatusesBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1874 | chip::System::PacketBufferHandle buf; |
| 1875 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1876 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1877 | |
| 1878 | DebugPrettyPrint(buf); |
| 1879 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1880 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1881 | err = reader.Next(); |
| 1882 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 64ffda0 | 2021-11-04 18:05:36 -0700 | [diff] [blame] | 1883 | ParseAttributeStatuses(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1886 | void AttributeDataIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1887 | { |
| 1888 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1889 | AttributeDataIB::Builder AttributeDataIBBuilder; |
| 1890 | AttributeDataIB::Parser AttributeDataIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1891 | chip::System::PacketBufferTLVWriter writer; |
| 1892 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1893 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1894 | AttributeDataIBBuilder.Init(&writer); |
| 1895 | BuildAttributeDataIB(apSuite, AttributeDataIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1896 | chip::System::PacketBufferHandle buf; |
| 1897 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1898 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1899 | |
| 1900 | DebugPrettyPrint(buf); |
| 1901 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1902 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1903 | err = reader.Next(); |
| 1904 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1905 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1906 | AttributeDataIBParser.Init(reader); |
| 1907 | ParseAttributeDataIB(apSuite, AttributeDataIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1908 | } |
| 1909 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1910 | void AttributeDataIBsTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1911 | { |
| 1912 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1913 | chip::System::PacketBufferTLVWriter writer; |
| 1914 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1915 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1916 | AttributeDataIBs::Builder AttributeDataIBsBuilder; |
| 1917 | AttributeDataIBsBuilder.Init(&writer); |
| 1918 | BuildAttributeDataIBs(apSuite, AttributeDataIBsBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1919 | chip::System::PacketBufferHandle buf; |
| 1920 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1921 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1922 | |
| 1923 | DebugPrettyPrint(buf); |
| 1924 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1925 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1926 | err = reader.Next(); |
| 1927 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 1928 | ParseAttributeDataIBs(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 1931 | void CommandDataIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1932 | { |
| 1933 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 1934 | CommandDataIB::Builder commandDataIBBuilder; |
| 1935 | CommandDataIB::Parser commandDataIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1936 | chip::System::PacketBufferTLVWriter writer; |
| 1937 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1938 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 1939 | commandDataIBBuilder.Init(&writer); |
| 1940 | BuildCommandDataIB(apSuite, commandDataIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1941 | chip::System::PacketBufferHandle buf; |
| 1942 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1943 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1944 | |
| 1945 | DebugPrettyPrint(buf); |
| 1946 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1947 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1948 | err = reader.Next(); |
| 1949 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1950 | |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 1951 | commandDataIBParser.Init(reader); |
| 1952 | ParseCommandDataIB(apSuite, commandDataIBParser); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1953 | } |
| 1954 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1955 | void CommandStatusIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1956 | { |
| 1957 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1958 | CommandStatusIB::Builder commandStatusIBBuilder; |
| 1959 | CommandStatusIB::Parser commandStatusIBParser; |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1960 | chip::System::PacketBufferTLVWriter writer; |
| 1961 | chip::System::PacketBufferTLVReader reader; |
| 1962 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1963 | commandStatusIBBuilder.Init(&writer); |
| 1964 | BuildCommandStatusIB(apSuite, commandStatusIBBuilder); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1965 | chip::System::PacketBufferHandle buf; |
| 1966 | err = writer.Finalize(&buf); |
| 1967 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1968 | |
| 1969 | DebugPrettyPrint(buf); |
| 1970 | |
| 1971 | reader.Init(std::move(buf)); |
| 1972 | err = reader.Next(); |
| 1973 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1974 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1975 | commandStatusIBParser.Init(reader); |
| 1976 | ParseCommandStatusIB(apSuite, commandStatusIBParser); |
yunhanw-google | 9577ff5 | 2021-04-05 12:51:14 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1979 | void InvokeResponseIBWithCommandDataIBTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1980 | { |
| 1981 | CHIP_ERROR err = CHIP_NO_ERROR; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1982 | InvokeResponseIB::Builder invokeResponseIBBuilder; |
| 1983 | InvokeResponseIB::Parser invokeResponseIBParser; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1984 | chip::System::PacketBufferTLVWriter writer; |
| 1985 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 1986 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1987 | invokeResponseIBBuilder.Init(&writer); |
| 1988 | BuildInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBBuilder); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1989 | chip::System::PacketBufferHandle buf; |
| 1990 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1991 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 1992 | |
| 1993 | DebugPrettyPrint(buf); |
| 1994 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 1995 | reader.Init(std::move(buf)); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 1996 | err = reader.Next(); |
| 1997 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1998 | |
| 1999 | invokeResponseIBParser.Init(reader); |
| 2000 | ParseInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBParser); |
| 2001 | } |
| 2002 | |
| 2003 | void InvokeResponseIBWithCommandStatusIBTest(nlTestSuite * apSuite, void * apContext) |
| 2004 | { |
| 2005 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2006 | InvokeResponseIB::Builder invokeResponseIBBuilder; |
| 2007 | InvokeResponseIB::Parser invokeResponseIBParser; |
| 2008 | chip::System::PacketBufferTLVWriter writer; |
| 2009 | chip::System::PacketBufferTLVReader reader; |
| 2010 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2011 | invokeResponseIBBuilder.Init(&writer); |
| 2012 | BuildInvokeResponseIBWithCommandStatusIB(apSuite, invokeResponseIBBuilder); |
| 2013 | chip::System::PacketBufferHandle buf; |
| 2014 | err = writer.Finalize(&buf); |
| 2015 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2016 | |
| 2017 | DebugPrettyPrint(buf); |
| 2018 | |
| 2019 | reader.Init(std::move(buf)); |
| 2020 | err = reader.Next(); |
| 2021 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2022 | |
| 2023 | invokeResponseIBParser.Init(reader); |
| 2024 | ParseInvokeResponseIBWithCommandStatusIB(apSuite, invokeResponseIBParser); |
| 2025 | } |
| 2026 | |
| 2027 | void InvokeResponseIBWithMalformDataTest(nlTestSuite * apSuite, void * apContext) |
| 2028 | { |
| 2029 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2030 | InvokeResponseIB::Builder invokeResponseIBBuilder; |
| 2031 | InvokeResponseIB::Parser invokeResponseIBParser; |
| 2032 | chip::System::PacketBufferTLVWriter writer; |
| 2033 | chip::System::PacketBufferTLVReader reader; |
| 2034 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2035 | invokeResponseIBBuilder.Init(&writer); |
| 2036 | BuildWrongInvokeResponseIB(apSuite, invokeResponseIBBuilder); |
| 2037 | chip::System::PacketBufferHandle buf; |
| 2038 | err = writer.Finalize(&buf); |
| 2039 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2040 | |
| 2041 | DebugPrettyPrint(buf); |
| 2042 | |
| 2043 | reader.Init(std::move(buf)); |
| 2044 | err = reader.Next(); |
| 2045 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2046 | |
| 2047 | invokeResponseIBParser.Init(reader); |
| 2048 | ParseWrongInvokeResponseIB(apSuite, invokeResponseIBParser); |
| 2049 | } |
| 2050 | |
| 2051 | void InvokeRequestsTest(nlTestSuite * apSuite, void * apContext) |
| 2052 | { |
| 2053 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2054 | chip::System::PacketBufferTLVWriter writer; |
| 2055 | chip::System::PacketBufferTLVReader reader; |
| 2056 | InvokeRequests::Builder invokeRequestsBuilder; |
| 2057 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2058 | invokeRequestsBuilder.Init(&writer); |
| 2059 | BuildInvokeRequests(apSuite, invokeRequestsBuilder); |
| 2060 | chip::System::PacketBufferHandle buf; |
| 2061 | err = writer.Finalize(&buf); |
| 2062 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2063 | |
| 2064 | DebugPrettyPrint(buf); |
| 2065 | |
| 2066 | reader.Init(std::move(buf)); |
| 2067 | err = reader.Next(); |
| 2068 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2069 | ParseInvokeRequests(apSuite, reader); |
| 2070 | } |
| 2071 | |
| 2072 | void InvokeResponsesTest(nlTestSuite * apSuite, void * apContext) |
| 2073 | { |
| 2074 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2075 | chip::System::PacketBufferTLVWriter writer; |
| 2076 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | f111727 | 2021-12-02 19:59:44 -0800 | [diff] [blame] | 2077 | InvokeResponseIBs::Builder invokeResponsesBuilder; |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 2078 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2079 | invokeResponsesBuilder.Init(&writer); |
| 2080 | BuildInvokeResponses(apSuite, invokeResponsesBuilder); |
| 2081 | chip::System::PacketBufferHandle buf; |
| 2082 | err = writer.Finalize(&buf); |
| 2083 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2084 | |
| 2085 | DebugPrettyPrint(buf); |
| 2086 | |
| 2087 | reader.Init(std::move(buf)); |
| 2088 | err = reader.Next(); |
| 2089 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2090 | ParseInvokeResponses(apSuite, reader); |
| 2091 | } |
| 2092 | |
| 2093 | void InvokeInvokeRequestMessageTest(nlTestSuite * apSuite, void * apContext) |
| 2094 | { |
| 2095 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2096 | chip::System::PacketBufferTLVWriter writer; |
| 2097 | chip::System::PacketBufferTLVReader reader; |
| 2098 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2099 | BuildInvokeRequestMessage(apSuite, writer); |
| 2100 | chip::System::PacketBufferHandle buf; |
| 2101 | err = writer.Finalize(&buf); |
| 2102 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2103 | |
| 2104 | DebugPrettyPrint(buf); |
| 2105 | |
| 2106 | reader.Init(std::move(buf)); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 2107 | ParseInvokeRequestMessage(apSuite, reader); |
| 2108 | } |
| 2109 | |
| 2110 | void InvokeInvokeResponseMessageTest(nlTestSuite * apSuite, void * apContext) |
| 2111 | { |
| 2112 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2113 | chip::System::PacketBufferTLVWriter writer; |
| 2114 | chip::System::PacketBufferTLVReader reader; |
| 2115 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
| 2116 | BuildInvokeResponseMessage(apSuite, writer); |
| 2117 | chip::System::PacketBufferHandle buf; |
| 2118 | err = writer.Finalize(&buf); |
| 2119 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2120 | |
| 2121 | DebugPrettyPrint(buf); |
| 2122 | |
| 2123 | reader.Init(std::move(buf)); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 2124 | ParseInvokeResponseMessage(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2125 | } |
| 2126 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2127 | void ReportDataMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2128 | { |
| 2129 | CHIP_ERROR err = CHIP_NO_ERROR; |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 2130 | chip::System::PacketBufferTLVWriter writer; |
| 2131 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 2132 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2133 | BuildReportDataMessage(apSuite, writer); |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 2134 | chip::System::PacketBufferHandle buf; |
| 2135 | err = writer.Finalize(&buf); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2136 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2137 | |
| 2138 | DebugPrettyPrint(buf); |
| 2139 | |
Kevin Schoedel | 4bb0e53 | 2021-01-11 22:28:18 -0500 | [diff] [blame] | 2140 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2141 | ParseReportDataMessage(apSuite, reader); |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2144 | void ReadRequestMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 2145 | { |
| 2146 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2147 | chip::System::PacketBufferTLVWriter writer; |
| 2148 | chip::System::PacketBufferTLVReader reader; |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 2149 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2150 | BuildReadRequestMessage(apSuite, writer); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 2151 | chip::System::PacketBufferHandle buf; |
| 2152 | err = writer.Finalize(&buf); |
| 2153 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2154 | |
| 2155 | DebugPrettyPrint(buf); |
| 2156 | |
| 2157 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2158 | ParseReadRequestMessage(apSuite, reader); |
yunhanw-google | 0c18355 | 2021-01-22 09:12:14 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2161 | void WriteRequestMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2162 | { |
| 2163 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2164 | chip::System::PacketBufferTLVWriter writer; |
| 2165 | chip::System::PacketBufferTLVReader reader; |
| 2166 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2167 | BuildWriteRequestMessage(apSuite, writer); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2168 | chip::System::PacketBufferHandle buf; |
| 2169 | err = writer.Finalize(&buf); |
| 2170 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2171 | |
| 2172 | DebugPrettyPrint(buf); |
| 2173 | |
| 2174 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2175 | ParseWriteRequestMessage(apSuite, reader); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2178 | void WriteResponseMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2179 | { |
| 2180 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2181 | chip::System::PacketBufferTLVWriter writer; |
| 2182 | chip::System::PacketBufferTLVReader reader; |
| 2183 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2184 | BuildWriteResponseMessage(apSuite, writer); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2185 | chip::System::PacketBufferHandle buf; |
| 2186 | err = writer.Finalize(&buf); |
| 2187 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2188 | |
| 2189 | DebugPrettyPrint(buf); |
| 2190 | |
| 2191 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2192 | ParseWriteResponseMessage(apSuite, reader); |
yunhanw-google | e4c0115 | 2021-04-16 08:22:10 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2195 | void SubscribeRequestMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2196 | { |
| 2197 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2198 | chip::System::PacketBufferTLVWriter writer; |
| 2199 | chip::System::PacketBufferTLVReader reader; |
| 2200 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2201 | BuildSubscribeRequestMessage(apSuite, writer); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2202 | chip::System::PacketBufferHandle buf; |
| 2203 | err = writer.Finalize(&buf); |
| 2204 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2205 | |
| 2206 | DebugPrettyPrint(buf); |
| 2207 | |
| 2208 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2209 | ParseSubscribeRequestMessage(apSuite, reader); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2212 | void SubscribeResponseMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2213 | { |
| 2214 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2215 | chip::System::PacketBufferTLVWriter writer; |
| 2216 | chip::System::PacketBufferTLVReader reader; |
| 2217 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2218 | BuildSubscribeResponseMessage(apSuite, writer); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2219 | chip::System::PacketBufferHandle buf; |
| 2220 | err = writer.Finalize(&buf); |
| 2221 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2222 | |
| 2223 | DebugPrettyPrint(buf); |
| 2224 | |
| 2225 | reader.Init(std::move(buf)); |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2226 | ParseSubscribeResponseMessage(apSuite, reader); |
yunhanw-google | fb773e8 | 2021-07-09 13:52:37 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 2229 | void TimedRequestMessageTest(nlTestSuite * apSuite, void * apContext) |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 2230 | { |
| 2231 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2232 | chip::System::PacketBufferTLVWriter writer; |
| 2233 | chip::System::PacketBufferTLVReader reader; |
| 2234 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 2235 | BuildTimedRequestMessage(apSuite, writer); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 2236 | chip::System::PacketBufferHandle buf; |
| 2237 | err = writer.Finalize(&buf); |
| 2238 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2239 | |
| 2240 | DebugPrettyPrint(buf); |
| 2241 | |
| 2242 | reader.Init(std::move(buf)); |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 2243 | ParseTimedRequestMessage(apSuite, reader); |
yunhanw-google | 8be8545 | 2021-07-12 07:20:09 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2246 | void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) |
| 2247 | { |
| 2248 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 2249 | size_t NumDataElement = 0; |
| 2250 | chip::System::PacketBufferTLVWriter writer; |
| 2251 | chip::System::PacketBufferTLVReader reader; |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 2252 | AttributeDataIBs::Parser AttributeDataIBsParser; |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2253 | chip::TLV::TLVWriter checkpoint; |
| 2254 | writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2255 | AttributeDataIBs::Builder attributeDataIBsBuilder; |
| 2256 | attributeDataIBsBuilder.Init(&writer); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2257 | |
| 2258 | // encode one attribute element |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2259 | AttributeDataIB::Builder & attributeDataIBBuilder1 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); |
| 2260 | NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 2261 | BuildAttributeDataIB(apSuite, attributeDataIBBuilder1); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2262 | // checkpoint |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2263 | attributeDataIBsBuilder.Checkpoint(checkpoint); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2264 | // encode another attribute element |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2265 | AttributeDataIB::Builder & attributeDataIBBuilder2 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); |
| 2266 | NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); |
| 2267 | BuildAttributeDataIB(apSuite, attributeDataIBBuilder2); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2268 | // rollback to previous checkpoint |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2269 | attributeDataIBsBuilder.Rollback(checkpoint); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2270 | |
yunhanw-google | 299393b | 2021-12-06 09:59:34 -0800 | [diff] [blame] | 2271 | attributeDataIBsBuilder.EndOfAttributeDataIBs(); |
| 2272 | NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2273 | |
| 2274 | chip::System::PacketBufferHandle buf; |
| 2275 | err = writer.Finalize(&buf); |
| 2276 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2277 | |
| 2278 | DebugPrettyPrint(buf); |
| 2279 | |
| 2280 | reader.Init(std::move(buf)); |
| 2281 | err = reader.Next(); |
| 2282 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2283 | |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 2284 | err = AttributeDataIBsParser.Init(reader); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2285 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2286 | |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 2287 | #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 2288 | err = AttributeDataIBsParser.CheckSchemaValidity(); |
yunhanw-google | d644bb0 | 2021-04-13 07:26:17 -0700 | [diff] [blame] | 2289 | NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); |
| 2290 | #endif |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 2291 | while (CHIP_NO_ERROR == (err = AttributeDataIBsParser.Next())) |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2292 | { |
| 2293 | ++NumDataElement; |
| 2294 | } |
| 2295 | |
| 2296 | NL_TEST_ASSERT(apSuite, NumDataElement == 1); |
| 2297 | } |
| 2298 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2299 | /** |
| 2300 | * Test Suite. It lists all the test functions. |
| 2301 | */ |
| 2302 | |
| 2303 | // clang-format off |
| 2304 | const nlTest sTests[] = |
| 2305 | { |
yunhanw-google | a1cb341 | 2021-12-06 13:32:40 -0800 | [diff] [blame] | 2306 | NL_TEST_DEF("ClusterPathIBTest", ClusterPathIBTest), |
| 2307 | NL_TEST_DEF("DataVersionFilterIBTest", DataVersionFilterIBTest), |
| 2308 | NL_TEST_DEF("DataVersionFilterIBsTest", DataVersionFilterIBsTest), |
yunhanw-google | bf585f8 | 2021-10-29 19:20:07 -0700 | [diff] [blame] | 2309 | NL_TEST_DEF("EventFilterTest", EventFilterTest), |
| 2310 | NL_TEST_DEF("EventFiltersTest", EventFiltersTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2311 | NL_TEST_DEF("AttributePathTest", AttributePathTest), |
| 2312 | NL_TEST_DEF("AttributePathListTest", AttributePathListTest), |
yunhanw-google | b717b36 | 2021-11-08 13:34:19 -0800 | [diff] [blame] | 2313 | NL_TEST_DEF("AttributeStatusIBTest", AttributeStatusIBTest), |
| 2314 | NL_TEST_DEF("AttributeStatusesTest", AttributeStatusesTest), |
| 2315 | NL_TEST_DEF("AttributeDataIBTest", AttributeDataIBTest), |
| 2316 | NL_TEST_DEF("AttributeDataIBsTest", AttributeDataIBsTest), |
| 2317 | NL_TEST_DEF("AttributeReportIBTest", AttributeReportIBTest), |
| 2318 | NL_TEST_DEF("AttributeReportIBsTest", AttributeReportIBsTest), |
yunhanw-google | 588d4c9 | 2022-05-11 23:50:15 -0700 | [diff] [blame] | 2319 | NL_TEST_DEF("EmptyAttributeReportIBsTest", EmptyAttributeReportIBsTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2320 | NL_TEST_DEF("EventPathTest", EventPathTest), |
yunhanw-google | 2fe9024 | 2021-11-01 15:13:44 -0700 | [diff] [blame] | 2321 | NL_TEST_DEF("EventPathsTest", EventPathsTest), |
yunhanw-google | 3bec0f9 | 2021-11-03 16:12:39 -0700 | [diff] [blame] | 2322 | NL_TEST_DEF("EventDataIBTest", EventDataIBTest), |
| 2323 | NL_TEST_DEF("EventReportIBTest", EventReportIBTest), |
| 2324 | NL_TEST_DEF("EventReportsTest", EventReportsTest), |
yunhanw-google | 588d4c9 | 2022-05-11 23:50:15 -0700 | [diff] [blame] | 2325 | NL_TEST_DEF("EmptyEventReportsTest", EmptyEventReportsTest), |
yunhanw-google | 35e6717 | 2021-10-11 17:12:06 -0700 | [diff] [blame] | 2326 | NL_TEST_DEF("StatusIBTest", StatusIBTest), |
yunhanw-google | 1f6c6e6 | 2021-11-02 10:09:53 -0700 | [diff] [blame] | 2327 | NL_TEST_DEF("EventStatusIBTest", EventStatusIBTest), |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 2328 | NL_TEST_DEF("CommandPathIBTest", CommandPathIBTest), |
yunhanw-google | 67f74a3 | 2021-10-21 12:15:08 -0700 | [diff] [blame] | 2329 | NL_TEST_DEF("CommandDataIBTest", CommandDataIBTest), |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 2330 | NL_TEST_DEF("CommandStatusIBTest", CommandStatusIBTest), |
| 2331 | NL_TEST_DEF("InvokeResponseIBWithCommandDataIBTest", InvokeResponseIBWithCommandDataIBTest), |
| 2332 | NL_TEST_DEF("InvokeResponseIBWithCommandStatusIBTest", InvokeResponseIBWithCommandStatusIBTest), |
| 2333 | NL_TEST_DEF("InvokeResponseIBWithMalformDataTest", InvokeResponseIBWithMalformDataTest), |
| 2334 | NL_TEST_DEF("InvokeRequestsTest", InvokeRequestsTest), |
| 2335 | NL_TEST_DEF("InvokeResponsesTest", InvokeResponsesTest), |
| 2336 | NL_TEST_DEF("InvokeInvokeRequestMessageTest", InvokeInvokeRequestMessageTest), |
| 2337 | NL_TEST_DEF("InvokeInvokeResponseMessageTest", InvokeInvokeResponseMessageTest), |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2338 | NL_TEST_DEF("ReportDataMessageTest", ReportDataMessageTest), |
yunhanw-google | 12ec702 | 2021-11-01 19:53:29 -0700 | [diff] [blame] | 2339 | NL_TEST_DEF("ReadRequestMessageTest", ReadRequestMessageTest), |
| 2340 | NL_TEST_DEF("WriteRequestMessageTest", WriteRequestMessageTest), |
| 2341 | NL_TEST_DEF("WriteResponseMessageTest", WriteResponseMessageTest), |
| 2342 | NL_TEST_DEF("SubscribeRequestMessageTest", SubscribeRequestMessageTest), |
| 2343 | NL_TEST_DEF("SubscribeResponseMessageTest", SubscribeResponseMessageTest), |
yunhanw-google | 7f05fb6 | 2021-10-29 06:55:58 -0700 | [diff] [blame] | 2344 | NL_TEST_DEF("TimedRequestMessageTest", TimedRequestMessageTest), |
yunhanw-google | 1a94b9e | 2021-03-25 18:32:44 -0700 | [diff] [blame] | 2345 | NL_TEST_DEF("CheckPointRollbackTest", CheckPointRollbackTest), |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2346 | NL_TEST_SENTINEL() |
| 2347 | }; |
| 2348 | // clang-format on |
| 2349 | } // namespace |
| 2350 | |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 2351 | /** |
| 2352 | * Set up the test suite. |
| 2353 | */ |
| 2354 | static int TestSetup(void * inContext) |
| 2355 | { |
| 2356 | CHIP_ERROR error = chip::Platform::MemoryInit(); |
| 2357 | if (error != CHIP_NO_ERROR) |
| 2358 | return FAILURE; |
| 2359 | return SUCCESS; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * Tear down the test suite. |
| 2364 | */ |
| 2365 | static int TestTeardown(void * inContext) |
| 2366 | { |
| 2367 | chip::Platform::MemoryShutdown(); |
| 2368 | return SUCCESS; |
| 2369 | } |
| 2370 | |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2371 | int TestMessageDef() |
| 2372 | { |
| 2373 | // clang-format off |
| 2374 | nlTestSuite theSuite = |
| 2375 | { |
| 2376 | "MessageDef", |
| 2377 | &sTests[0], |
Kevin Schoedel | 1b6a96b | 2021-02-10 14:29:33 -0500 | [diff] [blame] | 2378 | TestSetup, |
| 2379 | TestTeardown, |
yunhanw-google | fb62fb0 | 2020-11-20 08:27:21 -0800 | [diff] [blame] | 2380 | }; |
| 2381 | // clang-format on |
| 2382 | |
| 2383 | nlTestRunner(&theSuite, nullptr); |
| 2384 | |
| 2385 | return (nlTestRunnerStats(&theSuite)); |
| 2386 | } |
| 2387 | |
| 2388 | CHIP_REGISTER_TEST_SUITE(TestMessageDef) |