LCOV - code coverage report
Current view: top level - tests - appender.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/exception.h>
      31             : #include    <snaplogger/format.h>
      32             : #include    <snaplogger/logger.h>
      33             : #include    <snaplogger/map_diagnostic.h>
      34             : #include    <snaplogger/message.h>
      35             : #include    <snaplogger/severity.h>
      36             : #include    <snaplogger/version.h>
      37             : 
      38             : 
      39             : // C lib
      40             : //
      41             : #include    <unistd.h>
      42             : #include    <netdb.h>
      43             : #include    <sys/param.h>
      44             : 
      45             : 
      46             : 
      47             : 
      48             : 
      49           3 : CATCH_TEST_CASE("appender", "[appender]")
      50             : {
      51           2 :     CATCH_START_SECTION("Create Appender")
      52             :     {
      53           1 :         snaplogger::set_diagnostic(snaplogger::DIAG_KEY_PROGNAME, "appender");
      54             : 
      55           2 :         snaplogger::appender::pointer_t unknown(snaplogger::create_appender("unknown", "test-buffer"));
      56           1 :         CATCH_REQUIRE(unknown == nullptr);
      57             : 
      58           2 :         snaplogger::appender::pointer_t buffer(snaplogger::create_appender("buffer", "test-buffer"));
      59           1 :         CATCH_REQUIRE(buffer != nullptr);
      60             : 
      61           1 :         advgetopt::options_environment opt_env;
      62           1 :         opt_env.f_project_name = "test-logger";
      63           2 :         advgetopt::getopt opts(opt_env);
      64           1 :         buffer->set_config(opts);
      65             : 
      66           2 :         snaplogger::format::pointer_t f(std::make_shared<snaplogger::format>("${severity}: ${message}"));
      67           1 :         buffer->set_format(f);
      68             : 
      69           2 :         snaplogger::logger::pointer_t l(snaplogger::logger::get_instance());
      70           1 :         l->add_appender(buffer);
      71             : 
      72           1 :         SNAP_LOG_FATAL << "Appender created by name" << SNAP_LOG_SEND;
      73           1 :         CATCH_REQUIRE(std::dynamic_pointer_cast<snaplogger::buffer_appender>(buffer)->str() == "fatal: Appender created by name\n");
      74             : 
      75           1 :         l->reset();
      76             :     }
      77             :     CATCH_END_SECTION()
      78           7 : }
      79             : 
      80             : 
      81             : 
      82             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13