Fixed curl and urdl

This commit is contained in:
Pedro Pinto committed 2017-08-08 09:27:08 -04:00
1 parent fad9d2e5ec
commit e596dbc5d4
19 files changed
+1182 -453

No files matched your search

+1
View File
@@ -0,0 +1 @@
./work/
+3 -2
View File
@@ -17,8 +17,6 @@ if (Test-Path $target\include\curl) {
# expand
unzip -q $src\curl\$curl -d $work
# copy headers
Copy-Item $work\$curl\include\curl $target\include\curl -Recurse
#debug
cd $work\$curl
@@ -35,6 +33,9 @@ cd winbuild
nmake /f Makefile.vc mode=static ENABLE_SSPI=no ENABLE_SSPI=no ENABLE_IPV6=no ENABLE_IDN=no MACHINE=x64 RTLIBCFG=static DEBUG=no
Copy-Item ..\builds\libcurl-vc-x64-release-static\lib\libcurl_a.lib $target\lib\release\libcurl.lib
# copy headers
Copy-Item ..\builds\libcurl-vc-x64-release-static\include\curl $target\include\curl -Recurse
cd $root
Remove-Item -Force -Recurse $work
Pop-Location
+1
View File
@@ -15,6 +15,7 @@ if (Test-Path $target\include\urdl) {
unzip -q $src\urdl\$urdl -d $work
Copy-Item $work\$urdl\include\urdl $target\include\urdl -Recurse
Copy-Item $work\$urdl\test $target\include\urdl\test -Recurse
cd $root
Remove-Item -Force -Recurse $work
-4
View File
@@ -1,4 +0,0 @@
curlbuild.h
curlver.h.dist
stamp-h2
stamp-h3
-53
View File
@@ -1,53 +0,0 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################
pkginclude_HEADERS = \
curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \
typecheck-gcc.h curlbuild.h curlrules.h system.h
pkgincludedir= $(includedir)/curl
# curlbuild.h does not exist in the git tree. When the original libcurl
# source code distribution archive file is created, curlbuild.h.dist is
# renamed to curlbuild.h and included in the tarball so that it can be
# used directly on non-configure systems.
#
# The distributed curlbuild.h will be overwritten on configure systems
# when the configure script runs, with one that is suitable and specific
# to the library being configured and built.
#
# curlbuild.h.in is the distributed template file from which the configure
# script creates curlbuild.h at library configuration time, overwiting the
# one included in the distribution archive.
#
# curlbuild.h.dist is not included in the source code distribution archive.
EXTRA_DIST = curlbuild.h.in
DISTCLEANFILES = curlbuild.h
checksrc:
@@PERL@ $(top_srcdir)/lib/checksrc.pl -Wcurlbuild.h -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) $(EXTRA_DIST)
if CURLDEBUG
# for debug builds, we scan the sources on all regular make invokes
all-local: checksrc
endif
File renamed without changes.
-197
View File
@@ -1,197 +0,0 @@
#ifndef __CURL_CURLBUILD_H
#define __CURL_CURLBUILD_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* ================================================================ */
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
/* ================================================================ */
/*
* NOTE 1:
* -------
*
* Nothing in this file is intended to be modified or adjusted by the
* curl library user nor by the curl library builder.
*
* If you think that something actually needs to be changed, adjusted
* or fixed in this file, then, report it on the libcurl development
* mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/
*
* This header file shall only export symbols which are 'curl' or 'CURL'
* prefixed, otherwise public name space would be polluted.
*
* NOTE 2:
* -------
*
* Right now you might be staring at file include/curl/curlbuild.h.in or
* at file include/curl/curlbuild.h, this is due to the following reason:
*
* On systems capable of running the configure script, the configure process
* will overwrite the distributed include/curl/curlbuild.h file with one that
* is suitable and specific to the library being configured and built, which
* is generated from the include/curl/curlbuild.h.in template file.
*
*/
/* ================================================================ */
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
/* ================================================================ */
#ifdef CURL_SIZEOF_LONG
#error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined
#endif
#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
#error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined
#endif
#ifdef CURL_SIZEOF_CURL_SOCKLEN_T
#error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined
#endif
#ifdef CURL_TYPEOF_CURL_OFF_T
#error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined
#endif
#ifdef CURL_FORMAT_CURL_OFF_T
#error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined
#endif
#ifdef CURL_FORMAT_CURL_OFF_TU
#error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined
#endif
#ifdef CURL_FORMAT_OFF_T
#error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined
#endif
#ifdef CURL_SIZEOF_CURL_OFF_T
#error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined
#endif
#ifdef CURL_SUFFIX_CURL_OFF_T
#error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined
#endif
#ifdef CURL_SUFFIX_CURL_OFF_TU
#error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined
#endif
/* ================================================================ */
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
/* ================================================================ */
/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */
#cmakedefine CURL_PULL_WS2TCPIP_H
#ifdef CURL_PULL_WS2TCPIP_H
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/types.h must be included by the external interface. */
#cmakedefine CURL_PULL_SYS_TYPES_H
#ifdef CURL_PULL_SYS_TYPES_H
# include <sys/types.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file stdint.h must be included by the external interface. */
#cmakedefine CURL_PULL_STDINT_H
#ifdef CURL_PULL_STDINT_H
# include <stdint.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file inttypes.h must be included by the external interface. */
#cmakedefine CURL_PULL_INTTYPES_H
#ifdef CURL_PULL_INTTYPES_H
# include <inttypes.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/socket.h must be included by the external interface. */
#cmakedefine CURL_PULL_SYS_SOCKET_H
#ifdef CURL_PULL_SYS_SOCKET_H
# include <sys/socket.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/poll.h must be included by the external interface. */
#cmakedefine CURL_PULL_SYS_POLL_H
#ifdef CURL_PULL_SYS_POLL_H
# include <sys/poll.h>
#endif
/* The size of `long', as computed by sizeof. */
#define CURL_SIZEOF_LONG ${CURL_SIZEOF_LONG}
/* Integral data type used for curl_socklen_t. */
#define CURL_TYPEOF_CURL_SOCKLEN_T ${CURL_TYPEOF_CURL_SOCKLEN_T}
/* The size of `curl_socklen_t', as computed by sizeof. */
#define CURL_SIZEOF_CURL_SOCKLEN_T ${CURL_SIZEOF_CURL_SOCKLEN_T}
/* Data type definition of curl_socklen_t. */
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
/* Signed integral data type used for curl_off_t. */
#define CURL_TYPEOF_CURL_OFF_T ${CURL_TYPEOF_CURL_OFF_T}
/* Data type definition of curl_off_t. */
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
/* curl_off_t formatting string directive without "%" conversion specifier. */
#define CURL_FORMAT_CURL_OFF_T "${CURL_FORMAT_CURL_OFF_T}"
/* unsigned curl_off_t formatting string without "%" conversion specifier. */
#define CURL_FORMAT_CURL_OFF_TU "${CURL_FORMAT_CURL_OFF_TU}"
/* curl_off_t formatting string directive with "%" conversion specifier. */
#define CURL_FORMAT_OFF_T "${CURL_FORMAT_OFF_T}"
/* The size of `curl_off_t', as computed by sizeof. */
#define CURL_SIZEOF_CURL_OFF_T ${CURL_SIZEOF_CURL_OFF_T}
/* curl_off_t constant suffix. */
#define CURL_SUFFIX_CURL_OFF_T ${CURL_SUFFIX_CURL_OFF_T}
/* unsigned curl_off_t constant suffix. */
#define CURL_SUFFIX_CURL_OFF_TU ${CURL_SUFFIX_CURL_OFF_TU}
#endif /* __CURL_CURLBUILD_H */
-197
View File
@@ -1,197 +0,0 @@
#ifndef __CURL_CURLBUILD_H
#define __CURL_CURLBUILD_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* ================================================================ */
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
/* ================================================================ */
/*
* NOTE 1:
* -------
*
* Nothing in this file is intended to be modified or adjusted by the
* curl library user nor by the curl library builder.
*
* If you think that something actually needs to be changed, adjusted
* or fixed in this file, then, report it on the libcurl development
* mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/
*
* This header file shall only export symbols which are 'curl' or 'CURL'
* prefixed, otherwise public name space would be polluted.
*
* NOTE 2:
* -------
*
* Right now you might be staring at file include/curl/curlbuild.h.in or
* at file include/curl/curlbuild.h, this is due to the following reason:
*
* On systems capable of running the configure script, the configure process
* will overwrite the distributed include/curl/curlbuild.h file with one that
* is suitable and specific to the library being configured and built, which
* is generated from the include/curl/curlbuild.h.in template file.
*
*/
/* ================================================================ */
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
/* ================================================================ */
#ifdef CURL_SIZEOF_LONG
#error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined
#endif
#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
#error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined
#endif
#ifdef CURL_SIZEOF_CURL_SOCKLEN_T
#error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined
#endif
#ifdef CURL_TYPEOF_CURL_OFF_T
#error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined
#endif
#ifdef CURL_FORMAT_CURL_OFF_T
#error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined
#endif
#ifdef CURL_FORMAT_CURL_OFF_TU
#error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined
#endif
#ifdef CURL_FORMAT_OFF_T
#error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined
#endif
#ifdef CURL_SIZEOF_CURL_OFF_T
#error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined
#endif
#ifdef CURL_SUFFIX_CURL_OFF_T
#error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined
#endif
#ifdef CURL_SUFFIX_CURL_OFF_TU
#error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h"
Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined
#endif
/* ================================================================ */
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
/* ================================================================ */
/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */
#undef CURL_PULL_WS2TCPIP_H
#ifdef CURL_PULL_WS2TCPIP_H
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/types.h must be included by the external interface. */
#undef CURL_PULL_SYS_TYPES_H
#ifdef CURL_PULL_SYS_TYPES_H
# include <sys/types.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file stdint.h must be included by the external interface. */
#undef CURL_PULL_STDINT_H
#ifdef CURL_PULL_STDINT_H
# include <stdint.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file inttypes.h must be included by the external interface. */
#undef CURL_PULL_INTTYPES_H
#ifdef CURL_PULL_INTTYPES_H
# include <inttypes.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/socket.h must be included by the external interface. */
#undef CURL_PULL_SYS_SOCKET_H
#ifdef CURL_PULL_SYS_SOCKET_H
# include <sys/socket.h>
#endif
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/poll.h must be included by the external interface. */
#undef CURL_PULL_SYS_POLL_H
#ifdef CURL_PULL_SYS_POLL_H
# include <sys/poll.h>
#endif
/* The size of `long', as computed by sizeof. */
#undef CURL_SIZEOF_LONG
/* Integral data type used for curl_socklen_t. */
#undef CURL_TYPEOF_CURL_SOCKLEN_T
/* The size of `curl_socklen_t', as computed by sizeof. */
#undef CURL_SIZEOF_CURL_SOCKLEN_T
/* Data type definition of curl_socklen_t. */
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
/* Signed integral data type used for curl_off_t. */
#undef CURL_TYPEOF_CURL_OFF_T
/* Data type definition of curl_off_t. */
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
/* curl_off_t formatting string directive without "%" conversion specifier. */
#undef CURL_FORMAT_CURL_OFF_T
/* unsigned curl_off_t formatting string without "%" conversion specifier. */
#undef CURL_FORMAT_CURL_OFF_TU
/* curl_off_t formatting string directive with "%" conversion specifier. */
#undef CURL_FORMAT_OFF_T
/* The size of `curl_off_t', as computed by sizeof. */
#undef CURL_SIZEOF_CURL_OFF_T
/* curl_off_t constant suffix. */
#undef CURL_SUFFIX_CURL_OFF_T
/* unsigned curl_off_t constant suffix. */
#undef CURL_SUFFIX_CURL_OFF_TU
#endif /* __CURL_CURLBUILD_H */
+27
View File
@@ -0,0 +1,27 @@
#
# Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
project
:
requirements
<library>../build//urdl
<library>/boost/thread//boost_thread
:
default-build
debug
<threading>multi
<link>shared
<runtime-link>shared
;
test-suite "urdl" :
[ run istream.cpp ]
[ run istreambuf.cpp ]
[ run option_set.cpp ]
[ run read_stream.cpp ]
[ run url.cpp ]
;
+118
View File
@@ -0,0 +1,118 @@
//
// http_server.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef HTTP_SERVER_HPP
#define HTTP_SERVER_HPP
#include <boost/asio/buffer.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread.hpp>
// Helper class to test HTTP client functionality.
class http_server
{
public:
typedef boost::asio::ip::tcp tcp;
http_server()
: acceptor_(io_service_, tcp::endpoint(
boost::asio::ip::address_v4::loopback(), 0)),
socket_(io_service_),
response_delay_(0),
content_delay_(0),
success_(false)
{
}
unsigned short port() const
{
return acceptor_.local_endpoint().port();
}
void start(const std::string& expected_request,
std::size_t response_delay, const std::string& response,
std::size_t content_delay, const std::string& content)
{
success_ = false;
expected_request_ = expected_request;
response_delay_ = response_delay;
response_ = response;
content_delay_ = content_delay;
content_ = content;
thread_.reset(new boost::thread(boost::bind(&http_server::worker, this)));
}
bool stop()
{
thread_->join();
thread_.reset();
return success_;
}
private:
void worker()
{
try
{
acceptor_.accept(socket_);
// Wait for request.
boost::asio::streambuf buffer;
std::size_t size = boost::asio::read_until(socket_, buffer, "\r\n\r\n");
std::string request(size, 0);
buffer.sgetn(&request[0], size);
success_ = (request == expected_request_);
// Introduce a delay before sending the response.
boost::asio::deadline_timer timer(io_service_);
timer.expires_from_now(boost::posix_time::milliseconds(response_delay_));
timer.wait();
// Send response headers.
boost::system::error_code ec;
boost::asio::write(socket_, boost::asio::buffer(response_));
// Introduce a delay before sending the content.
timer.expires_from_now(boost::posix_time::milliseconds(content_delay_));
timer.wait();
// Now we can write the content.
boost::asio::write(socket_, boost::asio::buffer(content_));
// We're done. Shut down the connection.
socket_.shutdown(tcp::socket::shutdown_both, ec);
socket_.close(ec);
}
catch (std::exception&)
{
}
}
boost::asio::io_service io_service_;
tcp::acceptor acceptor_;
tcp::socket socket_;
std::string expected_request_;
std::size_t response_delay_;
std::string response_;
std::size_t content_delay_;
std::string content_;
boost::scoped_ptr<boost::thread> thread_;
bool success_;
};
#endif // HTTP_SERVER_HPP
+215
View File
@@ -0,0 +1,215 @@
//
// istream.cpp
// ~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "urdl/istream.hpp"
#include "unit_test.hpp"
#include "urdl/http.hpp"
#include "urdl/option_set.hpp"
#include "http_server.hpp"
#include <string>
#include <sstream>
// Ensure all functions compile correctly.
void istream_compile_test()
{
// Constructors
urdl::istream istream1;
urdl::istream istream2("file://foobar");
urdl::istream istream3(urdl::url("file://foobar"));
urdl::istream istream4("file://foobar", urdl::option_set());
urdl::istream istream5(urdl::url("file://foobar"), urdl::option_set());
// set_option()
istream1.set_option(0);
istream1.set_option<char>(0);
// set_options()
istream1.set_options(urdl::option_set());
// get_option()
const urdl::istream& const_istream1 = istream1;
want<int>(const_istream1.get_option<int>());
want<char>(const_istream1.get_option<char>());
// get_options()
want<urdl::option_set>(const_istream1.get_options());
// is_open()
want<bool>(const_istream1.is_open());
// open()
istream1.open("file://foobar");
istream1.open(urdl::url("file://foobar"));
// close()
istream1.close();
// rdbuf()
want<urdl::istreambuf*>(const_istream1.rdbuf());
// error()
want<boost::system::error_code>(const_istream1.error());
// read_timeout()
want<std::size_t>(const_istream1.read_timeout());
istream1.read_timeout(std::size_t(123));
// content_type()
want<std::string>(const_istream1.content_type());
// content_length()
want<std::size_t>(const_istream1.content_length());
// headers()
want<std::string>(const_istream1.headers());
}
// Test HTTP.
void istream_http_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 200 OK\r\n"
"Content-Length: 13\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Hello, World!";
server.start(request, 0, response, 0, content);
urdl::istream istream1("http://localhost:" + port + "/");
std::string returned_content;
std::getline(istream1, returned_content);
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(istream1.content_type() == "text/plain");
BOOST_CHECK(istream1.content_length() == 13);
BOOST_CHECK(returned_content == content);
}
// Test HTTP with an error status returned by the server.
void istream_http_not_found_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 404 Not Found\r\n"
"Content-Length: 9\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Not Found";
server.start(request, 0, response, 0, content);
urdl::istream istream1("http://localhost:" + port + "/");
std::string returned_content;
std::getline(istream1, returned_content);
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(istream1.error() == urdl::http::errc::not_found);
}
// Test HTTP with an open timeout.
void istream_http_open_timeout_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 200 OK\r\n"
"Content-Length: 13\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Hello, World!";
server.start(request, 1500, response, 0, content);
urdl::istream istream1;
istream1.open_timeout(1000);
istream1.open("http://localhost:" + port + "/");
server.stop();
BOOST_CHECK(istream1.error() == boost::system::errc::timed_out);
}
// Test HTTP with a read timeout.
void istream_http_read_timeout_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 200 OK\r\n"
"Content-Length: 13\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Hello, World!";
server.start(request, 0, response, 1500, content);
urdl::istream istream1;
istream1.open("http://localhost:" + port + "/");
istream1.read_timeout(1000);
std::string returned_content;
std::getline(istream1, returned_content);
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(istream1.error() == boost::system::errc::timed_out);
}
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("istream");
test->add(BOOST_TEST_CASE(&istream_compile_test));
test->add(BOOST_TEST_CASE(&istream_http_test));
test->add(BOOST_TEST_CASE(&istream_http_not_found_test));
test->add(BOOST_TEST_CASE(&istream_http_open_timeout_test));
test->add(BOOST_TEST_CASE(&istream_http_read_timeout_test));
return test;
}
+88
View File
@@ -0,0 +1,88 @@
//
// istreambuf.cpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "urdl/istreambuf.hpp"
#include "unit_test.hpp"
#include "urdl/option_set.hpp"
// Ensure all functions compile correctly.
void istreambuf_compile_test()
{
// Constructors
urdl::istreambuf istreambuf1;
// set_option()
istreambuf1.set_option(0);
istreambuf1.set_option<char>(0);
// set_options()
istreambuf1.set_options(urdl::option_set());
// get_option()
const urdl::istreambuf& const_istreambuf1 = istreambuf1;
want<int>(const_istreambuf1.get_option<int>());
want<char>(const_istreambuf1.get_option<char>());
// get_options()
want<urdl::option_set>(const_istreambuf1.get_options());
// is_open()
want<bool>(const_istreambuf1.is_open());
// open()
want<urdl::istreambuf*>(istreambuf1.open("file://foobar"));
want<urdl::istreambuf*>(istreambuf1.open(urdl::url("file://foobar")));
// close()
want<urdl::istreambuf*>(istreambuf1.close());
// puberror()
want<boost::system::error_code>(const_istreambuf1.puberror());
// read_timeout()
want<std::size_t>(const_istreambuf1.read_timeout());
istreambuf1.read_timeout(std::size_t(123));
// content_type()
want<std::string>(const_istreambuf1.content_type());
// content_length()
want<std::size_t>(const_istreambuf1.content_length());
// headers()
want<std::string>(const_istreambuf1.headers());
}
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("istreambuf");
test->add(BOOST_TEST_CASE(&istreambuf_compile_test));
return test;
}
+99
View File
@@ -0,0 +1,99 @@
//
// option_set.cpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "urdl/option_set.hpp"
#include "unit_test.hpp"
// Ensure all functions compile correctly.
void option_set_compile_test()
{
// Constructors
urdl::option_set set1;
urdl::option_set set2(set1);
// operator=
set1 = set2;
// set_option()
set1.set_option(0);
set1.set_option<char>(0);
// set_options()
const urdl::option_set& const_set1 = set1;
set2.set_options(const_set1);
// get_option()
want<int>(const_set1.get_option<int>());
want<char>(const_set1.get_option<char>());
// clear_option()
set1.clear_option<int>();
set1.clear_option<char>();
}
// Test option_set runtime behaviour.
void option_set_runtime_test()
{
urdl::option_set set1;
set1.set_option(std::string("foobar"));
set1.set_option(int(123));
urdl::option_set set2(set1);
BOOST_CHECK(set2.get_option<std::string>() == set1.get_option<std::string>());
BOOST_CHECK(set2.get_option<int>() == set1.get_option<int>());
urdl::option_set set3;
set3 = set2;
BOOST_CHECK(set3.get_option<std::string>() == set1.get_option<std::string>());
BOOST_CHECK(set3.get_option<int>() == set1.get_option<int>());
urdl::option_set set4;
set4.set_option(char('A'));
set4.set_options(set3);
BOOST_CHECK(set4.get_option<char>() == 'A');
BOOST_CHECK(set4.get_option<std::string>() == set1.get_option<std::string>());
BOOST_CHECK(set4.get_option<int>() == set1.get_option<int>());
set4.clear_option<std::string>();
BOOST_CHECK(set4.get_option<char>() == 'A');
BOOST_CHECK(set4.get_option<std::string>() == "");
BOOST_CHECK(set4.get_option<int>() == set1.get_option<int>());
set4.set_option(int(321));
BOOST_CHECK(set4.get_option<char>() == 'A');
BOOST_CHECK(set4.get_option<std::string>() == "");
BOOST_CHECK(set4.get_option<int>() == 321);
set4.set_options(set1);
BOOST_CHECK(set4.get_option<char>() == 'A');
BOOST_CHECK(set4.get_option<std::string>() == set1.get_option<std::string>());
BOOST_CHECK(set4.get_option<int>() == set1.get_option<int>());
}
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("option_set");
test->add(BOOST_TEST_CASE(&option_set_compile_test));
test->add(BOOST_TEST_CASE(&option_set_runtime_test));
return test;
}
+280
View File
@@ -0,0 +1,280 @@
//
// read_stream.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "urdl/read_stream.hpp"
#include "unit_test.hpp"
#include "urdl/option_set.hpp"
#include "http_server.hpp"
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/read.hpp>
void open_handler(const boost::system::error_code&) {}
void read_handler(const boost::system::error_code&, std::size_t) {}
// Ensure all functions compile correctly.
void read_stream_compile_test()
{
try
{
boost::asio::io_service io_service;
boost::system::error_code ec;
char buffer[1024];
// Constructors
urdl::read_stream stream1(io_service);
// get_io_service()
want<boost::asio::io_service>(stream1.get_io_service());
// set_option()
stream1.set_option(0);
stream1.set_option<char>(0);
// set_options()
stream1.set_options(urdl::option_set());
// get_option()
const urdl::read_stream& const_stream1 = stream1;
want<int>(const_stream1.get_option<int>());
want<char>(const_stream1.get_option<char>());
// get_options()
want<urdl::option_set>(const_stream1.get_options());
// is_open()
want<bool>(const_stream1.is_open());
// open()
stream1.open("file://xyz");
stream1.open(urdl::url("file://xyz"));
want<boost::system::error_code>(stream1.open("file://xyz", ec));
want<boost::system::error_code>(stream1.open(urdl::url("file://xyz"), ec));
// async_open()
stream1.async_open("file://xyz", open_handler);
stream1.async_open(urdl::url("file://xyz"), open_handler);
// close()
stream1.close();
want<boost::system::error_code>(stream1.close(ec));
// content_type()
want<std::string>(const_stream1.content_type());
// content_length()
want<std::size_t>(const_stream1.content_length());
// headers()
want<std::string>(const_stream1.headers());
// read_some()
want<std::size_t>(stream1.read_some(boost::asio::buffer(buffer)));
want<std::size_t>(stream1.read_some(boost::asio::buffer(buffer), ec));
// async_read_some()
stream1.async_read_some(boost::asio::buffer(buffer), read_handler);
}
catch (std::exception&)
{
}
}
// Test synchronous HTTP.
void read_stream_synchronous_http_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 200 OK\r\n"
"Content-Length: 13\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Hello, World!";
server.start(request, 0, response, 0, content);
boost::asio::io_service io_service;
urdl::read_stream stream1(io_service);
stream1.open("http://localhost:" + port + "/");
std::string returned_content(stream1.content_length(), 0);
boost::asio::read(stream1, boost::asio::buffer(
&returned_content[0], returned_content.size()));
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(stream1.content_type() == "text/plain");
BOOST_CHECK(stream1.content_length() == 13);
BOOST_CHECK(returned_content == content);
}
// Test synchronous HTTP with an error status returned by the server.
void read_stream_synchronous_http_not_found_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 404 Not Found\r\n"
"Content-Length: 9\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Not Found";
server.start(request, 0, response, 0, content);
boost::asio::io_service io_service;
urdl::read_stream stream1(io_service);
boost::system::error_code ec;
stream1.open("http://localhost:" + port + "/", ec);
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(ec == urdl::http::errc::not_found);
}
struct handler
{
boost::system::error_code& ec_;
std::size_t& size_;
void operator()(const boost::system::error_code& ec, std::size_t size = 0)
{
ec_ = ec;
size_ = size;
}
};
// Test asynchronous HTTP.
void read_stream_asynchronous_http_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 200 OK\r\n"
"Content-Length: 13\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Hello, World!";
server.start(request, 0, response, 0, content);
boost::asio::io_service io_service;
urdl::read_stream stream1(io_service);
boost::system::error_code ec;
std::size_t bytes_transferred = 0;
handler h = { ec, bytes_transferred };
stream1.async_open("http://localhost:" + port + "/", h);
io_service.run();
BOOST_CHECK(!ec);
std::string returned_content(stream1.content_length(), 0);
boost::asio::async_read(stream1, boost::asio::buffer(
&returned_content[0], returned_content.size()), h);
io_service.reset();
io_service.run();
BOOST_CHECK(!ec);
BOOST_CHECK(bytes_transferred == returned_content.size());
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(stream1.content_type() == "text/plain");
BOOST_CHECK(stream1.content_length() == 13);
BOOST_CHECK(returned_content == content);
}
// Test asynchronous HTTP with an error status returned by the server.
void read_stream_asynchronous_http_not_found_test()
{
http_server server;
std::string port = boost::lexical_cast<std::string>(server.port());
std::string request =
"GET / HTTP/1.0\r\n"
"Host: localhost:" + port + "\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n";
std::string response =
"HTTP/1.0 404 Not Found\r\n"
"Content-Length: 9\r\n"
"Content-Type: text/plain\r\n\r\n";
std::string content = "Not Found";
server.start(request, 0, response, 0, content);
boost::asio::io_service io_service;
urdl::read_stream stream1(io_service);
boost::system::error_code ec;
std::size_t bytes_transferred = 0;
handler h = { ec, bytes_transferred };
stream1.async_open("http://localhost:" + port + "/", h);
io_service.run();
bool request_matched = server.stop();
BOOST_CHECK(request_matched);
BOOST_CHECK(ec == urdl::http::errc::not_found);
}
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("read_stream");
test->add(BOOST_TEST_CASE(&read_stream_compile_test));
test->add(BOOST_TEST_CASE(&read_stream_synchronous_http_test));
test->add(BOOST_TEST_CASE(&read_stream_synchronous_http_not_found_test));
test->add(BOOST_TEST_CASE(&read_stream_asynchronous_http_test));
test->add(BOOST_TEST_CASE(&read_stream_asynchronous_http_not_found_test));
return test;
}
+39
View File
@@ -0,0 +1,39 @@
//
// unit_test.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef UNIT_TEST_HPP
#define UNIT_TEST_HPP
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
# pragma warning (push)
# pragma warning (disable:4244)
# pragma warning (disable:4535)
# pragma warning (disable:4702)
# pragma warning (disable:4996)
#endif // defined(BOOST_MSVC)
#include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test_framework.hpp>
using boost::unit_test::test_suite;
#if defined(BOOST_MSVC)
# pragma warning (pop)
# pragma warning (disable:4996) // Leave this disabled for the unit tests.
#endif // defined(BOOST_MSVC)
// Helper function to check the return type of a function.
template <typename T>
void want(const T&)
{
}
#endif // UNIT_TEST_HPP
+311
View File
@@ -0,0 +1,311 @@
//
// url.cpp
// ~~~~~~~
//
// Copyright (c) 2009-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "urdl/url.hpp"
#include "unit_test.hpp"
// Ensure all functions compile correctly.
void url_compile_test()
{
// Constructors
urdl::url url1;
urdl::url url2("http://foo/bar");
urdl::url url3(std::string("http://foo/bar"));
urdl::url url4(url1);
urdl::url url5 = url1;
// operator=
url5 = url2;
// protocol()
const urdl::url& const_url1 = url1;
want<std::string>(const_url1.protocol());
// user_info()
want<std::string>(const_url1.user_info());
// host()
want<std::string>(const_url1.host());
// port()
want<unsigned short>(const_url1.port());
// path()
want<std::string>(const_url1.path());
// query()
want<std::string>(const_url1.query());
// fragment()
want<std::string>(const_url1.fragment());
// to_string()
want<std::string>(const_url1.to_string());
want<std::string>(const_url1.to_string(urdl::url::protocol_component));
want<std::string>(const_url1.to_string(urdl::url::user_info_component));
want<std::string>(const_url1.to_string(urdl::url::host_component));
want<std::string>(const_url1.to_string(urdl::url::port_component));
want<std::string>(const_url1.to_string(urdl::url::path_component));
want<std::string>(const_url1.to_string(urdl::url::query_component));
want<std::string>(const_url1.to_string(urdl::url::fragment_component));
want<std::string>(const_url1.to_string(urdl::url::all_components));
// from_string()
boost::system::error_code ec;
want<urdl::url>(urdl::url::from_string("http://foo/bar"));
want<urdl::url>(urdl::url::from_string("http://foo/bar", ec));
want<urdl::url>(urdl::url::from_string(std::string("http://foo/bar")));
want<urdl::url>(urdl::url::from_string(std::string("http://foo/bar"), ec));
// operator==
const urdl::url& const_url2 = url2;
want<bool>(const_url1 == const_url2);
// operator!=
want<bool>(const_url1 != const_url2);
// operator<
want<bool>(const_url1 < const_url2);
}
// Test URL parsing.
void url_from_string_test()
{
boost::system::error_code ec;
urdl::url url = urdl::url::from_string("http://host", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("HTTP://host", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host:123", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://user@host", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "user");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://user@host:123", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "user");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://user:pass@host", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "user:pass");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://user:pass@host:123", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "user:pass");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host/path", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host:123/path", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host?query", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host:123?query", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host/path?query", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "");
url = urdl::url::from_string("http://host#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://host:123#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://host/path#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://host?query#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://host/path?query#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 80);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://host:123/path?query#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://user@host:123/path?query#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "user");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "fragment");
url = urdl::url::from_string("http://u:p@host:123/path?query#fragment", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(url.protocol() == "http");
BOOST_CHECK(url.user_info() == "u:p");
BOOST_CHECK(url.host() == "host");
BOOST_CHECK(url.port() == 123);
BOOST_CHECK(url.path() == "/path");
BOOST_CHECK(url.query() == "query");
BOOST_CHECK(url.fragment() == "fragment");
}
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("url");
test->add(BOOST_TEST_CASE(&url_compile_test));
test->add(BOOST_TEST_CASE(&url_from_string_test));
return test;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.