File: test_RefCount.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 (39 lines) | stat: -rw-r--r-- 799 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
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../catch.hpp"
#include "rkcommon/memory/RefCount.h"

using rkcommon::memory::Ref;
using rkcommon::memory::RefCount;

SCENARIO("Ref interface tests", "[Ref]")
{
  GIVEN("A const Ref<>")
  {
    struct A : public RefCount
    {
      int i1{0};
      int i2{0};
    };
    const Ref<A> a(new A);

    // Reference count is 2 at this moment we need to decrease it by 1,
    // this would be not needed once we initialize reference count with 0
    // instead of 1
    a->refDec();

    WHEN("setting values via pointer or reference")
    {
      A &aRef = *a;
      aRef.i1 = 1;
      a->i2 = 2;

      THEN("they should be set")
      {
        REQUIRE(a->i1 == 1);
        REQUIRE(a->i2 == 2);
      }
    }
  }
}