1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2016-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef HTTP_REQUEST_TEST_H
#define HTTP_REQUEST_TEST_H

#include <http/http_types.h>
#include <http/request.h>
#include <boost/lexical_cast.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/shared_ptr.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <utility><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace http {
namespace test {

/// @brief Base test fixture class for testing @ref HttpRequest class and its
/// derivations.
///
/// @tparam HttpRequestType Class under test.
template<typename HttpRequestType>
class HttpRequestTestBase : public ::testing::Test {
public:

    /// @brief Constructor.
    ///
    /// Creates HTTP request to be used in unit tests.
    HttpRequestTestBase()
        : request_(new HttpRequestType()) {
    }

    /// @brief Destructor.
    ///
    /// Does nothing.
    virtual ~HttpRequestTestBase() {
    }

    /// @brief Initializes HTTP request context with basic information.
    ///
    /// It sets:
    /// - HTTP method,
    /// - URI,
    /// - HTTP version number.
    ///
    /// @param method HTTP method as string.
    /// @param uri URI.
    /// @param version A pair of values of which the first is the major HTTP
    /// version and the second is the minor HTTP version.
    void setContextBasics(const std::string& method, const std::string& uri,
                          const HttpVersion& version) {
        request_->context()->method_ = method;
        request_->context()->uri_ = uri;
        request_->context()->http_version_major_ = version.major_;
        request_->context()->http_version_minor_ = version.minor_;
    }

    /// @brief Adds HTTP header to the context.
    ///
    /// @param header_name HTTP header name.
    /// @param header_value HTTP header value. This value will be converted to
    /// a string using @c boost::lexical_cast.
    /// @tparam ValueType Header value type.
    template<typename ValueType>
    void addHeaderToContext(const std::string& header_name,
                            const ValueType& header_value) {
        request_->context()->headers_.push_back(HttpHeaderContext(header_name, header_value));
    }

    /// @brief Instance of the @ref HttpRequest or its derivation.
    boost::shared_ptr<HttpRequestType> request_;
};

} // namespace test
} // namespace http
} // namespace isc

#endif