-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// | ||
// Copyright (c) 2019 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 Christian Mazakas | ||
// | ||
// 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) | ||
|
@@ -10,10 +11,12 @@ | |
// Test that header file is self-contained. | ||
#include <boost/http_proto/request.hpp> | ||
|
||
#include "test_helpers.hpp" | ||
#include <boost/http_proto/request_view.hpp> | ||
|
||
#include <utility> | ||
|
||
#include "test_suite.hpp" | ||
|
||
namespace boost { | ||
namespace http_proto { | ||
|
||
|
@@ -243,6 +246,57 @@ struct request_test | |
} | ||
} | ||
|
||
void | ||
testViewConstructor() | ||
{ | ||
{ | ||
request req; | ||
BOOST_TEST_EQ( | ||
req.buffer(), | ||
"GET / HTTP/1.1\r\n\r\n"); | ||
|
||
request_view req_view(req); | ||
request req2(req_view); | ||
|
||
BOOST_TEST_EQ( | ||
req2.buffer(), | ||
"GET / HTTP/1.1\r\n\r\n"); | ||
|
||
// default-constructed recycles the same string literal | ||
BOOST_TEST_EQ( | ||
req2.buffer().data(), | ||
req.buffer().data()); | ||
|
||
BOOST_TEST_EQ( | ||
req2.buffer().data(), | ||
req_view.buffer().data()); | ||
|
||
} | ||
|
||
{ | ||
request req; | ||
req.set_method("POST"); | ||
BOOST_TEST_EQ( | ||
req.buffer(), | ||
"POST / HTTP/1.1\r\n\r\n"); | ||
|
||
request_view req_view(req); | ||
request req2(req_view); | ||
|
||
BOOST_TEST_EQ( | ||
req2.buffer(), | ||
"POST / HTTP/1.1\r\n\r\n"); | ||
|
||
BOOST_TEST_NE( | ||
req2.buffer().data(), | ||
req.buffer().data()); | ||
|
||
BOOST_TEST_NE( | ||
req2.buffer().data(), | ||
req_view.buffer().data()); | ||
} | ||
} | ||
|
||
void | ||
testObservers() | ||
{ | ||
|
@@ -411,18 +465,108 @@ struct request_test | |
void | ||
testExpect() | ||
{ | ||
request req; | ||
req.set_expect_100_continue(true); | ||
BOOST_TEST(req.metadata().expect.is_100_continue == true); | ||
req.set_expect_100_continue(false); | ||
BOOST_TEST(req.metadata().expect.is_100_continue == false); | ||
{ | ||
request req; | ||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
|
||
req.set_expect_100_continue(false); | ||
BOOST_TEST( | ||
!req.metadata().expect.is_100_continue); | ||
} | ||
|
||
|
||
{ | ||
request req; | ||
req.set_expect_100_continue(false); | ||
BOOST_TEST( | ||
!req.metadata().expect.is_100_continue); | ||
} | ||
|
||
{ | ||
request req; | ||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
|
||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
} | ||
|
||
{ | ||
request req; | ||
BOOST_TEST( | ||
!req.metadata().expect.ec.failed()); | ||
|
||
req.set("Expect", "101-dalmations"); | ||
BOOST_TEST( | ||
req.metadata().expect.ec.failed()); | ||
|
||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
} | ||
|
||
{ | ||
request req; | ||
req.append("Expect", "100-continue"); | ||
req.append("Expect", "101-dalmations"); | ||
|
||
BOOST_TEST( | ||
req.metadata().expect.ec.failed()); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 2); | ||
|
||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 1); | ||
} | ||
|
||
{ | ||
request req; | ||
req.append("Expect", "100-continue"); | ||
req.append("Expect", "100-continue"); | ||
|
||
BOOST_TEST( | ||
req.metadata().expect.ec.failed()); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 2); | ||
|
||
req.set_expect_100_continue(true); | ||
BOOST_TEST( | ||
req.metadata().expect.is_100_continue); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 1); | ||
} | ||
|
||
{ | ||
request req; | ||
req.append("Expect", "100-continue"); | ||
req.append("Expect", "100-continue"); | ||
|
||
BOOST_TEST( | ||
req.metadata().expect.ec.failed()); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 2); | ||
|
||
req.set_expect_100_continue(false); | ||
BOOST_TEST( | ||
!req.metadata().expect.is_100_continue); | ||
BOOST_TEST_EQ( | ||
req.count("Expect"), 0); | ||
} | ||
} | ||
|
||
void | ||
run() | ||
{ | ||
testHelpers(); | ||
testSpecial(); | ||
testViewConstructor(); | ||
testObservers(); | ||
testModifiers(); | ||
testExpect(); | ||
|