LCOV - code coverage report
Current view: top level - tests - asynchronous.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 19 100.0 %
Date: 2019-12-13 00:59:36 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2006-2019  Made to Order Software Corp.  All Rights Reserved
       3             :  *
       4             :  * https://snapwebsites.org/project/snaplogger
       5             :  * contact@m2osw.com
       6             :  *
       7             :  * This program is free software; you can redistribute it and/or modify
       8             :  * it under the terms of the GNU General Public License as published by
       9             :  * the Free Software Foundation; either version 2 of the License, or
      10             :  * (at your option) any later version.
      11             :  *
      12             :  * This program is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  * GNU General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU General Public License along
      18             :  * with this program; if not, write to the Free Software Foundation, Inc.,
      19             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      20             :  */
      21             : 
      22             : // self
      23             : //
      24             : #include    "main.h"
      25             : 
      26             : 
      27             : // snaplogger lib
      28             : //
      29             : #include    <snaplogger/buffer_appender.h>
      30             : #include    <snaplogger/logger.h>
      31             : #include    <snaplogger/map_diagnostic.h>
      32             : #include    <snaplogger/message.h>
      33             : 
      34             : 
      35             : // C lib
      36             : //
      37             : #include    <unistd.h>
      38             : 
      39             : 
      40             : 
      41           3 : CATCH_TEST_CASE("example", "[example]")
      42             : {
      43           2 :     CATCH_START_SECTION("Simple logging")
      44             :     {
      45           1 :         snaplogger::set_diagnostic(snaplogger::DIAG_KEY_PROGNAME, "async-unittest");
      46           1 :         snaplogger::set_diagnostic(snaplogger::DIAG_KEY_VERSION, "1.0");
      47             : 
      48           2 :         snaplogger::logger::pointer_t l(snaplogger::logger::get_instance());
      49           2 :         snaplogger::buffer_appender::pointer_t buffer(std::make_shared<snaplogger::buffer_appender>("test-buffer"));
      50             : 
      51           1 :         advgetopt::options_environment opt_env;
      52           1 :         opt_env.f_project_name = "async-unittest";
      53           2 :         advgetopt::getopt opts(opt_env);
      54           1 :         buffer->set_config(opts);
      55             : 
      56           2 :         snaplogger::format::pointer_t f(std::make_shared<snaplogger::format>("${progname}: ${severity}: ${message} (${version})"));
      57           1 :         buffer->set_format(f);
      58             : 
      59           1 :         l->add_appender(buffer);
      60             : 
      61           1 :         l->set_asynchronous(true);
      62             : 
      63             :         //l->add_console_appender()->add_component(snaplogger::g_secure_component);
      64             :         //l->add_component_to_ignore(snaplogger::g_normal_component);
      65             :         //l->add_component_to_include(snaplogger::g_normal_component);
      66             : 
      67           2 :         SNAP_LOG_WARNING
      68           1 :             << "Sent through thread..."
      69             :             << SNAP_LOG_SEND;
      70             : 
      71             :         // this call blocks until the thread stopped and joined
      72             :         //
      73           1 :         l->set_asynchronous(false);
      74             : 
      75             :         // TODO: add the ${tid} as one of the message parameter and a way
      76             :         //       to retrieve the tid of the async. thread
      77             :         //
      78           1 :         CATCH_REQUIRE(buffer->str() == "async-unittest: warning: Sent through thread... (1.0)\n");
      79             :     }
      80             :     CATCH_END_SECTION()
      81           7 : }
      82             : 
      83             : 
      84             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13