diff --git a/TODO.txt b/TODO.txt index c0b285a4..758d8a47 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,6 +1,4 @@ Change sigs - Add tests with error_info*=nullptr - Change async_fetch_one to not use coroutines Take fetch_many() algorithm out into network_algorithms (e.g. read_many_rows) clear_errors() function to clear error_info and error_code at once Concept checking for async completion tokens diff --git a/test/integration/network_functions.cpp b/test/integration/network_functions.cpp index e813b04b..6100ddf0 100644 --- a/test/integration/network_functions.cpp +++ b/test/integration/network_functions.cpp @@ -229,42 +229,59 @@ public: class async_callback : public network_functions { + // This allows for two versions of the tests: one where we pass a + // non-nullptr error_info* to the initiating function, and another + // one where we pass nullptr. + bool use_errinfo_; + template - static network_result impl(Callable&& cb) + network_result impl(Callable&& cb) { struct handler { std::promise>& prom; - error_info& info; + error_info* info; // nullptr for !use_errinfo_ // For operations with a return type void operator()(error_code code, R retval) { - prom.set_value(network_result( - code, - std::move(info), - std::move(retval) - )); + if (info) + { + prom.set_value(network_result(code, std::move(*info), std::move(retval))); + } + else + { + prom.set_value(network_result(code, std::move(retval))); + } } // For operations without a return type (R=no_result) void operator()(error_code code) { - prom.set_value(network_result( - code, - std::move(info) - )); + if (info) + { + prom.set_value(network_result(code, std::move(*info))); + } + else + { + prom.set_value(network_result(code)); + } } }; std::promise> prom; error_info info = make_initial_error_info(); - cb(handler{prom, info}, &info); + error_info* infoptr = use_errinfo_ ? &info : nullptr; + cb(handler{prom, infoptr}, infoptr); return prom.get_future().get(); } public: - const char* name() const override { return "async_callback"; } + async_callback(bool use_errinfo): use_errinfo_(use_errinfo) {} + const char* name() const override + { + return use_errinfo_ ? "async_callback_errinfo" : "async_callback_noerrinfo"; + } network_result handshake( tcp_connection& conn, const boost::mysql::connection_params& params @@ -348,8 +365,10 @@ public: class async_coroutine : public network_functions { + bool use_errinfo_; + template - static auto impl(IoObj& obj, Callable&& cb) { + auto impl(IoObj& obj, Callable&& cb) { using R = decltype(cb( std::declval(), std::declval() @@ -357,22 +376,29 @@ class async_coroutine : public network_functions std::promise> prom; - boost::asio::spawn(obj.next_layer().get_executor(), [&](yield_context yield) { + boost::asio::spawn(obj.next_layer().get_executor(), [&, this](yield_context yield) { error_code ec = make_initial_error_code(); error_info info = make_initial_error_info(); - R result = cb(yield[ec], &info); - prom.set_value(network_result( - ec, - std::move(info), - std::move(result) - )); + R result = cb(yield[ec], use_errinfo_ ? &info: nullptr); + if (use_errinfo_) + { + prom.set_value(network_result(ec, std::move(info), std::move(result))); + } + else + { + prom.set_value(network_result(ec, std::move(result))); + } }); return prom.get_future().get(); } public: - const char* name() const override { return "async_coroutine"; } + async_coroutine(bool use_errinfo): use_errinfo_(use_errinfo) {} + const char* name() const override + { + return use_errinfo_ ? "async_coroutine_errinfo" : "async_coroutine_noerrinfo"; + } network_result handshake( tcp_connection& conn, const boost::mysql::connection_params& params @@ -494,7 +520,7 @@ class async_future : public network_functions } } public: - const char* name() const override { return "async_future"; } + const char* name() const override { return "async_future_noerrinfo"; } network_result handshake( tcp_connection& conn, const boost::mysql::connection_params& params @@ -579,15 +605,19 @@ public: // Global objects to be exposed sync_errc sync_errc_obj; sync_exc sync_exc_obj; -async_callback async_callback_obj; -async_coroutine async_coroutine_obj; +async_callback async_callback_errinfo_obj (true); +async_callback async_callback_noerrinfo_obj (false); +async_coroutine async_coroutine_errinfo_obj (true); +async_coroutine async_coroutine_noerrinfo_obj (false); async_future async_future_obj; } // Visible stuff -boost::mysql::test::network_functions* boost::mysql::test::sync_errc_network_functions = &sync_errc_obj; -boost::mysql::test::network_functions* boost::mysql::test::sync_exc_network_functions = &sync_exc_obj; -boost::mysql::test::network_functions* boost::mysql::test::async_callback_network_functions = &async_callback_obj; -boost::mysql::test::network_functions* boost::mysql::test::async_coroutine_network_functions = &async_coroutine_obj; -boost::mysql::test::network_functions* boost::mysql::test::async_future_network_functions = &async_future_obj; +network_functions* boost::mysql::test::sync_errc_network_functions = &sync_errc_obj; +network_functions* boost::mysql::test::sync_exc_network_functions = &sync_exc_obj; +network_functions* boost::mysql::test::async_callback_errinfo_network_functions = &async_callback_errinfo_obj; +network_functions* boost::mysql::test::async_callback_noerrinfo_network_functions = &async_callback_noerrinfo_obj; +network_functions* boost::mysql::test::async_coroutine_errinfo_network_functions = &async_coroutine_errinfo_obj; +network_functions* boost::mysql::test::async_coroutine_noerrinfo_network_functions = &async_coroutine_noerrinfo_obj; +network_functions* boost::mysql::test::async_future_noerrinfo_network_functions = &async_future_obj; diff --git a/test/integration/network_functions.hpp b/test/integration/network_functions.hpp index 8307c95d..67f4c69d 100644 --- a/test/integration/network_functions.hpp +++ b/test/integration/network_functions.hpp @@ -81,16 +81,20 @@ public: extern network_functions* sync_errc_network_functions; extern network_functions* sync_exc_network_functions; -extern network_functions* async_callback_network_functions; -extern network_functions* async_coroutine_network_functions; -extern network_functions* async_future_network_functions; +extern network_functions* async_callback_errinfo_network_functions; +extern network_functions* async_callback_noerrinfo_network_functions; +extern network_functions* async_coroutine_errinfo_network_functions; +extern network_functions* async_coroutine_noerrinfo_network_functions; +extern network_functions* async_future_noerrinfo_network_functions; inline network_functions* all_network_functions [] = { sync_errc_network_functions, sync_exc_network_functions, - async_callback_network_functions, - async_coroutine_network_functions, - async_future_network_functions + async_callback_errinfo_network_functions, + async_callback_noerrinfo_network_functions, + async_coroutine_errinfo_network_functions, + async_coroutine_noerrinfo_network_functions, + async_future_noerrinfo_network_functions }; #define MYSQL_NETWORK_TEST_SUITE(TestSuiteName) \