Search code examples
c++boostboost-log

Test whether a log message is generated using Boost.Log


I am currently using Boost.Log in one of my software projects. There is one case, where I report an error condition by using a log message. I would like to test whether this condition is detected correctly using google testing framework. Just to be clear, I want to test whether the message is generated. It may be removed by a filter, but this should not cause the test to fail. Is this possible at all? Any hints? Thanks!


Solution

  • For base yes-or-no testing, simply use assert, something like this:

    #include <assert.h>     /* assert */
    
    void print_number(int* myInt) {
      assert (myInt!=NULL);
      // Boost.Log stuff...
      // print_number stuff...
    }
    

    this will give you a straight up message (depending on compiler/OS) if the test fails.