Project
Loading...
Searching...
No Matches
headerstack.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
16
17#define BOOST_TEST_MODULE Test Algorithm HeaderStack
18#define BOOST_TEST_MAIN
19#define BOOST_TEST_DYN_LINK
20#include <boost/test/unit_test.hpp>
21#include <iostream>
22#include <iomanip>
23#include <cstring> // memcmp
24#include "Headers/DataHeader.h" // hexdump
25#include "Headers/NameHeader.h"
26#include "Headers/Stack.h"
27#include "../include/Algorithm/HeaderStack.h"
28
31
32BOOST_AUTO_TEST_CASE(test_headerstack)
33{
34 // make a header stack consisting of two O2 headers and extract them
35 // via function calls using dispatchHeaderStackCallback, and through object
36 // references using parseHeaderStack
40 dh.subSpecification = 0;
41 dh.payloadSize = 0;
42
43 using Name8Header = o2::header::NameHeader<8>;
44 Name8Header nh("NAMEHDR");
45
47
48 // check that the call without any other arguments is compiling
50
51 // lambda functor given as argument for dispatchHeaderStackCallback
52 auto checkDataHeader = [&dh](const auto& header) {
53 o2::header::hexDump("Extracted DataHeader", &header, sizeof(header));
54 BOOST_CHECK(header == dh);
55 };
56
57 // lambda functor given as argument for dispatchHeaderStackCallback
58 auto checkNameHeader = [&nh](const auto& header) {
59 o2::header::hexDump("Extracted NameHeader", &header, sizeof(header));
60 // have to compare on byte level, no operator==
61 BOOST_CHECK(memcmp(&header, &nh, sizeof(header)) == 0);
62 };
63
64 // check extraction of headers via callbacks
67 checkDataHeader,
68 Name8Header(),
69 checkNameHeader);
70
71 // check extraction of only one header via callback
73 Name8Header(),
74 checkNameHeader);
75
76 // check that the call without any other arguments is compiling
78
79 // check extraction of headers via object references
80 o2::header::DataHeader targetDataHeader;
81 Name8Header targetNameHeader;
83 targetDataHeader,
84 targetNameHeader);
85
86 BOOST_CHECK(targetDataHeader == dh);
87 BOOST_CHECK(memcmp(&targetNameHeader, &nh, sizeof(targetNameHeader)) == 0);
88}
uint32_t stack
Definition RawData.h:1
BOOST_AUTO_TEST_CASE(test_headerstack)
void parseHeaderStack(PtrType ptr, SizeType size, HeaderType &header, MoreTypes &&... types)
void dispatchHeaderStackCallback(PtrType ptr, SizeType size, HeaderType header, HeaderCallbackType onHeader, MoreTypes &&... types)
Definition HeaderStack.h:90
void hexDump(const char *desc, const void *voidaddr, size_t len, size_t max=0)
helper function to print a hex/ASCII dump of some memory
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
Descriptor< gSizeDataOriginString > DataOrigin
Definition DataHeader.h:550
the main header struct
Definition DataHeader.h:618
DataDescription dataDescription
Definition DataHeader.h:636
SubSpecificationType subSpecification
Definition DataHeader.h:656
PayloadSizeType payloadSize
Definition DataHeader.h:666
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
BOOST_CHECK(tree)