Matter SDK Coverage Report
Current view: top level - lib/support - TimerDelegateMock.h (source / functions) Coverage Total Hit
Test: SHA:4a1dff731dfd17f3623faad23ee07f07df60cba7 Lines: 100.0 % 15 15
Test Date: 2026-02-11 08:13:42 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2025 Project CHIP Authors
       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              : 
      18              : #pragma once
      19              : 
      20              : #include <lib/core/CHIPError.h>
      21              : #include <lib/support/TimerDelegate.h>
      22              : #include <system/SystemClock.h>
      23              : 
      24              : namespace chip {
      25              : 
      26              : class TimerDelegateMock : public TimerDelegate
      27              : {
      28              : public:
      29          390 :     CriticalFailure StartTimer(TimerContext * context, chip::System::Clock::Timeout aTimeout) override
      30              :     {
      31          390 :         mTimerContext = context;
      32          390 :         mTimerTimeout = mMockSystemTimestamp + aTimeout;
      33          390 :         return CHIP_NO_ERROR;
      34              :     }
      35              : 
      36          402 :     void CancelTimer(TimerContext * context) override
      37              :     {
      38          402 :         mTimerContext = nullptr;
      39          402 :         mTimerTimeout = chip::System::Clock::Milliseconds64(0x7FFFFFFFFFFFFFFF);
      40          402 :     }
      41              : 
      42          284 :     bool IsTimerActive(TimerContext * context) override { return mTimerContext != nullptr && mTimerTimeout > mMockSystemTimestamp; }
      43              : 
      44            9 :     chip::System::Clock::Timestamp GetCurrentMonotonicTimestamp() override { return mMockSystemTimestamp; }
      45              : 
      46          348 :     void AdvanceClock(chip::System::Clock::Timeout aTimeout)
      47              :     {
      48          348 :         mMockSystemTimestamp += aTimeout;
      49          348 :         if (mTimerContext && mMockSystemTimestamp >= mTimerTimeout)
      50              :         {
      51          334 :             mTimerContext->TimerFired();
      52              :         }
      53          348 :     }
      54              : 
      55              : private:
      56              :     TimerContext * mTimerContext                        = nullptr;
      57              :     chip::System::Clock::Timestamp mTimerTimeout        = chip::System::Clock::Milliseconds64(0x7FFFFFFFFFFFFFFF);
      58              :     chip::System::Clock::Timestamp mMockSystemTimestamp = chip::System::Clock::Milliseconds64(0);
      59              : };
      60              : 
      61              : } // namespace chip
        

Generated by: LCOV version 2.0-1