COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-uri.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for URIs manipulation"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Log.hpp"
13 #include "common/URI.hpp"
14 
15 using namespace std;
16 using namespace boost;
17 using namespace cf3;
18 using namespace cf3::common;
19 
21 
22 BOOST_AUTO_TEST_SUITE( URI_TestSuite )
23 
24 
26 BOOST_AUTO_TEST_CASE( constructors )
27 {
28  // empty contructor
29  URI p0;
30  BOOST_CHECK(p0.empty());
31  BOOST_CHECK_EQUAL(p0.string().size(), (size_t)0 );
32 
33  // string constructor
34  URI p1 ( "lolo" );
35  BOOST_CHECK(!p1.empty());
36  BOOST_CHECK_EQUAL( std::strcmp( p1.path().c_str(), "lolo" ), 0 );
37  BOOST_CHECK_EQUAL( std::strcmp( p1.string().c_str(), "cpath:lolo" ), 0 );
38 
39  // copy constructor
40  URI p2 ( "koko" );
41  URI p3 ( p2 );
42  BOOST_CHECK(!p2.empty());
43  BOOST_CHECK(!p3.empty());
44  BOOST_CHECK_EQUAL( std::strcmp( p2.string().c_str(), p3.string().c_str() ), 0 );
45 
46  URI uri_absolute ( "cpath:/hostname/root/component");
47  URI uri_relative ( "../component");
48 
49  URI p4(uri_absolute);
50  BOOST_CHECK(!p4.empty());
51  BOOST_CHECK_EQUAL( p4.string(), "cpath:/hostname/root/component");
52  BOOST_CHECK(p4.is_absolute());
53 
54  URI p5(uri_relative);
55  BOOST_CHECK(!p5.empty());
56  BOOST_CHECK_EQUAL( p5.string(), "cpath:../component");
57  BOOST_CHECK(p5.is_relative());
58 
59 }
60 
62 
63 BOOST_AUTO_TEST_CASE( concatenation )
64 {
65  URI p0 ( "/root/dir1" );
66  URI p1 ( "dir2/dir3" );
67 
68  URI p2 = p0 / p1;
69  BOOST_CHECK_EQUAL( std::strcmp( p2.path().c_str(), "/root/dir1/dir2/dir3" ), 0 );
70 
71  URI p3;
72  p3 /= p0;
73  BOOST_CHECK_EQUAL( std::strcmp( p3.path().c_str(), "/root/dir1" ), 0 );
74 
75  URI p5 = p0 / "dir5/dir55";
76  BOOST_CHECK_EQUAL( std::strcmp( p5.path().c_str(), "/root/dir1/dir5/dir55" ), 0 );
77 
78  URI p6 = "/root/dir6";
79  BOOST_CHECK_EQUAL( std::strcmp( p6.path().c_str(), "/root/dir6" ), 0 );
80 
81 }
82 
84 
85 BOOST_AUTO_TEST_CASE( protocol_management )
86 {
87  URI uri("//Component");
88 
89  // URI without any protocol
90  BOOST_CHECK_EQUAL( uri.scheme(), URI::Scheme::CPATH );
91  BOOST_CHECK_EQUAL( uri.string(), std::string("cpath:/Component") );
92  BOOST_CHECK_EQUAL( uri.path(), std::string("/Component") );
93 
94  // URI with a cpath
95  URI uri2("cpath:/Component");
96  BOOST_CHECK_EQUAL( uri2.scheme(), URI::Scheme::CPATH );
97  BOOST_CHECK_EQUAL( uri2.string(), std::string("cpath:/Component") );
98  BOOST_CHECK_EQUAL( uri2.path(), std::string("/Component") );
99 
100  // URI with a file
101  URI uri3("file:///etc/fstab.txt");
102  BOOST_CHECK_EQUAL( uri3.scheme(), URI::Scheme::FILE );
103  BOOST_CHECK_EQUAL( uri3.string(), std::string("file:///etc/fstab.txt") );
104  BOOST_CHECK_EQUAL( uri3.path(), std::string("///etc/fstab.txt") );
105  BOOST_CHECK_EQUAL( uri3.base_path().string(), std::string("file:///etc") );
106  BOOST_CHECK_EQUAL( uri3.extension(), std::string(".txt") );
107  BOOST_CHECK_EQUAL( uri3.base_name(), std::string("fstab") );
108 
109 
110  // URI with an http address
111 
112  URI uri4("http://coolfluidsrv.vki.ac.be");
113  BOOST_CHECK(true);
114  BOOST_CHECK_EQUAL( uri4.scheme(), URI::Scheme::HTTP );
115  BOOST_CHECK_EQUAL( uri4.string(), std::string("http://coolfluidsrv.vki.ac.be") );
116  BOOST_CHECK_EQUAL( uri4.path(), std::string("//coolfluidsrv.vki.ac.be") );
117 
118  // URI with an https address
119  URI uri5("https://coolfluidsrv.vki.ac.be");
120  BOOST_CHECK_EQUAL( uri5.scheme(), URI::Scheme::HTTPS );
121  BOOST_CHECK_EQUAL( uri5.string(), std::string("https://coolfluidsrv.vki.ac.be") );
122  BOOST_CHECK_EQUAL( uri5.path(), std::string("//coolfluidsrv.vki.ac.be") );
123 
124  // URI with a very long http address
125  URI uri6("http://coolfluidsrv.vki.ac.be/redmine/projects/activity/coolfluid3?"
126  "show_issues=1&show_changesets=1&show_news=1&show_documents=1&"
127  "show_files=1&show_wiki_edits=1");
128  BOOST_CHECK_EQUAL( uri6.scheme(), URI::Scheme::HTTP );
129  BOOST_CHECK_EQUAL( uri6.string(),
130  std::string("http://coolfluidsrv.vki.ac.be/redmine/projects/activity/"
131  "coolfluid3?show_issues=1&show_changesets=1&show_news=1&"
132  "show_documents=1&show_files=1&show_wiki_edits=1") );
133  BOOST_CHECK_EQUAL( uri6.path(),
134  std::string("//coolfluidsrv.vki.ac.be/redmine/projects/activity/"
135  "coolfluid3?show_issues=1&show_changesets=1&show_news=1&"
136  "show_documents=1&show_files=1&show_wiki_edits=1") );
137 
138 }
139 
141 
142 BOOST_AUTO_TEST_CASE( memory_failure )
143 {
144  BOOST_CHECK_EQUAL( URI::Scheme::Convert::instance().to_str(URI::Scheme::CPATH), std::string("cpath") );
145 }
146 
148 
149 BOOST_AUTO_TEST_SUITE_END()
150 
151 
external boost library namespace
Scheme::Type scheme() const
Definition: URI.cpp:248
std::string path() const
Definition: URI.cpp:253
STL namespace.
common::URI uri(ComponentWrapper &self)
Common_API std::string to_str(const T &v)
Converts to std::string.
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
bool empty() const
Definition: URI.hpp:137
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(constructors)
Definition: utest-uri.cpp:26
bool is_absolute() const
Definition: URI.cpp:194
Most basic kernel library.
Definition: Action.cpp:19
std::string string() const
Definition: URI.cpp:258
Send comments to:
COOLFluiD Web Admin