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

Commit73b0831

Browse files
committed
Added some additional tests for the HTTP URL.
1 parent71757f1 commit73b0831

File tree

2 files changed

+94
-19
lines changed

2 files changed

+94
-19
lines changed

‎http/src/network/http/v2/url.hpp‎

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6-
#ifndef__TTP_NETWORK_HTTP_V2_URL_INC__
7-
#define__HTTP_NETWORK_HTTP_V2_URL_INC__
6+
#ifndef__NETWORK_HTTP_V2_URL_INC__
7+
#define__NETWORK_HTTP_V2_URL_INC__
88

99
#include<network/uri.hpp>
10+
#include<boost/range/algorithm/equal.hpp>
11+
#include<boost/range/as_literal.hpp>
1012

1113
namespacenetwork {
1214
namespacehttp {
1315
namespacev2 {
14-
classinvalid_scheme :publicstd::runtime_error {
16+
classscheme_not_http :publicstd::runtime_error {
1517

1618
public:
1719

18-
virtual~invalid_scheme()noexcept {}
19-
virtualconstchar *what()constnoexcept {
20-
return"invalid_scheme";
21-
}
20+
scheme_not_http() : std::runtime_error("scheme_not_http") {}
21+
virtual~scheme_not_http()noexcept {}
2222

2323
};
2424

@@ -34,19 +34,25 @@ namespace network {
3434

3535
public:
3636

37-
url() {
38-
37+
url() {}
38+
39+
template<classSource>
40+
url(const Source &source)
41+
: uri_(source) {
42+
if (auto scheme_ = uri_.scheme()) {
43+
if (!boost::equal(boost::as_literal("http"), *scheme_) &&
44+
!boost::equal(boost::as_literal("https"), *scheme_) &&
45+
!boost::equal(boost::as_literal("shttp"), *scheme_)) {
46+
throwscheme_not_http();
47+
}
48+
}
3949
}
4050

4151
url(const url &other)
42-
: uri_(other.uri_) {
52+
: uri_(other.uri_) { }
4353

44-
}
45-
46-
url(url &&other)
47-
: uri_(other.uri_) {
48-
49-
}
54+
url(url &&other)noexcept
55+
: uri_(std::move(other.uri_)) { }
5056

5157
url &operator = (url other) {
5258
other.swap(*this);
@@ -65,6 +71,38 @@ namespace network {
6571
return uri_.end();
6672
}
6773

74+
boost::optional<string_view>user_info()const {
75+
return uri_.user_info();
76+
}
77+
78+
boost::optional<string_view>host()const {
79+
return uri_.host();
80+
}
81+
82+
boost::optional<string_view>port()const {
83+
return uri_.port();
84+
}
85+
86+
boost::optional<string_view>path()const {
87+
return uri_.path();
88+
}
89+
90+
boost::optional<string_view>query()const {
91+
return uri_.query();
92+
}
93+
94+
boost::optional<string_view>fragment()const {
95+
return uri_.fragment();
96+
}
97+
98+
boost::optional<string_view>authority()const {
99+
return uri_.authority();
100+
}
101+
102+
std::stringstring()const {
103+
return uri_.string();
104+
}
105+
68106
boolempty()constnoexcept {
69107
return uri_.empty();
70108
}
@@ -73,6 +111,31 @@ namespace network {
73111
return uri_.is_absolute();
74112
}
75113

114+
urlnormalize(uri_comparison_level level)const {
115+
returnurl(uri_.normalize(level));
116+
// if scheme-specific
117+
// normalize query arguments in alphanumeric order
118+
}
119+
120+
urlmake_reference(const url &other, uri_comparison_level level)const {
121+
returnurl(uri_.make_reference(other.uri_, level));
122+
}
123+
124+
urlresolve(const url &other, uri_comparison_level level)const {
125+
returnurl(uri_.resolve(other.uri_, level));
126+
}
127+
128+
intcompare(const url &other, uri_comparison_level level)constnoexcept {
129+
int result = uri_.compare(other.uri_, level);
130+
// if result == 0 and scheme-specific
131+
// compare query arguments
132+
return result;
133+
}
134+
135+
urito_uri()const {
136+
return uri_;
137+
}
138+
76139
private:
77140

78141
uri uri_;
@@ -82,5 +145,4 @@ namespace network {
82145
}// namespace http
83146
}// namespace network
84147

85-
86-
#endif// __HTTP_NETWORK_HTTP_V2_URL_INC__
148+
#endif// __NETWORK_HTTP_V2_URL_INC__

‎http/test/v2/url_test.cpp‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@
66
#include<gtest/gtest.h>
77
#include<network/http/v2/url.hpp>
88

9+
namespacehttp= network::http::v2;
10+
911
TEST(url_test, url_constructor) {
10-
network::http::v2::url instance;
12+
http::url instance;
1113
ASSERT_TRUE(instance.empty());
1214
}
1315

16+
TEST(url_test, construct_url_from_char_array) {
17+
ASSERT_NO_THROW(http::url("http://www.example.com/"));
18+
}
19+
20+
TEST(url_test, construct_https_url_from_char_array) {
21+
ASSERT_NO_THROW(http::url("https://www.example.com/"));
22+
}
23+
24+
TEST(url_test, construct_shttp_url_from_char_array) {
25+
ASSERT_NO_THROW(http::url("shttp://www.example.com/"));
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp