LCOV - code coverage report
Current view: top level - tests - catch_main.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2022-07-09 19:51:09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2006-2022  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/
       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 2 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 along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : #pragma once
      20             : 
      21             : #include    <string>
      22             : #include    <cstring>
      23             : #include    <cstdlib>
      24             : #include    <iostream>
      25             : 
      26             : #include    <boost/preprocessor/stringize.hpp>
      27             : 
      28             : #include    <catch2/snapcatch2.hpp>
      29             : 
      30             : 
      31             : // The message() can be used to verify that version
      32             : //
      33             : //#pragma message("Building unit tests with Catch2 version " BOOST_PP_STRINGIZE(CATCH_VERSION_MAJOR) "." BOOST_PP_STRINGIZE(CATCH_VERSION_MINOR) "." BOOST_PP_STRINGIZE(CATCH_VERSION_PATCH))
      34             : 
      35             : #pragma GCC diagnostic pop
      36             : 
      37             : 
      38             : namespace SNAP_CATCH2_NAMESPACE
      39             : {
      40             : 
      41             : 
      42             : 
      43             : class obj_setenv
      44             : {
      45             : public:
      46             :     obj_setenv(const std::string& var)
      47             :         : f_copy(strdup(var.c_str()))
      48             :     {
      49             :         putenv(f_copy);
      50             :         std::string::size_type p(var.find_first_of('='));
      51             :         f_name = var.substr(0, p);
      52             :     }
      53             :     obj_setenv(obj_setenv const & rhs) = delete;
      54             :     obj_setenv & operator = (obj_setenv const & rhs) = delete;
      55             :     ~obj_setenv()
      56             :     {
      57             :         putenv(strdup((f_name + "=").c_str()));
      58             :         free(f_copy);
      59             :     }
      60             : 
      61             : private:
      62             :     char *          f_copy = nullptr;
      63             :     std::string     f_name = std::string();
      64             : };
      65             : 
      66             : 
      67             : inline char32_t rand_char(bool full_range = false)
      68             : {
      69             :     char32_t const max((full_range ? 0x0110000 : 0x0010000) - (0xE000 - 0xD800));
      70             : 
      71             :     char32_t wc;
      72             :     do
      73             :     {
      74             :         wc = ((rand() << 16) ^ rand()) % max;
      75             :     }
      76             :     while(wc == 0);
      77             :     if(wc >= 0xD800)
      78             :     {
      79             :         // skip the surrogates
      80             :         //
      81             :         wc += 0xE000 - 0xD800;
      82             :     }
      83             : 
      84             :     return wc;
      85             : }
      86             : 
      87             : 
      88          10 : inline std::int64_t rand_int64()
      89             : {
      90          10 :     return (static_cast<std::int64_t>(rand()) << 48)
      91          10 :          | (static_cast<std::int64_t>(rand()) << 32)
      92          10 :          | (static_cast<std::int64_t>(rand()) << 16)
      93          10 :          | (static_cast<std::int64_t>(rand()) <<  0);
      94             : }
      95             : 
      96             : 
      97             : 
      98             : }
      99             : // unittest namespace
     100             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13