Skip to content

Commit 5237c2f

Browse files
committed
new test to cover the ready() wrapper
it does not compile now
1 parent 090e18b commit 5237c2f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

libs/network/test/http/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if (Boost_FOUND)
3939
client_get_test
4040
client_get_different_port_test
4141
# client_get_timeout_test
42+
client_get_ready_test
4243
client_get_streaming_test)
4344
foreach ( test ${TESTS} )
4445
add_executable(cpp-netlib-http-${test} ${test}.cpp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2010 Dean Michael Berris.
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 <gtest/gtest.h>
7+
#include <boost/network/include/http/client.hpp>
8+
#include "client_types.hpp"
9+
10+
namespace net = boost::network;
11+
namespace http = boost::network::http;
12+
using tclock = std::chrono::high_resolution_clock;
13+
14+
TYPED_TEST_CASE(HTTPClientTest, ClientTypes);
15+
16+
TYPED_TEST(HTTPClientTest, GetTest) {
17+
using client = TypeParam;
18+
typename client::request request("http://cpp-netlib.org/");
19+
client client_;
20+
auto response = client_.get(request);
21+
while (!http::ready(response)) {
22+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
23+
}
24+
auto t0 = tclock::now();
25+
auto data = body(response);
26+
auto t1 = tclock::now();
27+
EXPECT_TRUE(response.status() == 200u ||
28+
(response.status() >= 300 && response.status() < 400));
29+
EXPECT_TRUE(data.size() > 0);
30+
31+
// XXX we should find a better way to check if `ready()` has done his job
32+
namespace c = std::chrono;
33+
EXPECT_TRUE(c::duration_cast<c::milliseconds>(t1-t0).count() < 1);
34+
}

0 commit comments

Comments
 (0)