LCOV - code coverage report
Current view: top level - tests - catch_dispatcher.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 19 84.2 %
Date: 2024-09-14 18:11:21 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2012-2024  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/eventdispatcher
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      19             : 
      20             : // self
      21             : //
      22             : #include    "catch_main.h"
      23             : 
      24             : 
      25             : // eventdispatcher
      26             : //
      27             : #include    <eventdispatcher/dispatcher.h>
      28             : #include    <eventdispatcher/dispatcher_match.h>
      29             : 
      30             : 
      31             : // last include
      32             : //
      33             : #include    <snapdev/poison.h>
      34             : 
      35             : 
      36             : 
      37             : namespace
      38             : {
      39             : 
      40             : 
      41           0 : void callback(ed::message & msg)
      42             : {
      43           0 :     snapdev::NOT_USED(msg);
      44           0 : }
      45             : 
      46             : 
      47             : } // no name namespace
      48             : 
      49             : 
      50             : 
      51           3 : CATCH_TEST_CASE("dispatcher_setup_error", "[dispatcher][error][setup]")
      52             : {
      53           3 :     CATCH_START_SECTION("create a dispatcher with callback set to nullptr")
      54             :     {
      55             :         // the callback is required
      56             :         //
      57           7 :         CATCH_REQUIRE_THROWS_MATCHES(
      58             :               ::ed::define_match(
      59             :                   ::ed::Expression("REGISTER"),
      60             :                   ::ed::Callback(nullptr),
      61             :                   ::ed::MatchFunc(&ed::one_to_one_match)
      62             :               )
      63             :             , ed::parameter_error
      64             :             , Catch::Matchers::ExceptionMessage("parameter_error: a callback function is required in dispatcher_match, it cannot be set to nullptr."));
      65             :     }
      66           3 :     CATCH_END_SECTION()
      67             : 
      68           3 :     CATCH_START_SECTION("create a dispatcher with missing expression when using the one_to_one_match() function")
      69             :     {
      70             :         // the callback is required
      71             :         //
      72           7 :         CATCH_REQUIRE_THROWS_MATCHES(
      73             :               ::ed::define_match(
      74             :                   ::ed::Callback(&::callback),
      75             :                   ::ed::MatchFunc(&ed::one_to_one_match)
      76             :               )
      77             :             , ed::parameter_error
      78             :             , Catch::Matchers::ExceptionMessage("parameter_error: an expression is required for the one_to_one_match()."));
      79             :     }
      80           3 :     CATCH_END_SECTION()
      81             : 
      82           3 :     CATCH_START_SECTION("create a dispatcher with missing expression when using the one_to_one_match() function")
      83             :     {
      84             :         // the priority must be between min & max
      85             :         //
      86         101 :         for(int count(0); count < 100; ++count)
      87             :         {
      88         100 :             ed::dispatcher_match::priority_t priority(0);
      89             :             for(;;)
      90             :             {
      91         100 :                 priority = rand();
      92         100 :                 if(priority > ed::dispatcher_match::DISPATCHER_MATCH_MAX_PRIORITY)
      93             :                 {
      94         100 :                     break;
      95             :                 }
      96             :             }
      97         900 :             CATCH_REQUIRE_THROWS_MATCHES(
      98             :                   ::ed::define_match(
      99             :                       ::ed::Expression("REGISTER"),
     100             :                       ::ed::Callback(&::callback),
     101             :                       ::ed::MatchFunc(&ed::one_to_one_match),
     102             :                       ::ed::Priority(priority)
     103             :                   )
     104             :                 , ed::parameter_error
     105             :                 , Catch::Matchers::ExceptionMessage("parameter_error: priority too large for dispatcher match."));
     106             :         }
     107             :     }
     108           3 :     CATCH_END_SECTION()
     109           3 : }
     110             : 
     111             : 
     112             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

Snap C++ | List of projects | List of versions