LCOV - code coverage report
Current view: top level - tests - catch_reporter_statement.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 46 46 100.0 %
Date: 2024-09-14 18:11:21 Functions: 2 2 100.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 3 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
      17             : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18             : 
      19             : // this diagnostic has to be turned off "globally" so the catch2 does not
      20             : // generate the warning on the floating point == operator
      21             : //
      22             : #pragma GCC diagnostic ignored "-Wfloat-equal"
      23             : 
      24             : // self
      25             : //
      26             : #include    "catch_main.h"
      27             : 
      28             : 
      29             : // reporter
      30             : //
      31             : #include    <eventdispatcher/reporter/statement.h>
      32             : 
      33             : #include    <eventdispatcher/reporter/instruction_factory.h>
      34             : 
      35             : 
      36             : // last include
      37             : //
      38             : #include    <snapdev/poison.h>
      39             : 
      40             : 
      41             : 
      42             : namespace
      43             : {
      44             : 
      45             : 
      46             : 
      47             : 
      48             : } // no name namespace
      49             : 
      50             : 
      51             : 
      52           1 : CATCH_TEST_CASE("reporter_statement", "[statement][reporter]")
      53             : {
      54           1 :     CATCH_START_SECTION("verify basic program")
      55             :     {
      56           3 :         SNAP_CATCH2_NAMESPACE::reporter::instruction::pointer_t if_inst(SNAP_CATCH2_NAMESPACE::reporter::get_instruction("if"));
      57           1 :         SNAP_CATCH2_NAMESPACE::reporter::statement::pointer_t s(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::statement>(if_inst));
      58           1 :         CATCH_REQUIRE(s->get_instruction() == if_inst);
      59             : 
      60             :         // create an expression with 3.1 + 2.9
      61             :         //
      62           1 :         SNAP_CATCH2_NAMESPACE::reporter::token t1;
      63           1 :         t1.set_token(SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
      64           1 :         t1.set_string("unordered_label");
      65           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t c1(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      66           1 :         c1->set_operator(SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_PRIMARY);
      67           1 :         c1->set_token(t1);
      68           1 :         s->add_parameter("unordered", c1);
      69             : 
      70           1 :         SNAP_CATCH2_NAMESPACE::reporter::token t2;
      71           1 :         t2.set_token(SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
      72           1 :         t2.set_string("less_label");
      73           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t c2(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      74           1 :         c2->set_operator(SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_PRIMARY);
      75           1 :         c2->set_token(t2);
      76           1 :         s->add_parameter("less", c2);
      77             : 
      78           1 :         SNAP_CATCH2_NAMESPACE::reporter::token t3;
      79           1 :         t3.set_token(SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
      80           1 :         t3.set_string("equal_label");
      81           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t c3(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      82           1 :         c3->set_operator(SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_PRIMARY);
      83           1 :         c3->set_token(t3);
      84           1 :         s->add_parameter("equal", c3);
      85             : 
      86           1 :         SNAP_CATCH2_NAMESPACE::reporter::token t4;
      87           1 :         t4.set_token(SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_IDENTIFIER);
      88           1 :         t4.set_string("greater_label");
      89           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t c4(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      90           1 :         c4->set_operator(SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_PRIMARY);
      91           1 :         c4->set_token(t4);
      92           1 :         s->add_parameter("greater", c4);
      93             : 
      94           1 :         CATCH_REQUIRE(s->get_parameter("unordered") == c1);
      95           1 :         CATCH_REQUIRE(s->get_parameter("less") == c2);
      96           1 :         CATCH_REQUIRE(s->get_parameter("equal") == c3);
      97           1 :         CATCH_REQUIRE(s->get_parameter("greater") == c4);
      98           1 :         CATCH_REQUIRE(s->get_parameter("not-added") == SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t());
      99           1 :     }
     100           1 :     CATCH_END_SECTION()
     101           1 : }
     102             : 
     103             : 
     104           1 : CATCH_TEST_CASE("reporter_statement_error", "[statement][reporter][error]")
     105             : {
     106           1 :     CATCH_START_SECTION("statement without instruction")
     107             :     {
     108           3 :         CATCH_REQUIRE_THROWS_MATCHES(
     109             :               SNAP_CATCH2_NAMESPACE::reporter::statement(nullptr)
     110             :             , std::logic_error
     111             :             , Catch::Matchers::ExceptionMessage(
     112             :                       "an instruction must always be attached to a statement."));
     113             :     }
     114           1 :     CATCH_END_SECTION()
     115           1 : }
     116             : 
     117             : 
     118             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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