Matter SDK Coverage Report
Current view: top level - app/MessageDef - CommandStatusIB.cpp (source / functions) Coverage Total Hit
Test: SHA:e98a48c2e59f85a25417956e1d105721433aa5d1 Lines: 94.0 % 67 63
Test Date: 2026-01-09 16:53:50 Functions: 100.0 % 8 8

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2021 Project CHIP Authors
       4              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       5              :  *    you may not use this file except in compliance with the License.
       6              :  *    You may obtain a copy of the License at
       7              :  *
       8              :  *        http://www.apache.org/licenses/LICENSE-2.0
       9              :  *
      10              :  *    Unless required by applicable law or agreed to in writing, software
      11              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      12              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13              :  *    See the License for the specific language governing permissions and
      14              :  *    limitations under the License.
      15              :  */
      16              : 
      17              : #include "CommandStatusIB.h"
      18              : #include "MessageDefHelper.h"
      19              : #include "StructBuilder.h"
      20              : #include "StructParser.h"
      21              : 
      22              : #include <inttypes.h>
      23              : #include <stdarg.h>
      24              : #include <stdio.h>
      25              : 
      26              : #include <app/AppConfig.h>
      27              : 
      28              : namespace chip {
      29              : namespace app {
      30              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      31           44 : CHIP_ERROR CommandStatusIB::Parser::PrettyPrint() const
      32              : {
      33           44 :     CHIP_ERROR err      = CHIP_NO_ERROR;
      34           44 :     int tagPresenceMask = 0;
      35           44 :     TLV::TLVReader reader;
      36              : 
      37           44 :     PRETTY_PRINT("CommandStatusIB =");
      38           44 :     PRETTY_PRINT("{");
      39              : 
      40              :     // make a copy of the reader
      41           44 :     reader.Init(mReader);
      42              : 
      43          266 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      44              :     {
      45           89 :         if (!TLV::IsContextTag(reader.GetTag()))
      46              :         {
      47            0 :             continue;
      48              :         }
      49           89 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      50           89 :         switch (tagNum)
      51              :         {
      52           44 :         case to_underlying(Tag::kPath):
      53              :             // check if this tag has appeared before
      54           44 :             VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG);
      55           44 :             tagPresenceMask |= (1 << to_underlying(Tag::kPath));
      56              :             {
      57           44 :                 CommandPathIB::Parser path;
      58           44 :                 ReturnErrorOnFailure(path.Init(reader));
      59              : 
      60           44 :                 PRETTY_PRINT_INCDEPTH();
      61           44 :                 ReturnErrorOnFailure(path.PrettyPrint());
      62           44 :                 PRETTY_PRINT_DECDEPTH();
      63              :             }
      64           44 :             break;
      65           44 :         case to_underlying(Tag::kErrorStatus):
      66              :             // check if this tag has appeared before
      67           44 :             VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kErrorStatus))), CHIP_ERROR_INVALID_TLV_TAG);
      68           44 :             tagPresenceMask |= (1 << to_underlying(Tag::kErrorStatus));
      69              :             {
      70           44 :                 StatusIB::Parser errorStatus;
      71           44 :                 ReturnErrorOnFailure(errorStatus.Init(reader));
      72              : 
      73           44 :                 PRETTY_PRINT_INCDEPTH();
      74           44 :                 ReturnErrorOnFailure(errorStatus.PrettyPrint());
      75           44 :                 PRETTY_PRINT_DECDEPTH();
      76              :             }
      77           44 :             break;
      78            1 :         case to_underlying(Tag::kRef):
      79            1 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      80              :             {
      81              :                 uint16_t reference;
      82            1 :                 ReturnErrorOnFailure(reader.Get(reference));
      83            1 :                 PRETTY_PRINT("\tRef = 0x%x,", reference);
      84              :             }
      85            1 :             break;
      86            0 :         default:
      87            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      88            0 :             break;
      89              :         }
      90              :     }
      91              : 
      92           44 :     PRETTY_PRINT("},");
      93           44 :     PRETTY_PRINT_BLANK_LINE();
      94              : 
      95           88 :     if (CHIP_END_OF_TLV == err)
      96              :     {
      97           44 :         err = CHIP_NO_ERROR;
      98              :     }
      99              : 
     100           44 :     ReturnErrorOnFailure(err);
     101           44 :     return reader.ExitContainer(mOuterContainerType);
     102              : }
     103              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     104              : 
     105           43 : CHIP_ERROR CommandStatusIB::Parser::GetPath(CommandPathIB::Parser * const apPath) const
     106              : {
     107           43 :     TLV::TLVReader reader;
     108           43 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
     109           43 :     return apPath->Init(reader);
     110              : }
     111              : 
     112           43 : CHIP_ERROR CommandStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const
     113              : {
     114           43 :     TLV::TLVReader reader;
     115           43 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kErrorStatus), reader));
     116           43 :     return apErrorStatus->Init(reader);
     117              : }
     118              : 
     119           42 : CHIP_ERROR CommandStatusIB::Parser::GetRef(uint16_t * const apRef) const
     120              : {
     121           42 :     return GetUnsignedInteger(to_underlying(Tag::kRef), apRef);
     122              : }
     123              : 
     124           57 : CommandPathIB::Builder & CommandStatusIB::Builder::CreatePath()
     125              : {
     126          114 :     if (mError == CHIP_NO_ERROR)
     127              :     {
     128           57 :         mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
     129              :     }
     130           57 :     return mPath;
     131              : }
     132              : 
     133           57 : StatusIB::Builder & CommandStatusIB::Builder::CreateErrorStatus()
     134              : {
     135          114 :     if (mError == CHIP_NO_ERROR)
     136              :     {
     137           57 :         mError = mErrorStatus.Init(mpWriter, to_underlying(Tag::kErrorStatus));
     138              :     }
     139           57 :     return mErrorStatus;
     140              : }
     141              : 
     142            3 : CHIP_ERROR CommandStatusIB::Builder::Ref(const uint16_t aRef)
     143              : {
     144            3 :     return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef);
     145              : }
     146              : 
     147           57 : CHIP_ERROR CommandStatusIB::Builder::EndOfCommandStatusIB()
     148              : {
     149           57 :     EndOfContainer();
     150           57 :     return GetError();
     151              : }
     152              : } // namespace app
     153              : } // namespace chip
        

Generated by: LCOV version 2.0-1