Project
Loading...
Searching...
No Matches
test_DataRefUtils.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 <TObject.h>
13#include <TObjString.h>
14#include <TObjArray.h>
15#include <TMessage.h>
18#include <catch_amalgamated.hpp>
19
20#include <memory>
21
22using namespace o2::framework;
23
24TEST_CASE("PureRootTest")
25{
26 TBufferFile buffer(TBuffer::kWrite);
27 TObjString s("test");
28 buffer.WriteObject(&s);
29
30 TBufferFile buffer2(TBuffer::kRead, buffer.BufferSize(), buffer.Buffer(), false);
31 buffer2.SetReadMode();
32 buffer2.InitMap();
33 TClass* storedClass = buffer2.ReadClass();
34 // ReadClass advances the buffer, so we need to reset it.
35 buffer2.SetBufferOffset(0);
36 buffer2.ResetMap();
37 REQUIRE(storedClass != nullptr);
38 auto* outS = (TObjString*)buffer2.ReadObjectAny(storedClass);
39 REQUIRE(outS != nullptr);
40 REQUIRE(outS->GetString() == "test");
41}
42
43// Simple test to do root deserialization.
44TEST_CASE("TestRootSerialization")
45{
47 auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
48 auto msg = transport->CreateMessage(4096);
50 auto sOrig = std::make_unique<TObjString>("test");
51 tm << sOrig.get();
54 ref.payload = (char*)msg->GetData();
55 dh.payloadSize = (size_t)msg->GetSize();
56 ref.header = reinterpret_cast<char const*>(&dh);
57
58 // Check by using the same type
59 auto s = DataRefUtils::as<TObjString>(ref);
60 REQUIRE(s.get() != nullptr);
61 REQUIRE(std::string(s->GetString().Data()) == "test");
62 REQUIRE(std::string(s->GetName()) == "test");
63
64 // Check by using the base type.
65 auto o = DataRefUtils::as<TObject>(ref);
66 REQUIRE(o.get() != nullptr);
67 REQUIRE(std::string(o->GetName()) == "test");
68}
69
70// Simple test for ROOT container deserialization.
71TEST_CASE("TestRootContainerSerialization")
72{
74 TMessage* tm = new TMessage(kMESS_OBJECT);
75 TObjArray container;
76 // the original container is explicitly non-owning, its owning
77 // flag is preserved during serialization
78 container.SetOwner(false);
79 auto object = std::make_unique<TObjString>("test");
80 container.Add(object.get());
81 tm->WriteObject(&container);
84 ref.payload = tm->Buffer();
85 dh.payloadSize = tm->BufferSize();
86 ref.header = reinterpret_cast<char const*>(&dh);
87
88 auto s = DataRefUtils::as<TObjArray>(ref);
89 REQUIRE(s.get() != nullptr);
90 REQUIRE(s->GetEntries() == 1);
91 REQUIRE(std::string(s->At(0)->GetName()) == "test");
92 // the extracted object must be owning to avoid memory leaks
93 // the get method takes care of this
94 REQUIRE(s->IsOwner());
95}
bool o
GLuint buffer
Definition glcorearb.h:655
GLint ref
Definition glcorearb.h:291
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
constexpr o2::header::SerializationMethod gSerializationMethodROOT
Definition DataHeader.h:328
the main header struct
Definition DataHeader.h:618
SerializationMethod payloadSerializationMethod
Definition DataHeader.h:651
PayloadSizeType payloadSize
Definition DataHeader.h:666
TEST_CASE("PureRootTest")
uint64_t const void const *restrict const msg
Definition x9.h:153