-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathtest_InputSpan.cxx
More file actions
73 lines (67 loc) · 2.62 KB
/
Copy pathtest_InputSpan.cxx
File metadata and controls
73 lines (67 loc) · 2.62 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "Framework/InputSpan.h"
#include "Framework/DataRef.h"
#include <vector>
#include <string>
#include <catch_amalgamated.hpp>
using namespace o2::framework;
TEST_CASE("TestInputSpan")
{
std::vector<std::vector<std::string>> inputs(3);
int routeNo = 0;
for (auto& list : inputs) {
int nParts = routeNo != 1 ? 1 : 3;
for (size_t part = 0; part < nParts; ++part) {
list.emplace_back("header_" + std::to_string(routeNo) + "-" + std::to_string(part));
list.emplace_back("payload_" + std::to_string(routeNo) + "-" + std::to_string(part));
}
routeNo++;
}
auto nPartsGetter = [&inputs](size_t i) {
return inputs[i].size() / 2;
};
auto indicesGetter = [&inputs](size_t i, DataRefIndices indices) {
return DataRef{nullptr, inputs[i].at(indices.headerIdx).data(), inputs[i].at(indices.payloadIdx).data()};
};
auto nextIndicesGetter = [&inputs](size_t i, DataRefIndices current) -> DataRefIndices {
size_t next = current.headerIdx + 2;
return next < inputs[i].size() ? DataRefIndices{next, next + 1} : DataRefIndices{size_t(-1), size_t(-1)};
};
InputSpan span{nPartsGetter, nullptr, indicesGetter, nextIndicesGetter, inputs.size()};
REQUIRE(span.size() == inputs.size());
routeNo = 0;
for (; routeNo < span.size(); ++routeNo) {
auto ref = span.get(routeNo);
REQUIRE(inputs[routeNo].at(0) == ref.header);
REQUIRE(inputs[routeNo].at(1) == ref.payload);
if (routeNo == 1) {
REQUIRE(span.getNofParts(routeNo) == 3);
ref = span.get(routeNo, 1);
REQUIRE(inputs[routeNo].at(2) == ref.header);
REQUIRE(inputs[routeNo].at(3) == ref.payload);
} else {
REQUIRE(span.getNofParts(routeNo) == 1);
}
}
routeNo = 0;
for (auto it = span.begin(), end = span.end(); it != end; ++it) {
size_t partNo = 0;
auto parts = it.parts();
REQUIRE(parts.size() * 2 == inputs[routeNo].size());
for (auto const& ref : parts) {
REQUIRE(inputs[routeNo].at(partNo++) == ref.header);
REQUIRE(inputs[routeNo].at(partNo++) == ref.payload);
INFO(ref.header << " " << ref.payload);
}
routeNo++;
}
}