File: Test_Event.cpp

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (28 lines) | stat: -rw-r--r-- 573 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
#include "Test.h"

#include "Event.h"

static int x = 2;

static void some_func(int inc)
{
  x += inc;
  x += 100;
}

TEST_CASE("Event Test", "[Event]")
{
  auto callback = [&](int inc) {
    x += inc;
    x += 10;
  };
  pymol::Event<int> event_publisher{};
  REQUIRE(event_publisher.size() == 0);
  event_publisher.add_listener(callback);
  REQUIRE(event_publisher.size() == 1);
  event_publisher.invoke(5); // 2 + 5 + 10
  REQUIRE(x == 17);
  event_publisher.add_listener(some_func);
  event_publisher.invoke(-5);
  REQUIRE(x == 117); // 17 + (- 5 + 10) + (- 5 + 100)
}