LCOV - code coverage report
Current view: top level - tests - catch_reporter_expression.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 40 40 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             : 
      23             : // self
      24             : //
      25             : #include    "catch_main.h"
      26             : 
      27             : 
      28             : // reporter
      29             : //
      30             : #include    <eventdispatcher/reporter/expression.h>
      31             : 
      32             : 
      33             : // last include
      34             : //
      35             : #include    <snapdev/poison.h>
      36             : 
      37             : 
      38             : 
      39             : namespace
      40             : {
      41             : 
      42             : 
      43             : constexpr SNAP_CATCH2_NAMESPACE::reporter::operator_t const g_all_operators[] =
      44             : {
      45             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_NULL,
      46             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_NAMED,
      47             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_LIST,
      48             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_PRIMARY,
      49             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_IDENTITY,
      50             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_NEGATE,
      51             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_ADD,
      52             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_SUBTRACT,
      53             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_MULTIPLY,
      54             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_DIVIDE,
      55             :     SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_MODULO,
      56             : };
      57             : 
      58             : 
      59             : } // no name namespace
      60             : 
      61             : 
      62             : 
      63           2 : CATCH_TEST_CASE("reporter_token", "[operator][reporter]")
      64             : {
      65           2 :     CATCH_START_SECTION("set/get operator")
      66             :     {
      67          12 :         for(auto const op : g_all_operators)
      68             :         {
      69          11 :             SNAP_CATCH2_NAMESPACE::reporter::expression e;
      70          11 :             CATCH_REQUIRE(e.get_operator() == SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_NULL);
      71          11 :             e.set_operator(op);
      72          11 :             CATCH_REQUIRE(e.get_operator() == op);
      73          11 :         }
      74             :     }
      75           2 :     CATCH_END_SECTION()
      76             : 
      77           2 :     CATCH_START_SECTION("ADD of two integers")
      78             :     {
      79           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t e(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      80           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t l(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      81           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression::pointer_t r(std::make_shared<SNAP_CATCH2_NAMESPACE::reporter::expression>());
      82           1 :         CATCH_REQUIRE(e->get_expression_size() == 0);
      83           1 :         CATCH_REQUIRE(l->get_expression_size() == 0);
      84           1 :         CATCH_REQUIRE(r->get_expression_size() == 0);
      85           1 :         e->set_operator(SNAP_CATCH2_NAMESPACE::reporter::operator_t::OPERATOR_ADD);
      86           1 :         SNAP_CATCH2_NAMESPACE::reporter::token t;
      87           1 :         t.set_token(SNAP_CATCH2_NAMESPACE::reporter::token_t::TOKEN_INTEGER);
      88           1 :         t.set_integer(55);
      89           1 :         l->set_token(t);
      90           1 :         t.set_integer(105); // expressions make a copy of the token so we can reuse it
      91           1 :         r->set_token(t);
      92           1 :         e->add_expression(l);
      93           1 :         e->add_expression(r);    // here 'e' represents "55 + 105"
      94             : 
      95           1 :         CATCH_REQUIRE(e->get_expression_size() == 2ULL);
      96           1 :         CATCH_REQUIRE(e->get_expression(0) == l);
      97           1 :         CATCH_REQUIRE(e->get_expression(1) == r);
      98           1 :         CATCH_REQUIRE(e->get_expression(0)->get_token().get_integer() == 55);
      99           1 :         CATCH_REQUIRE(e->get_expression(1)->get_token().get_integer() == 105);
     100           1 :     }
     101           2 :     CATCH_END_SECTION()
     102           2 : }
     103             : 
     104             : 
     105           1 : CATCH_TEST_CASE("reporter_expression_error", "[operator][reporter][error]")
     106             : {
     107           1 :     CATCH_START_SECTION("get expression out of bounds")
     108             :     {
     109           1 :         SNAP_CATCH2_NAMESPACE::reporter::expression e;
     110           1 :         CATCH_REQUIRE_THROWS_MATCHES(
     111             :                   e.get_expression(0)
     112             :                 , std::overflow_error
     113             :                 , Catch::Matchers::ExceptionMessage(
     114             :                           "index too large to get sub-expression."));
     115           1 :     }
     116           1 :     CATCH_END_SECTION()
     117           1 : }
     118             : 
     119             : 
     120             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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