Project
Loading...
Searching...
No Matches
test_FairMQResizableBuffer.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 <catch_amalgamated.hpp>
15#include <fairmq/TransportFactory.h>
16#include <cstring>
17#include <arrow/io/memory.h>
18#include <arrow/ipc/writer.h>
19#include <arrow/util/config.h>
20
21using namespace o2::framework;
22
23template class std::unique_ptr<fair::mq::Message>;
24
25// A simple test where an input is provided
26// and the subsequent InputRecord is immediately requested.
27TEST_CASE("TestCreation")
28{
29 auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
30 FairMQResizableBuffer buffer{[&transport](size_t size) -> std::unique_ptr<fair::mq::Message> {
31 return std::move(transport->CreateMessage(size));
32 }};
33}
34
35// Check a few invariants for Resize and Reserve operations
36TEST_CASE("TestInvariants")
37{
38 auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
39 FairMQResizableBuffer buffer{[&transport](size_t size) -> std::unique_ptr<fair::mq::Message> {
40 return std::move(transport->CreateMessage(size));
41 }};
42
43 REQUIRE(buffer.size() == 0);
44 REQUIRE(buffer.size() <= buffer.capacity());
45
46 auto status = buffer.Reserve(10000);
47 REQUIRE(status.ok());
48 REQUIRE(buffer.capacity() == 10000);
49 REQUIRE(buffer.size() == 0);
50 auto old_ptr = buffer.data();
51
52 status = buffer.Resize(9000, false);
53 REQUIRE(status.ok());
54 REQUIRE(old_ptr == buffer.data());
55 REQUIRE(buffer.capacity() == 10000);
56 REQUIRE(buffer.size() == 9000);
57
58 status = buffer.Resize(11000, false);
59 REQUIRE(status.ok());
60 REQUIRE(buffer.capacity() == 11000);
61 REQUIRE(buffer.size() == 11000);
62
63 status = buffer.Resize(10000, false);
64 REQUIRE(status.ok());
65 REQUIRE(buffer.capacity() == 11000);
66 REQUIRE(buffer.size() == 10000);
67
68 status = buffer.Resize(9000, true);
69 REQUIRE(status.ok());
70 REQUIRE(buffer.capacity() == 11000);
71 REQUIRE(buffer.size() == 9000);
72
73 status = buffer.Resize(19000, true);
74 REQUIRE(status.ok());
75 REQUIRE(buffer.capacity() == 19000);
76 REQUIRE(buffer.size() == 19000);
77}
78
79// Check a few invariants for Resize and Reserve operations
80TEST_CASE("TestContents")
81{
82 auto transport = fair::mq::TransportFactory::CreateTransportFactory("zeromq");
83 FairMQResizableBuffer buffer{[&transport](size_t size) -> std::unique_ptr<fair::mq::Message> {
84 return std::move(transport->CreateMessage(size));
85 }};
86
87 REQUIRE(buffer.size() == 0);
88 REQUIRE(buffer.size() <= buffer.capacity());
89
90 auto status = buffer.Resize(10, true);
91 REQUIRE(status.ok());
92 REQUIRE(buffer.capacity() == 10);
93 REQUIRE(buffer.size() == 10);
94 auto old_ptr = buffer.data();
95
96 strcpy((char*)buffer.mutable_data(), "foo");
97
98 status = buffer.Resize(9000, false);
99 REQUIRE(status.ok());
100 REQUIRE(buffer.capacity() == 9000);
101 REQUIRE(buffer.size() == 9000);
102 REQUIRE(strncmp((const char*)buffer.data(), "foo", 3) == 0);
103
104 status = buffer.Resize(4000, false);
105 REQUIRE(status.ok());
106 REQUIRE(buffer.capacity() == 9000);
107 REQUIRE(buffer.size() == 4000);
108 REQUIRE(strncmp((const char*)buffer.data(), "foo", 3) == 0);
109
110 status = buffer.Resize(40, true);
111 REQUIRE(status.ok());
112 REQUIRE(buffer.capacity() == 9000);
113 REQUIRE(buffer.size() == 40);
114 REQUIRE(strncmp((const char*)buffer.data(), "foo", 3) == 0);
115}
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")