[Boost.Test + Turtle] Suggestion how to test async events.

Hi, I'm trying to take a first touch with Boost.Test and Turtle. I have some objects for network communication with async notifications. class ServerHandler : public MessageEventHandler { public: ServerHandler() { // Register the messages I want to manage this->RegisterMsg(E_MSG_METHOD_CONNECT, Poco::delegate(this, &ServerHandler::OnMsgMethodConnect)); } // Messages Handlers virtual void OnMsgMethodConnect(const void* pSender, TArgs& args) { cout << "ServerHandler receive E_MSG_METHOD_CONNECT" << endl; MSG_METHOD_CONNECT& msg = RetrieveMessage<MSG_METHOD_CONNECT>(args.msg); }; }; This class is an observer which handle the notification through the OnMsgMethodConnect method. The test body I wrote is: // declare a 'mockServerHandler' class implementing 'ServerHandler' MOCK_BASE_CLASS( mockServerHandler, ServerHandler ) { MOCK_METHOD( OnMsgMethodConnect, 2 ); }; BOOST_AUTO_TEST_SUITE(NetMessageDispatcherTest) BOOST_AUTO_TEST_CASE(Test1) { mockServerHandler mockSvr; SessionFactory* sf = new SessionFactory( &mockSvr ); IMessageFactory* mf = new PBMessageFactory(); NetMessageDispatcher* server = new NetMessageDispatcher(sf, mf, NULL, E_DISP_SERVER); NetMessageDispatcher* client = new NetMessageDispatcher(sf, mf, NULL, E_DISP_CLIENT); BOOST_CHECK( server->Init("LOCALHOST", "TestServer") == 0 ); BOOST_CHECK( server->Connect(8000, "127.0.0.1") == 0 ); BOOST_CHECK( client->Init("LOCALHOST", "TestClient") == 0 ); BOOST_CHECK( client->Connect(8000, "127.0.0.1") == 0 ); MOCK_EXPECT( mockSvr.OnMsgMethodConnect ).once().with(????) } BOOST_AUTO_TEST_SUITE_END() Now, I have to test if into the ServerHandler::OnMsgMethodConnect() the argument args.msg (which is a message class) has the correct values. EG. if (msg.station_type() == EStationType::ST_CLIENT) => OK Which is the correct way to do it? Regards, Daniele.

On 08/04/2013 16:32, Daniele Barzotti wrote:
(...)
Now, I have to test if into the ServerHandler::OnMsgMethodConnect() the argument args.msg (which is a message class) has the correct values.
EG. if (msg.station_type() == EStationType::ST_CLIENT) => OK
Which is the correct way to do it?
Regards, Daniele.
Hi Daniele, Turtle is not a boost component, so you might want to create a ticket for support directly to the project (see http://sourceforge.net/projects/turtle/support/). A 'with' takes a constraint which general form is a functor testing the received argument (see http://turtle.sourceforge.net/turtle/customisation.html#turtle.customisation...). The simplest solution for your problem would be a free function : bool CheckArgs( TArgs& args ) { return args.msg.station_type() == EStationType::ST_CLIENT; } with the expectation being : MOCK_EXPECT( mockSvr.OnMsgMethodConnect ).once().with( mock::any, &CheckArgs ); Of course this will quickly become tedious if you write several tests checking various values, and you might want to factorize things a bit. If you need more information, just create a support ticket and I will be happy to help ! Cheers, MAT.

On 08/04/2013 18:43, Mathieu Champlon wrote:
Hi Daniele,
Turtle is not a boost component, so you might want to create a ticket for support directly to the project (see http://sourceforge.net/projects/turtle/support/). (...) If you need more information, just create a support ticket and I will be happy to help !
Cheers, MAT.
Hi Mat! Thanks a lot for your reply! I'm sorry to have posted here, I supposed the ticket system was only for bugs :-) Thanks for your suggestion! I will open a ticket in the support page! Cheers, Daniele.
participants (2)
-
Daniele Barzotti
-
Mathieu Champlon