Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit-testing and boost::asio

I'm writing small XMPP server using boost::asio and I want to unit-test my code. Questions:

  1. Are there some ready-to-use frameworks for this? As far as I understand, I need to provide mock objects for boost::asio classes/templates and I really want to make this (semi)automatically.
  2. Is it possible to test concurrency (e.g. multiple connections to server and message routing between them)?
like image 592
hate-engine Avatar asked Jun 28 '12 23:06

hate-engine


1 Answers

1) I wrote a small socket class that can be used as a replacement for the boost::asio::ip::tcp::socket. If you like, you can have a look at robitzki.de/test_socket.h (test_socket.cpp, test_io_plan.h and test_io_plan.cpp). Depending on the constructor used, the socket can simulate reading/writing of chunks with different sizes. Errors can be simulated too. You are free to use it, if you like.

2) With the socket replacement one can build stress tests for the software under test. This will never guaranty that the code doesn't contain bugs but is better than nothing ;-). Personally I like code reviews best to make sure multithreaded code contains as few bugs as possible.

HTH

Torsten

like image 152
Torsten Robitzki Avatar answered Oct 19 '22 17:10

Torsten Robitzki