Matter SDK Coverage Report
Current view: top level - app/data-model-provider - MetadataLookup.cpp (source / functions) Coverage Total Hit
Test: SHA:f84fe08d06f240e801b5d923f8a938a9938ca110 Lines: 96.3 % 27 26
Test Date: 2025-02-22 08:08:07 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2024 Project CHIP Authors
       3              :  *
       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              : #include <app/data-model-provider/MetadataLookup.h>
      17              : 
      18              : #include <app/data-model-provider/MetadataList.h>
      19              : 
      20              : namespace chip {
      21              : namespace app {
      22              : namespace DataModel {
      23              : 
      24              : using Protocols::InteractionModel::Status;
      25              : 
      26         4589 : std::optional<ServerClusterEntry> ServerClusterFinder::Find(const ConcreteClusterPath & path)
      27              : {
      28         4589 :     VerifyOrReturnValue(mProvider != nullptr, std::nullopt);
      29              : 
      30         4589 :     if (mEndpointId != path.mEndpointId)
      31              :     {
      32         4589 :         mEndpointId     = path.mEndpointId;
      33         4589 :         mClusterEntries = mProvider->ServerClustersIgnoreError(path.mEndpointId);
      34              :     }
      35              : 
      36         5563 :     for (auto & clusterEntry : mClusterEntries)
      37              :     {
      38         5464 :         if (clusterEntry.clusterId == path.mClusterId)
      39              :         {
      40         4490 :             return clusterEntry;
      41              :         }
      42              :     }
      43              : 
      44           99 :     return std::nullopt;
      45              : }
      46              : 
      47         8983 : std::optional<AttributeEntry> AttributeFinder::Find(const ConcreteAttributePath & path)
      48              : {
      49         8983 :     VerifyOrReturnValue(mProvider != nullptr, std::nullopt);
      50              : 
      51         8983 :     if (mClusterPath != path)
      52              :     {
      53         8977 :         mClusterPath = path;
      54         8977 :         mAttributes  = mProvider->AttributesIgnoreError(path);
      55              :     }
      56              : 
      57        27564 :     for (auto & attributeEntry : mAttributes)
      58              :     {
      59        27149 :         if (attributeEntry.attributeId == path.mAttributeId)
      60              :         {
      61         8568 :             return attributeEntry;
      62              :         }
      63              :     }
      64              : 
      65          415 :     return std::nullopt;
      66              : }
      67              : 
      68           63 : Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * provider, const ConcreteClusterPath & path,
      69              :                                                         Protocols::InteractionModel::Status successStatus)
      70              : {
      71           63 :     if (ServerClusterFinder(provider).Find(path).has_value())
      72              :     {
      73           60 :         return successStatus;
      74              :     }
      75              : 
      76              :     // If we get here, the cluster identified by the path does not exist.
      77            3 :     auto endpoints = provider->EndpointsIgnoreError();
      78            9 :     for (auto & endpointEntry : endpoints)
      79              :     {
      80            6 :         if (endpointEntry.id == path.mEndpointId)
      81              :         {
      82              :             // endpoint is valid
      83            0 :             return Protocols::InteractionModel::Status::UnsupportedCluster;
      84              :         }
      85              :     }
      86              : 
      87            3 :     return Protocols::InteractionModel::Status::UnsupportedEndpoint;
      88            3 : }
      89              : 
      90              : } // namespace DataModel
      91              : } // namespace app
      92              : } // namespace chip
        

Generated by: LCOV version 2.0-1