Boost logo

Boost Users :

Subject: [Boost-users] Testing and faking ASIO I/O objects
From: Cristian Morales Vega (cristian_at_[hidden])
Date: 2018-08-29 21:03:02


How is people around here testing code which uses ASIO?
I guess something like

GIVEN("SOMETHING THAT STARTS BY DOING A NAME RESOLVER IS STARTED")
    fakeResolver.async_resolve("www.google.com", "80",
HandlerCallingConnect); // This stores the completion handler (and an
executor_work_guard) internally

    WHEN("THE RESOLVER RETURNS WITHOUT ERROR")
        fakeResolver.completeWithFakeResult("1.2.3.4", error_code());
// This post() the completion handler with the arguments you give it
here
        io_context.poll();

        THEN("A CONNECTION IS ATTEMPTED")
            EXPECT_CALL(fakeSocket, async_connect());

would be nice. But the "stores the completion handler" part doesn't
look that simple. I have found some attempts online, but they seems to
store the completion handlers into a vector of std::function and post
them through std::bind, so possibly using the wrong executor, etc.
There is any good set of ASIO I/O object fakes available?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net