Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Test + Turtle] Suggestion how to test async events.
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2013-04-08 11:32:28


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.


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