Project
Loading...
Searching...
No Matches
test_InputSpan.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 "Framework/InputSpan.h"
13#include "Framework/DataRef.h"
14#include <vector>
15#include <string>
16#include <catch_amalgamated.hpp>
17
18using namespace o2::framework;
19
20TEST_CASE("TestInputSpan")
21{
22 std::vector<std::vector<std::string>> inputs(3);
23 int routeNo = 0;
24 for (auto& list : inputs) {
25 int nParts = routeNo != 1 ? 1 : 3;
26 for (size_t part = 0; part < nParts; ++part) {
27 list.emplace_back("header_" + std::to_string(routeNo) + "-" + std::to_string(part));
28 list.emplace_back("payload_" + std::to_string(routeNo) + "-" + std::to_string(part));
29 }
30 routeNo++;
31 }
32
33 auto getter = [&inputs](size_t i, size_t part) {
34 return DataRef{nullptr, inputs[i].at(part * 2).data(), inputs[i].at(part * 2 + 1).data()};
35 };
36 auto nPartsGetter = [&inputs](size_t i) {
37 return inputs[i].size() / 2;
38 };
39
40 InputSpan span{getter, nPartsGetter, inputs.size()};
41 REQUIRE(span.size() == inputs.size());
42 routeNo = 0;
43 for (; routeNo < span.size(); ++routeNo) {
44 auto ref = span.get(routeNo);
45 REQUIRE(inputs[routeNo].at(0) == ref.header);
46 REQUIRE(inputs[routeNo].at(1) == ref.payload);
47 if (routeNo == 1) {
48 REQUIRE(span.getNofParts(routeNo) == 3);
49 ref = span.get(routeNo, 1);
50 REQUIRE(inputs[routeNo].at(2) == ref.header);
51 REQUIRE(inputs[routeNo].at(3) == ref.payload);
52 } else {
53 REQUIRE(span.getNofParts(routeNo) == 1);
54 }
55 }
56
57 routeNo = 0;
58 for (auto it = span.begin(), end = span.end(); it != end; ++it) {
59 size_t partNo = 0;
60 REQUIRE(it.size() * 2 == inputs[routeNo].size());
61 for (auto const& ref : it) {
62 REQUIRE(inputs[routeNo].at(partNo++) == ref.header);
63 REQUIRE(inputs[routeNo].at(partNo++) == ref.payload);
64 INFO(ref.header << " " << ref.payload);
65 }
66 routeNo++;
67 }
68}
int32_t i
size_t size() const
Number of elements in the InputSpan.
Definition InputSpan.h:70
GLuint GLuint end
Definition glcorearb.h:469
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
Definition list.h:40