add unittests for moving/copying Completer

This commit is contained in:
falsycat 2023-07-17 06:06:02 +09:00
parent 172efc758f
commit 07209204b9

View File

@ -5,6 +5,7 @@
#include <cstdint>
#include <optional>
#include <utility>
#include "iface/common/exception.hh"
@ -222,6 +223,33 @@ TEST(Future, ThenAndWhenError) {
EXPECT_EQ(called2, 0);
}
TEST(Future_Completer, CompleteAfterCopy) {
std::optional<nf7::Future<int32_t>> fut;
{
std::optional<nf7::Future<int32_t>::Completer> sut;
{
nf7::Future<int32_t>::Completer sut2;
fut.emplace(sut2.future());
sut.emplace(sut2);
}
sut->Complete(int32_t {777});
}
EXPECT_TRUE(fut->done());
}
TEST(Future_Completer, CompleteAfterMove) {
std::optional<nf7::Future<int32_t>> fut;
{
std::optional<nf7::Future<int32_t>::Completer> sut;
{
nf7::Future<int32_t>::Completer sut2;
fut.emplace(sut2.future());
sut.emplace(std::move(sut2));
}
sut->Complete(int32_t {777});
}
EXPECT_TRUE(fut->done());
}
#if !defined(NDEBUG)
TEST(Future, DeathByListenInCallback) {
nf7::Future<int32_t> sut {int32_t{777}};