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