Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9e2a7e

Browse files
committed
Added first unit test for a URI builder.
1 parent1619604 commitd9e2a7e

File tree

6 files changed

+208
-1
lines changed

6 files changed

+208
-1
lines changed

‎boost/network/uri/builder.hpp‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __BOOST_NETWORK_URI_BUILDER_INC__
8+
#define__BOOST_NETWORK_URI_BUILDER_INC__
9+
10+
11+
#include<boost/network/uri/uri.hpp>
12+
13+
14+
namespaceboost {
15+
namespacenetwork {
16+
namespaceuri {
17+
namespacebuilder {
18+
template<
19+
classT
20+
>
21+
structscheme_t {
22+
scheme_t(const T &scheme)
23+
: scheme(scheme) {
24+
25+
}
26+
27+
const T &scheme;
28+
};
29+
30+
template<
31+
classT
32+
>
33+
inline
34+
scheme_t<T>scheme(const T &scheme) {
35+
returnscheme_t<T>(scheme);
36+
}
37+
38+
template<
39+
classT
40+
>
41+
structhost_t {
42+
host_t(const T &host)
43+
: host(host) {
44+
45+
}
46+
47+
const T &host;
48+
};
49+
50+
template<
51+
classT
52+
>
53+
inline
54+
host_t<T>host(const T &host) {
55+
returnhost_t<T>(host);
56+
}
57+
58+
template<
59+
classT
60+
>
61+
structpath_t {
62+
path_t(const T &path)
63+
: path(path) {
64+
65+
}
66+
67+
const T &path;
68+
};
69+
70+
template<
71+
classT
72+
>
73+
inline
74+
path_t<T>path(const T &path) {
75+
returnpath_t<T>(path);
76+
}
77+
}// namespace builder
78+
79+
template<
80+
classTag
81+
>
82+
classbasic_builder {
83+
84+
public:
85+
86+
public:
87+
88+
basic_builder(basic_uri<Tag> &uri)
89+
: uri_(uri) {
90+
91+
}
92+
93+
const basic_uri<Tag> &uri()const {
94+
return uri_;
95+
}
96+
97+
private:
98+
basic_uri<Tag> &uri_;
99+
};
100+
101+
template<
102+
classTag
103+
>
104+
inline
105+
basic_builder<Tag>operator << (basic_uri<Tag> &uri,const builder::scheme_t<typename string<Tag>::type> &scheme) {
106+
// uri.set_scheme(
107+
return basic_builder<Tag>(uri);
108+
}
109+
110+
template<
111+
classTag
112+
>
113+
inline
114+
basic_builder<Tag> &operator << (basic_builder<Tag> &builder,const builder::scheme_t<typename string<Tag>::type> &scheme) {
115+
// uri.set_scheme(
116+
return builder;
117+
}
118+
119+
template<
120+
classTag
121+
>
122+
inline
123+
basic_builder<Tag> &operator << (basic_builder<Tag> &builder,const builder::host_t<typename string<Tag>::type> &host) {
124+
// uri.set_host(
125+
return builder;
126+
}
127+
128+
template<
129+
classTag
130+
>
131+
inline
132+
basic_builder<Tag> &operator << (basic_builder<Tag> &builder,const builder::path_t<typename string<Tag>::type> &path) {
133+
// uri.set_path(
134+
return builder;
135+
}
136+
}// namespace uri
137+
}// namespace network
138+
}// namespace boost
139+
140+
141+
#endif// __BOOST_NETWORK_URI_BUILDER_INC__

‎boost/network/uri/http/uri.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
17
#ifndef __BOOST_NETWORK_URI_HTTP_URI_INC__
28
#define__BOOST_NETWORK_URI_HTTP_URI_INC__
39

‎boost/network/uri/mailto/uri.hpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
17
#ifndef __BOOST_NETWORK_URI_MAILTO_URI_INC__
28
#define__BOOST_NETWORK_URI_MAILTO_URI_INC__
39

@@ -54,7 +60,7 @@ class basic_uri
5460
return *this;
5561
}
5662

57-
63+
5864

5965
};
6066
}// namespace mailto

‎boost/network/uri/uri_accessors.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
17
#ifndef __BOOST_NETWORK_URI_URI_ACCESSORS_INC__
28
#define__BOOST_NETWORK_URI_URI_ACCESSORS_INC__
39

‎libs/network/test/uri/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (Boost_FOUND)
1717
url_test
1818
url_http_test
1919
url_mailto_test
20+
builder_test
2021
)
2122
foreach (test${TESTS})
2223
set_source_files_properties(${test}.cpp
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#defineBOOST_TEST_MODULE URI builder test
7+
#include<boost/config/warning_disable.hpp>
8+
#include<boost/test/unit_test.hpp>
9+
#include<boost/network/uri/uri.hpp>
10+
#include<boost/network/uri/builder.hpp>
11+
#include<boost/network/tags.hpp>
12+
#include<boost/mpl/list.hpp>
13+
#include<boost/range/algorithm/equal.hpp>
14+
#include<boost/range/algorithm/copy.hpp>
15+
16+
17+
usingnamespaceboost::network;
18+
19+
typedef boost::mpl::list<
20+
tags::default_string
21+
// , tags::default_wstring
22+
> tag_types;
23+
24+
25+
BOOST_AUTO_TEST_CASE_TEMPLATE(builder_test, T, tag_types)
26+
{
27+
typedef uri::basic_uri<T> uri_type;
28+
typedeftypename uri_type::string_type string_type;
29+
30+
const std::stringscheme("http");
31+
const std::stringhost("www.example.com");
32+
const std::stringpath("/");
33+
34+
uri_type instance;
35+
uri::basic_builder<T>builder(instance);
36+
builder <<uri::builder::scheme(string_type(boost::begin(scheme),
37+
boost::end(scheme)))
38+
<<uri::builder::host(string_type(boost::begin(host),
39+
boost::end(host)))
40+
<<uri::builder::path(string_type(boost::begin(path),
41+
boost::end(path)))
42+
;
43+
BOOST_REQUIRE(uri::is_valid(instance));
44+
BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
45+
BOOST_CHECK(boost::equal(uri::host(instance), host));
46+
BOOST_CHECK(boost::equal(uri::path(instance), path));
47+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp