|
| 1 | +// Copyright 2019-2025 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 <fairmq/Message.h> |
| 13 | +#include "Framework/MessageSet.h" |
| 14 | +#include <catch_amalgamated.hpp> |
| 15 | + |
| 16 | +using namespace o2::framework; |
| 17 | + |
| 18 | +TEST_CASE("MessageSet") { |
| 19 | + o2::framework::MessageSet msgSet; |
| 20 | + std::vector<fair::mq::MessagePtr> ptrs; |
| 21 | + std::unique_ptr<fair::mq::Message> msg(nullptr); |
| 22 | + std::unique_ptr<fair::mq::Message> msg2(nullptr); |
| 23 | + ptrs.emplace_back(std::move(msg)); |
| 24 | + ptrs.emplace_back(std::move(msg2)); |
| 25 | + msgSet.add([&ptrs](size_t i) -> fair::mq::MessagePtr& { return ptrs[i]; }, 2); |
| 26 | + |
| 27 | + REQUIRE(msgSet.messages.size() == 2); |
| 28 | + REQUIRE(msgSet.messageMap.size() == 1); |
| 29 | + REQUIRE(msgSet.pairMap.size() == 1); |
| 30 | + REQUIRE(msgSet.messageMap[0].position == 0); |
| 31 | + REQUIRE(msgSet.messageMap[0].size == 1); |
| 32 | + |
| 33 | + REQUIRE(msgSet.pairMap[0].partIndex == 0); |
| 34 | + REQUIRE(msgSet.pairMap[0].payloadIndex == 0); |
| 35 | +} |
| 36 | + |
| 37 | +TEST_CASE("MessageSetWithFunction") { |
| 38 | + std::vector<fair::mq::MessagePtr> ptrs; |
| 39 | + std::unique_ptr<fair::mq::Message> msg(nullptr); |
| 40 | + std::unique_ptr<fair::mq::Message> msg2(nullptr); |
| 41 | + ptrs.emplace_back(std::move(msg)); |
| 42 | + ptrs.emplace_back(std::move(msg2)); |
| 43 | + o2::framework::MessageSet msgSet([&ptrs](size_t i) -> fair::mq::MessagePtr& { return ptrs[i]; }, 2); |
| 44 | + |
| 45 | + REQUIRE(msgSet.messages.size() == 2); |
| 46 | + REQUIRE(msgSet.messageMap.size() == 1); |
| 47 | + REQUIRE(msgSet.pairMap.size() == 1); |
| 48 | + REQUIRE(msgSet.messageMap[0].position == 0); |
| 49 | + REQUIRE(msgSet.messageMap[0].size == 1); |
| 50 | + |
| 51 | + REQUIRE(msgSet.pairMap[0].partIndex == 0); |
| 52 | + REQUIRE(msgSet.pairMap[0].payloadIndex == 0); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_CASE("MessageSetWithMultipart") { |
| 56 | + std::vector<fair::mq::MessagePtr> ptrs; |
| 57 | + std::unique_ptr<fair::mq::Message> msg(nullptr); |
| 58 | + std::unique_ptr<fair::mq::Message> msg2(nullptr); |
| 59 | + std::unique_ptr<fair::mq::Message> msg3(nullptr); |
| 60 | + ptrs.emplace_back(std::move(msg)); |
| 61 | + ptrs.emplace_back(std::move(msg2)); |
| 62 | + ptrs.emplace_back(std::move(msg3)); |
| 63 | + o2::framework::MessageSet msgSet([&ptrs](size_t i) -> fair::mq::MessagePtr& { return ptrs[i]; }, 3); |
| 64 | + |
| 65 | + REQUIRE(msgSet.messages.size() == 3); |
| 66 | + REQUIRE(msgSet.messageMap.size() == 1); |
| 67 | + REQUIRE(msgSet.pairMap.size() == 2); |
| 68 | + REQUIRE(msgSet.messageMap[0].position == 0); |
| 69 | + REQUIRE(msgSet.messageMap[0].size == 2); |
| 70 | + |
| 71 | + REQUIRE(msgSet.pairMap[0].partIndex == 0); |
| 72 | + REQUIRE(msgSet.pairMap[0].payloadIndex == 0); |
| 73 | + REQUIRE(msgSet.pairMap[1].partIndex == 0); |
| 74 | + REQUIRE(msgSet.pairMap[1].payloadIndex == 1); |
| 75 | +} |
| 76 | + |
| 77 | +TEST_CASE("MessageSetAddPartRef") { |
| 78 | + std::vector<fair::mq::MessagePtr> ptrs; |
| 79 | + std::unique_ptr<fair::mq::Message> msg(nullptr); |
| 80 | + std::unique_ptr<fair::mq::Message> msg2(nullptr); |
| 81 | + ptrs.emplace_back(std::move(msg)); |
| 82 | + ptrs.emplace_back(std::move(msg2)); |
| 83 | + PartRef ref {std::move(msg), std::move(msg2)}; |
| 84 | + o2::framework::MessageSet msgSet; |
| 85 | + msgSet.add(std::move(ref)); |
| 86 | + |
| 87 | + REQUIRE(msgSet.messages.size() == 2); |
| 88 | + REQUIRE(msgSet.messageMap.size() == 1); |
| 89 | + REQUIRE(msgSet.pairMap.size() == 1); |
| 90 | + REQUIRE(msgSet.messageMap[0].position == 0); |
| 91 | + REQUIRE(msgSet.messageMap[0].size == 1); |
| 92 | + |
| 93 | + REQUIRE(msgSet.pairMap[0].partIndex == 0); |
| 94 | + REQUIRE(msgSet.pairMap[0].payloadIndex == 0); |
| 95 | +} |
0 commit comments