LCOV - code coverage report
Current view: top level - tests - catch_main.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 34 97.1 %
Date: 2024-02-03 18:59:18 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2006-2024  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/prinbee
       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             : // prinbee
      26             : //
      27             : #include    <prinbee/bigint/uint512.h>
      28             : 
      29             : 
      30             : // C++
      31             : //
      32             : #include    <string>
      33             : #include    <cstring>
      34             : #include    <cstdlib>
      35             : #include    <iostream>
      36             : 
      37             : 
      38             : 
      39             : namespace SNAP_CATCH2_NAMESPACE
      40             : {
      41             : 
      42             : 
      43             : 
      44             : std::string setup_context(std::string const & path, std::vector<std::string> const & xmls);
      45             : 
      46             : 
      47             : inline char32_t rand_char(bool full_range = false)
      48             : {
      49             :     // -1 so we can avoid '\0' which in most cases is not useful
      50             :     //
      51             :     char32_t const max((full_range ? 0x0110000 : 0x0010000) - (0xE000 - 0xD800) - 1);
      52             : 
      53             :     char32_t const wc(((rand() << 16) ^ rand()) % max + 1);
      54             : 
      55             :     // skip the surrogates for the larger characters
      56             :     //
      57             :     return wc >= 0xD800 ?  wc + (0xE000 - 0xD800) : wc;
      58             : }
      59             : 
      60             : 
      61         854 : inline std::string rand_string(int len = rand() % 200 + 10)
      62             : {
      63         854 :     std::string result;
      64    20005564 :     for(int i(0); i < len; ++i)
      65             :     {
      66    20004710 :         result += rand() % 26 + 'a';
      67             :     }
      68         854 :     return result;
      69           0 : }
      70             : 
      71             : 
      72        1022 : inline std::uint32_t rand32()
      73             : {
      74        1022 :     return rand() ^ (rand() << 16);
      75             : }
      76             : 
      77             : 
      78       52765 : inline std::uint64_t rand64()
      79             : {
      80       52765 :     std::uint64_t const a(rand());
      81       52765 :     std::uint64_t const b(rand());
      82       52765 :     std::uint64_t const c(rand());
      83       52765 :     std::uint64_t const d(rand());
      84       52765 :     return a ^ (b << 16) ^ (c << 32) ^ (d << 48);
      85             : }
      86             : 
      87             : 
      88             : #pragma GCC diagnostic push
      89             : #pragma GCC diagnostic ignored "-Wpedantic"
      90         497 : inline unsigned __int128 rand128()
      91             : {
      92         497 :     unsigned __int128 const a(rand());
      93         497 :     unsigned __int128 const b(rand());
      94         497 :     unsigned __int128 const c(rand());
      95         497 :     unsigned __int128 const d(rand());
      96         497 :     unsigned __int128 const e(rand());
      97         497 :     unsigned __int128 const f(rand());
      98         497 :     unsigned __int128 const g(rand());
      99         497 :     unsigned __int128 const h(rand());
     100         497 :     return (a <<  0) ^ (b << 16) ^ (c << 32) ^ (d <<  48)
     101         497 :          ^ (e << 64) ^ (f << 80) ^ (g << 96) ^ (h << 112);
     102             : }
     103             : #pragma GCC diagnostic pop
     104             : 
     105             : 
     106        1849 : inline void rand512(prinbee::uint512_t & a)
     107             : {
     108       16641 :     for(std::size_t i(0); i < 8; ++i)
     109             :     {
     110       14792 :         a.f_value[i] = SNAP_CATCH2_NAMESPACE::rand64();
     111             :     }
     112        1849 : }
     113             : 
     114             : 
     115         500 : inline void rand512(prinbee::int512_t & a)
     116             : {
     117        4000 :     for(std::size_t i(0); i < 7; ++i)
     118             :     {
     119        3500 :         a.f_value[i] = SNAP_CATCH2_NAMESPACE::rand64();
     120             :     }
     121         500 :     a.f_high_value = SNAP_CATCH2_NAMESPACE::rand64();
     122         500 : }
     123             : 
     124             : 
     125             : 
     126             : } // namespace SNAP_CATCH2_NAMESPACE
     127             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

Snap C++ | List of projects | List of versions