Skip to content

Commit

Permalink
request tests expanded for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Feb 13, 2024
1 parent e1b4aa1 commit 42cc4d6
Showing 1 changed file with 150 additions and 6 deletions.
156 changes: 150 additions & 6 deletions test/unit/request.cpp
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)
Expand All @@ -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 {

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 42cc4d6

Please sign in to comment.