μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
31
32#include <boost/test/unit_test.hpp>
33
34
35namespace uhal {
36namespace tests {
37
38URI 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
51BOOST_AUTO_TEST_SUITE( grammars )
52
53BOOST_AUTO_TEST_SUITE( uri )
54
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, "");
64 BOOST_CHECK(lURI.mArguments.empty());
65}
66
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, "");
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
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, "");
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, "");
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, "");
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
117BOOST_AUTO_TEST_SUITE_END()
118
119BOOST_AUTO_TEST_SUITE_END()
120
121} // end ns tests
122} // end ns uhal
None tests(nox.Session session)
Definition: noxfile.py:19
std::string uri
Definition: test_single.cpp:89
BOOST_CHECK_EQUAL(mem.size(), N)
BOOST_CHECK(!mem.valid())
BOOST_AUTO_TEST_CASE(core_clients)
URI parseURI(const std::string &aUri)
Definition: test_uri.cpp:38
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50
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
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
std::string mProtocol
The "protocol" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?...
Definition: URI.hpp:52
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
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
std::string mPath
The "patha/pathb/blah" part of a URI of the form "protocol://host:port/patha/pathb/blah....
Definition: URI.hpp:58