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

Commitb895062

Browse files
committed
Async resolver tests now use igloo.
1 parent7bcf001 commitb895062

File tree

10 files changed

+92
-40
lines changed

10 files changed

+92
-40
lines changed

‎CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ if(CPP-NETLIB_BUILD_TESTS)
134134
set(GMOCK_LIBRARIES {$GTEST_LIBRARIES} gmock)
135135
set(GMOCK_MAIN_LIBRARIES gmock_main)
136136
set(GMOCK_BOTH_LIBRARIES${GMOCK_LIBRARIES}${GMOCK_MAIN_LIBRARIES})
137+
138+
set(IGLOO_ROOT ${CPP-NETLIB_SOURCE_DIR}/deps/igloo)
139+
set(IGLOO_FOUNDON)
140+
set(IGLOO_INCLUDE_DIR${IGLOO_ROOT})
137141
endif()
138142

139143
if(CPP-NETLIB_BUILD_SINGLE_LIB)

‎http/src/network/http/v2/client/connection/async_resolver_delegate.hpp‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,12 @@ namespace network {
6464
resolver_strand_->wrap(
6565
[=](const boost::system::error_code &ec,
6666
resolver_iterator endpoint_iterator) {
67+
68+
auto resolvers =std::make_pair(endpoint_iterator,resolver_iterator());
6769
if (!ec && cache_resolved_) {
68-
endpoint_cache::iterator cache_it;
69-
bool inserted =false;
70-
std::tie(cache_it, inserted) = endpoint_cache_.insert(
71-
std::make_pair(host,
72-
std::make_pair(endpoint_iterator,resolver_iterator())));
73-
on_resolved(ec, cache_it->second);
74-
}
75-
else {
76-
on_resolved(ec,std::make_pair(endpoint_iterator,resolver_iterator()));
70+
endpoint_cache_.insert(std::make_pair(host, resolvers));
7771
}
72+
on_resolved(ec, resolvers);
7873
}));
7974
}
8075

@@ -88,8 +83,7 @@ namespace network {
8883
private:
8984

9085
typedef boost::asio::io_service::strand strand;
91-
typedef std::unordered_map<
92-
std::string, boost::iterator_range<resolver_iterator>> endpoint_cache;
86+
typedef std::unordered_map<std::string, resolver_iterator_range> endpoint_cache;
9387

9488
resolver resolver_;
9589
std::unique_ptr<strand> resolver_strand_;

‎http/src/network/http/v2/client/connection/resolver_delegate.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace network {
2424

2525
typedef boost::asio::ip::tcp::resolver resolver;
2626
typedef resolver::iterator resolver_iterator;
27+
typedef boost::iterator_range<resolver_iterator> resolver_iterator_range;
2728
typedef std::function<void (const boost::system::error_code &,
2829
boost::iterator_range<resolver_iterator>)> on_resolved_fn;
2930

‎http/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ include_directories(
1111
${CPP-NETLIB_SOURCE_DIR}/logging/src
1212
${CPP-NETLIB_SOURCE_DIR}/http/src
1313
${GTEST_INCLUDE_DIRS}
14+
${IGLOO_INCLUDE_DIR}
1415
${CPP-NETLIB_SOURCE_DIR})
1516

1617
add_subdirectory(v2)

‎http/test/v2/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
add_subdirectory(units)
7-
#add_subdirectory(features)
7+
add_subdirectory(features)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (C) 2013 by Glyn Matthews
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+
add_subdirectory(client)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2013 by Glyn Matthews
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+
set(CPP-NETLIB_CLIENT_TESTS
7+
async_resolver_test
8+
)
9+
10+
foreach(test ${CPP-NETLIB_CLIENT_TESTS})
11+
if (${CMAKE_CXX_COMPILER_ID}MATCHES GNU)
12+
set_source_files_properties(${test}.cpp
13+
PROPERTIESCOMPILE_FLAGS"-Wall")
14+
endif()
15+
16+
add_executable(cpp-netlib-http-v2-${test}${test}.cpp)
17+
target_link_libraries(cpp-netlib-http-v2-${test}
18+
cppnetlib-uri
19+
network-http-constants-v2
20+
network-http-client-v2
21+
${Boost_LIBRARIES}
22+
${ICU_LIBRARIES}${ICU_I18N_LIBRARIES}
23+
${CMAKE_THREAD_LIBS_INIT}
24+
)
25+
set_target_properties(cpp-netlib-http-v2-${test}
26+
PROPERTIESRUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
27+
add_test(cpp-netlib-http-v2-${test}
28+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-v2-${test})
29+
30+
endforeach(test)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (C) 2013 by Glyn Matthews
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+
#include<iostream>
7+
#include<igloo/igloo_alt.h>
8+
#include<boost/asio.hpp>
9+
#include"network/http/v2/client/connection/async_resolver_delegate.hpp"
10+
11+
usingnamespaceigloo;
12+
namespacehttp= network::http::v2;
13+
14+
Describe(async_resolver) {
15+
16+
voidSetUp() {
17+
io_service_.reset(new boost::asio::io_service);
18+
resolver_.reset(newhttp::async_resolver_delegate(*io_service_));
19+
}
20+
21+
It(resolves_localhost) {
22+
// An HTTP server must be running on 127.0.0.1:80
23+
// maybe execute a script
24+
25+
resolver_->resolve("127.0.0.1",80,
26+
[] (const boost::system::error_code &ec,
27+
const http::async_resolver_delegate::resolver_iterator_range &endpoints) {
28+
for (auto endpoint : endpoints) {
29+
Assert::That(endpoint.endpoint().address().to_string(),Equals("127.0.0.1"));
30+
Assert::That(endpoint.endpoint().port(),Equals(80));
31+
}
32+
});
33+
io_service_->run_one();
34+
}
35+
36+
std::unique_ptr<boost::asio::io_service> io_service_;
37+
std::unique_ptr<http::async_resolver_delegate> resolver_;
38+
39+
};
40+
41+
int
42+
main(int argc,char *argv[]) {
43+
returnTestRunner::RunAllTests(argc,const_cast<constchar **>(argv));
44+
}

‎http/test/v2/units/client/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ set(CPP-NETLIB_CLIENT_TESTS
99
byte_source_test
1010
response_test
1111
request_test
12-
async_resolver_test
1312
normal_connection_test
1413
client_test
1514
)

‎http/test/v2/units/client/async_resolver_test.cpp‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp