proxygen
proxygen::HasHTTPHeaderMatcherImpl Class Reference

#include <MockHTTPHeaders.h>

Inheritance diagram for proxygen::HasHTTPHeaderMatcherImpl:
testing::MatcherInterface< HTTPHeaders & > testing::MatcherDescriberInterface testing::MatcherDescriberInterface testing::MatcherDescriberInterface

Public Member Functions

 HasHTTPHeaderMatcherImpl (std::string name)
 
 HasHTTPHeaderMatcherImpl (std::string name, std::string value)
 
bool MatchAndExplain (const HTTPHeaders &headers,::testing::MatchResultListener *) const override
 
void DescribeTo (::std::ostream *os) const override
 
void DescribeNegationTo (::std::ostream *os) const override
 
- Public Member Functions inherited from testing::MatcherInterface< HTTPHeaders & >
virtual bool MatchAndExplain (HTTPHeaders &x, MatchResultListener *listener) const =0
 
virtual bool MatchAndExplain (HTTPHeaders &x, MatchResultListener *listener) const =0
 
virtual bool MatchAndExplain (HTTPHeaders &x, MatchResultListener *listener) const =0
 
- Public Member Functions inherited from testing::MatcherDescriberInterface
virtual ~MatcherDescriberInterface ()
 
virtual ~MatcherDescriberInterface ()
 
virtual ~MatcherDescriberInterface ()
 

Private Attributes

const std::string name_
 
const folly::Optional< std::stringvalue_
 

Detailed Description

A gmock matcher for HTTPHeader objects.

This can be used for check for the existence of a header, or for a header with a specific value. To check for multiple headers, or more complicated predicate logic, use testing::AllOf() and friends from gmock.

Use the factory functions below in tests rather than using this class directly.

Definition at line 29 of file MockHTTPHeaders.h.

Constructor & Destructor Documentation

proxygen::HasHTTPHeaderMatcherImpl::HasHTTPHeaderMatcherImpl ( std::string  name)
inlineexplicit

Definition at line 32 of file MockHTTPHeaders.h.

Referenced by proxygen::HasHTTPHeader().

32  :
33  name_(name) {
34  }
const char * name
Definition: http_parser.c:437
proxygen::HasHTTPHeaderMatcherImpl::HasHTTPHeaderMatcherImpl ( std::string  name,
std::string  value 
)
inline

Definition at line 36 of file MockHTTPHeaders.h.

36  :
37  name_(name),
38  value_(value) {
39  }
const char * name
Definition: http_parser.c:437
static const char *const value
Definition: Conv.cpp:50
const folly::Optional< std::string > value_

Member Function Documentation

void proxygen::HasHTTPHeaderMatcherImpl::DescribeNegationTo ( ::std::ostream *  os) const
inlineoverridevirtual

Reimplemented from testing::MatcherDescriberInterface.

Definition at line 64 of file MockHTTPHeaders.h.

References name_, and value_.

64  {
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  }
const folly::Optional< std::string > value_
void proxygen::HasHTTPHeaderMatcherImpl::DescribeTo ( ::std::ostream *  os) const
inlineoverridevirtual

Implements testing::MatcherDescriberInterface.

Definition at line 56 of file MockHTTPHeaders.h.

References name_, and value_.

56  {
57  if (!value_) {
58  *os << "has the '" << name_ << "' header";
59  } else {
60  *os << "has the header '" << name_ << "' equal to '" << *value_ << "'";
61  }
62  }
const folly::Optional< std::string > value_
bool proxygen::HasHTTPHeaderMatcherImpl::MatchAndExplain ( const HTTPHeaders headers,
::testing::MatchResultListener  
) const
inlineoverride

Definition at line 41 of file MockHTTPHeaders.h.

References proxygen::HTTPHeaders::forEach(), name, name_, string, value, and value_.

43  {
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  }
const char * name
Definition: http_parser.c:437
static const char *const value
Definition: Conv.cpp:50
const char * string
Definition: Conv.cpp:212
const folly::Optional< std::string > value_

Member Data Documentation

const std::string proxygen::HasHTTPHeaderMatcherImpl::name_
private

Definition at line 74 of file MockHTTPHeaders.h.

Referenced by DescribeNegationTo(), DescribeTo(), and MatchAndExplain().

const folly::Optional<std::string> proxygen::HasHTTPHeaderMatcherImpl::value_
private

Definition at line 75 of file MockHTTPHeaders.h.

Referenced by DescribeNegationTo(), DescribeTo(), and MatchAndExplain().


The documentation for this class was generated from the following file: