File: test_OnScopeExit.cpp

package info (click to toggle)
rkcommon 1.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,276 kB
  • sloc: cpp: 33,504; sh: 31; makefile: 13
file content (27 lines) | stat: -rw-r--r-- 543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../catch.hpp"

#include "rkcommon/utility/OnScopeExit.h"

using rkcommon::utility::OnScopeExit;

SCENARIO("OnScopeExit correctness", "[OnScopeExit]")
{
  GIVEN("A value captured by an OnScopeExit lambda")
  {
    int testValue = 0;

    THEN("The value is only affected after OnScopeExit is out of scope")
    {
      {
        OnScopeExit guard([&]() { testValue++; });

        REQUIRE(testValue == 0);
      }

      REQUIRE(testValue == 1);
    }
  }
}