Project
Loading...
Searching...
No Matches
test_CompletionPolicy.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>
16#include "Headers/DataHeader.h"
17#include "Headers/NameHeader.h"
19#include "Framework/InputSpan.h"
20#include "Headers/Stack.h"
21
22using namespace o2::framework;
23
24TEST_CASE("TestCompletionPolicy")
25{
26 std::ostringstream oss;
27 oss << CompletionPolicy::CompletionOp::Consume
28 << CompletionPolicy::CompletionOp::Process
29 << CompletionPolicy::CompletionOp::Wait
30 << CompletionPolicy::CompletionOp::Discard;
31
32 REQUIRE(oss.str() == "consumeprocesswaitdiscard");
33}
34
35TEST_CASE("TestCompletionPolicy_callback")
36{
37 o2::header::Stack stack{o2::header::DataHeader{"SOMEDATA", "TST", 0, 0}, o2::header::NameHeader<9>{"somename"}};
38
39 auto matcher = [](auto const&) {
40 return true;
41 };
42
43 ServiceRegistry services;
44
45 auto callback = [&stack](InputSpan const& inputRefs, std::vector<InputSpec> const&, ServiceRegistryRef&) {
46 for (auto const& ref : inputRefs) {
47 auto const* header = CompletionPolicyHelpers::getHeader<o2::header::DataHeader>(ref);
48 REQUIRE(header == reinterpret_cast<o2::header::DataHeader*>(stack.data()));
51 }
52 return CompletionPolicy::CompletionOp::Consume;
53 };
54
55 std::vector<CompletionPolicy> policies{
56 {"test", matcher, callback}};
57 CompletionPolicy::InputSetElement ref{nullptr, reinterpret_cast<const char*>(stack.data()), nullptr};
58 InputSpan const& inputs{[&ref](size_t) { return ref; }, 1};
59 std::vector<InputSpec> specs;
60 ServiceRegistryRef servicesRef{services};
61 for (auto& policy : policies) {
62 policy.callbackFull(inputs, specs, servicesRef);
63 }
64}
uint32_t stack
Definition RawData.h:1
GLint ref
Definition glcorearb.h:291
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
static auto getHeader(U const &input)
Get a specific header from the input.
the main header struct
Definition DataHeader.h:618
an example data header containing a name of an object as a null terminated char arr....
Definition NameHeader.h:39
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36
TEST_CASE("TestCompletionPolicy")