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 nPartsGetter = [&inputs](size_t i) {
34 return inputs[i].size() / 2;
35 };
36 auto indicesGetter = [&inputs](size_t i, DataRefIndices indices) {
37 return DataRef{nullptr, inputs[i].at(indices.headerIdx).data(), inputs[i].at(indices.payloadIdx).data()};
38 };
39 auto nextIndicesGetter = [&inputs](size_t i, DataRefIndices current) -> DataRefIndices {
40 size_t next = current.headerIdx + 2;
41 return next < inputs[i].size() ? DataRefIndices{next, next + 1} : DataRefIndices{size_t(-1), size_t(-1)};
42 };
43
44 InputSpan span{nPartsGetter, nullptr, indicesGetter, nextIndicesGetter, inputs.size()};
45 REQUIRE(span.size() == inputs.size());
46 routeNo = 0;
47 for (; routeNo < span.size(); ++routeNo) {
48 auto ref = span.get(routeNo);
49 REQUIRE(inputs[routeNo].at(0) == ref.header);
50 REQUIRE(inputs[routeNo].at(1) == ref.payload);
51 if (routeNo == 1) {
52 REQUIRE(span.getNofParts(routeNo) == 3);
53 ref = span.get(routeNo, 1);
54 REQUIRE(inputs[routeNo].at(2) == ref.header);
55 REQUIRE(inputs[routeNo].at(3) == ref.payload);
56 } else {
57 REQUIRE(span.getNofParts(routeNo) == 1);
58 }
59 }
60
61 routeNo = 0;
62 for (auto it = span.begin(), end = span.end(); it != end; ++it) {
63 size_t partNo = 0;
64 REQUIRE(it.size() * 2 == inputs[routeNo].size());
65 for (auto const& ref : it) {
66 REQUIRE(inputs[routeNo].at(partNo++) == ref.header);
67 REQUIRE(inputs[routeNo].at(partNo++) == ref.payload);
68 INFO(ref.header << " " << ref.payload);
69 }
70 routeNo++;
71 }
72}
int32_t i
size_t size() const
Number of elements in the InputSpan.
Definition InputSpan.h:93
GLuint GLuint end
Definition glcorearb.h:469
GLsizei GLenum const void * indices
Definition glcorearb.h:400
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
TEST_CASE("test_prepareArguments")
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52