|
| 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