File: test_Observers.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-- 835 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/utility/Observer.h"

using namespace rkcommon::utility;

SCENARIO("Observable/Observer interfaces", "[Observers]")
{
  GIVEN("A single observable and two observers")
  {
    Observable at;

    Observer look1(at);
    Observer look2(at);

    THEN("Neither observer has been notified after construction")
    {
      REQUIRE(!look1.wasNotified());
      REQUIRE(!look2.wasNotified());
    }

    WHEN("The observable notifies")
    {
      at.notifyObservers();

      THEN("Both observers independently are notified exactly once")
      {
        REQUIRE(look1.wasNotified());
        REQUIRE(look2.wasNotified());

        REQUIRE(!look1.wasNotified());
        REQUIRE(!look2.wasNotified());
      }
    }
  }
}