LCOV - code coverage report
Current view: top level - tests - catch_routes.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 35 100.0 %
Date: 2022-06-26 14:27:46 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2011-2022  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/libaddr
       4             : // contact@m2osw.com
       5             : //
       6             : // Permission is hereby granted, free of charge, to any
       7             : // person obtaining a copy of this software and
       8             : // associated documentation files (the "Software"), to
       9             : // deal in the Software without restriction, including
      10             : // without limitation the rights to use, copy, modify,
      11             : // merge, publish, distribute, sublicense, and/or sell
      12             : // copies of the Software, and to permit persons to whom
      13             : // the Software is furnished to do so, subject to the
      14             : // following conditions:
      15             : //
      16             : // The above copyright notice and this permission notice
      17             : // shall be included in all copies or substantial
      18             : // portions of the Software.
      19             : //
      20             : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      21             : // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      22             : // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      23             : // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      24             : // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      25             : // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      26             : // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      27             : // ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      28             : // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      29             : // SOFTWARE.
      30             : 
      31             : /** \file
      32             :  * \brief Verify the route class a little further.
      33             :  *
      34             :  * This file implements a test that verifies a few additional things
      35             :  * in the route table.
      36             :  */
      37             : 
      38             : // libaddr
      39             : //
      40             : #include    <libaddr/route.h>
      41             : 
      42             : 
      43             : // self
      44             : //
      45             : #include    "catch_main.h"
      46             : 
      47             : 
      48             : 
      49             : // C
      50             : //
      51             : #include    <net/if.h>
      52             : #include    <net/route.h>
      53             : 
      54             : 
      55             : // last include
      56             : //
      57             : #include    <snapdev/poison.h>
      58             : 
      59             : 
      60             : 
      61           4 : CATCH_TEST_CASE("ipv4::routes", "[ipv4]")
      62             : {
      63           4 :     CATCH_GIVEN("route::get_ipv4_routes()")
      64             :     {
      65           4 :         addr::route::vector_t routes(addr::route::get_ipv4_routes());
      66           4 :         addr::route::vector_t routes_without_default;
      67             : 
      68           4 :         CATCH_START_SECTION("routes: verify list")
      69             :         {
      70           1 :             CATCH_REQUIRE_FALSE(routes.empty()); // at least the default route
      71             : 
      72             :             // check a few things
      73             :             //
      74           1 :             bool found_default(false);
      75           1 :             bool found_gateway(false);
      76          12 :             for(auto r : routes)
      77             :             {
      78          11 :                 CATCH_REQUIRE_FALSE(r->get_interface_name().empty());
      79          11 :                 CATCH_REQUIRE(r->get_interface_name().length() < IFNAMSIZ); // IFNAMSIZ includes the '\0' so '<' and not '<='
      80             : 
      81             :                 // at least one flag is not zero
      82          11 :                 int const f(r->get_flags());
      83          22 :                 std::string const flags(r->flags_to_string());
      84             : 
      85          11 :                 CATCH_REQUIRE(f != 0);
      86          11 :                 CATCH_REQUIRE(!flags.empty());
      87             : 
      88          11 :                 if(r->get_destination_address().is_default())
      89             :                 {
      90           1 :                     CATCH_REQUIRE_FALSE(found_default);
      91           1 :                     found_default = true;
      92             : 
      93           1 :                     CATCH_REQUIRE((f & RTF_UP) != 0);
      94             :                 }
      95             :                 else
      96             :                 {
      97          10 :                     routes_without_default.push_back(r);
      98             :                 }
      99             : 
     100          11 :                 if(!r->get_gateway_address().is_default())
     101             :                 {
     102           1 :                     CATCH_REQUIRE_FALSE(found_gateway);
     103           1 :                     found_gateway = true;
     104             : 
     105           1 :                     CATCH_REQUIRE((f & RTF_GATEWAY) != 0);
     106             :                 }
     107             : 
     108             :                 // Not much I can test on the following?
     109             :                 //r->get_flags()
     110          11 :                 CATCH_REQUIRE(r->get_reference_count() >= 0);
     111          11 :                 CATCH_REQUIRE(r->get_use() >= 0);
     112          11 :                 CATCH_REQUIRE(r->get_metric() >= 0);
     113          11 :                 CATCH_REQUIRE(r->get_mtu() >= 0);
     114          11 :                 CATCH_REQUIRE(r->get_window() >= 0);
     115          11 :                 CATCH_REQUIRE(r->get_irtt() >= 0);
     116             :             }
     117           1 :             CATCH_REQUIRE(found_default);
     118           1 :             CATCH_REQUIRE(found_gateway);
     119             :         }
     120             :         CATCH_END_SECTION()
     121             : 
     122           4 :         CATCH_START_SECTION("routes: verify a search without a default route")
     123             :         {
     124           1 :             CATCH_REQUIRE(find_default_route(routes_without_default) == nullptr);
     125             :         }
     126             :         CATCH_END_SECTION()
     127             :     }
     128           8 : }
     129             : 
     130             : 
     131             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13