diff --git a/CMakeLists.txt b/CMakeLists.txt index af1836a..1029ba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,6 +201,7 @@ if(SLED_BUILD_TESTS) sled_add_test(NAME sled_event_bus_test SRCS src/sled/event_bus/event_bus_test.cc) sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc) + sled_add_test(NAME sled_asio_test SRCS tests/asio_test.cc) sled_add_test(NAME sled_move_on_copy_test SRCS src/sled/utility/move_on_copy_test.cc) sled_add_test(NAME sled_symbolize_test SRCS diff --git a/src/sled/sled.h b/src/sled/sled.h index 0133e7e..b891f9c 100644 --- a/src/sled/sled.h +++ b/src/sled/sled.h @@ -3,6 +3,7 @@ #define SLED_SLED_H // thrid_party +#include #include "rx.h" #include "sled/nonstd/cxxopts.h" #include "sled/nonstd/expected.h" diff --git a/tests/asio_test.cc b/tests/asio_test.cc new file mode 100644 index 0000000..747fbf7 --- /dev/null +++ b/tests/asio_test.cc @@ -0,0 +1,39 @@ +#include + +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); + } + + } +}