proxygen
ThenTest.cpp File Reference
#include <folly/futures/Future.h>
#include <folly/portability/GTest.h>
#include <thread>

Go to the source code of this file.

Functions

 TEST (Then, tryConstructor)
 
 TEST (Then, makeFuture)
 
 TEST (Then, tryConstRValueReference)
 
 TEST (Then, tryRValueReference)
 
 TEST (Then, tryConstLValueReference)
 
 TEST (Then, tryValue)
 
 TEST (Then, tryConstValue)
 
 TEST (Then, constRValueReference)
 
 TEST (Then, rValueReference)
 
 TEST (Then, constLValueReference)
 
 TEST (Then, value)
 
 TEST (Then, constValue)
 
 TEST (Then, objectAliveDuringImmediateNoParamContinuation)
 
 TEST (Then, objectAliveDuringDeferredNoParamContinuation)
 
 TEST (Then, voidThenShouldPropagateExceptions)
 

Function Documentation

TEST ( Then  ,
tryConstructor   
)

Definition at line 75 of file ThenTest.cpp.

References EXPECT_EQ, and folly::pushmi::detail::t.

75  {
76  auto t = Try<Widget>(23);
77  EXPECT_EQ(t.value().v_, 23);
78  EXPECT_EQ(t.value().copied_, 0);
79  EXPECT_EQ(t.value().moved_, 1);
80 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
TEST ( Then  ,
makeFuture   
)

Definition at line 82 of file ThenTest.cpp.

References EXPECT_EQ.

82  {
83  auto future = makeFuture<Widget>(23);
84  EXPECT_EQ(future.value().v_, 23);
85  EXPECT_EQ(future.value().copied_, 0);
86  EXPECT_EQ(future.value().moved_, 2);
87 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
tryConstRValueReference   
)

Definition at line 89 of file ThenTest.cpp.

References EXPECT_EQ, and folly::pushmi::detail::t.

89  {
90  auto future = makeFuture<Widget>(23).then([](const Try<Widget>&& t) {
91  EXPECT_EQ(t.value().copied_, 0);
92  EXPECT_EQ(t.value().moved_, 2);
93  return t.value().v_;
94  });
95  EXPECT_EQ(future.value(), 23);
96 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
TEST ( Then  ,
tryRValueReference   
)

Definition at line 98 of file ThenTest.cpp.

References EXPECT_EQ, and folly::pushmi::detail::t.

98  {
99  auto future = makeFuture<Widget>(23).then([](Try<Widget>&& t) {
100  EXPECT_EQ(t.value().copied_, 0);
101  EXPECT_EQ(t.value().moved_, 2);
102  return t.value().v_;
103  });
104  EXPECT_EQ(future.value(), 23);
105 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
TEST ( Then  ,
tryConstLValueReference   
)

Definition at line 107 of file ThenTest.cpp.

References EXPECT_EQ, folly::pushmi::detail::t, and folly::Try< T >::value().

107  {
108  auto future = makeFuture<Widget>(23).then([](const Try<Widget>& t) {
109  EXPECT_EQ(t.value().copied_, 0);
110  EXPECT_EQ(t.value().moved_, 2);
111  return t.value().v_;
112  });
113  EXPECT_EQ(future.value(), 23);
114 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
T & value()&
Definition: Try-inl.h:140
TEST ( Then  ,
tryValue   
)

Definition at line 116 of file ThenTest.cpp.

References EXPECT_EQ, folly::pushmi::detail::t, and folly::Try< T >::value().

116  {
117  auto future = makeFuture<Widget>(23).then([](Try<Widget> t) {
118  EXPECT_EQ(t.value().copied_, 0);
119  EXPECT_EQ(t.value().moved_, 3);
120  return t.value().v_;
121  });
122  EXPECT_EQ(future.value(), 23);
123 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
T & value()&
Definition: Try-inl.h:140
TEST ( Then  ,
tryConstValue   
)

Definition at line 125 of file ThenTest.cpp.

References EXPECT_EQ, folly::pushmi::detail::t, and folly::Try< T >::value().

125  {
126  auto future = makeFuture<Widget>(23).then([](const Try<Widget> t) {
127  EXPECT_EQ(t.value().copied_, 0);
128  EXPECT_EQ(t.value().moved_, 3);
129  return t.value().v_;
130  });
131  EXPECT_EQ(future.value(), 23);
132 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Definition: Try.h:51
T & value()&
Definition: Try-inl.h:140
TEST ( Then  ,
constRValueReference   
)

Definition at line 134 of file ThenTest.cpp.

References EXPECT_EQ.

134  {
135  auto future = makeFuture<Widget>(23).then([](const Widget&& w) {
136  EXPECT_EQ(w.copied_, 0);
137  EXPECT_EQ(w.moved_, 2);
138  return w.v_;
139  });
140  EXPECT_EQ(future.value(), 23);
141 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
rValueReference   
)

Definition at line 143 of file ThenTest.cpp.

References EXPECT_EQ.

143  {
144  auto future = makeFuture<Widget>(23).then([](Widget&& w) {
145  EXPECT_EQ(w.copied_, 0);
146  EXPECT_EQ(w.moved_, 2);
147  return w.v_;
148  });
149  EXPECT_EQ(future.value(), 23);
150 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
constLValueReference   
)

Definition at line 152 of file ThenTest.cpp.

References EXPECT_EQ.

152  {
153  auto future = makeFuture<Widget>(23).then([](const Widget& w) {
154  EXPECT_EQ(w.copied_, 0);
155  EXPECT_EQ(w.moved_, 2);
156  return w.v_;
157  });
158  EXPECT_EQ(future.value(), 23);
159 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
value   
)

Definition at line 161 of file ThenTest.cpp.

References EXPECT_EQ.

161  {
162  auto future = makeFuture<Widget>(23).then([](Widget w) {
163  EXPECT_EQ(w.copied_, 0);
164  EXPECT_EQ(w.moved_, 3);
165  return w.v_;
166  });
167  EXPECT_EQ(future.value(), 23);
168 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
constValue   
)

Definition at line 170 of file ThenTest.cpp.

References EXPECT_EQ.

170  {
171  auto future = makeFuture<Widget>(23).then([](const Widget w) {
172  EXPECT_EQ(w.copied_, 0);
173  EXPECT_EQ(w.moved_, 3);
174  return w.v_;
175  });
176  EXPECT_EQ(future.value(), 23);
177 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( Then  ,
objectAliveDuringImmediateNoParamContinuation   
)

Definition at line 179 of file ThenTest.cpp.

References EXPECT_EQ, f, folly::gen::move, and folly::size().

179  {
180  auto f = makeFuture<CountedWidget>(23);
181  auto called = false;
182  std::move(f).thenValue([&](auto&&) {
183  EXPECT_EQ(CountedWidget::instances_.size(), 1u);
184  EXPECT_EQ(CountedWidget::instances_[0]->v_, 23);
185  called = true;
186  });
187  EXPECT_EQ(true, called);
188 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST ( Then  ,
objectAliveDuringDeferredNoParamContinuation   
)

Definition at line 190 of file ThenTest.cpp.

References EXPECT_EQ, folly::Promise< T >::getFuture(), and folly::size().

190  {
191  auto p = Promise<CountedWidget>{};
192  bool called = false;
193  p.getFuture().thenValue([&](auto&&) {
194  EXPECT_EQ(CountedWidget::instances_.size(), 1u);
195  EXPECT_EQ(CountedWidget::instances_[0]->v_, 23);
196  called = true;
197  });
198  p.setValue(CountedWidget{23});
199  EXPECT_EQ(true, called);
200 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( Then  ,
voidThenShouldPropagateExceptions   
)

Definition at line 202 of file ThenTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, and folly::makeFuture().

202  {
203  EXPECT_FALSE(makeFuture(42).then().hasException());
204  EXPECT_TRUE(makeFuture<int>(std::runtime_error("err")).then().hasException());
205 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310