Project
Loading...
Searching...
No Matches
test_CallbackRegistry.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
14#include <iostream>
15
16using namespace o2::framework;
17
18TEST_CASE("TestCallbackregistry")
19{
20 enum class StepId { Void,
21 Int };
22
23 using VoidCallback = std::function<void()>;
24 using IntCallback = std::function<void(int)>;
25
26 using Callbacks = CallbackRegistry<StepId, //
29 Callbacks callbacks;
30 REQUIRE(callbacks.size == 2);
31
32 bool voidWasCalled = false;
33 auto voidcb = [&]() {
34 voidWasCalled = true;
35 };
36 callbacks.set<StepId::Void>(voidcb);
37 int intWasCalled = -1;
38 auto intcb = [&](int val) {
39 intWasCalled = val;
40 };
41 callbacks.set<StepId::Int>(intcb);
42
43 callbacks.call<StepId::Void>();
44 REQUIRE(voidWasCalled);
45 callbacks.call<StepId::Int>(5);
46 REQUIRE(intWasCalled == 5);
47
48 SECTION("test resetting")
49 {
50 auto intcb2 = [&](int val) {
51 intWasCalled = 4;
52 };
53 callbacks.set<StepId::Int>(intcb2);
54 callbacks.call<StepId::Int>(6);
55 REQUIRE(intWasCalled == 4);
56 }
57
58 SECTION("test mutable")
59 {
60 int invoked = 0;
61 callbacks.set<StepId::Int>([&invoked](int val) { invoked = val; });
62 callbacks.call<StepId::Int>(6);
63 REQUIRE(invoked == 6);
64 }
65}
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")