40 #include <gtest/gtest.h> 59 const bool start_upon_creation =
false;
97 for (
const auto expected : expected_values) {
98 argument = yield.get();
106 for (
const auto val : input) {
122 auto returning_task =
125 for (
const auto ret :
output) {
133 for (
const auto expected : expected_values) {
134 int returned = coro.
get();
149 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };
151 const int steps = expected_values.size();
153 auto fibonacci_task =
159 for (
auto iter = 0; iter < steps; iter++) {
160 int sum = prev + current;
171 for (
const auto expected : expected_values) {
173 int returned = coro.
get();
189 const std::string caller_str(
"HloWrd");
190 const std::string coro_str(
"el ol!");
191 const std::string
expected(
"Hello World!");
193 auto cooperative_task =
196 for (
auto& appended_c : coro_str) {
197 auto old_str = yield.get();
198 yield(old_str + appended_c);
205 for (
auto&
c : caller_str) {
208 result = coro(result).
get();
211 ASSERT_EQ(result, expected);
222 const std::string wrong(
"Inner");
223 const std::string
expected(
"Inner + Outer");
228 std::string inner_string(
"Inner");
236 std::string inner_string = coro.
get();
238 std::string outer_string(
"Outer");
239 yield(inner_string +
" + " + outer_string);
246 std::string result = coro.
get();
248 ASSERT_NE(result, wrong);
249 ASSERT_EQ(result, expected);
263 bool valid_return =
false;
280 ASSERT_TRUE(valid_return);
static void output(const char *filename)
CallerType: A reference to an object of this class will be passed to the coroutine task...
TEST(Coroutine, Unstarted)
This test is checking if the Coroutine, once it's created it doesn't start since the second argument ...
std::vector< SwitchingFiber * > expected({ &a, &b, &a, &a, &a, &b, &c, &a, &c, &c, &c })
This template defines a Coroutine wrapper type with a Boost-like interface.
std::enable_if<!std::is_same< T, void >::value, T >::type get()
get() is the way we can extrapolate return values (yielded) from the coroutine.
bool started() const
Returns whether the "main" function of this fiber has started.