proxygen
UnwrapTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (Unwrap, simpleScenario)
 
 TEST (Unwrap, chainCommands)
 
 TEST (Unwrap, futureNotReady)
 

Function Documentation

TEST ( Unwrap  ,
simpleScenario   
)

Definition at line 24 of file UnwrapTest.cpp.

References EXPECT_EQ, folly::makeFuture(), folly::gen::move, folly::gen::unwrap, and folly::value().

24  {
25  Future<int> encapsulated_future = makeFuture(5484);
26  Future<Future<int>> future = makeFuture(std::move(encapsulated_future));
27  EXPECT_EQ(5484, std::move(future).unwrap().value());
28 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static const char *const value
Definition: Conv.cpp:50
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Unwrap  ,
chainCommands   
)

Definition at line 31 of file UnwrapTest.cpp.

References EXPECT_EQ, i, folly::makeFuture(), and folly::gen::move.

31  {
32  Future<Future<int>> future = makeFuture(makeFuture(5484));
33  auto unwrapped = std::move(future).unwrap().then([](int i) { return i; });
34  EXPECT_EQ(5484, unwrapped.value());
35 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Unwrap  ,
futureNotReady   
)

Definition at line 40 of file UnwrapTest.cpp.

References ASSERT_FALSE, ASSERT_TRUE, EXPECT_EQ, folly::Promise< T >::getFuture(), folly::futures::detail::FutureBase< T >::isReady(), folly::makeFuture(), folly::gen::move, folly::Promise< T >::setValue(), and folly::futures::detail::FutureBase< T >::value().

40  {
42  Future<Future<int>> future = p.getFuture();
43  Future<int> unwrapped = std::move(future).unwrap();
44  // Sanity - should not be ready before the promise is fulfilled.
45  ASSERT_FALSE(unwrapped.isReady());
46  // Fulfill the promise and make sure the unwrapped future is now ready.
47  p.setValue(makeFuture(5484));
48  ASSERT_TRUE(unwrapped.isReady());
49  EXPECT_EQ(5484, unwrapped.value());
50 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > getFuture()
Definition: Promise-inl.h:97
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310