Project
Loading...
Searching...
No Matches
test_ChannelSpecHelpers.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>
14#include <sstream>
15
16using namespace o2::framework;
17
18TEST_CASE("TestChannelMethod")
19{
20 std::ostringstream oss;
21 oss << ChannelSpecHelpers::methodAsString(ChannelMethod::Bind)
22 << ChannelSpecHelpers::methodAsString(ChannelMethod::Connect);
23
24 REQUIRE(oss.str() == "bindconnect");
25 std::ostringstream oss2;
26}
27
28TEST_CASE("TestChannelType")
29{
30 std::ostringstream oss;
31 oss << ChannelSpecHelpers::typeAsString(ChannelType::Pub)
32 << ChannelSpecHelpers::typeAsString(ChannelType::Sub)
33 << ChannelSpecHelpers::typeAsString(ChannelType::Push)
34 << ChannelSpecHelpers::typeAsString(ChannelType::Pull);
35
36 REQUIRE(oss.str() == "pubsubpushpull");
37}
38
40 void beginChannel() override
41 {
42 str << "@";
43 }
44
45 void endChannel() override
46 {
47 str << "*";
48 }
49 void error() override
50 {
51 hasError = true;
52 }
53
54 void property(std::string_view k, std::string_view v) override
55 {
56 str << k << "=" << v;
57 }
59 std::ostringstream str;
60};
61
62TEST_CASE("TestChannelParser")
63{
66 REQUIRE(h.str.str() == "@name=foo*");
67 TestHandler h1;
68 ChannelSpecHelpers::parseChannelConfig("name=foo,bar=fur", h1);
69 REQUIRE(h1.str.str() == "@name=foobar=fur*");
70 TestHandler h2;
71 ChannelSpecHelpers::parseChannelConfig("name=foo,bar=fur,abc=cdf;name=bar,foo=a", h2);
72 REQUIRE(h2.str.str() == "@name=foobar=furabc=cdf*@name=barfoo=a*");
73 TestHandler h3;
74 ChannelSpecHelpers::parseChannelConfig("foo:bar=fur,abc=cdf;name=bar,foo=a", h3);
75 REQUIRE(h3.str.str() == "@name=foobar=furabc=cdf*@name=barfoo=a*");
76
77 // Test the OutputChannelSpecConfigParser::parseChannelConfig method
80 REQUIRE(p.specs.size() == 1);
81 REQUIRE(p.specs.back().name == "foo");
82
85 REQUIRE(p2.specs.size() == 1);
86 REQUIRE(p2.specs.back().name == "foo");
87
89 ChannelSpecHelpers::parseChannelConfig("name=foo,method=bind,type=pub", p3);
90 REQUIRE(p3.specs.size() == 1);
91 REQUIRE(p3.specs.back().name == "foo");
92 REQUIRE(p3.specs.back().method == ChannelMethod::Bind);
93 REQUIRE(p3.specs.back().type == ChannelType::Pub);
94
95 // Check the case for a channel with a protocol TPC
97 ChannelSpecHelpers::parseChannelConfig("name=foo,method=connect,type=sub,address=tcp://127.0.0.2:8080", p4);
98 REQUIRE(p4.specs.size() == 1);
99 REQUIRE(p4.specs.back().name == "foo");
100 REQUIRE(p4.specs.back().method == ChannelMethod::Connect);
101 REQUIRE(p4.specs.back().type == ChannelType::Sub);
102 REQUIRE(p4.specs.back().hostname == "127.0.0.2");
103 REQUIRE(p4.specs.back().port == 8080);
104 REQUIRE(p4.specs.back().protocol == ChannelProtocol::Network);
105
106 // Check the case for a channel with a protocol IPC
108 ChannelSpecHelpers::parseChannelConfig("name=foo,method=connect,type=sub,address=ipc://@some_ipc_file_8080", p5);
109 REQUIRE(p5.specs.size() == 1);
110 REQUIRE(p5.specs.back().name == "foo");
111 REQUIRE(p5.specs.back().method == ChannelMethod::Connect);
112 REQUIRE(p5.specs.back().type == ChannelType::Sub);
113 REQUIRE(p5.specs.back().hostname == "@some_ipc_file_8080");
114 REQUIRE(p5.specs.back().port == 0);
115 REQUIRE(p5.specs.back().protocol == ChannelProtocol::IPC);
116}
constexpr int p2()
Class for time synchronization of RawReader instances.
const GLdouble * v
Definition glcorearb.h:832
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
void endChannel() override
std::ostringstream str
void beginChannel() override
void property(std::string_view k, std::string_view v) override
void error() override
static void parseChannelConfig(char const *channelConfig, FairMQChannelConfigParser &parser)
static char const * typeAsString(enum ChannelType type)
return a ChannelType as a lowercase string
static char const * methodAsString(enum ChannelMethod method)
return a ChannelMethod as a lowercase string
Handler to parse the description of the –channel-config.
A parser which creates an OutputChannelSpec from the –channel-config.
TEST_CASE("TestChannelMethod")