LCOV - code coverage report
Current view: top level - tests - test1.cpp (source / functions) Hit Total Coverage
Test: wlog-coverage.info Lines: 35 38 92.1 %
Date: 2019-09-12 Functions: 7 7 100.0 %

          Line data    Source code
       1             : //#include <wlog/logstream.hpp>
       2             : #include <wlog/logging.hpp>
       3             : #include "test.hpp"
       4             : 
       5             : int test1();
       6             : int test2();
       7             : 
       8           1 : int test1()
       9             : {
      10           1 :   wlog::mutex_type m;
      11           1 :   std::string message;
      12             :   {
      13             :     wlog::logstream log(m, "test", "message", 
      14           1 :       [&message](const wlog::time_point&, const std::string& name, const std::string& ident, const std::string& text)
      15             :       {
      16           1 :         WCOUT( name << "," << ident << "," << text << " >> " << message << std::endl );
      17           1 :         message = name + ident + text;
      18           1 :         std::cout << "<<" << message << std::endl;
      19           1 :         return true;
      20             :       }
      21           1 :     );
      22             : 
      23           1 :     TEST( log.str().empty() );
      24           1 :     log.log() << "hello " << 1;
      25           1 :     log.log() << 2;
      26           1 :     TEST( !log.str().empty() );
      27           1 :     TEST( log.str()=="hello 12" );
      28             :   }
      29           1 :   WCOUT( message << std::endl )
      30           1 :   WCLOG( "WCLOG" )
      31           1 :   WCERR( "WCERR" )
      32           1 :   TEST( message=="testmessagehello 12" );
      33           1 :   return 0;
      34             : }
      35             : 
      36           1 : int test2()
      37             : {
      38           1 :   std::string message;
      39             :   {
      40           1 :     wlog::mutex_type m;
      41             :     wlog::logstream log(m, "test", "message", 
      42           1 :       [&message](wlog::time_point, std::string name, std::string type, std::string text)
      43             :       {
      44           1 :         message = name + type + text;
      45           1 :         return true;
      46             :       }
      47           1 :     );
      48             : 
      49           1 :     log.log() << "hello " << 1;
      50           1 :     log.log() << 2;
      51             :   }
      52             : 
      53           1 :   if ( !test( message=="testmessagehello 12", __FILE__, __LINE__ ) )
      54           0 :     return __LINE__;
      55             :   
      56           1 :   return 0;
      57             : }
      58           1 : int main(int , char* [])
      59             : {
      60           1 :   if ( int res = test1() )
      61           0 :     return res;
      62           1 :   if ( int res = test2() )
      63           0 :     return res;
      64           1 :   return 0;  
      65           3 : }

Generated by: LCOV version 1.10