1
0
Fork 0
mirror of https://gitlab.com/niansa/libcrosscoro.git synced 2025-03-06 20:53:32 +01:00
libcrosscoro/test/test_generator.cpp
Josh Baldwin 80fea9c49a
io_scheduler uses thread pool to schedule work (#42)
* io_scheduler uses thread pool to schedule work

fixes #41

* use task_container in bench tcp server test

* adjust benchmark for github actions CI

* fix io_scheduler tests cross thread memory boundaries

* more memory barriers

* sprinkle some shutdowns in there

* update readme
2021-01-24 19:34:39 -07:00

40 lines
752 B
C++

#include "catch.hpp"
#include <coro/coro.hpp>
TEST_CASE("generator single yield", "[generator]")
{
std::string msg{"Hello World Generator!"};
auto func = [&]() -> coro::generator<std::string> { co_yield msg; };
for (const auto& v : func())
{
REQUIRE(v == msg);
}
}
TEST_CASE("generator infinite incrementing integer yield", "[generator]")
{
constexpr const int64_t max = 1024;
auto func = []() -> coro::generator<int64_t> {
int64_t i{0};
while (true)
{
++i;
co_yield i;
}
};
int64_t v{1};
for (const auto& v_1 : func())
{
REQUIRE(v == v_1);
++v;
if (v > max)
{
break;
}
}
}