-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathheaderstack.cxx
More file actions
88 lines (74 loc) · 3.45 KB
/
headerstack.cxx
File metadata and controls
88 lines (74 loc) · 3.45 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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.
/// @file headerstack.cxx
/// @author Matthias Richter
/// @since 2017-09-19
/// @brief Unit test for O2 header stack utilities
#define BOOST_TEST_MODULE Test Algorithm HeaderStack
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <iomanip>
#include <cstring> // memcmp
#include "Headers/DataHeader.h" // hexdump
#include "Headers/NameHeader.h"
#include "Headers/Stack.h"
#include "../include/Algorithm/HeaderStack.h"
using DataHeader = o2::header::DataHeader;
using HeaderStack = o2::header::Stack;
BOOST_AUTO_TEST_CASE(test_headerstack)
{
// make a header stack consisting of two O2 headers and extract them
// via function calls using dispatchHeaderStackCallback, and through object
// references using parseHeaderStack
o2::header::DataHeader dh;
dh.dataDescription = o2::header::DataDescription("SOMEDATA");
dh.dataOrigin = o2::header::DataOrigin("TST");
dh.subSpecification = 0;
dh.payloadSize = 0;
using Name8Header = o2::header::NameHeader<8>;
Name8Header nh("NAMEHDR");
o2::header::Stack stack(dh, nh);
// check that the call without any other arguments is compiling
o2::algorithm::dispatchHeaderStackCallback(stack.data(), stack.size());
// lambda functor given as argument for dispatchHeaderStackCallback
auto checkDataHeader = [&dh](const auto& header) {
o2::header::hexDump("Extracted DataHeader", &header, sizeof(header));
BOOST_CHECK(header == dh);
};
// lambda functor given as argument for dispatchHeaderStackCallback
auto checkNameHeader = [&nh](const auto& header) {
o2::header::hexDump("Extracted NameHeader", &header, sizeof(header));
// have to compare on byte level, no operator==
BOOST_CHECK(memcmp(&header, &nh, sizeof(header)) == 0);
};
// check extraction of headers via callbacks
o2::algorithm::dispatchHeaderStackCallback(stack.data(), stack.size(),
o2::header::DataHeader(),
checkDataHeader,
Name8Header(),
checkNameHeader);
// check extraction of only one header via callback
o2::algorithm::dispatchHeaderStackCallback(stack.data(), stack.size(),
Name8Header(),
checkNameHeader);
// check that the call without any other arguments is compiling
o2::algorithm::parseHeaderStack(stack.data(), stack.size());
// check extraction of headers via object references
o2::header::DataHeader targetDataHeader;
Name8Header targetNameHeader;
o2::algorithm::parseHeaderStack(stack.data(), stack.size(),
targetDataHeader,
targetNameHeader);
BOOST_CHECK(targetDataHeader == dh);
BOOST_CHECK(memcmp(&targetNameHeader, &nh, sizeof(targetNameHeader)) == 0);
}