Merge branch 'master' of code.uocat.com:tqcq/sled
This commit is contained in:
39
tests/asio_test.cc
Normal file
39
tests/asio_test.cc
Normal file
@ -0,0 +1,39 @@
|
||||
#include <sled/sled.h>
|
||||
|
||||
TEST_SUITE("asio") {
|
||||
TEST_CASE("io_context") {
|
||||
asio::io_context ctx;
|
||||
int x = 0;
|
||||
asio::dispatch(ctx, [&]{
|
||||
CHECK_EQ(x, 0);
|
||||
++x;
|
||||
});
|
||||
asio::post(ctx, [&]{
|
||||
CHECK_EQ(x, 1);
|
||||
++x;
|
||||
asio::dispatch(ctx, [&]{
|
||||
CHECK_EQ(x, 2);
|
||||
++x;
|
||||
});
|
||||
CHECK_EQ(x, 3);
|
||||
++x;
|
||||
});
|
||||
|
||||
asio::steady_timer timer(ctx, std::chrono::milliseconds(500));
|
||||
timer.async_wait([&](const asio::error_code& ec){
|
||||
if (ec.value() == asio::error::operation_aborted) {
|
||||
return;
|
||||
}
|
||||
CHECK_EQ(x, 4);
|
||||
++x;
|
||||
});
|
||||
|
||||
// start ctx
|
||||
{
|
||||
CHECK_EQ(x, 0);
|
||||
ctx.run();
|
||||
CHECK_EQ(x, 5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user