proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
MockHTTPHeaders.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015-present, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
*/
10
#pragma once
11
12
#include <
folly/portability/GMock.h
>
13
14
#include <
folly/Optional.h
>
15
#include <
proxygen/lib/http/HTTPHeaders.h
>
16
17
namespace
proxygen
{
18
29
class
HasHTTPHeaderMatcherImpl
:
30
public
::testing::MatcherInterface
<HTTPHeaders&> {
31
public
:
32
explicit
HasHTTPHeaderMatcherImpl
(
std::string
name
) :
33
name_
(name) {
34
}
35
36
HasHTTPHeaderMatcherImpl
(
std::string
name
,
std::string
value
) :
37
name_
(name),
38
value_
(value) {
39
}
40
41
bool
MatchAndExplain
(
42
const
HTTPHeaders
& headers,
43
::
testing::MatchResultListener
*
/*listener*/
)
const override
{
44
bool
matches =
false
;
45
headers.
forEach
([&](
const
std::string
&
name
,
const
std::string
&
value
) {
46
if
(
name_
!= name) {
47
return
;
48
}
49
50
matches = matches || !
value_
|| *
value_
==
value
;
51
});
52
53
return
matches;
54
}
55
56
void
DescribeTo
(::std::ostream* os)
const override
{
57
if
(!
value_
) {
58
*os <<
"has the '"
<<
name_
<<
"' header"
;
59
}
else
{
60
*os <<
"has the header '"
<<
name_
<<
"' equal to '"
<< *
value_
<<
"'"
;
61
}
62
}
63
64
void
DescribeNegationTo
(::std::ostream* os)
const override
{
65
if
(!
value_
) {
66
*os <<
"does not have the '"
<<
name_
<<
"' header"
;
67
}
else
{
68
*os <<
"does not have the '"
<<
name_
<<
"' header "
<<
69
"equal to '"
<< *
value_
<<
"'"
;
70
}
71
}
72
73
private
:
74
const
std::string
name_
;
75
const
folly::Optional<std::string>
value_
;
76
};
77
78
// Factory function for matching an HTTPHeaders that contains the given header
79
inline ::testing::Matcher<HTTPHeaders&>
80
HasHTTPHeader
(
std::string
name
) {
81
return ::testing::MakeMatcher
(
new
HasHTTPHeaderMatcherImpl
(name));
82
}
83
84
85
// Factory function for matching an HTTPHeaders that contains the given header
86
// and has it set to the specified value
87
inline ::testing::Matcher<HTTPHeaders&>
88
HasHTTPHeader
(
std::string
name
,
std::string
value
) {
89
return ::testing::MakeMatcher
(
new
HasHTTPHeaderMatcherImpl
(name, value));
90
}
91
92
}
proxygen::HasHTTPHeaderMatcherImpl::DescribeNegationTo
void DescribeNegationTo(::std::ostream *os) const override
Definition:
MockHTTPHeaders.h:64
testing::MatchResultListener
Definition:
gmock-matchers.h:80
HTTPHeaders.h
proxygen::HasHTTPHeaderMatcherImpl::HasHTTPHeaderMatcherImpl
HasHTTPHeaderMatcherImpl(std::string name, std::string value)
Definition:
MockHTTPHeaders.h:36
GMock.h
proxygen::HTTPHeaders
Definition:
HTTPHeaders.h:68
proxygen::HasHTTPHeaderMatcherImpl::HasHTTPHeaderMatcherImpl
HasHTTPHeaderMatcherImpl(std::string name)
Definition:
MockHTTPHeaders.h:32
name
const char * name
Definition:
http_parser.c:437
folly::Optional< std::string >
testing::MakeMatcher
Matcher< T > MakeMatcher(const MatcherInterface< T > *impl)
Definition:
gmock-matchers.h:484
proxygen::HTTPHeaders::forEach
void forEach(LAMBDA func) const
Definition:
HTTPHeaders.h:337
value
static const char *const value
Definition:
Conv.cpp:50
proxygen::HasHTTPHeaderMatcherImpl
Definition:
MockHTTPHeaders.h:29
proxygen::HasHTTPHeader
inline::testing::Matcher< HTTPHeaders & > HasHTTPHeader(std::string name)
Definition:
MockHTTPHeaders.h:80
proxygen::HasHTTPHeaderMatcherImpl::MatchAndExplain
bool MatchAndExplain(const HTTPHeaders &headers,::testing::MatchResultListener *) const override
Definition:
MockHTTPHeaders.h:41
string
const char * string
Definition:
Conv.cpp:212
proxygen
Definition:
ExMessageHandler.h:14
proxygen::HasHTTPHeaderMatcherImpl::value_
const folly::Optional< std::string > value_
Definition:
MockHTTPHeaders.h:75
proxygen::HasHTTPHeaderMatcherImpl::DescribeTo
void DescribeTo(::std::ostream *os) const override
Definition:
MockHTTPHeaders.h:56
proxygen::HasHTTPHeaderMatcherImpl::name_
const std::string name_
Definition:
MockHTTPHeaders.h:74
testing::MatcherInterface
Definition:
gmock-matchers.h:143
Optional.h
proxygen
lib
http
test
MockHTTPHeaders.h
Generated by
1.8.11