38#include <gtest/gtest.h>
57 const bool start_upon_creation =
false;
95 for (
const auto expected : expected_values) {
96 argument = yield.get();
104 for (
const auto val : input) {
120 auto returning_task =
123 for (
const auto ret :
output) {
131 for (
const auto expected : expected_values) {
132 int returned = coro.
get();
147 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };
149 const int steps = expected_values.size();
151 auto fibonacci_task =
157 for (
auto iter = 0; iter < steps; iter++) {
158 int sum = prev + current;
169 for (
const auto expected : expected_values) {
171 int returned = coro.
get();
187 const std::string caller_str(
"HloWrd");
188 const std::string coro_str(
"el ol!");
189 const std::string
expected(
"Hello World!");
191 auto cooperative_task =
194 for (
auto& appended_c : coro_str) {
195 auto old_str = yield.get();
196 yield(old_str + appended_c);
203 for (
auto&
c : caller_str) {
206 result = coro(result).
get();
220 const std::string wrong(
"Inner");
221 const std::string
expected(
"Inner + Outer");
226 std::string inner_string(
"Inner");
234 std::string inner_string = coro.
get();
236 std::string outer_string(
"Outer");
237 yield(inner_string +
" + " + outer_string);
244 std::string result = coro.
get();
246 ASSERT_NE(result, wrong);
261 bool valid_return =
false;
278 ASSERT_TRUE(valid_return);
CallerType: A reference to an object of this class will be passed to the coroutine task.
This template defines a Coroutine wrapper type with a Boost-like interface.
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 })
std::enable_if_t<!std::is_same_v< T, void >, T > 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.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
static void output(const char *filename)