9 #include <gmock/gmock.h> 10 #include <gtest/gtest.h> 20 using namespace folly;
36 MATCHER_P(WriteNewSessionTicketMatches, expected,
"") {
56 using Action = boost::variant<A1, A2>;
72 return processAppWrite_(state,
write);
78 return processEarlyAppWrite_(state,
write);
82 processWriteNewSessionTicket_,
87 return processWriteNewSessionTicket_(state, ticket);
91 processEarlyAppWrite_,
113 :
public FizzBase<TestFizzBase, ActionMoveVisitor, TestStateMachine>,
143 std::unique_ptr<TestFizzBase, DelayedDestruction::Destructor>
testFizz_;
150 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
153 testFizz_->waitForData();
155 testFizz_->newTransportData();
159 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
167 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
171 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
176 .WillOnce(
Invoke([
this]() { testFizz_->waitForData(); }));
177 testFizz_->newTransportData();
181 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
184 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
189 .WillOnce(
Invoke([
this]() { testFizz_->waitForData(); }));
190 testFizz_->newTransportData();
194 EXPECT_CALL(*TestStateMachine::instance, processWriteNewSessionTicket_(
_,
_))
201 EXPECT_CALL(*TestStateMachine::instance, processAppWrite_(
_,
_))
208 EXPECT_CALL(*TestStateMachine::instance, processEarlyAppWrite_(
_,
_))
216 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
219 testFizz_->appWrite(
appWrite(
"write1"));
221 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
224 testFizz_->appWrite(
appWrite(
"write2"));
228 EXPECT_CALL(*TestStateMachine::instance, processAppClose(
_))
231 testFizz_->appClose();
235 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
240 .WillOnce(
Invoke([
this]() {
241 testFizz_->waitForData();
245 *TestStateMachine::instance,
246 processWriteNewSessionTicket_(
247 _, WriteNewSessionTicketMatches(
"appToken")))
252 .WillOnce(
Invoke([
this]() { testFizz_->appWrite(
appWrite(
"write")); }));
254 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write")))
257 testFizz_->newTransportData();
262 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
267 .WillOnce(
Invoke([
this]() {
268 testFizz_->appWrite(
appWrite(
"write2"));
269 testFizz_->appWrite(
appWrite(
"write3"));
272 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
277 .WillOnce(
Invoke([
this]() { testFizz_->appWrite(
appWrite(
"write4")); }));
279 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write3")))
283 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write4")))
286 testFizz_->appWrite(
appWrite(
"write1"));
290 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
295 .WillOnce(
Invoke([
this]() { testFizz_->appClose(); }));
296 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
301 .WillOnce(
Invoke([
this]() { testFizz_->waitForData(); }));
302 EXPECT_CALL(*TestStateMachine::instance, processAppClose(
_))
305 testFizz_->newTransportData();
310 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
315 .WillOnce(
Invoke([
this]() {
316 testFizz_->appWrite(
appWrite(
"write2"));
317 testFizz_->appClose();
320 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
323 EXPECT_CALL(*TestStateMachine::instance, processAppClose(
_))
326 testFizz_->appWrite(
appWrite(
"write1"));
330 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
335 .WillOnce(
Invoke([
this]() { testFizz_.reset(); }));
336 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
341 .WillOnce(
Invoke([
ptr = testFizz_.get()]() {
ptr->waitForData(); }));
342 testFizz_->newTransportData();
346 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
354 testFizz_->newTransportData();
361 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
363 testFizz_->appWrite(
appWrite(
"write1"));
364 testFizz_->appWrite(
appWrite(
"write2"));
366 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
374 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
376 testFizz_->appWrite(
appWrite(
"write1"));
377 testFizz_->appWrite(
appWrite(
"write2"));
380 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
386 EXPECT_CALL(*TestStateMachine::instance, processAppClose(
_))
392 testFizz_->appClose();
398 EXPECT_CALL(*TestStateMachine::instance, processAppClose(
_))
404 testFizz_->appClose();
412 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write1")))
415 testFizz_->appWrite(
appWrite(
"write2"));
417 earlyWrite.
callback = &earlyWriteCallback_;
418 testFizz_->earlyAppWrite(
std::move(earlyWrite));
420 w3.callback = &writeCallback_;
422 testFizz_->appWrite(
appWrite(
"write4"));
423 testFizz_->appClose();
426 *TestStateMachine::instance, processAppWrite_(
_, WriteMatches(
"write2")))
428 testFizz_->moveToErrorState(
435 testFizz_->appWrite(
appWrite(
"write1"));
440 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
442 testFizz_->moveToErrorState(
447 testFizz_->newTransportData();
453 EXPECT_CALL(*TestStateMachine::instance, processSocketData(
_,
_))
456 testFizz_->waitForData();
460 testFizz_->newTransportData();
Future< Actions > processAppWrite(const State &state, AppWrite &&write)
static WriteNewSessionTicket writeNewSessionTicket(const std::string &str)
void write(const T &in, folly::io::Appender &appender)
MATCHER_P(WriteNewSessionTicketMatches, expected,"")
void startActions(Future< Actions > actions)
static TestStateMachine * instance
void processActions(typename TestStateMachine::CompletedActions actions)
constexpr detail::Map< Move > move
boost::variant< A1, A2 > Action
Future< Actions > processEarlyAppWrite(const State &state, EarlyAppWrite &&write)
static AppWrite appWrite(const std::string &str)
—— Concurrent Priority Queue Implementation ——
MockWriteCallback writeCallback_
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Future< Actions > processWriteNewSessionTicket(const State &state, WriteNewSessionTicket ticket)
static constexpr StringPiece ticket
State
See Core for details.
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
ActionMoveVisitor visitor_
Actions actions(Args &&...act)
#define EXPECT_TRUE(condition)
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
std::vector< Action > Actions
std::unique_ptr< TestFizzBase, DelayedDestruction::Destructor > testFizz_
TEST_F(RSAPSSTest, TestSignVerify)
#define MOCK_METHOD1(m,...)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
MockWriteCallback earlyWriteCallback_
#define EXPECT_FALSE(condition)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
#define MOCK_METHOD2(m,...)
std::unique_ptr< folly::IOBuf > data
folly::AsyncTransportWrapper::WriteCallback * callback
#define MOCK_METHOD0(m,...)