LCOV - code coverage report
Current view: top level - tests - test2.cpp (source / functions) Hit Total Coverage
Test: wlog-coverage.info Lines: 46 55 83.6 %
Date: 2019-09-12 Functions: 8 8 100.0 %

          Line data    Source code
       1             : 
       2             : 
       3             : #include <wlog/init.hpp>
       4             : #include <wlog/logging.hpp>
       5             : #include "test.hpp"
       6             : 
       7             : int test1();
       8             : int test2();
       9             : int test3();
      10             : 
      11           1 : int test1()
      12             : {
      13           1 :   std::string message;
      14             :   wlog::init(
      15           1 :     [&message](wlog::time_point, std::string name, std::string type, std::string text)
      16             :     {
      17           1 :       message = name + type + text;
      18           1 :       return true;
      19             :     }
      20           1 :   );
      21             :   
      22           1 :   wlog::global_log("test", "message").log() << "hello " << 1 << 2;
      23             : 
      24           1 :   if ( !test( message=="testmessagehello 12", __FILE__, __LINE__ ) )
      25           0 :     return __LINE__;
      26             :   
      27           1 :   return 0;
      28             : }
      29             : 
      30           1 : int test2()
      31             : {
      32           1 :   std::string message;
      33           1 :   wlog::init();
      34             :   
      35           1 :   wlog::global_log("test", "message").log() << "hello " << 1 << 2 << std::endl;
      36             : 
      37           1 :   if ( !test( message=="", __FILE__, __LINE__ ) )
      38           0 :     return __LINE__;
      39             : 
      40           1 :   wlog::global_cout().log() << "global_cout"<< std::endl;
      41           1 :   wlog::global_clog().log() << "global_clog"<< std::endl;
      42           1 :   wlog::global_cerr().log() << "global_cerr"<< std::endl;
      43             : 
      44             :   //std::clog << std::endl;
      45           1 :   return 0;
      46             : }
      47             : 
      48           1 : int test3()
      49             : {
      50           1 :   std::string message;
      51             :   wlog::init(
      52           9 :     [&message](wlog::time_point, std::string name, std::string type, std::string text)
      53             :     {
      54           9 :       message += name + type + text;
      55           9 :       return true;
      56             :     }
      57           1 :   );
      58             : 
      59           1 :   WLOG_MESSAGE(1)
      60           1 :   WLOG_WARNING(2)
      61           1 :   WLOG_ERROR(3)
      62           1 :   WLOG_FATAL(4)
      63           1 :   WLOG_BEGIN(5)
      64           1 :   WLOG_END(6)
      65           1 :   WLOG_DEBUG(7)
      66           1 :   WLOG_TRACE(8)
      67             : 
      68             : #ifndef NDEBUG
      69           2 :   std::string checkmsg="WLOGMESSAGE1\nWLOGWARNING2\nWLOGERROR3\nWLOGFATAL4\nWLOGBEGIN5\nWLOGEND6\nWLOGDEBUG7\nWLOGTRACE8\n";
      70             : #else  
      71             :   std::string checkmsg="WLOGMESSAGE1\nWLOGWARNING2\nWLOGERROR3\nWLOGFATAL4\nWLOGBEGIN5\nWLOGEND6\n";
      72             : #endif
      73           1 :   if ( !test( message==checkmsg, __FILE__, __LINE__ ) )
      74           0 :     return __LINE__;
      75             :   
      76           1 :   message.clear();
      77           1 :   WLOG_PROGRESS(9)
      78           1 :   checkmsg="WLOGPROGRESS9\r";
      79           1 :   if ( !test( message==checkmsg, __FILE__, __LINE__ ) )
      80             :   {
      81           0 :     std::cout << message << std::endl;
      82           0 :     std::cout << checkmsg << std::endl;
      83           0 :     return __LINE__;
      84             :   }
      85             :   
      86           2 :   return 0;
      87             : }
      88             : 
      89           1 : int main()
      90             : {
      91           1 :   if ( int res = test1() )
      92           0 :     return res;
      93           1 :   if ( int res = test2() )
      94           0 :     return res;
      95           1 :   if ( int res = test3() )
      96           0 :     return res;
      97           1 :   wlog::disable();
      98           1 :   return 0;  
      99           3 : }

Generated by: LCOV version 1.10