LCOV - code coverage report
Current view: top level - tests - catch_version.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 26 26 100.0 %
Date: 2023-05-29 16:11:08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2018-2023  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdev
       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             : /** \file
      20             :  * \brief Verify the version macros.
      21             :  *
      22             :  * This file implements tests for the version macros.
      23             :  */
      24             : 
      25             : // self
      26             : //
      27             : #include    <snapdev/version.h>
      28             : 
      29             : #include    "catch_main.h"
      30             : 
      31             : 
      32             : // last include
      33             : //
      34             : #include    <snapdev/poison.h>
      35             : 
      36             : 
      37             : 
      38             : 
      39           4 : CATCH_TEST_CASE("version", "[version]")
      40             : {
      41           4 :     CATCH_START_SECTION("version: snapdev version")
      42             :     {
      43           1 :         std::string v;
      44           1 :         v += std::to_string(SNAPDEV_VERSION_MAJOR);
      45           1 :         v += '.';
      46           1 :         v += std::to_string(SNAPDEV_VERSION_MINOR);
      47           1 :         v += '.';
      48           1 :         v += std::to_string(SNAPDEV_VERSION_PATCH);
      49             : 
      50           1 :         CATCH_REQUIRE(SNAPDEV_VERSION_STRING == v);
      51           1 :     }
      52           4 :     CATCH_END_SECTION()
      53             : 
      54           4 :     CATCH_START_SECTION("version: check wanted/current version")
      55             :     {
      56             :         // we probably will never reach version 1 billion...
      57             :         //
      58           1 :         bool const result(SNAPDEV_CHECK_VERSION(1'000'000'000, 555, 123, SNAPDEV_VERSION_MAJOR, SNAPDEV_VERSION_MINOR, SNAPDEV_VERSION_PATCH));
      59           1 :         CATCH_REQUIRE_FALSE(result);
      60             :     }
      61           4 :     CATCH_END_SECTION()
      62             : 
      63           4 :     CATCH_START_SECTION("version: check explicit versions")
      64             :     {
      65             :         // now compare explicit versions on both sides to make sure we got that right
      66             :         //
      67             :         struct wanted_t
      68             :         {
      69             :             int     f_wanted_major = 0;
      70             :             int     f_wanted_minor = 0;
      71             :             int     f_wanted_patch = 0;
      72             :             int     f_current_major = 0;
      73             :             int     f_current_minor = 0;
      74             :             int     f_current_patch = 0;
      75             :             bool    f_result = false;
      76             :         };
      77             : 
      78           1 :         constexpr wanted_t const wanted[] =
      79             :         {
      80             :             // true if left version <= to right version
      81             :             { 7, 3,  9, 7, 3,  9, true  },
      82             :             { 7, 3,  9, 7, 3, 10, true  },
      83             :             { 7, 3, 11, 7, 3, 10, false },
      84             :             { 7, 4,  9, 7, 3, 10, false },
      85             :             { 7, 2, 11, 7, 3, 10, true  },
      86             :             { 8, 3,  9, 7, 3,  9, false },
      87             :             { 7, 3,  9, 8, 3,  9, true  },
      88             :             { 8, 2,  9, 7, 3,  9, false },
      89             :             { 7, 9,  9, 8, 3,  9, true  },
      90             :             { 7, 9,  9, 8, 3,  1, true  },
      91             :             { 7, 0,  0, 8, 0,  0, true  },
      92             :             { 8, 0,  0, 8, 0,  0, true  },
      93             :             { 9, 0,  0, 8, 0,  0, false },
      94             :         };
      95             : 
      96          14 :         for(std::size_t idx(0); idx < std::size(wanted); ++idx)
      97             :         {
      98          13 :             bool const result(SNAPDEV_CHECK_VERSION(
      99             :                             wanted[idx].f_wanted_major,
     100             :                             wanted[idx].f_wanted_minor,
     101             :                             wanted[idx].f_wanted_patch,
     102             :                             wanted[idx].f_current_major,
     103             :                             wanted[idx].f_current_minor,
     104             :                             wanted[idx].f_current_patch));
     105             : 
     106             : //std::cout << "--- compare versions "
     107             : //<< wanted[idx].f_wanted_major << '.' << wanted[idx].f_wanted_minor << '.' << wanted[idx].f_wanted_patch
     108             : //<< " <=> "
     109             : //<< wanted[idx].f_current_major << '.' << wanted[idx].f_current_minor << '.' << wanted[idx].f_current_patch
     110             : //<< " -> " << result << " (expected: " << wanted[idx].f_result << ")\n";
     111             : 
     112          13 :             CATCH_REQUIRE(wanted[idx].f_result == result);
     113             :         }
     114             :     }
     115           4 :     CATCH_END_SECTION()
     116             : 
     117           4 :     CATCH_START_SECTION("version: we need at least g++ 7.x")
     118             :     {
     119           1 :         bool const wanted(SNAPDEV_CHECK_GCC_VERSION(7, 5, 0));
     120           1 :         CATCH_REQUIRE(wanted);
     121             :     }
     122           4 :     CATCH_END_SECTION()
     123           4 : }
     124             : 
     125             : 
     126             : 
     127             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14