proxygen
GenericFilterTest< Owned > Class Template Reference
Inheritance diagram for GenericFilterTest< Owned >:
testing::Test

Public Member Functions

void basicTest ()
 
void testFilters (const std::deque< TestFilter< Owned > * > &filters, MockTesterCallback *expectedCb)
 
void SetUp () override
 
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain ()
 
template<typename FilterT >
std::enable_if<!Owned, FilterT * >::type getFilter ()
 
template<typename FilterT >
std::enable_if< Owned, unique_ptr< FilterT > >::type getFilter ()
 
template<typename FilterT >
void addFilterToChain (std::deque< TestFilter< Owned > * > &refs)
 
std::deque< TestFilter< Owned > * > getRandomFilters (unsigned num)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Public Attributes

MockTesterCallback callback_
 
unique_ptr< FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > > chain_
 
MockTesteractor_ {nullptr}
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 

Detailed Description

template<bool Owned>
class GenericFilterTest< Owned >

Definition at line 132 of file GenericFilterTest.cpp.

Member Function Documentation

template<bool Owned>
template<typename FilterT >
void GenericFilterTest< Owned >::addFilterToChain ( std::deque< TestFilter< Owned > * > &  refs)
inline

Definition at line 165 of file GenericFilterTest.cpp.

References f, detail::get_pointer(), folly::gen::move, and refs.

165  {
166  auto f = getFilter<FilterT>();
167  refs.push_front(::detail::get_pointer(f));
168  chain().addFilters(std::move(f));
169  }
auto f
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain()
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
T * get_pointer(const unique_ptr< T > &ptr)
template<bool Owned>
void GenericFilterTest< Owned >::basicTest ( )

Definition at line 198 of file GenericFilterTest.cpp.

References callback_, and EXPECT_CALL.

198  {
199  InSequence enforceOrder;
200 
201  // Test call side
202  EXPECT_CALL(*actor_, doA());
203  chain()->doA();
204 
205  // Now poke the callback side
206  EXPECT_CALL(callback_, onA());
207  CHECK_NOTNULL(actor_->cb_);
208  actor_->cb_->onA();
209 }
Callback * cb_
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain()
MockTesterCallback callback_
#define EXPECT_CALL(obj, call)
virtual void onA()=0
template<bool Owned>
FilterChain<TesterInterface, TesterInterface::Callback, TestFilter<Owned>, &TesterInterface::setCallback, Owned>& GenericFilterTest< Owned >::chain ( )
inline

Definition at line 150 of file GenericFilterTest.cpp.

150  {
151  return *chain_;
152  }
unique_ptr< FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > > chain_
template<bool Owned>
template<typename FilterT >
std::enable_if<!Owned, FilterT*>::type GenericFilterTest< Owned >::getFilter ( )
inline

Definition at line 155 of file GenericFilterTest.cpp.

155  {
156  return new FilterT();
157  }
template<bool Owned>
template<typename FilterT >
std::enable_if<Owned, unique_ptr<FilterT> >::type GenericFilterTest< Owned >::getFilter ( )
inline

Definition at line 160 of file GenericFilterTest.cpp.

160  {
161  return std::make_unique<FilterT>();
162  }
template<bool Owned>
std::deque<TestFilter<Owned>*> GenericFilterTest< Owned >::getRandomFilters ( unsigned  num)
inline

Definition at line 171 of file GenericFilterTest.cpp.

References folly::basicTest(), and i.

171  {
172  std::deque<TestFilter<Owned>*> filters;
173  srand(0);
174  for (unsigned i = 0; i < num; ++i) {
175  auto r = rand() % 4;
176  if (r == 0) {
177  addFilterToChain<TestFilter<Owned>>(filters);
178  } else if (r == 1) {
179  addFilterToChain<TestFilterNoCall<Owned>>(filters);
180  } else if (r == 2) {
181  addFilterToChain<TestFilterNoCallback<Owned>>(filters);
182  } else if (r == 3) {
183  addFilterToChain<TestFilterNoCallbackNoCall<Owned>>(filters);
184  }
185  basicTest();
186  }
187  return filters;
188  }
template<bool Owned>
void GenericFilterTest< Owned >::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 139 of file GenericFilterTest.cpp.

References callback_, folly::make_unique(), and TesterInterface::setCallback().

139  {
144  Owned>>(getTester<Owned>());
145  chain().setCallback(&callback_);
146  actor_ = CHECK_NOTNULL(static_cast<MockTester*>(chain_->call()));
147  }
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain()
virtual void setCallback(Callback *cb)=0
unique_ptr< FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > > chain_
MockTesterCallback callback_
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Definition: Memory.h:259
template<bool Owned>
void GenericFilterTest< Owned >::testFilters ( const std::deque< TestFilter< Owned > * > &  filters,
MockTesterCallback expectedCb 
)

Definition at line 211 of file GenericFilterTest.cpp.

References EXPECT_CALL, EXPECT_EQ, and f.

213  {
214  for (auto f: filters) {
215  f->do_ = 0;
216  f->on_ = 0;
217  }
218  // Call
219  EXPECT_CALL(*actor_, doA());
220  chain()->doA();
221  // Callback
222  if (expectedCb) {
223  EXPECT_CALL(*expectedCb, onA());
224  CHECK_NOTNULL(actor_->cb_);
225  actor_->cb_->onA();
226  }
227  for (auto f: filters) {
228  if (f->kWantsCalls_) {
229  EXPECT_EQ(f->do_, 1);
230  } else {
231  EXPECT_EQ(f->do_, 0);
232  }
233  if (f->kWantsCallbacks_) {
234  EXPECT_EQ(f->on_, expectedCb ? 1 : 0);
235  } else {
236  EXPECT_EQ(f->on_, 0);
237  }
238  }
239 }
auto f
Callback * cb_
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain()
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_CALL(obj, call)
virtual void onA()=0

Member Data Documentation

template<bool Owned>
MockTester* GenericFilterTest< Owned >::actor_ {nullptr}

Definition at line 194 of file GenericFilterTest.cpp.

template<bool Owned>
MockTesterCallback GenericFilterTest< Owned >::callback_

Definition at line 190 of file GenericFilterTest.cpp.

template<bool Owned>
unique_ptr<FilterChain<TesterInterface, TesterInterface::Callback, TestFilter<Owned>, &TesterInterface::setCallback, Owned> > GenericFilterTest< Owned >::chain_

Definition at line 193 of file GenericFilterTest.cpp.


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