MCPcopy Create free account
hub / github.com/HelenOS/helenos / test_promise

Method test_promise

uspace/lib/cpp/src/__bits/test/future.cpp:95–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93 }
94
95 void future_test::test_promise()
96 {
97 std::promise<int> p1{};
98 test("default constructed promise has state", p1.__state());
99
100 std::promise<int> p2{};
101 auto* s1 = p1.__state();
102 auto* s2 = p2.__state();
103 p2.swap(p1);
104 std::swap(s1, s2);
105
106 test_eq("swap switches states pt1", s1, p1.__state());
107 test_eq("swap switches states pt2", s2, p2.__state());
108
109 std::promise<int> p3{std::move(p1)};
110 test_eq("move construction state moved", s1, p3.__state());
111 test_eq("move construction source empty", p1.__state(), nullptr);
112
113 p1 = std::move(p3);
114 test_eq("move assignment state move", s1, p1.__state());
115 test_eq("move assignment source empty", p3.__state(), nullptr);
116
117 p1.set_value(42);
118 test("set_value marks state as ready", s1->is_set());
119 test_eq("set_value sets value", s1->get(), 42);
120 }
121
122 void future_test::test_future_promise()
123 {

Callers

nothing calls this directly

Calls 7

moveFunction · 0.85
is_setMethod · 0.80
swapFunction · 0.50
__stateMethod · 0.45
swapMethod · 0.45
set_valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected