-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoFutureTests.cpp
More file actions
58 lines (48 loc) · 1.14 KB
/
CoFutureTests.cpp
File metadata and controls
58 lines (48 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <co/future.hpp>
#include <catch2/catch.hpp>
#include "helper.hpp"
TEST_CASE("co::future")
{
SECTION("default constructed")
{
co::future<int> f;
static_assert(std::is_same<decltype(f.get()), int>::value, "f.get() should return type T");
REQUIRE(f.valid() == false);
}
}
TEST_CASE("co::make_ready_future")
{
auto f = co::make_ready_future(42);
REQUIRE(f.valid());
REQUIRE(f.is_ready());
REQUIRE(f.await_resume() == 42);
REQUIRE(f.get() == 42);
}
TEST_CASE("co::make_exceptional_future")
{
co::future<int> f;
SECTION("from exception value")
{
f = co::make_exceptional_future<int>(42);
}
SECTION("from std::exception_ptr")
{
f = [](){
try {
throw 42;
} catch(...) {
return co::make_exceptional_future<int>(std::current_exception());
}
FAIL("expected return from catch(int)");
}();
}
REQUIRE(f.valid());
REQUIRE(f.is_ready());
REQUIRE_THROWS_AS(f.await_resume(), int);
REQUIRE_THROWS_AS(f.get(), int);
try {
f.get();
} catch(int val) {
REQUIRE(val == 42);
}
}