Matter SDK Coverage Report
Current view: top level - app/server-cluster/testing - TestAttributeChangeListener.h (source / functions) Coverage Total Hit
Test: SHA:3f9cd168e84cd831b7699126f5296f5c5498690f Lines: 72.7 % 11 8
Test Date: 2026-04-27 19:52:19 Functions: 75.0 % 4 3

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2026 Project CHIP Authors
       3              :  *    All rights reserved.
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : #pragma once
      18              : 
      19              : #include <app/ConcreteAttributePath.h>
      20              : #include <app/data-model-provider/AttributeChangeListener.h>
      21              : 
      22              : #include <algorithm>
      23              : #include <vector>
      24              : 
      25              : namespace chip {
      26              : namespace Testing {
      27              : 
      28              : /// A provider change listener that stores all dirty reports
      29              : /// into an internal vector
      30              : class TestAttributeChangeListener : public app::DataModel::AttributeChangeListener
      31              : {
      32              : public:
      33         1722 :     void OnAttributeChanged(const app::ConcreteAttributePath & path, app::DataModel::AttributeChangeType type) override
      34              :     {
      35         1722 :         mChangedList.push_back(path);
      36         1722 :         if (type == app::DataModel::AttributeChangeType::kReportable)
      37              :         {
      38         1722 :             mDirtyList.push_back(path);
      39              :         }
      40         1722 :     }
      41              : 
      42            0 :     void OnEndpointChanged(EndpointId endpointId, app::DataModel::EndpointChangeType type) override
      43              :     {
      44            0 :         mChangedEndpoints.push_back(endpointId);
      45            0 :     }
      46              : 
      47          129 :     std::vector<app::ConcreteAttributePath> & DirtyList() { return mDirtyList; }
      48              :     const std::vector<app::ConcreteAttributePath> & DirtyList() const { return mDirtyList; }
      49              : 
      50              :     std::vector<app::ConcreteAttributePath> & ChangedList() { return mChangedList; }
      51              :     const std::vector<app::ConcreteAttributePath> & ChangedList() const { return mChangedList; }
      52              : 
      53              :     std::vector<EndpointId> & ChangedEndpoints() { return mChangedEndpoints; }
      54              :     const std::vector<EndpointId> & ChangedEndpoints() const { return mChangedEndpoints; }
      55              : 
      56              :     /**
      57              :      * @brief Check if a specific attribute path is dirty.
      58              :      *
      59              :      * @param path The concrete attribute path to check
      60              :      * @return true if the path is dirty, false otherwise
      61              :      */
      62           24 :     bool IsDirty(const app::ConcreteAttributePath & path) const
      63              :     {
      64           24 :         return std::find(mDirtyList.cbegin(), mDirtyList.cend(), path) != mDirtyList.cend();
      65              :     }
      66              : 
      67              :     bool IsChanged(const app::ConcreteAttributePath & path) const
      68              :     {
      69              :         return std::find(mChangedList.cbegin(), mChangedList.cend(), path) != mChangedList.cend();
      70              :     }
      71              : 
      72              :     bool IsChangedEndpoint(EndpointId endpoint) const
      73              :     {
      74              :         return std::find(mChangedEndpoints.cbegin(), mChangedEndpoints.cend(), endpoint) != mChangedEndpoints.cend();
      75              :     }
      76              : 
      77              : private:
      78              :     std::vector<app::ConcreteAttributePath> mDirtyList;
      79              :     std::vector<app::ConcreteAttributePath> mChangedList;
      80              :     std::vector<EndpointId> mChangedEndpoints;
      81              : };
      82              : 
      83              : } // namespace Testing
      84              : } // namespace chip
        

Generated by: LCOV version 2.0-1