Project
Loading...
Searching...
No Matches
o2formatparser.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, DataHeader
25#include "../include/Algorithm/O2FormatParser.h"
26
27template <typename... Targs>
28void hexDump(Targs... Fargs)
29{
30 // a simple redirect to enable/disable the hexdump printout
31 o2::header::hexDump(Fargs...);
32}
33
34BOOST_AUTO_TEST_CASE(test_o2formatparser)
35{
36 std::vector<const char*> thedata = {
37 "I'm raw data",
38 "reconstructed data"};
39 unsigned dataidx = 0;
40 std::vector<o2::header::DataHeader> dataheaders;
41 dataheaders.emplace_back(o2::header::DataDescription("RAWDATA"),
43 0,
44 strlen(thedata[dataidx++]));
45 dataheaders.emplace_back(o2::header::DataDescription("RECODATA"),
47 0,
48 strlen(thedata[dataidx++]));
49
50 std::vector<std::pair<const char*, size_t>> messages;
51 for (dataidx = 0; dataidx < thedata.size(); ++dataidx) {
52 messages.emplace_back(reinterpret_cast<char*>(&dataheaders[dataidx]),
54 messages.emplace_back(thedata[dataidx],
55 dataheaders[dataidx].payloadSize);
56 }
57
58 // handler callback for parseO2Format method
59 auto insertFct = [&](const auto& dataheader,
60 auto ptr,
61 auto size) {
62 hexDump("header", &dataheader, sizeof(dataheader));
63 hexDump("data", ptr, size);
64 BOOST_CHECK(dataheader == dataheaders[dataidx]);
65 BOOST_CHECK(strncmp(ptr, thedata[dataidx], size) == 0);
66 ++dataidx;
67 }; // end handler callback
68
69 // handler callback to get the pointer for message
70 auto getPointerFct = [](auto arg) { return arg.first; };
71 // handler callback to get the size for message
72 auto getSizeFct = [](auto arg) { return arg.second; };
73
74 dataidx = 0;
76 getPointerFct,
77 getSizeFct,
78 insertFct);
79
80 BOOST_REQUIRE(result >= 0);
81 BOOST_CHECK(result == 2);
82}
TBranch * ptr
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizeiptr size
Definition glcorearb.h:659
int parseO2Format(const InputListT &list, GetPointerFctT getPointer, GetSizeFctT getSize, InsertFctT insert, HeaderStackTypes &&... stackArgs)
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
BOOST_AUTO_TEST_CASE(test_o2formatparser)
void hexDump(Targs... Fargs)
the main header struct
Definition DataHeader.h:618
BOOST_CHECK(tree)