LCOV - code coverage report
Current view: top level - tests - test_addr_routes.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 35 100.0 %
Date: 2019-09-02 12:15:29 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* test_addr_routes.cpp
       2             :  * Copyright (c) 2011-2019  Made to Order Software Corp.  All Rights Reserved
       3             :  *
       4             :  * Project: https://snapwebsites.org/project/libaddr
       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             : 
      32             : /** \file
      33             :  * \brief Verify the route class a little further.
      34             :  *
      35             :  * This file implements a test that verifies a few additional things
      36             :  * in the route table.
      37             :  */
      38             : 
      39             : // self
      40             : //
      41             : #include "test_addr_main.h"
      42             : 
      43             : // addr lib
      44             : //
      45             : #include "libaddr/route.h"
      46             : 
      47             : // C lib
      48             : //
      49             : #include <net/if.h>
      50             : #include <net/route.h>
      51             : 
      52             : 
      53           4 : CATCH_TEST_CASE( "ipv4::routes", "[ipv4]" )
      54             : {
      55           4 :     CATCH_GIVEN("route::get_ipv4_routes()")
      56             :     {
      57           4 :         addr::route::vector_t routes(addr::route::get_ipv4_routes());
      58           4 :         addr::route::vector_t routes_without_default;
      59             : 
      60           4 :         CATCH_SECTION("verify list")
      61             :         {
      62           1 :             CATCH_REQUIRE_FALSE(routes.empty()); // at least the default route
      63             : 
      64             :             // check a few things
      65             :             //
      66           1 :             bool found_default(false);
      67           1 :             bool found_gateway(false);
      68           8 :             for(auto r : routes)
      69             :             {
      70           7 :                 CATCH_REQUIRE_FALSE(r->get_interface_name().empty());
      71           7 :                 CATCH_REQUIRE(r->get_interface_name().length() < IFNAMSIZ - 1); // IFNAMSIZ includes the '\0'
      72             : 
      73             :                 // at least one flag is not zero
      74           7 :                 int const f(r->get_flags());
      75          14 :                 std::string const flags(r->flags_to_string());
      76             : 
      77           7 :                 CATCH_REQUIRE(f != 0);
      78           7 :                 CATCH_REQUIRE(!flags.empty());
      79             : 
      80           7 :                 if(r->get_destination_address().is_default())
      81             :                 {
      82           1 :                     CATCH_REQUIRE_FALSE(found_default);
      83           1 :                     found_default = true;
      84             : 
      85           1 :                     CATCH_REQUIRE((f & RTF_UP) != 0);
      86             :                 }
      87             :                 else
      88             :                 {
      89           6 :                     routes_without_default.push_back(r);
      90             :                 }
      91             : 
      92           7 :                 if(!r->get_gateway_address().is_default())
      93             :                 {
      94           1 :                     CATCH_REQUIRE_FALSE(found_gateway);
      95           1 :                     found_gateway = true;
      96             : 
      97           1 :                     CATCH_REQUIRE((f & RTF_GATEWAY) != 0);
      98             :                 }
      99             : 
     100             :                 // Not much I can test on the following?
     101             :                 //r->get_flags()
     102           7 :                 CATCH_REQUIRE(r->get_reference_count() >= 0);
     103           7 :                 CATCH_REQUIRE(r->get_use() >= 0);
     104           7 :                 CATCH_REQUIRE(r->get_metric() >= 0);
     105           7 :                 CATCH_REQUIRE(r->get_mtu() >= 0);
     106           7 :                 CATCH_REQUIRE(r->get_window() >= 0);
     107           7 :                 CATCH_REQUIRE(r->get_irtt() >= 0);
     108             :             }
     109           1 :             CATCH_REQUIRE(found_default);
     110           1 :             CATCH_REQUIRE(found_gateway);
     111             :         }
     112             : 
     113           4 :         CATCH_SECTION("verify a search without a default route")
     114             :         {
     115           1 :             CATCH_REQUIRE(find_default_route(routes_without_default) == nullptr);
     116             :         }
     117             :     }
     118           8 : }
     119             : 
     120             : 
     121             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12