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: 2023-05-29 16:11:08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14