μHAL (v2.7.9)
Part of the IPbus software repository
tests
src
common
test_uri.cpp
Go to the documentation of this file.
1
/*
2
---------------------------------------------------------------------------
3
4
This file is part of uHAL.
5
6
uHAL is a hardware access library and programming framework
7
originally developed for upgrades of the Level-1 trigger of the CMS
8
experiment at CERN.
9
10
uHAL is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
14
15
uHAL is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
19
20
You should have received a copy of the GNU General Public License
21
along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
24
email: tom.williams <AT> cern.ch
25
26
---------------------------------------------------------------------------
27
*/
28
29
#include "
uhal/grammars/URI.hpp
"
30
#include "
uhal/grammars/URIGrammar.hpp
"
31
32
#include <boost/test/unit_test.hpp>
33
34
35
namespace
uhal
{
36
namespace
tests {
37
38
URI
parseURI
(
const
std::string& aUri)
39
{
40
URI
lUri;
41
42
grammars::URIGrammar lGrammar;
43
std::string::const_iterator lBegin ( aUri.begin() );
44
std::string::const_iterator lEnd ( aUri.end() );
45
boost::spirit::qi::phrase_parse ( lBegin , lEnd , lGrammar , boost::spirit::ascii::space , lUri );
46
47
return
lUri;
48
}
49
50
51
BOOST_AUTO_TEST_SUITE( grammars )
52
53
BOOST_AUTO_TEST_SUITE(
uri
)
54
55
BOOST_AUTO_TEST_CASE
(udp)
56
{
57
URI
lURI =
parseURI
(
"ipbusudp-2.0://someHost.xyz:2468"
);
58
59
BOOST_CHECK_EQUAL
(lURI.
mProtocol
,
"ipbusudp-2.0"
);
60
BOOST_CHECK_EQUAL
(lURI.
mHostname
,
"someHost.xyz"
);
61
BOOST_CHECK_EQUAL
(lURI.
mPort
,
"2468"
);
62
BOOST_CHECK_EQUAL
(lURI.
mPath
,
""
);
63
BOOST_CHECK_EQUAL
(lURI.
mExtension
,
""
);
64
BOOST_CHECK
(lURI.
mArguments
.empty());
65
}
66
67
BOOST_AUTO_TEST_CASE
(controlhub)
68
{
69
URI
lURI =
parseURI
(
"chtcp-2.0://someHost.xyz:2468?target=other-host.domain:3579"
);
70
71
BOOST_CHECK_EQUAL
(lURI.
mProtocol
,
"chtcp-2.0"
);
72
BOOST_CHECK_EQUAL
(lURI.
mHostname
,
"someHost.xyz"
);
73
BOOST_CHECK_EQUAL
(lURI.
mPort
,
"2468"
);
74
BOOST_CHECK_EQUAL
(lURI.
mPath
,
""
);
75
BOOST_CHECK_EQUAL
(lURI.
mExtension
,
""
);
76
BOOST_CHECK_EQUAL
(lURI.
mArguments
.size(),
size_t
(1));
77
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).first,
"target"
);
78
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).second,
"other-host.domain:3579"
);
79
}
80
81
BOOST_AUTO_TEST_CASE
(pcie)
82
{
83
URI
lURI =
parseURI
(
"ipbuspcie-2.0:///dev/aFile,/dev/anotherFile"
);
84
85
BOOST_CHECK_EQUAL
(lURI.
mProtocol
,
"ipbuspcie-2.0"
);
86
BOOST_CHECK_EQUAL
(lURI.
mHostname
,
"/dev/aFile,/dev/anotherFile"
);
87
BOOST_CHECK_EQUAL
(lURI.
mPort
,
""
);
88
BOOST_CHECK_EQUAL
(lURI.
mPath
,
""
);
89
BOOST_CHECK_EQUAL
(lURI.
mExtension
,
""
);
90
BOOST_CHECK
(lURI.
mArguments
.empty());
91
92
lURI =
parseURI
(
"ipbuspcie-2.0:///dev/aFile,/dev/anotherFile?events=/path/to/someOtherFile"
);
93
94
BOOST_CHECK_EQUAL
(lURI.
mProtocol
,
"ipbuspcie-2.0"
);
95
BOOST_CHECK_EQUAL
(lURI.
mHostname
,
"/dev/aFile,/dev/anotherFile"
);
96
BOOST_CHECK_EQUAL
(lURI.
mPort
,
""
);
97
BOOST_CHECK_EQUAL
(lURI.
mPath
,
""
);
98
BOOST_CHECK_EQUAL
(lURI.
mExtension
,
""
);
99
BOOST_CHECK_EQUAL
(lURI.
mArguments
.size(),
size_t
(1));
100
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).first,
"events"
);
101
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).second,
"/path/to/someOtherFile"
);
102
103
lURI =
parseURI
(
"ipbuspcie-2.0:///dev/aFile,/dev/anotherFile?events=/path/to/someOtherFile&sleep=20"
);
104
105
BOOST_CHECK_EQUAL
(lURI.
mProtocol
,
"ipbuspcie-2.0"
);
106
BOOST_CHECK_EQUAL
(lURI.
mHostname
,
"/dev/aFile,/dev/anotherFile"
);
107
BOOST_CHECK_EQUAL
(lURI.
mPort
,
""
);
108
BOOST_CHECK_EQUAL
(lURI.
mPath
,
""
);
109
BOOST_CHECK_EQUAL
(lURI.
mExtension
,
""
);
110
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).first,
"events"
);
111
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(0).second,
"/path/to/someOtherFile"
);
112
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(1).first,
"sleep"
);
113
BOOST_CHECK_EQUAL
(lURI.
mArguments
.at(1).second,
"20"
);
114
}
115
116
117
BOOST_AUTO_TEST_SUITE_END()
118
119
BOOST_AUTO_TEST_SUITE_END()
120
121
}
// end ns tests
122
}
// end ns uhal
uhal::tests::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(core_clients)
Definition:
test_client_factory.cpp:78
uhal::URI::mHostname
std::string mHostname
The "host" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&k...
Definition:
URI.hpp:54
uhal::URI::mPath
std::string mPath
The "patha/pathb/blah" part of a URI of the form "protocol://host:port/patha/pathb/blah....
Definition:
URI.hpp:58
uhal::tests::BOOST_CHECK
BOOST_CHECK(!mem.valid())
uhal::URI::mArguments
NameValuePairVectorType mArguments
The "key1=val1&key2=val2&key3=val3" part of a URI of the form "protocol://host:port/patha/pathb/blah....
Definition:
URI.hpp:62
uhal
Definition:
HttpResponseGrammar.hpp:49
uhal::URI::mExtension
std::string mExtension
The "ext" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&ke...
Definition:
URI.hpp:60
uhal::tests::uri
std::string uri
Definition:
test_single.cpp:89
URIGrammar.hpp
uhal::tests::BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(mem.size(), N)
URI.hpp
uhal::URI::mProtocol
std::string mProtocol
The "protocol" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?...
Definition:
URI.hpp:52
uhal::URI
Struct to store a URI when parsed by boost spirit.
Definition:
URI.hpp:50
uhal::tests::parseURI
URI parseURI(const std::string &aUri)
Definition:
test_uri.cpp:38
uhal::URI::mPort
std::string mPort
The "port" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&k...
Definition:
URI.hpp:56
Generated on Tue Sep 22 2020 19:18:38 for μHAL (v2.7.9) by
1.8.18