#include <folly/futures/Future.h>
#include <folly/portability/GTest.h>
+#include <memory>
+
using namespace folly;
using std::unique_ptr;
using std::string;
typedef FutureException eggs_t;
static eggs_t eggs("eggs");
+TEST(Promise, makeEmpty) {
+ auto p = Promise<int>::makeEmpty();
+ EXPECT_TRUE(p.isFulfilled());
+}
+
TEST(Promise, special) {
EXPECT_FALSE(std::is_copy_constructible<Promise<int>>::value);
EXPECT_FALSE(std::is_copy_assignable<Promise<int>>::value);
Promise<unique_ptr<int>> mov;
auto fmov = mov.getFuture();
- mov.setValue(unique_ptr<int>(new int(42)));
+ mov.setValue(std::make_unique<int>(42));
unique_ptr<int> ptr = std::move(fmov.value());
EXPECT_EQ(42, *ptr);
{
Promise<Unit> p;
auto f = p.getFuture();
- try {
- throw eggs;
- } catch (const std::exception& e) {
- p.setException(exception_wrapper(std::current_exception(), e));
- } catch (...) {
- p.setException(exception_wrapper(std::current_exception()));
- }
+ p.setException(std::make_exception_ptr(eggs));
+ EXPECT_THROW(f.value(), eggs_t);
+ }
+ {
+ Promise<Unit> p;
+ auto f = p.getFuture();
+ p.setException(exception_wrapper(eggs));
EXPECT_THROW(f.value(), eggs_t);
}
}
}
TEST(Promise, brokenOnDelete) {
- auto p = folly::make_unique<Promise<int>>();
+ auto p = std::make_unique<Promise<int>>();
auto f = p->getFuture();
EXPECT_FALSE(f.isReady());
}
TEST(Promise, brokenPromiseHasTypeInfo) {
- auto pInt = folly::make_unique<Promise<int>>();
+ auto pInt = std::make_unique<Promise<int>>();
auto fInt = pInt->getFuture();
- auto pFloat = folly::make_unique<Promise<float>>();
+ auto pFloat = std::make_unique<Promise<float>>();
auto fFloat = pFloat->getFuture();
pInt.reset();