proxygen
SharedPromiseTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (SharedPromise, setGetSemiFuture)
 
 TEST (SharedPromise, setGetMixed)
 
 TEST (SharedPromise, setGet)
 
 TEST (SharedPromise, getSet)
 
 TEST (SharedPromise, getSetGet)
 
 TEST (SharedPromise, reset)
 
 TEST (SharedPromise, getMoveSet)
 
 TEST (SharedPromise, setMoveGet)
 
 TEST (SharedPromise, moveSetGet)
 
 TEST (SharedPromise, moveGetSet)
 
 TEST (SharedPromise, moveMove)
 
 TEST (SharedPromise, setWith)
 
 TEST (SharedPromise, isFulfilled)
 
 TEST (SharedPromise, interruptHandler)
 

Function Documentation

TEST ( SharedPromise  ,
setGetSemiFuture   
)

Definition at line 22 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getSemiFuture(), and folly::SharedPromise< T >::setValue().

22  {
24  p.setValue(1);
25  auto f1 = p.getSemiFuture();
26  auto f2 = p.getSemiFuture();
27  EXPECT_EQ(1, f1.value());
28  EXPECT_EQ(1, f2.value());
29 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
SemiFuture< T > getSemiFuture()
TEST ( SharedPromise  ,
setGetMixed   
)

Definition at line 31 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getFuture(), folly::SharedPromise< T >::getSemiFuture(), and folly::SharedPromise< T >::setValue().

31  {
33  p.setValue(1);
34  auto f1 = p.getSemiFuture();
35  auto f2 = p.getFuture();
36  EXPECT_EQ(1, f1.value());
37  EXPECT_EQ(1, f2.value());
38 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
SemiFuture< T > getSemiFuture()
TEST ( SharedPromise  ,
setGet   
)

Definition at line 40 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setValue().

40  {
42  p.setValue(1);
43  auto f1 = p.getFuture();
44  auto f2 = p.getFuture();
45  EXPECT_EQ(1, f1.value());
46  EXPECT_EQ(1, f2.value());
47 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
TEST ( SharedPromise  ,
getSet   
)

Definition at line 48 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setValue().

48  {
50  auto f1 = p.getFuture();
51  auto f2 = p.getFuture();
52  p.setValue(1);
53  EXPECT_EQ(1, f1.value());
54  EXPECT_EQ(1, f2.value());
55 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
TEST ( SharedPromise  ,
getSetGet   
)

Definition at line 57 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setValue().

57  {
59  auto f1 = p.getFuture();
60  p.setValue(1);
61  auto f2 = p.getFuture();
62  EXPECT_EQ(1, f1.value());
63  EXPECT_EQ(1, f2.value());
64 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
TEST ( SharedPromise  ,
reset   
)

Definition at line 66 of file SharedPromiseTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setValue().

66  {
68 
69  auto f1 = p.getFuture();
70  p.setValue(1);
71  EXPECT_EQ(1, f1.value());
72 
73  p = SharedPromise<int>();
74  auto f2 = p.getFuture();
75  EXPECT_FALSE(f2.isReady());
76  p.setValue(2);
77  EXPECT_EQ(2, f2.value());
78 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( SharedPromise  ,
getMoveSet   
)

Definition at line 80 of file SharedPromiseTest.cpp.

References EXPECT_EQ, f, folly::SharedPromise< T >::getFuture(), and folly::gen::move.

80  {
82  auto f = p.getFuture();
83  auto p2 = std::move(p);
84  p2.setValue(1);
85  EXPECT_EQ(1, f.value());
86 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( SharedPromise  ,
setMoveGet   
)

Definition at line 88 of file SharedPromiseTest.cpp.

References EXPECT_EQ, f, folly::gen::move, and folly::SharedPromise< T >::setValue().

88  {
90  p.setValue(1);
91  auto p2 = std::move(p);
92  auto f = p2.getFuture();
93  EXPECT_EQ(1, f.value());
94 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
TEST ( SharedPromise  ,
moveSetGet   
)

Definition at line 96 of file SharedPromiseTest.cpp.

References EXPECT_EQ, f, and folly::gen::move.

96  {
98  auto p2 = std::move(p);
99  p2.setValue(1);
100  auto f = p2.getFuture();
101  EXPECT_EQ(1, f.value());
102 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( SharedPromise  ,
moveGetSet   
)

Definition at line 104 of file SharedPromiseTest.cpp.

References EXPECT_EQ, f, and folly::gen::move.

104  {
106  auto p2 = std::move(p);
107  auto f = p2.getFuture();
108  p2.setValue(1);
109  EXPECT_EQ(1, f.value());
110 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( SharedPromise  ,
moveMove   
)

Definition at line 112 of file SharedPromiseTest.cpp.

References folly::SharedPromise< T >::getFuture(), folly::gen::move, and folly::SharedPromise< T >::setValue().

112  {
114  auto f1 = p.getFuture();
115  auto f2 = p.getFuture();
116  auto p2 = std::move(p);
117  p = std::move(p2);
118  p.setValue(std::make_shared<int>(1));
119 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Sugar to fulfill this SharedPromise<Unit>
Definition: SharedPromise.h:92
TEST ( SharedPromise  ,
setWith   
)

Definition at line 121 of file SharedPromiseTest.cpp.

References EXPECT_EQ, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setWith().

121  {
123  p.setWith([] { return 1; });
124  EXPECT_EQ(1, p.getFuture().value());
125 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( SharedPromise  ,
isFulfilled   
)

Definition at line 127 of file SharedPromiseTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, folly::SharedPromise< T >::isFulfilled(), and folly::gen::move.

127  {
130  auto p2 = std::move(p);
131  EXPECT_FALSE(p2.isFulfilled());
132  p2.setValue(1);
133  EXPECT_TRUE(p2.isFulfilled());
134  p = std::move(p2);
135  EXPECT_TRUE(p.isFulfilled());
136 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( SharedPromise  ,
interruptHandler   
)

Definition at line 138 of file SharedPromiseTest.cpp.

References EXPECT_TRUE, f, flag, folly::SharedPromise< T >::getFuture(), and folly::SharedPromise< T >::setInterruptHandler().

138  {
140  bool flag = false;
141  p.setInterruptHandler([&](const exception_wrapper&) { flag = true; });
142  auto f = p.getFuture();
143  f.cancel();
144  EXPECT_TRUE(flag);
145 }
auto f
void setInterruptHandler(std::function< void(exception_wrapper const &)>)
static once_flag flag
Definition: Random.cpp:75
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859