LCOV - code coverage report
Current view: top level - tests - catch_convert.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1924 1957 98.3 %
Date: 2024-02-03 18:59:18 Functions: 17 17 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2019-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             : 
      19             : // self
      20             : //
      21             : #include    "catch_main.h"
      22             : 
      23             : 
      24             : // prinbee
      25             : //
      26             : #include    <prinbee/exception.h>
      27             : #include    <prinbee/data/convert.h>
      28             : 
      29             : 
      30             : // snapdev
      31             : //
      32             : #include    <snapdev/hexadecimal_string.h>
      33             : #include    <snapdev/math.h>
      34             : #include    <snapdev/ostream_int128.h>
      35             : 
      36             : 
      37             : // C++
      38             : //
      39             : #include    <fstream>
      40             : #include    <iomanip>
      41             : 
      42             : 
      43             : // C
      44             : //
      45             : #include    <sys/stat.h>
      46             : #include    <sys/types.h>
      47             : 
      48             : 
      49             : // last include
      50             : //
      51             : #include    <snapdev/poison.h>
      52             : 
      53             : 
      54             : namespace
      55             : {
      56             : 
      57             : 
      58     3569976 : std::string decorate(std::string s)
      59             : {
      60     3569976 :     if(s[0] != '-'
      61     3569976 :     && (rand() % 3) == 0)
      62             :     {
      63      903940 :         s = '+' + s;
      64             :     }
      65     7144114 :     while((rand() & 1) != 0)
      66             :     {
      67     3574138 :         s = ' ' + s;
      68             :     }
      69     7144318 :     while((rand() & 1) != 0)
      70             :     {
      71     3574342 :         s += ' ';
      72             :     }
      73     3569976 :     return s;
      74             : }
      75             : 
      76             : 
      77             : template<typename T>
      78        2158 : std::string to_binary(T const n)
      79             : {
      80        2158 :     std::stringstream ss;
      81        2158 :     ss << std::bitset<sizeof(T) * 8>(n).to_string(); // fun but adds leading '0's
      82        2158 :     std::string result(ss.str());
      83        2158 :     std::string::size_type const pos(result.find('1'));
      84        2158 :     if(pos == std::string::npos)
      85             :     {
      86           0 :         return "0";
      87             :     }
      88        2158 :     return result.substr(pos);
      89        2158 : }
      90             : 
      91             : 
      92             : template<>
      93         398 : std::string to_binary(prinbee::uint512_t const n)
      94             : {
      95         398 :     if(n.is_zero())
      96             :     {
      97           0 :         return "0";
      98             :     }
      99         398 :     prinbee::uint512_t b;
     100         398 :     b.f_value[7] = 0x8000000000000000ULL;
     101       51109 :     for(;; b >>= 1)
     102             :     {
     103       51507 :         if((n & b) != 0)
     104             :         {
     105         398 :             break;
     106             :         }
     107             :     }
     108         398 :     std::string result;
     109      153065 :     while(!b.is_zero())
     110             :     {
     111      152667 :         result += (n & b) != 0 ? '1' : '0';
     112      152667 :         b >>= 1;
     113             :     }
     114         398 :     return result;
     115         398 : }
     116             : 
     117             : 
     118             : template<>
     119         198 : std::string to_binary(prinbee::int512_t const n)
     120             : {
     121         198 :     if(n.is_zero())
     122             :     {
     123           0 :         return "0";
     124             :     }
     125         198 :     prinbee::uint512_t a;
     126         198 :     if(n < 0)
     127             :     {
     128           0 :         a = -n;
     129             :     }
     130             :     else
     131             :     {
     132         198 :         a = n;
     133             :     }
     134         198 :     prinbee::uint512_t b;
     135         198 :     b.f_value[7] = 0x8000000000000000ULL;
     136       25699 :     for(;; b >>= 1)
     137             :     {
     138       25897 :         if((a & b) != 0)
     139             :         {
     140         198 :             break;
     141             :         }
     142             :     }
     143         198 :     std::string result;
     144       75875 :     while(!b.is_zero())
     145             :     {
     146       75677 :         result += (a & b) != 0 ? '1' : '0';
     147       75677 :         b >>= 1;
     148             :     }
     149         198 :     return result;
     150         198 : }
     151             : 
     152             : 
     153             : } // no name namespace
     154             : 
     155             : 
     156             : 
     157           2 : CATCH_TEST_CASE("convert_8bit", "[convert] [valid]")
     158             : {
     159           2 :     CATCH_START_SECTION("convert_8bit: uint8_t")
     160             :     {
     161         257 :         for(uint32_t i(0); i < (1ULL << 8); ++i)
     162             :         {
     163             :             {
     164         256 :                 std::stringstream ss;
     165         256 :                 ss << i;
     166         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     167         256 :                 CATCH_REQUIRE(c == i);
     168         256 :             }
     169             : 
     170             :             {
     171         256 :                 std::stringstream ss;
     172         256 :                 ss << "0x" << std::hex << std::uppercase << i;
     173         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     174         256 :                 CATCH_REQUIRE(c == i);
     175         256 :             }
     176             : 
     177             :             {
     178         256 :                 std::stringstream ss;
     179         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     180         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     181         256 :                 CATCH_REQUIRE(c == i);
     182         256 :             }
     183             : 
     184             :             {
     185         256 :                 std::stringstream ss;
     186         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     187         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     188         256 :                 CATCH_REQUIRE(c == i);
     189         256 :             }
     190             : 
     191             :             {
     192         256 :                 std::stringstream ss;
     193         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     194         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     195         256 :                 CATCH_REQUIRE(c == i);
     196         256 :             }
     197             : 
     198             :             {
     199         256 :                 std::stringstream ss;
     200         256 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     201         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     202         256 :                 CATCH_REQUIRE(c == i);
     203         256 :             }
     204             : 
     205             :             {
     206         256 :                 std::stringstream ss;
     207         256 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     208         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     209         256 :                 CATCH_REQUIRE(c == i);
     210         256 :             }
     211             : 
     212             :             {
     213         256 :                 std::stringstream ss;
     214         256 :                 ss << "x'" << std::hex << i << '\'';
     215         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     216         256 :                 CATCH_REQUIRE(c == i);
     217         256 :             }
     218             : 
     219             :             {
     220         256 :                 std::stringstream ss;
     221         256 :                 ss << "X'" << std::hex << i << '\'';
     222         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     223         256 :                 CATCH_REQUIRE(c == i);
     224         256 :             }
     225             : 
     226             :             {
     227         256 :                 std::stringstream ss;
     228         256 :                 ss << "0" << std::oct << i;
     229         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 8));
     230         256 :                 CATCH_REQUIRE(c == i);
     231         256 :             }
     232             : 
     233         256 :             uint32_t v(i);
     234         256 :             std::string r;
     235        2049 :             while(v != 0)
     236             :             {
     237        1793 :                 r += (v & 1) + '0';
     238        1793 :                 v >>= 1;
     239             :             }
     240         256 :             std::reverse(r.begin(), r.end());
     241         256 :             r = "0b" + r;
     242             :             {
     243         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 8));
     244         256 :                 CATCH_REQUIRE(c == i);
     245             :             }
     246             : 
     247         256 :             r[1] &= 0x5F;
     248             :             {
     249         256 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 8));
     250         256 :                 CATCH_REQUIRE(c == i);
     251             :             }
     252         256 :         }
     253             :     }
     254           2 :     CATCH_END_SECTION()
     255             : 
     256           2 :     CATCH_START_SECTION("convert_8bit: int8_t")
     257             :     {
     258         257 :         for(uint32_t i(0); i < (1ULL << 8); ++i)
     259             :         {
     260             :             {
     261         256 :                 std::stringstream ss;
     262         256 :                 ss << i;
     263         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     264         256 :                 CATCH_REQUIRE(c == i);
     265         256 :             }
     266             : 
     267             :             {
     268         256 :                 std::stringstream ss;
     269         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     270         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     271         256 :                 CATCH_REQUIRE(c == i);
     272         256 :             }
     273             : 
     274             :             {
     275         256 :                 std::stringstream ss;
     276         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     277         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     278         256 :                 CATCH_REQUIRE(c == i);
     279         256 :             }
     280             : 
     281             :             {
     282         256 :                 std::stringstream ss;
     283         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     284         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     285         256 :                 CATCH_REQUIRE(c == i);
     286         256 :             }
     287             : 
     288             :             {
     289         256 :                 std::stringstream ss;
     290         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     291         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     292         256 :                 CATCH_REQUIRE(c == i);
     293         256 :             }
     294             : 
     295             :             {
     296         256 :                 std::stringstream ss;
     297         256 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     298         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     299         256 :                 CATCH_REQUIRE(c == i);
     300         256 :             }
     301             : 
     302             :             {
     303         256 :                 std::stringstream ss;
     304         256 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     305         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     306         256 :                 CATCH_REQUIRE(c == i);
     307         256 :             }
     308             : 
     309             :             {
     310         256 :                 std::stringstream ss;
     311         256 :                 ss << "x'" << std::hex << i << '\'';
     312         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     313         256 :                 CATCH_REQUIRE(c == i);
     314         256 :             }
     315             : 
     316             :             {
     317         256 :                 std::stringstream ss;
     318         256 :                 ss << "X'" << std::hex << i << '\'';
     319         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     320         256 :                 CATCH_REQUIRE(c == i);
     321         256 :             }
     322             : 
     323             :             {
     324         256 :                 std::stringstream ss;
     325         256 :                 ss << "0" << std::oct << i;
     326         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 8));
     327         256 :                 CATCH_REQUIRE(c == i);
     328         256 :             }
     329             : 
     330         256 :             uint32_t v(i);
     331         256 :             std::string r;
     332        2049 :             while(v != 0)
     333             :             {
     334        1793 :                 r += (v & 1) + '0';
     335        1793 :                 v >>= 1;
     336             :             }
     337         256 :             std::reverse(r.begin(), r.end());
     338         256 :             r = "0b" + r;
     339             :             {
     340         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(r), 8));
     341         256 :                 CATCH_REQUIRE(c == i);
     342             :             }
     343             : 
     344         256 :             r[1] &= 0x5F;
     345             :             {
     346         256 :                 uint64_t const c(prinbee::convert_to_int(decorate(r), 8));
     347         256 :                 CATCH_REQUIRE(c == i);
     348             :             }
     349         256 :         }
     350             :     }
     351           2 :     CATCH_END_SECTION()
     352           2 : }
     353             : 
     354             : 
     355           2 : CATCH_TEST_CASE("convert_16bit", "[convert] [valid]")
     356             : {
     357           2 :     CATCH_START_SECTION("convert_16bit: uint16_t")
     358             :     {
     359        4996 :         for(uint32_t i(0); i < (1ULL << 16); i += rand() % 27)
     360             :         {
     361             :             {
     362        4995 :                 std::stringstream ss;
     363        4995 :                 ss << i;
     364        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     365        4995 :                 CATCH_REQUIRE(c == i);
     366        4995 :             }
     367             : 
     368             :             {
     369        4995 :                 std::stringstream ss;
     370        4995 :                 ss << "0x" << std::hex << std::uppercase << i;
     371        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     372        4995 :                 CATCH_REQUIRE(c == i);
     373        4995 :             }
     374             : 
     375             :             {
     376        4995 :                 std::stringstream ss;
     377        4995 :                 ss << "0X" << std::hex << std::uppercase << i;
     378        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     379        4995 :                 CATCH_REQUIRE(c == i);
     380        4995 :             }
     381             : 
     382             :             {
     383        4995 :                 std::stringstream ss;
     384        4995 :                 ss << "0x" << std::hex << i;
     385        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     386        4995 :                 CATCH_REQUIRE(c == i);
     387        4995 :             }
     388             : 
     389             :             {
     390        4995 :                 std::stringstream ss;
     391        4995 :                 ss << "0X" << std::hex << i;
     392        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     393        4995 :                 CATCH_REQUIRE(c == i);
     394        4995 :             }
     395             : 
     396             :             {
     397        4995 :                 std::stringstream ss;
     398        4995 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     399        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     400        4995 :                 CATCH_REQUIRE(c == i);
     401        4995 :             }
     402             : 
     403             :             {
     404        4995 :                 std::stringstream ss;
     405        4995 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     406        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     407        4995 :                 CATCH_REQUIRE(c == i);
     408        4995 :             }
     409             : 
     410             :             {
     411        4995 :                 std::stringstream ss;
     412        4995 :                 ss << "x'" << std::hex << i << '\'';
     413        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     414        4995 :                 CATCH_REQUIRE(c == i);
     415        4995 :             }
     416             : 
     417             :             {
     418        4995 :                 std::stringstream ss;
     419        4995 :                 ss << "X'" << std::hex << i << '\'';
     420        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     421        4995 :                 CATCH_REQUIRE(c == i);
     422        4995 :             }
     423             : 
     424             :             {
     425        4995 :                 std::stringstream ss;
     426        4995 :                 ss << "0" << std::oct << i;
     427        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 16));
     428        4995 :                 CATCH_REQUIRE(c == i);
     429        4995 :             }
     430             : 
     431        4995 :             uint32_t v(i);
     432        4995 :             std::string r;
     433       79927 :             while(v != 0)
     434             :             {
     435       74932 :                 r += (v & 1) + '0';
     436       74932 :                 v >>= 1;
     437             :             }
     438        4995 :             std::reverse(r.begin(), r.end());
     439        4995 :             r = "0b" + r;
     440             :             {
     441        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 16));
     442        4995 :                 CATCH_REQUIRE(c == i);
     443             :             }
     444             : 
     445        4995 :             r[1] &= 0x5F;
     446             :             {
     447        4995 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 16));
     448        4995 :                 CATCH_REQUIRE(c == i);
     449             :             }
     450        4995 :         }
     451             :     }
     452           2 :     CATCH_END_SECTION()
     453             : 
     454           2 :     CATCH_START_SECTION("convert_16bit: int16_t")
     455             :     {
     456        4965 :         for(uint32_t i(0); i < (1ULL << 16); i += rand() % 27)
     457             :         {
     458             :             {
     459        4964 :                 std::stringstream ss;
     460        4964 :                 ss << i;
     461        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     462        4964 :                 CATCH_REQUIRE(c == i);
     463        4964 :             }
     464             : 
     465             :             {
     466        4964 :                 std::stringstream ss;
     467        4964 :                 ss << "0x" << std::hex << std::uppercase << i;
     468        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     469        4964 :                 CATCH_REQUIRE(c == i);
     470        4964 :             }
     471             : 
     472             :             {
     473        4964 :                 std::stringstream ss;
     474        4964 :                 ss << "0X" << std::hex << std::uppercase << i;
     475        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     476        4964 :                 CATCH_REQUIRE(c == i);
     477        4964 :             }
     478             : 
     479             :             {
     480        4964 :                 std::stringstream ss;
     481        4964 :                 ss << "0x" << std::hex << i;
     482        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     483        4964 :                 CATCH_REQUIRE(c == i);
     484        4964 :             }
     485             : 
     486             :             {
     487        4964 :                 std::stringstream ss;
     488        4964 :                 ss << "0X" << std::hex << i;
     489        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     490        4964 :                 CATCH_REQUIRE(c == i);
     491        4964 :             }
     492             : 
     493             :             {
     494        4964 :                 std::stringstream ss;
     495        4964 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     496        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     497        4964 :                 CATCH_REQUIRE(c == i);
     498        4964 :             }
     499             : 
     500             :             {
     501        4964 :                 std::stringstream ss;
     502        4964 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     503        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     504        4964 :                 CATCH_REQUIRE(c == i);
     505        4964 :             }
     506             : 
     507             :             {
     508        4964 :                 std::stringstream ss;
     509        4964 :                 ss << "x'" << std::hex << i << '\'';
     510        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     511        4964 :                 CATCH_REQUIRE(c == i);
     512        4964 :             }
     513             : 
     514             :             {
     515        4964 :                 std::stringstream ss;
     516        4964 :                 ss << "X'" << std::hex << i << '\'';
     517        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     518        4964 :                 CATCH_REQUIRE(c == i);
     519        4964 :             }
     520             : 
     521             :             {
     522        4964 :                 std::stringstream ss;
     523        4964 :                 ss << "0" << std::oct << i;
     524        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(ss.str()), 16));
     525        4964 :                 CATCH_REQUIRE(c == i);
     526        4964 :             }
     527             : 
     528        4964 :             uint32_t v(i);
     529        4964 :             std::string r;
     530       79361 :             while(v != 0)
     531             :             {
     532       74397 :                 r += (v & 1) + '0';
     533       74397 :                 v >>= 1;
     534             :             }
     535        4964 :             std::reverse(r.begin(), r.end());
     536        4964 :             r = "0b" + r;
     537             :             {
     538        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(r), 16));
     539        4964 :                 CATCH_REQUIRE(c == i);
     540             :             }
     541             : 
     542        4964 :             r[1] &= 0x5F;
     543             :             {
     544        4964 :                 uint64_t const c(prinbee::convert_to_int(decorate(r), 16));
     545        4964 :                 CATCH_REQUIRE(c == i);
     546             :             }
     547        4964 :         }
     548             :     }
     549           2 :     CATCH_END_SECTION()
     550           2 : }
     551             : 
     552             : 
     553           2 : CATCH_TEST_CASE("convert_32bit", "[convert] [valid]")
     554             : {
     555           2 :     CATCH_START_SECTION("convert_32bit: uint32_t")
     556             :     {
     557      143806 :         for(uint64_t i(0); i < (1ULL << 32); i += rand() % 60000)
     558             :         {
     559             :             {
     560      143805 :                 std::stringstream ss;
     561      143805 :                 ss << i;
     562      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     563      143805 :                 CATCH_REQUIRE(c == i);
     564      143805 :             }
     565             : 
     566             :             {
     567      143805 :                 std::stringstream ss;
     568      143805 :                 ss << "0x" << std::hex << std::uppercase << i;
     569      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     570      143805 :                 CATCH_REQUIRE(c == i);
     571      143805 :             }
     572             : 
     573             :             {
     574      143805 :                 std::stringstream ss;
     575      143805 :                 ss << "0X" << std::hex << std::uppercase << i;
     576      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     577      143805 :                 CATCH_REQUIRE(c == i);
     578      143805 :             }
     579             : 
     580             :             {
     581      143805 :                 std::stringstream ss;
     582      143805 :                 ss << "0x" << std::hex << i;
     583      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     584      143805 :                 CATCH_REQUIRE(c == i);
     585      143805 :             }
     586             : 
     587             :             {
     588      143805 :                 std::stringstream ss;
     589      143805 :                 ss << "0X" << std::hex << i;
     590      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     591      143805 :                 CATCH_REQUIRE(c == i);
     592      143805 :             }
     593             : 
     594             :             {
     595      143805 :                 std::stringstream ss;
     596      143805 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     597      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     598      143805 :                 CATCH_REQUIRE(c == i);
     599      143805 :             }
     600             : 
     601             :             {
     602      143805 :                 std::stringstream ss;
     603      143805 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     604      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     605      143805 :                 CATCH_REQUIRE(c == i);
     606      143805 :             }
     607             : 
     608             :             {
     609      143805 :                 std::stringstream ss;
     610      143805 :                 ss << "x'" << std::hex << i << '\'';
     611      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     612      143805 :                 CATCH_REQUIRE(c == i);
     613      143805 :             }
     614             : 
     615             :             {
     616      143805 :                 std::stringstream ss;
     617      143805 :                 ss << "X'" << std::hex << i << '\'';
     618      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     619      143805 :                 CATCH_REQUIRE(c == i);
     620      143805 :             }
     621             : 
     622             :             {
     623      143805 :                 std::stringstream ss;
     624      143805 :                 ss << "0" << std::oct << i;
     625      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(ss.str()), 32));
     626      143805 :                 CATCH_REQUIRE(c == i);
     627      143805 :             }
     628             : 
     629      143805 :             uint32_t v(i);
     630      143805 :             std::string r;
     631     4601640 :             while(v != 0)
     632             :             {
     633     4457835 :                 r += (v & 1) + '0';
     634     4457835 :                 v >>= 1;
     635             :             }
     636      143805 :             std::reverse(r.begin(), r.end());
     637      143805 :             r = "0b" + r;
     638             :             {
     639      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 32));
     640      143805 :                 CATCH_REQUIRE(c == i);
     641             :             }
     642             : 
     643      143805 :             r[1] &= 0x5F;
     644             :             {
     645      143805 :                 uint64_t const c(prinbee::convert_to_uint(decorate(r), 32));
     646      143805 :                 CATCH_REQUIRE(c == i);
     647             :             }
     648      143805 :         }
     649             :     }
     650           2 :     CATCH_END_SECTION()
     651             : 
     652           2 :     CATCH_START_SECTION("convert_32bit: int32_t")
     653             :     {
     654       71612 :         for(std::int64_t i(0); i < (1LL << 31); i += rand() % 60000)
     655             :         {
     656             :             {
     657       71611 :                 std::stringstream ss;
     658       71611 :                 ss << i;
     659       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     660       71611 :                 CATCH_REQUIRE(c == i);
     661       71611 :             }
     662             : 
     663             :             {
     664       71611 :                 std::stringstream ss;
     665       71611 :                 ss << -i;
     666       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     667       71611 :                 CATCH_REQUIRE(c == -i);
     668       71611 :             }
     669             : 
     670             :             {
     671       71611 :                 std::stringstream ss;
     672       71611 :                 ss << "0x" << std::hex << std::uppercase << i;
     673       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     674       71611 :                 CATCH_REQUIRE(c == i);
     675       71611 :             }
     676             : 
     677             :             {
     678       71611 :                 std::stringstream ss;
     679       71611 :                 ss << "-0x" << std::hex << std::uppercase << i;
     680       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     681       71611 :                 CATCH_REQUIRE(c == -i);
     682       71611 :             }
     683             : 
     684             :             {
     685       71611 :                 std::stringstream ss;
     686       71611 :                 ss << "0X" << std::hex << std::uppercase << i;
     687       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     688       71611 :                 CATCH_REQUIRE(c == i);
     689       71611 :             }
     690             : 
     691             :             {
     692       71611 :                 std::stringstream ss;
     693       71611 :                 ss << "-0X" << std::hex << std::uppercase << i;
     694       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     695       71611 :                 CATCH_REQUIRE(c == -i);
     696       71611 :             }
     697             : 
     698             :             {
     699       71611 :                 std::stringstream ss;
     700       71611 :                 ss << "0x" << std::hex << i;
     701       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     702       71611 :                 CATCH_REQUIRE(c == i);
     703       71611 :             }
     704             : 
     705             :             {
     706       71611 :                 std::stringstream ss;
     707       71611 :                 ss << "-0x" << std::hex << i;
     708       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     709       71611 :                 CATCH_REQUIRE(c == -i);
     710       71611 :             }
     711             : 
     712             :             {
     713       71611 :                 std::stringstream ss;
     714       71611 :                 ss << "0X" << std::hex << i;
     715       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     716       71611 :                 CATCH_REQUIRE(c == i);
     717       71611 :             }
     718             : 
     719             :             {
     720       71611 :                 std::stringstream ss;
     721       71611 :                 ss << "-0X" << std::hex << i;
     722       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     723       71611 :                 CATCH_REQUIRE(c == -i);
     724       71611 :             }
     725             : 
     726             :             {
     727       71611 :                 std::stringstream ss;
     728       71611 :                 ss << "x'" << std::hex << std::uppercase << i << '\'';
     729       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     730       71611 :                 CATCH_REQUIRE(c == i);
     731       71611 :             }
     732             : 
     733             :             {
     734       71611 :                 std::stringstream ss;
     735       71611 :                 ss << "-x'" << std::hex << std::uppercase << i << '\'';
     736       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     737       71611 :                 CATCH_REQUIRE(c == -i);
     738       71611 :             }
     739             : 
     740             :             {
     741       71611 :                 std::stringstream ss;
     742       71611 :                 ss << "X'" << std::hex << std::uppercase << i << '\'';
     743       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     744       71611 :                 CATCH_REQUIRE(c == i);
     745       71611 :             }
     746             : 
     747             :             {
     748       71611 :                 std::stringstream ss;
     749       71611 :                 ss << "-X'" << std::hex << std::uppercase << i << '\'';
     750       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     751       71611 :                 CATCH_REQUIRE(c == -i);
     752       71611 :             }
     753             : 
     754             :             {
     755       71611 :                 std::stringstream ss;
     756       71611 :                 ss << "x'" << std::hex << i << '\'';
     757       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     758       71611 :                 CATCH_REQUIRE(c == i);
     759       71611 :             }
     760             : 
     761             :             {
     762       71611 :                 std::stringstream ss;
     763       71611 :                 ss << "-x'" << std::hex << i << '\'';
     764       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     765       71611 :                 CATCH_REQUIRE(c == -i);
     766       71611 :             }
     767             : 
     768             :             {
     769       71611 :                 std::stringstream ss;
     770       71611 :                 ss << "X'" << std::hex << i << '\'';
     771       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     772       71611 :                 CATCH_REQUIRE(c == i);
     773       71611 :             }
     774             : 
     775             :             {
     776       71611 :                 std::stringstream ss;
     777       71611 :                 ss << "-X'" << std::hex << i << '\'';
     778       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     779       71611 :                 CATCH_REQUIRE(c == -i);
     780       71611 :             }
     781             : 
     782             :             {
     783       71611 :                 std::stringstream ss;
     784       71611 :                 ss << "0" << std::oct << i;
     785       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     786       71611 :                 CATCH_REQUIRE(c == i);
     787       71611 :             }
     788             : 
     789             :             {
     790       71611 :                 std::stringstream ss;
     791       71611 :                 ss << "-0" << std::oct << i;
     792       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(ss.str()), 32));
     793       71611 :                 CATCH_REQUIRE(c == -i);
     794       71611 :             }
     795             : 
     796       71611 :             std::int32_t v(i);
     797       71611 :             CATCH_REQUIRE(v >= 0);
     798       71611 :             std::string r;
     799     2219914 :             while(v != 0)
     800             :             {
     801     2148303 :                 r += (v & 1) + '0';
     802     2148303 :                 v >>= 1;
     803             :             }
     804       71611 :             if(i == 0)
     805             :             {
     806           1 :                 v += '0';
     807             :             }
     808       71611 :             std::reverse(r.begin(), r.end());
     809       71611 :             r = "0b" + r;
     810             :             {
     811       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(r), 32));
     812       71611 :                 CATCH_REQUIRE(c == i);
     813             :             }
     814             : 
     815       71611 :             r[1] &= 0x5F;
     816             :             {
     817       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(r), 32));
     818       71611 :                 CATCH_REQUIRE(c == i);
     819             :             }
     820             : 
     821       71611 :             r = '-' + r;
     822             :             {
     823       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(r), 32));
     824       71611 :                 CATCH_REQUIRE(c == -i);
     825             :             }
     826             : 
     827       71611 :             r[2] |= 0x20;
     828             :             {
     829       71611 :                 std::int64_t const c(prinbee::convert_to_int(decorate(r), 32));
     830       71611 :                 CATCH_REQUIRE(c == -i);
     831             :             }
     832       71611 :         }
     833             :     }
     834           2 :     CATCH_END_SECTION()
     835           2 : }
     836             : 
     837             : 
     838           1 : CATCH_TEST_CASE("convert_size", "[convert] [size] [valid]")
     839             : {
     840           1 :     CATCH_START_SECTION("convert_size")
     841             :     {
     842             :         struct size_info
     843             :         {
     844             :             char const *    f_name = nullptr;
     845             :             int             f_power = 1;
     846             :             bool            f_1000 = true;
     847             :         };
     848           1 :         size_info si[] =
     849             :         {
     850             :             { "byte",     0 },
     851             :             { "bytes",    0 },
     852             : 
     853             :             { "kb",       1 },
     854             :             { "kib",      1, false },
     855             :             { "kibi",     1, false },
     856             :             { "kilo",     1 },
     857             :             // TODO: the "byte[s]" in the following are WRONG at this time...
     858             :             { "kb byte",  1 },
     859             :             { "kb bytes", 1 },
     860             :             { "kibbyte",  1, false },
     861             :             { "kibbytes", 1, false },
     862             : 
     863             :             { "mb",       2 },
     864             :             { "mebi",     2, false },
     865             :             { "mega",     2 },
     866             :             { "mib",      2, false },
     867             : 
     868             :             { "gb",       3 },
     869             :             { "gibi",     3, false },
     870             :             { "giga",     3 },
     871             :             { "gib",      3, false },
     872             : 
     873             :             { "tb",       4 },
     874             :             { "tebi",     4, false },
     875             :             { "tera",     4 },
     876             :             { "tib",      4, false },
     877             :         };
     878          23 :         for(auto const & s : si)
     879             :         {
     880          22 :             int count(rand() % 10);
     881          22 :             std::string const n(std::to_string(count));
     882          44 :             std::string unit(s.f_name);
     883          22 :             if((rand() & 1) != 0)
     884             :             {
     885             :                 // make one character uppercase, which should have no effects
     886             :                 //
     887          12 :                 unit[rand() % unit.length()] &= 0x5F;
     888             :             }
     889          22 :             std::uint64_t const c(prinbee::convert_to_uint(n + ' ' + unit, 64, prinbee::unit_t::UNIT_SIZE));
     890          22 :             std::uint64_t const expected(snapdev::pow(s.f_1000 ? 1000ULL : 1024ULL, s.f_power) * count);
     891          22 :             CATCH_REQUIRE(c == expected);
     892          22 :         }
     893             :     }
     894           1 :     CATCH_END_SECTION()
     895           1 : }
     896             : 
     897             : 
     898          37 : CATCH_TEST_CASE("convert_buffer", "[convert] [size] [valid]")
     899             : {
     900          37 :     CATCH_START_SECTION("convert_buffer: string -> bits8")
     901             :     {
     902         257 :         for(int i(0); i < 256; ++i)
     903             :         {
     904             :             {
     905         256 :                 std::stringstream ss;
     906         256 :                 if(i == 0)
     907             :                 {
     908           1 :                     ss << "0";
     909             :                 }
     910             :                 else
     911             :                 {
     912         255 :                     ss << "0B" << to_binary(i);
     913             :                 }
     914         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, ss.str()));
     915         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 2));
     916             : 
     917         256 :                 CATCH_REQUIRE(ss.str() == back);
     918         256 :             }
     919             :             {
     920         256 :                 std::stringstream ss;
     921         256 :                 ss << std::showbase << std::oct << i;
     922         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, ss.str()));
     923         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 8));
     924             : 
     925         256 :                 CATCH_REQUIRE(ss.str() == back);
     926         256 :             }
     927             :             {
     928         256 :                 std::stringstream ss;
     929         256 :                 ss << std::dec << i;
     930         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, ss.str()));
     931         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 10));
     932             : 
     933         256 :                 CATCH_REQUIRE(ss.str() == back);
     934         256 :             }
     935             :             {
     936         256 :                 std::stringstream ss;
     937         256 :                 ss << std::showbase << std::hex << std::uppercase << i;
     938         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, ss.str()));
     939         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 16));
     940             : 
     941         256 :                 CATCH_REQUIRE(ss.str() == back);
     942         256 :             }
     943             :         }
     944             :     }
     945          37 :     CATCH_END_SECTION()
     946             : 
     947          37 :     CATCH_START_SECTION("convert_buffer: string -> uint8")
     948             :     {
     949         257 :         for(int i(0); i < 256; ++i)
     950             :         {
     951             :             {
     952         256 :                 std::stringstream ss;
     953         256 :                 if(i == 0)
     954             :                 {
     955           1 :                     ss << "0";
     956             :                 }
     957             :                 else
     958             :                 {
     959         255 :                     ss << "0B" << to_binary(i);
     960             :                 }
     961         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT8, ss.str()));
     962         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT8, buffer, 2));
     963             : 
     964         256 :                 CATCH_REQUIRE(ss.str() == back);
     965         256 :             }
     966             :             {
     967         256 :                 std::stringstream ss;
     968         256 :                 if(i == 0)
     969             :                 {
     970           1 :                     ss << '0';
     971             :                 }
     972             :                 else
     973             :                 {
     974         255 :                     ss << std::oct << '0' << i;
     975             :                 }
     976         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT8, ss.str()));
     977         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT8, buffer, 8));
     978             : 
     979         256 :                 CATCH_REQUIRE(ss.str() == back);
     980         256 :             }
     981             :             {
     982         256 :                 std::stringstream ss;
     983         256 :                 ss << std::dec << i;
     984         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT8, ss.str()));
     985         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT8, buffer, 10));
     986             : 
     987         256 :                 CATCH_REQUIRE(ss.str() == back);
     988         256 :             }
     989             :             {
     990         256 :                 std::stringstream ss;
     991         256 :                 if(i == 0)
     992             :                 {
     993           1 :                     ss << "0";
     994             :                 }
     995             :                 else
     996             :                 {
     997         255 :                     ss << std::hex << std::uppercase << "0X" << i;
     998             :                 }
     999         512 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT8, ss.str()));
    1000         256 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT8, buffer, 16));
    1001             : 
    1002         256 :                 CATCH_REQUIRE(ss.str() == back);
    1003         256 :             }
    1004             :         }
    1005             :     }
    1006          37 :     CATCH_END_SECTION()
    1007             : 
    1008          37 :     CATCH_START_SECTION("convert_buffer: string -> int8")
    1009             :     {
    1010         256 :         for(int i(-128); i < 127; ++i)
    1011             :         {
    1012             :             {
    1013         255 :                 std::stringstream ss;
    1014         255 :                 if(i == 0)
    1015             :                 {
    1016           1 :                     ss << "0";
    1017             :                 }
    1018         254 :                 else if(i > 0)
    1019             :                 {
    1020         126 :                     ss << "0B" << to_binary(i);
    1021             :                 }
    1022             :                 else
    1023             :                 {
    1024         128 :                     ss << "-0B" << to_binary(-i);
    1025             :                 }
    1026         510 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, ss.str()));
    1027         255 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 2));
    1028             : 
    1029         255 :                 CATCH_REQUIRE(ss.str() == back);
    1030         255 :             }
    1031             :             {
    1032         255 :                 std::stringstream ss;
    1033         255 :                 if(i == 0)
    1034             :                 {
    1035           1 :                     ss << "0";
    1036             :                 }
    1037         254 :                 else if(i > 0)
    1038             :                 {
    1039         126 :                     ss << std::oct << std::showbase << i;
    1040             :                 }
    1041             :                 else
    1042             :                 {
    1043         128 :                     ss << std::oct << std::showbase << '-' << -i;
    1044             :                 }
    1045         510 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, ss.str()));
    1046         255 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 8));
    1047             : 
    1048         255 :                 CATCH_REQUIRE(ss.str() == back);
    1049         255 :             }
    1050             :             {
    1051         255 :                 std::stringstream ss;
    1052         255 :                 ss << std::dec << i;
    1053         510 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, ss.str()));
    1054         255 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 10));
    1055             : 
    1056         255 :                 CATCH_REQUIRE(ss.str() == back);
    1057         255 :             }
    1058             :             {
    1059         255 :                 std::stringstream ss;
    1060         255 :                 if(i == 0)
    1061             :                 {
    1062           1 :                     ss << "0";
    1063             :                 }
    1064         254 :                 else if(i > 0)
    1065             :                 {
    1066         126 :                     ss << std::showbase << std::hex << std::uppercase << i;
    1067             :                 }
    1068             :                 else
    1069             :                 {
    1070         128 :                     ss << std::showbase << std::hex << std::uppercase << '-' << -i;
    1071             :                 }
    1072         510 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, ss.str()));
    1073         255 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 16));
    1074             : 
    1075         255 :                 CATCH_REQUIRE(ss.str() == back);
    1076         255 :             }
    1077             :         }
    1078             :     }
    1079          37 :     CATCH_END_SECTION()
    1080             : 
    1081          37 :     CATCH_START_SECTION("convert_buffer: string -> bits16")
    1082             :     {
    1083         101 :         for(int j(0); j < 100; ++j)
    1084             :         {
    1085         100 :             std::uint16_t const i(rand());
    1086             :             {
    1087         100 :                 std::stringstream ss;
    1088         100 :                 ss << "0B" << to_binary(i);
    1089         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS16, ss.str()));
    1090         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS16, buffer, 2));
    1091             : 
    1092         100 :                 CATCH_REQUIRE(ss.str() == back);
    1093         100 :             }
    1094             :             {
    1095         100 :                 std::stringstream ss;
    1096         100 :                 if(i == 0)
    1097             :                 {
    1098           0 :                     ss << '0';
    1099             :                 }
    1100             :                 else
    1101             :                 {
    1102         100 :                     ss << std::oct << '0' << i;
    1103             :                 }
    1104         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS16, ss.str()));
    1105         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS16, buffer, 8));
    1106             : 
    1107         100 :                 CATCH_REQUIRE(ss.str() == back);
    1108         100 :             }
    1109             :             {
    1110         100 :                 std::stringstream ss;
    1111         100 :                 ss << std::dec << i;
    1112         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS16, ss.str()));
    1113         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS16, buffer, 10));
    1114             : 
    1115         100 :                 CATCH_REQUIRE(ss.str() == back);
    1116         100 :             }
    1117             :             {
    1118         100 :                 std::stringstream ss;
    1119         100 :                 if(i == 0)
    1120             :                 {
    1121           0 :                     ss << "0";
    1122             :                 }
    1123             :                 else
    1124             :                 {
    1125         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1126             :                 }
    1127         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS16, ss.str()));
    1128         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS16, buffer, 16));
    1129             : 
    1130         100 :                 CATCH_REQUIRE(ss.str() == back);
    1131         100 :             }
    1132             :         }
    1133             :     }
    1134          37 :     CATCH_END_SECTION()
    1135             : 
    1136          37 :     CATCH_START_SECTION("convert_buffer: string -> uint16")
    1137             :     {
    1138         101 :         for(int j(0); j < 100; ++j)
    1139             :         {
    1140         100 :             std::uint16_t const i(rand());
    1141             :             {
    1142         100 :                 std::stringstream ss;
    1143         100 :                 if(i == 0)
    1144             :                 {
    1145           0 :                     ss << '0';
    1146             :                 }
    1147             :                 else
    1148             :                 {
    1149         100 :                     ss << "0B" << to_binary(i);
    1150             :                 }
    1151         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT16, ss.str()));
    1152         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT16, buffer, 2));
    1153             : 
    1154         100 :                 CATCH_REQUIRE(ss.str() == back);
    1155         100 :             }
    1156             :             {
    1157         100 :                 std::stringstream ss;
    1158         100 :                 if(i == 0)
    1159             :                 {
    1160           0 :                     ss << '0';
    1161             :                 }
    1162             :                 else
    1163             :                 {
    1164         100 :                     ss << std::oct << '0' << i;
    1165             :                 }
    1166         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT16, ss.str()));
    1167         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT16, buffer, 8));
    1168             : 
    1169         100 :                 CATCH_REQUIRE(ss.str() == back);
    1170         100 :             }
    1171             :             {
    1172         100 :                 std::stringstream ss;
    1173         100 :                 ss << std::dec << i;
    1174         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT16, ss.str()));
    1175         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT16, buffer, 10));
    1176             : 
    1177         100 :                 CATCH_REQUIRE(ss.str() == back);
    1178         100 :             }
    1179             :             {
    1180         100 :                 std::stringstream ss;
    1181         100 :                 if(i == 0)
    1182             :                 {
    1183           0 :                     ss << "0";
    1184             :                 }
    1185             :                 else
    1186             :                 {
    1187         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1188             :                 }
    1189         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT16, ss.str()));
    1190         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT16, buffer, 16));
    1191             : 
    1192         100 :                 CATCH_REQUIRE(ss.str() == back);
    1193         100 :             }
    1194             :         }
    1195             :     }
    1196          37 :     CATCH_END_SECTION()
    1197             : 
    1198          37 :     CATCH_START_SECTION("convert_buffer: string -> int16")
    1199             :     {
    1200         101 :         for(int j(0); j < 100; ++j)
    1201             :         {
    1202         100 :             std::int16_t const i(rand());
    1203             :             {
    1204         100 :                 std::stringstream ss;
    1205         100 :                 if(i == 0)
    1206             :                 {
    1207           0 :                     ss << '0';
    1208             :                 }
    1209         100 :                 else if(i > 0)
    1210             :                 {
    1211          49 :                     ss << "0B" << to_binary(i);
    1212             :                 }
    1213             :                 else
    1214             :                 {
    1215          51 :                     ss << "-0B" << to_binary(-i);
    1216             :                 }
    1217         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, ss.str()));
    1218         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT16, buffer, 2));
    1219             : 
    1220         100 :                 CATCH_REQUIRE(ss.str() == back);
    1221         100 :             }
    1222             :             {
    1223         100 :                 std::stringstream ss;
    1224         100 :                 if(i == 0)
    1225             :                 {
    1226           0 :                     ss << '0';
    1227             :                 }
    1228         100 :                 else if(i < 0)
    1229             :                 {
    1230          51 :                     ss << '-' << std::showbase << std::oct << -i;
    1231             :                 }
    1232             :                 else
    1233             :                 {
    1234          49 :                     ss << std::showbase << std::oct << i;
    1235             :                 }
    1236         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, ss.str()));
    1237         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT16, buffer, 8));
    1238             : 
    1239         100 :                 CATCH_REQUIRE(ss.str() == back);
    1240         100 :             }
    1241             :             {
    1242         100 :                 std::stringstream ss;
    1243         100 :                 ss << std::dec << i;
    1244         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, ss.str()));
    1245         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT16, buffer, 10));
    1246             : 
    1247         100 :                 CATCH_REQUIRE(ss.str() == back);
    1248         100 :             }
    1249             :             {
    1250         100 :                 std::stringstream ss;
    1251         100 :                 if(i == 0)
    1252             :                 {
    1253           0 :                     ss << '0';
    1254             :                 }
    1255         100 :                 else if(i < 0)
    1256             :                 {
    1257          51 :                     ss << '-' << std::showbase << std::hex << std::uppercase << -i;
    1258             :                 }
    1259             :                 else
    1260             :                 {
    1261          49 :                     ss << std::showbase << std::hex << std::uppercase << i;
    1262             :                 }
    1263         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, ss.str()));
    1264         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT16, buffer, 16));
    1265             : 
    1266         100 :                 CATCH_REQUIRE(ss.str() == back);
    1267         100 :             }
    1268             :         }
    1269             :     }
    1270          37 :     CATCH_END_SECTION()
    1271             : 
    1272          37 :     CATCH_START_SECTION("convert_buffer: string -> bits32")
    1273             :     {
    1274         101 :         for(int j(0); j < 100; ++j)
    1275             :         {
    1276         100 :             std::uint32_t const i(SNAP_CATCH2_NAMESPACE::rand32());
    1277             :             {
    1278         100 :                 std::stringstream ss;
    1279         100 :                 ss << "0B" << to_binary(i);
    1280         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS32, ss.str()));
    1281         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS32, buffer, 2));
    1282             : 
    1283         100 :                 CATCH_REQUIRE(ss.str() == back);
    1284         100 :             }
    1285             :             {
    1286         100 :                 std::stringstream ss;
    1287         100 :                 if(i == 0)
    1288             :                 {
    1289           0 :                     ss << '0';
    1290             :                 }
    1291             :                 else
    1292             :                 {
    1293         100 :                     ss << std::oct << '0' << i;
    1294             :                 }
    1295         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS32, ss.str()));
    1296         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS32, buffer, 8));
    1297             : 
    1298         100 :                 CATCH_REQUIRE(ss.str() == back);
    1299         100 :             }
    1300             :             {
    1301         100 :                 std::stringstream ss;
    1302         100 :                 ss << std::dec << i;
    1303         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS32, ss.str()));
    1304         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS32, buffer, 10));
    1305             : 
    1306         100 :                 CATCH_REQUIRE(ss.str() == back);
    1307         100 :             }
    1308             :             {
    1309         100 :                 std::stringstream ss;
    1310         100 :                 if(i == 0)
    1311             :                 {
    1312           0 :                     ss << "0";
    1313             :                 }
    1314             :                 else
    1315             :                 {
    1316         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1317             :                 }
    1318         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS32, ss.str()));
    1319         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS32, buffer, 16));
    1320             : 
    1321         100 :                 CATCH_REQUIRE(ss.str() == back);
    1322         100 :             }
    1323             :         }
    1324             :     }
    1325          37 :     CATCH_END_SECTION()
    1326             : 
    1327          37 :     CATCH_START_SECTION("convert_buffer: string -> uint32")
    1328             :     {
    1329         101 :         for(int j(0); j < 100; ++j)
    1330             :         {
    1331         100 :             std::uint32_t const i(SNAP_CATCH2_NAMESPACE::rand32());
    1332             :             {
    1333         100 :                 std::stringstream ss;
    1334         100 :                 ss << "0B" << to_binary(i);
    1335         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT32, ss.str()));
    1336         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT32, buffer, 2));
    1337             : 
    1338         100 :                 CATCH_REQUIRE(ss.str() == back);
    1339         100 :             }
    1340             :             {
    1341         100 :                 std::stringstream ss;
    1342         100 :                 if(i == 0)
    1343             :                 {
    1344           0 :                     ss << '0';
    1345             :                 }
    1346             :                 else
    1347             :                 {
    1348         100 :                     ss << std::oct << '0' << i;
    1349             :                 }
    1350         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT32, ss.str()));
    1351         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT32, buffer, 8));
    1352             : 
    1353         100 :                 CATCH_REQUIRE(ss.str() == back);
    1354         100 :             }
    1355             :             {
    1356         100 :                 std::stringstream ss;
    1357         100 :                 ss << std::dec << i;
    1358         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT32, ss.str()));
    1359         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT32, buffer, 10));
    1360             : 
    1361         100 :                 CATCH_REQUIRE(ss.str() == back);
    1362         100 :             }
    1363             :             {
    1364         100 :                 std::stringstream ss;
    1365         100 :                 if(i == 0)
    1366             :                 {
    1367           0 :                     ss << "0";
    1368             :                 }
    1369             :                 else
    1370             :                 {
    1371         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1372             :                 }
    1373         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT32, ss.str()));
    1374         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT32, buffer, 16));
    1375             : 
    1376         100 :                 CATCH_REQUIRE(ss.str() == back);
    1377         100 :             }
    1378             :         }
    1379             :     }
    1380          37 :     CATCH_END_SECTION()
    1381             : 
    1382          37 :     CATCH_START_SECTION("convert_buffer: string -> int32")
    1383             :     {
    1384         101 :         for(int j(0); j < 100; ++j)
    1385             :         {
    1386         100 :             std::int32_t const i(SNAP_CATCH2_NAMESPACE::rand32());
    1387             :             {
    1388         100 :                 std::stringstream ss;
    1389         100 :                 if(i < 0)
    1390             :                 {
    1391          46 :                     ss << "-0B" << to_binary(-i);
    1392             :                 }
    1393             :                 else
    1394             :                 {
    1395          54 :                     ss << "0B" << to_binary(i);
    1396             :                 }
    1397         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT32, ss.str()));
    1398         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT32, buffer, 2));
    1399             : 
    1400         100 :                 CATCH_REQUIRE(ss.str() == back);
    1401         100 :             }
    1402             :             {
    1403         100 :                 std::stringstream ss;
    1404         100 :                 if(i == 0)
    1405             :                 {
    1406           0 :                     ss << '0';
    1407             :                 }
    1408         100 :                 else if(i < 0)
    1409             :                 {
    1410          46 :                     ss << '-' << std::showbase << std::oct << -i;
    1411             :                 }
    1412             :                 else
    1413             :                 {
    1414          54 :                     ss << std::showbase << std::oct << i;
    1415             :                 }
    1416         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT32, ss.str()));
    1417         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT32, buffer, 8));
    1418             : 
    1419         100 :                 CATCH_REQUIRE(ss.str() == back);
    1420         100 :             }
    1421             :             {
    1422         100 :                 std::stringstream ss;
    1423         100 :                 ss << std::dec << i;
    1424         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT32, ss.str()));
    1425         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT32, buffer, 10));
    1426             : 
    1427         100 :                 CATCH_REQUIRE(ss.str() == back);
    1428         100 :             }
    1429             :             {
    1430         100 :                 std::stringstream ss;
    1431         100 :                 if(i == 0)
    1432             :                 {
    1433           0 :                     ss << "0";
    1434             :                 }
    1435         100 :                 else if(i < 0)
    1436             :                 {
    1437          46 :                     ss << '-' << std::hex << std::uppercase << "0X" << -i;
    1438             :                 }
    1439             :                 else
    1440             :                 {
    1441          54 :                     ss << std::hex << std::uppercase << "0X" << i;
    1442             :                 }
    1443         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT32, ss.str()));
    1444         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT32, buffer, 16));
    1445             : 
    1446         100 :                 CATCH_REQUIRE(ss.str() == back);
    1447         100 :             }
    1448             :         }
    1449             :     }
    1450          37 :     CATCH_END_SECTION()
    1451             : 
    1452          37 :     CATCH_START_SECTION("convert_buffer: string -> bits64")
    1453             :     {
    1454         101 :         for(int j(0); j < 100; ++j)
    1455             :         {
    1456         100 :             std::uint64_t const i(SNAP_CATCH2_NAMESPACE::rand64());
    1457             :             {
    1458         100 :                 std::stringstream ss;
    1459         100 :                 ss << "0B" << to_binary(i);
    1460         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS64, ss.str()));
    1461         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS64, buffer, 2));
    1462             : 
    1463         100 :                 CATCH_REQUIRE(ss.str() == back);
    1464         100 :             }
    1465             :             {
    1466         100 :                 std::stringstream ss;
    1467         100 :                 if(i == 0)
    1468             :                 {
    1469           0 :                     ss << '0';
    1470             :                 }
    1471             :                 else
    1472             :                 {
    1473         100 :                     ss << std::oct << '0' << i;
    1474             :                 }
    1475         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS64, ss.str()));
    1476         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS64, buffer, 8));
    1477             : 
    1478         100 :                 CATCH_REQUIRE(ss.str() == back);
    1479         100 :             }
    1480             :             {
    1481         100 :                 std::stringstream ss;
    1482         100 :                 ss << std::dec << i;
    1483         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS64, ss.str()));
    1484         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS64, buffer, 10));
    1485             : 
    1486         100 :                 CATCH_REQUIRE(ss.str() == back);
    1487         100 :             }
    1488             :             {
    1489         100 :                 std::stringstream ss;
    1490         100 :                 if(i == 0)
    1491             :                 {
    1492           0 :                     ss << "0";
    1493             :                 }
    1494             :                 else
    1495             :                 {
    1496         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1497             :                 }
    1498         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS64, ss.str()));
    1499         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS64, buffer, 16));
    1500             : 
    1501         100 :                 CATCH_REQUIRE(ss.str() == back);
    1502         100 :             }
    1503             :         }
    1504             :     }
    1505          37 :     CATCH_END_SECTION()
    1506             : 
    1507          37 :     CATCH_START_SECTION("convert_buffer: string -> uint64")
    1508             :     {
    1509         101 :         for(int j(0); j < 100; ++j)
    1510             :         {
    1511         100 :             std::uint64_t const i(SNAP_CATCH2_NAMESPACE::rand64());
    1512             :             {
    1513         100 :                 std::stringstream ss;
    1514         100 :                 ss << "0B" << to_binary(i);
    1515         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT64, ss.str()));
    1516         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT64, buffer, 2));
    1517             : 
    1518         100 :                 CATCH_REQUIRE(ss.str() == back);
    1519         100 :             }
    1520             :             {
    1521         100 :                 std::stringstream ss;
    1522         100 :                 if(i == 0)
    1523             :                 {
    1524           0 :                     ss << '0';
    1525             :                 }
    1526             :                 else
    1527             :                 {
    1528         100 :                     ss << std::oct << '0' << i;
    1529             :                 }
    1530         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT64, ss.str()));
    1531         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT64, buffer, 8));
    1532             : 
    1533         100 :                 CATCH_REQUIRE(ss.str() == back);
    1534         100 :             }
    1535             :             {
    1536         100 :                 std::stringstream ss;
    1537         100 :                 ss << std::dec << i;
    1538         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT64, ss.str()));
    1539         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT64, buffer, 10));
    1540             : 
    1541         100 :                 CATCH_REQUIRE(ss.str() == back);
    1542         100 :             }
    1543             :             {
    1544         100 :                 std::stringstream ss;
    1545         100 :                 if(i == 0)
    1546             :                 {
    1547           0 :                     ss << "0";
    1548             :                 }
    1549             :                 else
    1550             :                 {
    1551         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    1552             :                 }
    1553         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT64, ss.str()));
    1554         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT64, buffer, 16));
    1555             : 
    1556         100 :                 CATCH_REQUIRE(ss.str() == back);
    1557         100 :             }
    1558             :         }
    1559             :     }
    1560          37 :     CATCH_END_SECTION()
    1561             : 
    1562          37 :     CATCH_START_SECTION("convert_buffer: string -> int64")
    1563             :     {
    1564         101 :         for(int j(0); j < 100; ++j)
    1565             :         {
    1566         100 :             std::int64_t const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand64());
    1567             :             {
    1568         100 :                 std::stringstream ss;
    1569         100 :                 if(i == 0)
    1570             :                 {
    1571           1 :                     ss << '0';
    1572             :                 }
    1573          99 :                 else if(i < 0)
    1574             :                 {
    1575          48 :                     ss << "-0B" << to_binary(-i);
    1576             :                 }
    1577             :                 else
    1578             :                 {
    1579          51 :                     ss << "0B" << to_binary(i);
    1580             :                 }
    1581         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT64, ss.str()));
    1582         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT64, buffer, 2));
    1583             : 
    1584         100 :                 CATCH_REQUIRE(ss.str() == back);
    1585         100 :             }
    1586             :             {
    1587         100 :                 std::stringstream ss;
    1588         100 :                 if(i == 0)
    1589             :                 {
    1590           1 :                     ss << '0';
    1591             :                 }
    1592          99 :                 else if(i < 0)
    1593             :                 {
    1594          48 :                     ss << '-' << std::showbase << std::oct << -i;
    1595             :                 }
    1596             :                 else
    1597             :                 {
    1598          51 :                     ss << std::showbase << std::oct << i;
    1599             :                 }
    1600         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT64, ss.str()));
    1601         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT64, buffer, 8));
    1602             : 
    1603         100 :                 CATCH_REQUIRE(ss.str() == back);
    1604         100 :             }
    1605             :             {
    1606         100 :                 std::stringstream ss;
    1607         100 :                 ss << std::dec << i;
    1608         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT64, ss.str()));
    1609         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT64, buffer, 10));
    1610             : 
    1611         100 :                 CATCH_REQUIRE(ss.str() == back);
    1612         100 :             }
    1613             :             {
    1614         100 :                 std::stringstream ss;
    1615         100 :                 if(i == 0)
    1616             :                 {
    1617           1 :                     ss << '0';
    1618             :                 }
    1619          99 :                 else if(i < 0)
    1620             :                 {
    1621          48 :                     ss << '-' << std::showbase << std::hex << std::uppercase << -i;
    1622             :                 }
    1623             :                 else
    1624             :                 {
    1625          51 :                     ss << std::showbase << std::hex << std::uppercase << i;
    1626             :                 }
    1627         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT64, ss.str()));
    1628         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT64, buffer, 16));
    1629             : 
    1630         100 :                 CATCH_REQUIRE(ss.str() == back);
    1631         100 :             }
    1632             :         }
    1633             :     }
    1634          37 :     CATCH_END_SECTION()
    1635             : 
    1636          37 :     CATCH_START_SECTION("convert_buffer: string -> oid")
    1637             :     {
    1638         101 :         for(int j(0); j < 100; ++j)
    1639             :         {
    1640         100 :             std::uint64_t const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand64());
    1641             :             {
    1642         100 :                 std::stringstream ss;
    1643         100 :                 if(i == 0)
    1644             :                 {
    1645           1 :                     ss << '0';
    1646             :                 }
    1647             :                 else
    1648             :                 {
    1649          99 :                     ss << "0B" << to_binary(i);
    1650             :                 }
    1651         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_OID, ss.str()));
    1652         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_OID, buffer, 2));
    1653             : 
    1654         100 :                 CATCH_REQUIRE(ss.str() == back);
    1655         100 :             }
    1656             :             {
    1657         100 :                 std::stringstream ss;
    1658         100 :                 if(i == 0)
    1659             :                 {
    1660           1 :                     ss << '0';
    1661             :                 }
    1662             :                 else
    1663             :                 {
    1664          99 :                     ss << std::oct << '0' << i;
    1665             :                 }
    1666         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_OID, ss.str()));
    1667         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_OID, buffer, 8));
    1668             : 
    1669         100 :                 CATCH_REQUIRE(ss.str() == back);
    1670         100 :             }
    1671             :             {
    1672         100 :                 std::stringstream ss;
    1673         100 :                 ss << std::dec << i;
    1674         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_OID, ss.str()));
    1675         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_OID, buffer, 10));
    1676             : 
    1677         100 :                 CATCH_REQUIRE(ss.str() == back);
    1678         100 :             }
    1679             :             {
    1680         100 :                 std::stringstream ss;
    1681         100 :                 if(i == 0)
    1682             :                 {
    1683           1 :                     ss << "0";
    1684             :                 }
    1685             :                 else
    1686             :                 {
    1687          99 :                     ss << std::hex << std::uppercase << "0X" << i;
    1688             :                 }
    1689         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_OID, ss.str()));
    1690         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_OID, buffer, 16));
    1691             : 
    1692         100 :                 CATCH_REQUIRE(ss.str() == back);
    1693         100 :             }
    1694             :         }
    1695             :     }
    1696          37 :     CATCH_END_SECTION()
    1697             : 
    1698          37 :     CATCH_START_SECTION("convert_buffer: string -> reference")
    1699             :     {
    1700         101 :         for(int j(0); j < 100; ++j)
    1701             :         {
    1702         100 :             std::uint64_t const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand64());
    1703             :             {
    1704         100 :                 std::stringstream ss;
    1705         100 :                 if(i == 0)
    1706             :                 {
    1707           1 :                     ss << '0';
    1708             :                 }
    1709             :                 else
    1710             :                 {
    1711          99 :                     ss << "0B" << to_binary(i);
    1712             :                 }
    1713         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, ss.str()));
    1714         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, buffer, 2));
    1715             : 
    1716         100 :                 CATCH_REQUIRE(ss.str() == back);
    1717         100 :             }
    1718             :             {
    1719         100 :                 std::stringstream ss;
    1720         100 :                 if(i == 0)
    1721             :                 {
    1722           1 :                     ss << '0';
    1723             :                 }
    1724             :                 else
    1725             :                 {
    1726          99 :                     ss << std::oct << '0' << i;
    1727             :                 }
    1728         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, ss.str()));
    1729         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, buffer, 8));
    1730             : 
    1731         100 :                 CATCH_REQUIRE(ss.str() == back);
    1732         100 :             }
    1733             :             {
    1734         100 :                 std::stringstream ss;
    1735         100 :                 ss << std::dec << i;
    1736         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, ss.str()));
    1737         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, buffer, 10));
    1738             : 
    1739         100 :                 CATCH_REQUIRE(ss.str() == back);
    1740         100 :             }
    1741             :             {
    1742         100 :                 std::stringstream ss;
    1743         100 :                 if(i == 0)
    1744             :                 {
    1745           1 :                     ss << '0';
    1746             :                 }
    1747             :                 else
    1748             :                 {
    1749          99 :                     ss << std::hex << std::uppercase << "0X" << i;
    1750             :                 }
    1751         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, ss.str()));
    1752         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_REFERENCE, buffer, 16));
    1753             : 
    1754         100 :                 CATCH_REQUIRE(ss.str() == back);
    1755         100 :             }
    1756             :         }
    1757             :     }
    1758          37 :     CATCH_END_SECTION()
    1759             : 
    1760          37 :     CATCH_START_SECTION("convert_buffer: string -> bits128")
    1761             :     {
    1762             : #pragma GCC diagnostic push
    1763             : #pragma GCC diagnostic ignored "-Wpedantic"
    1764         101 :         for(int j(0); j < 100; ++j)
    1765             :         {
    1766         100 :             unsigned __int128 const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand128());
    1767             :             {
    1768         100 :                 std::stringstream ss;
    1769         100 :                 if(i == 0)
    1770             :                 {
    1771           1 :                     ss << '0';
    1772             :                 }
    1773             :                 else
    1774             :                 {
    1775          99 :                     ss << "0B" << to_binary(i);
    1776             :                 }
    1777         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS128, ss.str()));
    1778         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS128, buffer, 2));
    1779             : 
    1780         100 :                 CATCH_REQUIRE(ss.str() == back);
    1781         100 :             }
    1782             :             {
    1783         100 :                 std::stringstream ss;
    1784         100 :                 ss << std::showbase << std::oct << i;
    1785         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS128, ss.str()));
    1786         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS128, buffer, 8));
    1787             : 
    1788         100 :                 CATCH_REQUIRE(ss.str() == back);
    1789         100 :             }
    1790             :             {
    1791         100 :                 std::stringstream ss;
    1792         100 :                 ss << std::dec << i;
    1793         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS128, ss.str()));
    1794         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS128, buffer, 10));
    1795             : 
    1796         100 :                 CATCH_REQUIRE(ss.str() == back);
    1797         100 :             }
    1798             :             {
    1799         100 :                 std::stringstream ss;
    1800         100 :                 if(i == 0)
    1801             :                 {
    1802           1 :                     ss << "0";
    1803             :                 }
    1804             :                 else
    1805             :                 {
    1806          99 :                     ss << std::hex << std::uppercase << "0X" << i;
    1807             :                 }
    1808         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS128, ss.str()));
    1809         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS128, buffer, 16));
    1810             : 
    1811         100 :                 CATCH_REQUIRE(ss.str() == back);
    1812         100 :             }
    1813             :         }
    1814             : #pragma GCC diagnostic pop
    1815             :     }
    1816          37 :     CATCH_END_SECTION()
    1817             : 
    1818          37 :     CATCH_START_SECTION("convert_buffer: string -> uint128")
    1819             :     {
    1820             : #pragma GCC diagnostic push
    1821             : #pragma GCC diagnostic ignored "-Wpedantic"
    1822         101 :         for(int j(0); j < 100; ++j)
    1823             :         {
    1824         100 :             unsigned __int128 const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand128());
    1825             :             {
    1826         100 :                 std::stringstream ss;
    1827         100 :                 if(i == 0)
    1828             :                 {
    1829           1 :                     ss << '0';
    1830             :                 }
    1831             :                 else
    1832             :                 {
    1833          99 :                     ss << "0B" << to_binary(i);
    1834             :                 }
    1835         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT128, ss.str()));
    1836         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT128, buffer, 2));
    1837             : 
    1838         100 :                 CATCH_REQUIRE(ss.str() == back);
    1839         100 :             }
    1840             :             {
    1841         100 :                 std::stringstream ss;
    1842         100 :                 if(i == 0)
    1843             :                 {
    1844           1 :                     ss << '0';
    1845             :                 }
    1846             :                 else
    1847             :                 {
    1848          99 :                     ss << std::oct << '0' << i;
    1849             :                 }
    1850         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT128, ss.str()));
    1851         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT128, buffer, 8));
    1852             : 
    1853         100 :                 CATCH_REQUIRE(ss.str() == back);
    1854         100 :             }
    1855             :             {
    1856         100 :                 std::stringstream ss;
    1857         100 :                 ss << std::dec << i;
    1858         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT128, ss.str()));
    1859         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT128, buffer, 10));
    1860             : 
    1861         100 :                 CATCH_REQUIRE(ss.str() == back);
    1862         100 :             }
    1863             :             {
    1864         100 :                 std::stringstream ss;
    1865         100 :                 if(i == 0)
    1866             :                 {
    1867           1 :                     ss << "0";
    1868             :                 }
    1869             :                 else
    1870             :                 {
    1871          99 :                     ss << std::hex << std::uppercase << "0X" << i;
    1872             :                 }
    1873         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT128, ss.str()));
    1874         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT128, buffer, 16));
    1875             : 
    1876         100 :                 CATCH_REQUIRE(ss.str() == back);
    1877         100 :             }
    1878             :         }
    1879             : #pragma GCC diagnostic pop
    1880             :     }
    1881          37 :     CATCH_END_SECTION()
    1882             : 
    1883          37 :     CATCH_START_SECTION("convert_buffer: string -> int128")
    1884             :     {
    1885             : #pragma GCC diagnostic push
    1886             : #pragma GCC diagnostic ignored "-Wpedantic"
    1887         101 :         for(int j(0); j < 100; ++j)
    1888             :         {
    1889         100 :             __int128 const i(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand128());
    1890             :             {
    1891         100 :                 std::stringstream ss;
    1892         100 :                 if(i == 0)
    1893             :                 {
    1894           1 :                     ss << '0';
    1895             :                 }
    1896          99 :                 else if(i < 0)
    1897             :                 {
    1898          51 :                     ss << "-0B" << to_binary(-i);
    1899             :                 }
    1900             :                 else
    1901             :                 {
    1902          48 :                     ss << "0B" << to_binary(i);
    1903             :                 }
    1904         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT128, ss.str()));
    1905         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT128, buffer, 2));
    1906             : 
    1907         100 :                 CATCH_REQUIRE(ss.str() == back);
    1908         100 :             }
    1909             :             {
    1910         100 :                 std::stringstream ss;
    1911         100 :                 if(i == 0)
    1912             :                 {
    1913           1 :                     ss << '0';
    1914             :                 }
    1915          99 :                 else if(i < 0)
    1916             :                 {
    1917          51 :                     ss << '-' << std::showbase << std::oct << -i;
    1918             :                 }
    1919             :                 else
    1920             :                 {
    1921          48 :                     ss << std::showbase << std::oct << i;
    1922             :                 }
    1923         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT128, ss.str()));
    1924         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT128, buffer, 8));
    1925             : 
    1926         100 :                 CATCH_REQUIRE(ss.str() == back);
    1927         100 :             }
    1928             :             {
    1929         100 :                 std::stringstream ss;
    1930         100 :                 ss << std::dec << i;
    1931         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT128, ss.str()));
    1932         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT128, buffer, 10));
    1933             : 
    1934         100 :                 CATCH_REQUIRE(ss.str() == back);
    1935         100 :             }
    1936             :             {
    1937         100 :                 std::stringstream ss;
    1938         100 :                 if(i < 0)
    1939             :                 {
    1940          51 :                     ss << '-' << std::showbase << std::hex << std::uppercase << -i;
    1941             :                 }
    1942             :                 else
    1943             :                 {
    1944          49 :                     ss << std::showbase << std::hex << std::uppercase << i;
    1945             :                 }
    1946         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT128, ss.str()));
    1947         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT128, buffer, 16));
    1948             : 
    1949         100 :                 CATCH_REQUIRE(ss.str() == back);
    1950         100 :             }
    1951             :         }
    1952             : #pragma GCC diagnostic pop
    1953             :     }
    1954          37 :     CATCH_END_SECTION()
    1955             : 
    1956          37 :     CATCH_START_SECTION("convert_buffer: string -> bits256")
    1957             :     {
    1958         101 :         for(int j(0); j < 100; ++j)
    1959             :         {
    1960         100 :             prinbee::uint512_t i;
    1961         100 :             if(j != 0)
    1962             :             {
    1963          99 :                 SNAP_CATCH2_NAMESPACE::rand512(i);
    1964          99 :                 i.f_value[4] = 0;
    1965          99 :                 i.f_value[5] = 0;
    1966          99 :                 i.f_value[6] = 0;
    1967          99 :                 i.f_value[7] = 0;
    1968             :             }
    1969             :             {
    1970         100 :                 std::stringstream ss;
    1971         100 :                 if(i == 0)
    1972             :                 {
    1973           1 :                     ss << '0';
    1974             :                 }
    1975             :                 else
    1976             :                 {
    1977          99 :                     ss << "0B" << to_binary(i);
    1978             :                 }
    1979         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS256, ss.str()));
    1980         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS256, buffer, 2));
    1981             : 
    1982         100 :                 CATCH_REQUIRE(ss.str() == back);
    1983         100 :             }
    1984             :             {
    1985         100 :                 std::stringstream ss;
    1986         100 :                 if(i == 0)
    1987             :                 {
    1988           1 :                     ss << '0';
    1989             :                 }
    1990             :                 else
    1991             :                 {
    1992          99 :                     ss << std::oct << '0' << i;
    1993             :                 }
    1994         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS256, ss.str()));
    1995         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS256, buffer, 8));
    1996             : 
    1997         100 :                 CATCH_REQUIRE(ss.str() == back);
    1998         100 :             }
    1999             :             {
    2000         100 :                 std::stringstream ss;
    2001         100 :                 ss << std::dec << i;
    2002         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS256, ss.str()));
    2003         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS256, buffer, 10));
    2004             : 
    2005         100 :                 CATCH_REQUIRE(ss.str() == back);
    2006         100 :             }
    2007             :             {
    2008         100 :                 std::stringstream ss;
    2009         100 :                 if(i == 0)
    2010             :                 {
    2011           1 :                     ss << "0";
    2012             :                 }
    2013             :                 else
    2014             :                 {
    2015          99 :                     ss << std::hex << std::uppercase << "0X" << i;
    2016             :                 }
    2017         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS256, ss.str()));
    2018         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS256, buffer, 16));
    2019             : 
    2020         100 :                 CATCH_REQUIRE(ss.str() == back);
    2021         100 :             }
    2022             :         }
    2023             :     }
    2024          37 :     CATCH_END_SECTION()
    2025             : 
    2026          37 :     CATCH_START_SECTION("convert_buffer: string -> uint256")
    2027             :     {
    2028         101 :         for(int j(0); j < 100; ++j)
    2029             :         {
    2030         100 :             prinbee::uint512_t i;
    2031         100 :             if(j != 0)
    2032             :             {
    2033          99 :                 SNAP_CATCH2_NAMESPACE::rand512(i);
    2034          99 :                 i.f_value[4] = 0;
    2035          99 :                 i.f_value[5] = 0;
    2036          99 :                 i.f_value[6] = 0;
    2037          99 :                 i.f_value[7] = 0;
    2038             :             }
    2039             :             {
    2040         100 :                 std::stringstream ss;
    2041         100 :                 if(i == 0)
    2042             :                 {
    2043           1 :                     ss << '0';
    2044             :                 }
    2045             :                 else
    2046             :                 {
    2047          99 :                     ss << "0B" << to_binary(i);
    2048             :                 }
    2049         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT256, ss.str()));
    2050         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT256, buffer, 2));
    2051             : 
    2052         100 :                 CATCH_REQUIRE(ss.str() == back);
    2053         100 :             }
    2054             :             {
    2055         100 :                 std::stringstream ss;
    2056         100 :                 if(i == 0)
    2057             :                 {
    2058           1 :                     ss << '0';
    2059             :                 }
    2060             :                 else
    2061             :                 {
    2062          99 :                     ss << std::oct << '0' << i;
    2063             :                 }
    2064         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT256, ss.str()));
    2065         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT256, buffer, 8));
    2066             : 
    2067         100 :                 CATCH_REQUIRE(ss.str() == back);
    2068         100 :             }
    2069             :             {
    2070         100 :                 std::stringstream ss;
    2071         100 :                 ss << std::dec << i;
    2072         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT256, ss.str()));
    2073         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT256, buffer, 10));
    2074             : 
    2075         100 :                 CATCH_REQUIRE(ss.str() == back);
    2076         100 :             }
    2077             :             {
    2078         100 :                 std::stringstream ss;
    2079         100 :                 ss << std::showbase << std::hex << std::uppercase << i;
    2080         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT256, ss.str()));
    2081         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT256, buffer, 16));
    2082             : 
    2083         100 :                 CATCH_REQUIRE(ss.str() == back);
    2084         100 :             }
    2085             :         }
    2086             :     }
    2087          37 :     CATCH_END_SECTION()
    2088             : 
    2089          37 :     CATCH_START_SECTION("convert_buffer: string -> int256")
    2090             :     {
    2091         101 :         for(int j(0); j < 100; ++j)
    2092             :         {
    2093         100 :             prinbee::int512_t i;
    2094         100 :             if(j != 0)
    2095             :             {
    2096          99 :                 SNAP_CATCH2_NAMESPACE::rand512(i);
    2097          99 :                 if(i.f_value[3] & 0x8000000000000000UL)
    2098             :                 {
    2099          50 :                     i.f_value[4] = 0xFFFFFFFFFFFFFFFF;
    2100          50 :                     i.f_value[5] = 0xFFFFFFFFFFFFFFFF;
    2101          50 :                     i.f_value[6] = 0xFFFFFFFFFFFFFFFF;
    2102          50 :                     i.f_high_value = -1;
    2103             :                 }
    2104             :                 else
    2105             :                 {
    2106          49 :                     i.f_value[4] = 0;
    2107          49 :                     i.f_value[5] = 0;
    2108          49 :                     i.f_value[6] = 0;
    2109          49 :                     i.f_high_value = 0;
    2110             :                 }
    2111             :             }
    2112             :             {
    2113         100 :                 std::stringstream ss;
    2114         100 :                 if(i == 0)
    2115             :                 {
    2116           1 :                     ss << '0';
    2117             :                 }
    2118          99 :                 else if(i < 0)
    2119             :                 {
    2120          50 :                     ss << "-0B" << to_binary(-i);
    2121             :                 }
    2122             :                 else
    2123             :                 {
    2124          49 :                     ss << "0B" << to_binary(i);
    2125             :                 }
    2126         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT256, ss.str()));
    2127         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT256, buffer, 2));
    2128             : 
    2129         100 :                 CATCH_REQUIRE(ss.str() == back);
    2130         100 :             }
    2131             :             {
    2132         100 :                 std::stringstream ss;
    2133         100 :                 if(i == 0)
    2134             :                 {
    2135           1 :                     ss << '0';
    2136             :                 }
    2137          99 :                 else if(i < 0)
    2138             :                 {
    2139          50 :                     ss << '-' << std::showbase << std::oct << -i;
    2140             :                 }
    2141             :                 else
    2142             :                 {
    2143          49 :                     ss << std::showbase << std::oct << i;
    2144             :                 }
    2145         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT256, ss.str()));
    2146         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT256, buffer, 8));
    2147             : 
    2148         100 :                 CATCH_REQUIRE(ss.str() == back);
    2149         100 :             }
    2150             :             {
    2151         100 :                 std::stringstream ss;
    2152         100 :                 ss << std::dec << i;
    2153         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT256, ss.str()));
    2154         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT256, buffer, 10));
    2155             : 
    2156         100 :                 CATCH_REQUIRE(ss.str() == back);
    2157         100 :             }
    2158             :             {
    2159         100 :                 std::stringstream ss;
    2160         100 :                 ss << std::showbase << std::hex << std::uppercase << i;
    2161         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT256, ss.str()));
    2162         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT256, buffer, 16));
    2163             : 
    2164         100 :                 CATCH_REQUIRE(ss.str() == back);
    2165         100 :             }
    2166             :         }
    2167             :     }
    2168          37 :     CATCH_END_SECTION()
    2169             : 
    2170          37 :     CATCH_START_SECTION("convert_buffer: string -> bits512")
    2171             :     {
    2172         101 :         for(int j(0); j < 100; ++j)
    2173             :         {
    2174         100 :             prinbee::uint512_t i;
    2175         100 :             SNAP_CATCH2_NAMESPACE::rand512(i);
    2176             :             {
    2177         100 :                 std::stringstream ss;
    2178         100 :                 ss << "0B" << to_binary(i);
    2179         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS512, ss.str()));
    2180         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS512, buffer, 2));
    2181             : 
    2182         100 :                 CATCH_REQUIRE(ss.str() == back);
    2183         100 :             }
    2184             :             {
    2185         100 :                 std::stringstream ss;
    2186         100 :                 if(i == 0)
    2187             :                 {
    2188           0 :                     ss << '0';
    2189             :                 }
    2190             :                 else
    2191             :                 {
    2192         100 :                     ss << std::oct << '0' << i;
    2193             :                 }
    2194         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS512, ss.str()));
    2195         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS512, buffer, 8));
    2196             : 
    2197         100 :                 CATCH_REQUIRE(ss.str() == back);
    2198         100 :             }
    2199             :             {
    2200         100 :                 std::stringstream ss;
    2201         100 :                 ss << std::dec << i;
    2202         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS512, ss.str()));
    2203         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS512, buffer, 10));
    2204             : 
    2205         100 :                 CATCH_REQUIRE(ss.str() == back);
    2206         100 :             }
    2207             :             {
    2208         100 :                 std::stringstream ss;
    2209         100 :                 if(i == 0)
    2210             :                 {
    2211           0 :                     ss << "0";
    2212             :                 }
    2213             :                 else
    2214             :                 {
    2215         100 :                     ss << std::hex << std::uppercase << "0X" << i;
    2216             :                 }
    2217         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS512, ss.str()));
    2218         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS512, buffer, 16));
    2219             : 
    2220         100 :                 CATCH_REQUIRE(ss.str() == back);
    2221         100 :             }
    2222             :         }
    2223             :     }
    2224          37 :     CATCH_END_SECTION()
    2225             : 
    2226          37 :     CATCH_START_SECTION("convert_buffer: string -> uint512")
    2227             :     {
    2228         101 :         for(int j(0); j < 100; ++j)
    2229             :         {
    2230         100 :             prinbee::uint512_t i;
    2231         100 :             SNAP_CATCH2_NAMESPACE::rand512(i);
    2232             :             {
    2233         100 :                 std::stringstream ss;
    2234         100 :                 ss << "0B" << to_binary(i);
    2235         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT512, ss.str()));
    2236         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT512, buffer, 2));
    2237             : 
    2238         100 :                 CATCH_REQUIRE(ss.str() == back);
    2239         100 :             }
    2240             :             {
    2241         100 :                 std::stringstream ss;
    2242         100 :                 if(i == 0)
    2243             :                 {
    2244           0 :                     ss << '0';
    2245             :                 }
    2246             :                 else
    2247             :                 {
    2248         100 :                     ss << std::oct << '0' << i;
    2249             :                 }
    2250         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT512, ss.str()));
    2251         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT512, buffer, 8));
    2252             : 
    2253         100 :                 CATCH_REQUIRE(ss.str() == back);
    2254         100 :             }
    2255             :             {
    2256         100 :                 std::stringstream ss;
    2257         100 :                 ss << std::dec << i;
    2258         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT512, ss.str()));
    2259         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT512, buffer, 10));
    2260             : 
    2261         100 :                 CATCH_REQUIRE(ss.str() == back);
    2262         100 :             }
    2263             :             {
    2264         100 :                 std::stringstream ss;
    2265         100 :                 ss << std::showbase << std::hex << std::uppercase << i;
    2266         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT512, ss.str()));
    2267         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT512, buffer, 16));
    2268             : 
    2269         100 :                 CATCH_REQUIRE(ss.str() == back);
    2270         100 :             }
    2271             :         }
    2272             :     }
    2273          37 :     CATCH_END_SECTION()
    2274             : 
    2275          37 :     CATCH_START_SECTION("convert_buffer: string -> int512")
    2276             :     {
    2277         101 :         for(int j(0); j < 100; ++j)
    2278             :         {
    2279         100 :             prinbee::int512_t i;
    2280         100 :             if(j != 0)
    2281             :             {
    2282          99 :                 SNAP_CATCH2_NAMESPACE::rand512(i);
    2283             :             }
    2284             :             {
    2285         100 :                 std::stringstream ss;
    2286         100 :                 if(i == 0)
    2287             :                 {
    2288           1 :                     ss << '0';
    2289             :                 }
    2290          99 :                 else if(i < 0)
    2291             :                 {
    2292          38 :                     ss << "-0B" << to_binary(-i);
    2293             :                 }
    2294             :                 else
    2295             :                 {
    2296          61 :                     ss << "0B" << to_binary(i);
    2297             :                 }
    2298         200 :                 prinbee::buffer_t buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT512, ss.str()));
    2299         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 2));
    2300             : 
    2301         100 :                 CATCH_REQUIRE(ss.str() == back);
    2302             : 
    2303             :                 // the buffer can be shorten in this case which hits a specific
    2304             :                 // case when the value is negative; the following loop is used
    2305             :                 // to test all 63 bytes
    2306             :                 //
    2307         100 :                 if(i < 0)
    2308             :                 {
    2309        2432 :                     for(int pos(63); pos > 0; --pos)
    2310             :                     {
    2311        2394 :                         buffer[pos] = 0xFF;
    2312        2394 :                         buffer[pos - 1] |= 0x80;
    2313             : 
    2314             :                         // the output of a negative number in binary actually
    2315             :                         // outputs the positive version of the number with a
    2316             :                         // '-' sign in front of it (since we deal primarily
    2317             :                         // with small numbers, this means we often will have
    2318             :                         // very small output in number of characters)
    2319             :                         // so here I create a copy of buffer and compute
    2320             :                         // the additive inverse
    2321             :                         //
    2322        2394 :                         prinbee::buffer_t binary(buffer);
    2323        2394 :                         int carry(1);
    2324      155610 :                         for(int neg(0); neg < 64; ++neg) // WARNING: this assumes little endian
    2325             :                         {
    2326      153216 :                             binary[neg] = ~binary[neg] + carry;
    2327      153216 :                             carry = binary[neg] == 0 && carry == 1 ? 1 : 0;
    2328             :                         }
    2329        2394 :                         std::stringstream sn;
    2330        2394 :                         sn << "-0B";
    2331        2394 :                         bool found(false);
    2332      155610 :                         for(int byte(63); byte >= 0; --byte)
    2333             :                         {
    2334      153216 :                             int bit(8);
    2335     1378944 :                             while(bit > 0)
    2336             :                             {
    2337     1225728 :                                 --bit;
    2338     1225728 :                                 if((binary[byte] & (1 << bit)) != 0)
    2339             :                                 {
    2340      306464 :                                     sn << '1';
    2341      306464 :                                     found = true;
    2342             :                                 }
    2343      919264 :                                 else if(found)
    2344             :                                 {
    2345      301720 :                                     sn << '0';
    2346             :                                 }
    2347             :                             }
    2348             :                         }
    2349        2394 :                         if(!found) // if input is 0
    2350             :                         {
    2351           0 :                             sn << '0';
    2352             :                         }
    2353        2394 :                         std::string const small(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 2));
    2354        2394 :                         CATCH_REQUIRE(sn.str() == small);
    2355        2394 :                     }
    2356             :                 }
    2357         100 :             }
    2358             :             {
    2359         100 :                 std::stringstream ss;
    2360         100 :                 if(i == 0)
    2361             :                 {
    2362           1 :                     ss << '0';
    2363             :                 }
    2364          99 :                 else if(i < 0)
    2365             :                 {
    2366          38 :                     ss << '-' << std::oct << std::showbase << -i;
    2367             :                 }
    2368             :                 else
    2369             :                 {
    2370          61 :                     ss << std::oct << std::showbase << i;
    2371             :                 }
    2372         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT512, ss.str()));
    2373         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 8));
    2374             : 
    2375         100 :                 CATCH_REQUIRE(ss.str() == back);
    2376         100 :             }
    2377             :             {
    2378         100 :                 std::stringstream ss;
    2379         100 :                 ss << std::dec << i;
    2380         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT512, ss.str()));
    2381         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 10));
    2382             : 
    2383         100 :                 CATCH_REQUIRE(ss.str() == back);
    2384         100 :             }
    2385             :             {
    2386         100 :                 std::stringstream ss;
    2387         100 :                 ss << std::showbase << std::hex << std::uppercase << i;
    2388         200 :                 prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT512, ss.str()));
    2389         100 :                 std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 16));
    2390             : 
    2391         100 :                 CATCH_REQUIRE(ss.str() == back);
    2392         100 :             }
    2393             :         }
    2394             :     }
    2395          37 :     CATCH_END_SECTION()
    2396             : 
    2397          37 :     CATCH_START_SECTION("convert_buffer: string -> float32")
    2398             :     {
    2399         101 :         for(int j(0); j < 100; ++j)
    2400             :         {
    2401         100 :             float const i(SNAP_CATCH2_NAMESPACE::rand32() / (SNAP_CATCH2_NAMESPACE::rand32() | 1));
    2402             : 
    2403         100 :             std::stringstream ss;
    2404         100 :             ss << i;
    2405         800 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, std::string(rand() % 10, ' ') + ss.str() + std::string(rand() % 10, ' ')));
    2406         100 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, buffer, 2));
    2407             : 
    2408         100 :             CATCH_REQUIRE(ss.str() == back);
    2409         100 :         }
    2410             :     }
    2411          37 :     CATCH_END_SECTION()
    2412             : 
    2413          37 :     CATCH_START_SECTION("convert_buffer: string -> float64")
    2414             :     {
    2415         101 :         for(int j(0); j < 100; ++j)
    2416             :         {
    2417         100 :             double const i(SNAP_CATCH2_NAMESPACE::rand64() / (SNAP_CATCH2_NAMESPACE::rand64() | 1));
    2418             : 
    2419         100 :             std::stringstream ss;
    2420         100 :             ss << i;
    2421         800 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, std::string(rand() % 10, ' ') + ss.str() + std::string(rand() % 10, ' ')));
    2422         100 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, buffer, 2));
    2423             : 
    2424         100 :             CATCH_REQUIRE(ss.str() == back);
    2425         100 :         }
    2426             :     }
    2427          37 :     CATCH_END_SECTION()
    2428             : 
    2429          37 :     CATCH_START_SECTION("convert_buffer: string -> float128")
    2430             :     {
    2431         101 :         for(int j(0); j < 100; ++j)
    2432             :         {
    2433         100 :             long double const i(SNAP_CATCH2_NAMESPACE::rand128() / (SNAP_CATCH2_NAMESPACE::rand128() | 1));
    2434             : 
    2435         100 :             std::stringstream ss;
    2436         100 :             ss << i;
    2437         800 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, std::string(rand() % 10, ' ') + ss.str() + std::string(rand() % 10, ' ')));
    2438         100 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, buffer, 2));
    2439             : 
    2440         100 :             CATCH_REQUIRE(ss.str() == back);
    2441         100 :         }
    2442             :     }
    2443          37 :     CATCH_END_SECTION()
    2444             : 
    2445          37 :     CATCH_START_SECTION("convert_buffer: string -> version")
    2446             :     {
    2447         101 :         for(int j(0); j < 100; ++j)
    2448             :         {
    2449         100 :             std::uint16_t vmajor(rand());
    2450         100 :             std::uint16_t vminor(rand());
    2451             : 
    2452         100 :             std::stringstream ss;
    2453         198 :             for(int i(rand() % 10 - 5); i > 0; --i)
    2454             :             {
    2455          98 :                 ss << ' ';
    2456             :             }
    2457         100 :             if(rand() % 5 == 0)
    2458             :             {
    2459          22 :                 ss << 'v';
    2460             :             }
    2461         100 :             ss << vmajor << '.' << vminor;
    2462         214 :             for(int i(rand() % 10 - 5); i > 0; --i)
    2463             :             {
    2464         114 :                 ss << ' ';
    2465             :             }
    2466         200 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, ss.str()));
    2467         100 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_VERSION, buffer, 2));
    2468             : 
    2469         100 :             std::stringstream expect;
    2470         100 :             expect << vmajor << '.' << vminor;
    2471         100 :             CATCH_REQUIRE(expect.str() == back);
    2472         100 :         }
    2473             :     }
    2474          37 :     CATCH_END_SECTION()
    2475             : 
    2476          37 :     CATCH_START_SECTION("convert_buffer: string -> time (seconds)")
    2477             :     {
    2478          26 :         for(int j(0); j < 25; ++j)
    2479             :         {
    2480             :             // negative numbers are not that useful to us at the moment
    2481             :             // and very negative are not representing valid dates
    2482             :             //
    2483             :             // note: the 3,000 years is very approximative since I use 365
    2484             :             //       days per year (to simplify); it still takes use close
    2485             :             //       enough I think
    2486             :             //
    2487          25 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2488          25 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2489             : 
    2490             :             // we only output back to UTC so use UTC here
    2491             :             //
    2492          50 :             std::string cmd("date -u +%Y-%m-%dT%T -d @");
    2493          25 :             cmd += std::to_string(d);
    2494          25 :             FILE * p(popen(cmd.c_str(), "r"));
    2495          25 :             CATCH_REQUIRE(p != nullptr);
    2496          25 :             char buf[256] = {};
    2497          25 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2498          25 :             CATCH_REQUIRE(sz >= 1);
    2499          25 :             CATCH_REQUIRE(sz < sizeof(buf));
    2500          25 :             if(buf[sz - 1] == '\n')
    2501             :             {
    2502          25 :                 --sz;
    2503             :             }
    2504          25 :             buf[sz] = '\0';
    2505          25 :             CATCH_REQUIRE(pclose(p) == 0);
    2506             : 
    2507          75 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_TIME, buf));
    2508          25 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_TIME, buffer, 2));
    2509             : 
    2510             :             // the prinbee always includes the timezone (+0000)
    2511             :             //
    2512          25 :             CATCH_REQUIRE(std::string(buf) + "+0000" == back);
    2513          25 :         }
    2514             :     }
    2515          37 :     CATCH_END_SECTION()
    2516             : 
    2517          37 :     CATCH_START_SECTION("convert_buffer: string -> time (seconds + timezone)")
    2518             :     {
    2519          26 :         for(int j(0); j < 25; ++j)
    2520             :         {
    2521             :             // negative numbers are not that useful to us at the moment
    2522             :             // and very negative are not representing valid dates
    2523             :             //
    2524             :             // note: the 3,000 years is very approximative since I use 365
    2525             :             //       days per year (to simplify); it still takes use close
    2526             :             //       enough I think
    2527             :             //
    2528          25 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2529          25 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2530             : 
    2531             :             // we only output back to UTC so use UTC here
    2532             :             //
    2533          50 :             std::string cmd("date -u +%Y-%m-%dT%T%z -d @");
    2534          25 :             cmd += std::to_string(d);
    2535          25 :             FILE * p(popen(cmd.c_str(), "r"));
    2536          25 :             CATCH_REQUIRE(p != nullptr);
    2537          25 :             char buf[256] = {};
    2538          25 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2539          25 :             CATCH_REQUIRE(sz >= 1);
    2540          25 :             CATCH_REQUIRE(sz < sizeof(buf));
    2541          25 :             if(buf[sz - 1] == '\n')
    2542             :             {
    2543          25 :                 --sz;
    2544             :             }
    2545          25 :             buf[sz] = '\0';
    2546          25 :             CATCH_REQUIRE(pclose(p) == 0);
    2547             : 
    2548          75 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_TIME, buf));
    2549          25 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_TIME, buffer, 2));
    2550             : 
    2551          25 :             CATCH_REQUIRE(buf == back);
    2552          25 :         }
    2553             :     }
    2554          37 :     CATCH_END_SECTION()
    2555             : 
    2556          37 :     CATCH_START_SECTION("convert_buffer: string -> time (milliseconds + timezone)")
    2557             :     {
    2558          11 :         for(int j(0); j < 10; ++j)
    2559             :         {
    2560             :             // negative numbers are not that useful to us at the moment
    2561             :             // and very negative are not representing valid dates
    2562             :             //
    2563             :             // note: the 3,000 years is very approximative since I use 365
    2564             :             //       days per year (to simplify); it still takes use close
    2565             :             //       enough I think
    2566             :             //
    2567          10 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2568          10 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2569          10 :             std::uint32_t const ms(rand() % 10); // 0 to 9
    2570             : 
    2571             :             // we only output back to UTC so use UTC here
    2572             :             //
    2573          20 :             std::string cmd("date -u +%Y-%m-%dT%T.");
    2574          10 :             cmd += std::to_string(ms);
    2575          10 :             cmd += "%z -d @";
    2576          10 :             cmd += std::to_string(d);
    2577          10 :             FILE * p(popen(cmd.c_str(), "r"));
    2578          10 :             CATCH_REQUIRE(p != nullptr);
    2579          10 :             char buf[256] = {};
    2580          10 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2581          10 :             CATCH_REQUIRE(sz >= 1);
    2582          10 :             CATCH_REQUIRE(sz < sizeof(buf));
    2583          10 :             if(buf[sz - 1] == '\n')
    2584             :             {
    2585          10 :                 --sz;
    2586             :             }
    2587          10 :             buf[sz] = '\0';
    2588          10 :             CATCH_REQUIRE(pclose(p) == 0);
    2589             : 
    2590          20 :             std::string mstime(buf);
    2591          10 :             std::string::size_type const pos(mstime.find('+'));
    2592          10 :             CATCH_REQUIRE(pos != std::string::npos);
    2593          10 :             mstime =
    2594          20 :                   mstime.substr(0, pos)
    2595          30 :                 + "00"
    2596          30 :                 + mstime.substr(pos);
    2597             : 
    2598          30 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buf));
    2599          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buffer, 2));
    2600             : 
    2601          10 :             CATCH_REQUIRE(mstime == back);
    2602          10 :         }
    2603          11 :         for(int j(0); j < 10; ++j)
    2604             :         {
    2605             :             // negative numbers are not that useful to us at the moment
    2606             :             // and very negative are not representing valid dates
    2607             :             //
    2608             :             // note: the 3,000 years is very approximative since I use 365
    2609             :             //       days per year (to simplify); it still takes use close
    2610             :             //       enough I think
    2611             :             //
    2612          10 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2613          10 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2614          10 :             std::uint32_t const ms(rand() % (100 - 10) + 10); // 10 to 99
    2615             : 
    2616             :             // we only output back to UTC so use UTC here
    2617             :             //
    2618          20 :             std::string cmd("date -u +%Y-%m-%dT%T.");
    2619          10 :             cmd += std::to_string(ms);
    2620          10 :             cmd += "%z -d @";
    2621          10 :             cmd += std::to_string(d);
    2622          10 :             FILE * p(popen(cmd.c_str(), "r"));
    2623          10 :             CATCH_REQUIRE(p != nullptr);
    2624          10 :             char buf[256] = {};
    2625          10 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2626          10 :             CATCH_REQUIRE(sz >= 1);
    2627          10 :             CATCH_REQUIRE(sz < sizeof(buf));
    2628          10 :             if(buf[sz - 1] == '\n')
    2629             :             {
    2630          10 :                 --sz;
    2631             :             }
    2632          10 :             buf[sz] = '\0';
    2633          10 :             CATCH_REQUIRE(pclose(p) == 0);
    2634             : 
    2635          20 :             std::string mstime(buf);
    2636          10 :             std::string::size_type const pos(mstime.find('+'));
    2637          10 :             CATCH_REQUIRE(pos != std::string::npos);
    2638          10 :             mstime =
    2639          20 :                   mstime.substr(0, pos)
    2640          30 :                 + "0"
    2641          30 :                 + mstime.substr(pos);
    2642             : 
    2643          30 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buf));
    2644          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buffer, 2));
    2645             : 
    2646          10 :             CATCH_REQUIRE(mstime == back);
    2647          10 :         }
    2648          11 :         for(int j(0); j < 10; ++j)
    2649             :         {
    2650             :             // negative numbers are not that useful to us at the moment
    2651             :             // and very negative are not representing valid dates
    2652             :             //
    2653             :             // note: the 3,000 years is very approximative since I use 365
    2654             :             //       days per year (to simplify); it still takes use close
    2655             :             //       enough I think
    2656             :             //
    2657          10 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2658          10 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2659          10 :             std::uint32_t const ms(rand() % 1'000);
    2660             : 
    2661             :             // we only output back to UTC so use UTC here
    2662             :             //
    2663          20 :             std::string cmd("date -u +%Y-%m-%dT%T.");
    2664          10 :             if(ms < 10)
    2665             :             {
    2666           0 :                 cmd += '0';
    2667             :             }
    2668          10 :             if(ms < 100)
    2669             :             {
    2670           0 :                 cmd += '0';
    2671             :             }
    2672          10 :             cmd += std::to_string(ms);
    2673          10 :             cmd += "%z -d @";
    2674          10 :             cmd += std::to_string(d);
    2675          10 :             FILE * p(popen(cmd.c_str(), "r"));
    2676          10 :             CATCH_REQUIRE(p != nullptr);
    2677          10 :             char buf[256] = {};
    2678          10 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2679          10 :             CATCH_REQUIRE(sz >= 1);
    2680          10 :             CATCH_REQUIRE(sz < sizeof(buf));
    2681          10 :             if(buf[sz - 1] == '\n')
    2682             :             {
    2683          10 :                 --sz;
    2684             :             }
    2685          10 :             buf[sz] = '\0';
    2686          10 :             CATCH_REQUIRE(pclose(p) == 0);
    2687             : 
    2688          20 :             std::string mstime(buf);
    2689          10 :             int const extra_zeroes(rand() % 4);
    2690          10 :             if(extra_zeroes > 0)
    2691             :             {
    2692           8 :                 std::string::size_type const pos(mstime.find('+'));
    2693           8 :                 if(pos != std::string::npos)
    2694             :                 {
    2695           8 :                     mstime =
    2696          16 :                           mstime.substr(0, pos)
    2697          32 :                         + std::string(extra_zeroes, '0')
    2698          24 :                         + mstime.substr(pos + 1);
    2699             :                 }
    2700             :             }
    2701             : 
    2702          10 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, mstime));
    2703          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buffer, 2));
    2704             : 
    2705          10 :             CATCH_REQUIRE(buf == back);
    2706          10 :         }
    2707             :     }
    2708          37 :     CATCH_END_SECTION()
    2709             : 
    2710          37 :     CATCH_START_SECTION("convert_buffer: string -> time (microseconds + timezone)")
    2711             :     {
    2712          26 :         for(int j(0); j < 25; ++j)
    2713             :         {
    2714             :             // negative numbers are not that useful to us at the moment
    2715             :             // and very negative are not representing valid dates
    2716             :             //
    2717             :             // note: the 3,000 years is very approximative since I use 365
    2718             :             //       days per year (to simplify); it still takes use close
    2719             :             //       enough I think
    2720             :             //
    2721          25 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    2722          25 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    2723          25 :             std::uint32_t const us(SNAP_CATCH2_NAMESPACE::rand32() % 1'000'000LL);
    2724             : 
    2725             :             // we only output back to UTC so use UTC here
    2726             :             //
    2727          50 :             std::string cmd("date -u +%Y-%m-%dT%T.");
    2728          25 :             if(us < 10)
    2729             :             {
    2730           0 :                 cmd += '0';
    2731             :             }
    2732          25 :             if(us < 100)
    2733             :             {
    2734           0 :                 cmd += '0';
    2735             :             }
    2736          25 :             if(us < 1'000)
    2737             :             {
    2738           0 :                 cmd += '0';
    2739             :             }
    2740          25 :             if(us < 10'000)
    2741             :             {
    2742           0 :                 cmd += '0';
    2743             :             }
    2744          25 :             if(us < 100'000)
    2745             :             {
    2746           0 :                 cmd += '0';
    2747             :             }
    2748          25 :             cmd += std::to_string(us);
    2749          25 :             cmd += "%z -d @";
    2750          25 :             cmd += std::to_string(d);
    2751          25 :             FILE * p(popen(cmd.c_str(), "r"));
    2752          25 :             CATCH_REQUIRE(p != nullptr);
    2753          25 :             char buf[256] = {};
    2754          25 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    2755          25 :             CATCH_REQUIRE(sz >= 1);
    2756          25 :             CATCH_REQUIRE(sz < sizeof(buf));
    2757          25 :             if(buf[sz - 1] == '\n')
    2758             :             {
    2759          25 :                 --sz;
    2760             :             }
    2761          25 :             buf[sz] = '\0';
    2762          25 :             CATCH_REQUIRE(pclose(p) == 0);
    2763             : 
    2764          50 :             std::string ustime(buf);
    2765          25 :             int const extra_zeroes(rand() % 4);
    2766          25 :             if(extra_zeroes > 0)
    2767             :             {
    2768          18 :                 std::string::size_type const pos(ustime.find('+'));
    2769          18 :                 if(pos != std::string::npos)
    2770             :                 {
    2771          18 :                     ustime =
    2772          36 :                           ustime.substr(0, pos)
    2773          72 :                         + std::string(extra_zeroes, '0')
    2774          54 :                         + ustime.substr(pos + 1);
    2775             :                 }
    2776             :             }
    2777             : 
    2778          25 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_USTIME, ustime));
    2779          25 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_USTIME, buffer, 2));
    2780             : 
    2781          25 :             CATCH_REQUIRE(buf == back);
    2782          25 :         }
    2783             :     }
    2784          37 :     CATCH_END_SECTION()
    2785             : 
    2786          37 :     CATCH_START_SECTION("convert_buffer: string -> p8string")
    2787             :     {
    2788         257 :         for(int j(0); j < 256; ++j)
    2789             :         {
    2790         256 :             std::string const str(SNAP_CATCH2_NAMESPACE::rand_string(j));
    2791         256 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_P8STRING, str));
    2792         256 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P8STRING, buffer, rand()));
    2793             : 
    2794         256 :             CATCH_REQUIRE(str == back);
    2795         256 :         }
    2796             :     }
    2797          37 :     CATCH_END_SECTION()
    2798             : 
    2799          37 :     CATCH_START_SECTION("convert_buffer: string -> p16string")
    2800             :     {
    2801          11 :         for(int j(0); j < 10; ++j)
    2802             :         {
    2803          10 :             int const len(j == 0 ? 0 : (j == 1 ? 65'535 : rand() % 1'000));
    2804          10 :             std::string const str(SNAP_CATCH2_NAMESPACE::rand_string(len));
    2805          10 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, str));
    2806          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, buffer, rand()));
    2807             : 
    2808          10 :             CATCH_REQUIRE(str == back);
    2809          10 :         }
    2810             :     }
    2811          37 :     CATCH_END_SECTION()
    2812             : 
    2813          37 :     CATCH_START_SECTION("convert_buffer: string -> p32string")
    2814             :     {
    2815          11 :         for(int j(0); j < 10; ++j)
    2816             :         {
    2817          10 :             int const len(j == 0 ? 0 : (j == 1 ? 100'000 : rand() % 2'500));
    2818          10 :             std::string const str(SNAP_CATCH2_NAMESPACE::rand_string(len));
    2819          10 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, str));
    2820          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer, rand()));
    2821             : 
    2822          10 :             CATCH_REQUIRE(str == back);
    2823          10 :         }
    2824             :     }
    2825          37 :     CATCH_END_SECTION()
    2826             : 
    2827          37 :     CATCH_START_SECTION("convert_buffer: string -> buffer8")
    2828             :     {
    2829         257 :         for(int j(0); j < 256; ++j)
    2830             :         {
    2831         512 :             prinbee::buffer_t buffer(j + 1);
    2832         256 :             std::string str;
    2833         256 :             buffer[0] = j;
    2834       32896 :             for(int i(1); i <= j; ++i)
    2835             :             {
    2836       32640 :                 buffer[i] = rand();
    2837       32640 :                 str += snapdev::to_hex(buffer[i] >> 4);
    2838       32640 :                 str += snapdev::to_hex(buffer[i] & 15);
    2839             :             }
    2840             : 
    2841         256 :             prinbee::buffer_t const pbuffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BUFFER8, str));
    2842         256 :             CATCH_REQUIRE(buffer == pbuffer);
    2843             : 
    2844         256 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER8, pbuffer, rand()));
    2845         256 :             CATCH_REQUIRE(str == back);
    2846         256 :         }
    2847             :     }
    2848          37 :     CATCH_END_SECTION()
    2849             : 
    2850          37 :     CATCH_START_SECTION("convert_buffer: string -> buffer16")
    2851             :     {
    2852         101 :         for(int j(0); j < 100; ++j)
    2853             :         {
    2854             :             std::size_t const size(
    2855             :                     j == 0
    2856         198 :                         ? 0
    2857             :                         : j == 1
    2858             :                             ? 65535
    2859          98 :                             : rand() & 0xFFFF);
    2860             : 
    2861         200 :             prinbee::buffer_t buffer(size + 2);
    2862         100 :             std::string str;
    2863         100 :             buffer[0] = size;          // Little Endian specific
    2864         100 :             buffer[1] = size >> 8;
    2865     3532591 :             for(std::size_t i(2); i < size + 2; ++i)
    2866             :             {
    2867     3532491 :                 buffer[i] = rand();
    2868     3532491 :                 str += snapdev::to_hex(buffer[i] >> 4);
    2869     3532491 :                 str += snapdev::to_hex(buffer[i] & 15);
    2870             :             }
    2871             : 
    2872         100 :             prinbee::buffer_t const pbuffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, str));
    2873         100 :             CATCH_REQUIRE(buffer == pbuffer);
    2874             : 
    2875         100 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, pbuffer, rand()));
    2876         100 :             CATCH_REQUIRE(str == back);
    2877         100 :         }
    2878             :     }
    2879          37 :     CATCH_END_SECTION()
    2880             : 
    2881          37 :     CATCH_START_SECTION("convert_buffer: string -> buffer32")
    2882             :     {
    2883          11 :         for(int j(0); j < 10; ++j)
    2884             :         {
    2885          10 :             std::size_t const size(j == 0 ? 0 : SNAP_CATCH2_NAMESPACE::rand32() % 100'000);
    2886             : 
    2887          20 :             prinbee::buffer_t buffer(size + 4);
    2888          10 :             std::string str;
    2889          10 :             buffer[0] = size;          // Little Endian specific
    2890          10 :             buffer[1] = size >> 8;
    2891          10 :             buffer[2] = size >> 16;
    2892          10 :             buffer[3] = size >> 24;
    2893      522299 :             for(std::size_t i(4); i < size + 4; ++i)
    2894             :             {
    2895      522289 :                 buffer[i] = rand();
    2896      522289 :                 str += snapdev::to_hex(buffer[i] >> 4);
    2897      522289 :                 str += snapdev::to_hex(buffer[i] & 15);
    2898             :             }
    2899             : 
    2900          10 :             prinbee::buffer_t const pbuffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, str));
    2901          10 :             CATCH_REQUIRE(buffer == pbuffer);
    2902             : 
    2903          10 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, pbuffer, rand()));
    2904          10 :             CATCH_REQUIRE(str == back);
    2905          10 :         }
    2906             :     }
    2907          37 :     CATCH_END_SECTION()
    2908          37 : }
    2909             : 
    2910             : 
    2911          27 : CATCH_TEST_CASE("convert_errors", "[convert] [invalid]")
    2912             : {
    2913          27 :     CATCH_START_SECTION("convert_errors: too large")
    2914             :     {
    2915          62 :         for(int i(0); i < 61; ++i)
    2916             :         {
    2917          61 :             std::string s(std::to_string(1ULL << (i + 1)));
    2918             : 
    2919          61 :             CATCH_REQUIRE_THROWS_MATCHES(
    2920             :                       prinbee::convert_to_int(s, i)
    2921             :                     , prinbee::out_of_range
    2922             :                     , Catch::Matchers::ExceptionMessage(
    2923             :                               "out_of_range: number \""
    2924             :                             + s
    2925             :                             + "\" too large for a signed "
    2926             :                             + std::to_string(i)
    2927             :                             + " bit value."));
    2928             : 
    2929          61 :             CATCH_REQUIRE_THROWS_MATCHES(
    2930             :                       prinbee::convert_to_uint(s, i)
    2931             :                     , prinbee::out_of_range
    2932             :                     , Catch::Matchers::ExceptionMessage(
    2933             :                               "out_of_range: number \""
    2934             :                             + s
    2935             :                             + "\" too large for a signed "
    2936             :                             + std::to_string(i)
    2937             :                             + " bit value."));
    2938          61 :         }
    2939             :     }
    2940          27 :     CATCH_END_SECTION()
    2941             : 
    2942          27 :     CATCH_START_SECTION("convert_errors: negative uint")
    2943             :     {
    2944           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2945             :                   prinbee::convert_to_uint("-64", 4)
    2946             :                 , prinbee::invalid_number
    2947             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: negative values are not accepted, \"-64\" is not valid."));
    2948             :     }
    2949          27 :     CATCH_END_SECTION()
    2950             : 
    2951          27 :     CATCH_START_SECTION("convert_errors: missing closing quote")
    2952             :     {
    2953           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2954             :                   prinbee::convert_to_int("-X'64", 4)
    2955             :                 , prinbee::invalid_number
    2956             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: closing quote missing in \"-X'64\"."));
    2957             :     }
    2958          27 :     CATCH_END_SECTION()
    2959             : 
    2960          27 :     CATCH_START_SECTION("convert_errors: data when no unit is expected")
    2961             :     {
    2962           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2963             :                   prinbee::convert_to_int("64 m", 120)
    2964             :                 , prinbee::invalid_number
    2965             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: could not convert number \"64 m\" to a valid uint512_t value (spurious data found after number)."));
    2966             :     }
    2967          27 :     CATCH_END_SECTION()
    2968             : 
    2969          27 :     CATCH_START_SECTION("convert_errors: number too large for bits8 type")
    2970             :     {
    2971           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2972             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, "256")
    2973             :                 , prinbee::out_of_range
    2974             :                 , Catch::Matchers::ExceptionMessage("out_of_range: number \"256\" too large for an 8 bit value."));
    2975             :     }
    2976          27 :     CATCH_END_SECTION()
    2977             : 
    2978          27 :     CATCH_START_SECTION("convert_errors: number too large for uint8 type")
    2979             :     {
    2980           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2981             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT8, "256")
    2982             :                 , prinbee::out_of_range
    2983             :                 , Catch::Matchers::ExceptionMessage("out_of_range: number \"256\" too large for an 8 bit value."));
    2984             : 
    2985           3 :         prinbee::buffer_t buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT512, "256"));
    2986           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    2987             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_UINT8, buffer, 10)
    2988             :                 , prinbee::out_of_range
    2989             :                 , Catch::Matchers::ExceptionMessage("out_of_range: value too large (512 bits) for this field (max: 8 bits)."));
    2990           1 :     }
    2991          27 :     CATCH_END_SECTION()
    2992             : 
    2993          27 :     CATCH_START_SECTION("convert_errors: number too large for int8 type")
    2994             :     {
    2995           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    2996             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, "256")
    2997             :                 , prinbee::out_of_range
    2998             :                 , Catch::Matchers::ExceptionMessage("out_of_range: number \"256\" too large for a signed 8 bit value."));
    2999             : 
    3000           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3001             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, "128")
    3002             :                 , prinbee::out_of_range
    3003             :                 , Catch::Matchers::ExceptionMessage("out_of_range: number \"128\" too large for a signed 8 bit value."));
    3004             : 
    3005           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3006             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, "-129")
    3007             :                 , prinbee::out_of_range
    3008             :                 , Catch::Matchers::ExceptionMessage("out_of_range: number \"-129\" too large for a signed 8 bit value."));
    3009             : 
    3010             :         {
    3011           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, "-129"));
    3012           1 :             CATCH_REQUIRE_THROWS_MATCHES(
    3013             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 10)
    3014             :                 , prinbee::out_of_range
    3015             :                 , Catch::Matchers::ExceptionMessage("out_of_range: value too large (16 bits) for this field (max: 8 bits)."));
    3016           1 :         }
    3017             : 
    3018             :         // simple negative
    3019             :         {
    3020           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, "-127"));
    3021           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 10));
    3022           1 :             CATCH_REQUIRE("-127" == back);
    3023           1 :         }
    3024             : 
    3025             :         // I have this one here because -(-128) = -128 in an 8 bit number
    3026             :         // (and larger) and this could look like an overflow if not
    3027             :         // properly handled
    3028             :         {
    3029           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT8, "-128"));
    3030           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT8, buffer, 10));
    3031           1 :             CATCH_REQUIRE("-128" == back);
    3032           1 :         }
    3033             :         {
    3034           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT16, "-32768"));
    3035           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT16, buffer, 10));
    3036           1 :             CATCH_REQUIRE("-32768" == back);
    3037           1 :         }
    3038             :         {
    3039           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT32, "-2147483648"));
    3040           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT32, buffer, 10));
    3041           1 :             CATCH_REQUIRE("-2147483648" == back);
    3042           1 :         }
    3043             :         {
    3044           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT64, "-9223372036854775808"));
    3045           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT64, buffer, 10));
    3046           1 :             CATCH_REQUIRE("-9223372036854775808" == back);
    3047           1 :         }
    3048             :         {
    3049           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT128, "-170141183460469231731687303715884105728"));
    3050           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT128, buffer, 10));
    3051           1 :             CATCH_REQUIRE("-170141183460469231731687303715884105728" == back);
    3052           1 :         }
    3053             :         {
    3054           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT256, "-57896044618658097711785492504343953926634992332820282019728792003956564819968"));
    3055           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT256, buffer, 10));
    3056           1 :             CATCH_REQUIRE("-57896044618658097711785492504343953926634992332820282019728792003956564819968" == back);
    3057           1 :         }
    3058             :         {
    3059           3 :             prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_INT512, "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"));
    3060           1 :             std::string const back(prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_INT512, buffer, 10));
    3061           1 :             CATCH_REQUIRE("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048" == back);
    3062           1 :         }
    3063             :     }
    3064          27 :     CATCH_END_SECTION()
    3065             : 
    3066          27 :     CATCH_START_SECTION("convert_errors: unknown base")
    3067             :     {
    3068           3 :         prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BITS8, "100"));
    3069           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3070             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 37)
    3071             :                 , prinbee::conversion_unavailable
    3072             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: base 37 not supported."));
    3073           1 :     }
    3074          27 :     CATCH_END_SECTION()
    3075             : 
    3076          27 :     CATCH_START_SECTION("convert_errors: mismatch -> value too large")
    3077             :     {
    3078           3 :         prinbee::buffer_t const buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_UINT16, "256"));
    3079           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3080             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BITS8, buffer, 10)
    3081             :                 , prinbee::out_of_range
    3082             :                 , Catch::Matchers::ExceptionMessage("out_of_range: value too large (16 bits) for this field (max: 8 bits)."));
    3083           1 :     }
    3084          27 :     CATCH_END_SECTION()
    3085             : 
    3086          27 :     CATCH_START_SECTION("convert_errors: version missing '.'")
    3087             :     {
    3088           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3089             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, "v3")
    3090             :                 , prinbee::invalid_parameter
    3091             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: version \"v3\" must include a period (.) between the major and minor numbers."));
    3092             :     }
    3093          27 :     CATCH_END_SECTION()
    3094             : 
    3095          27 :     CATCH_START_SECTION("convert_errors: version out of range")
    3096             :     {
    3097           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3098             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, "v300000.45")
    3099             :                 , prinbee::out_of_range
    3100             :                 , Catch::Matchers::ExceptionMessage("out_of_range: one or both of the major or minor numbers from version \"v300000.45\" are too large for a version number (max. is 65535)."));
    3101             : 
    3102           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3103             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, "v300.450009")
    3104             :                 , prinbee::out_of_range
    3105             :                 , Catch::Matchers::ExceptionMessage("out_of_range: one or both of the major or minor numbers from version \"v300.450009\" are too large for a version number (max. is 65535)."));
    3106             :     }
    3107          27 :     CATCH_END_SECTION()
    3108             : 
    3109          27 :     CATCH_START_SECTION("convert_errors: buffer does not match version")
    3110             :     {
    3111           3 :         prinbee::buffer_t buffer(prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, "v3.5"));
    3112           1 :         buffer.push_back(1);
    3113           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3114             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_VERSION, buffer, 10)
    3115             :                 , prinbee::out_of_range
    3116             :                 , Catch::Matchers::ExceptionMessage("out_of_range: a buffer representing a version must be exactly 4 bytes, not 5."));
    3117             : 
    3118           1 :         buffer = prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_VERSION, "v5.6");
    3119           1 :         buffer.pop_back();
    3120           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3121             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_VERSION, buffer, 10)
    3122             :                 , prinbee::out_of_range
    3123             :                 , Catch::Matchers::ExceptionMessage("out_of_range: a buffer representing a version must be exactly 4 bytes, not 3."));
    3124           1 :     }
    3125          27 :     CATCH_END_SECTION()
    3126             : 
    3127          27 :     CATCH_START_SECTION("convert_errors: floats out of range")
    3128             :     {
    3129           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3130             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, "3.40282346638528859811704183485E+39")
    3131             :                 , prinbee::out_of_range
    3132             :                 , Catch::Matchers::ExceptionMessage("out_of_range: floating point number \"3.40282346638528859811704183485E+39\" out of range."));
    3133             : 
    3134           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3135             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, "1.79769313486231570814527423732E+309")
    3136             :                 , prinbee::out_of_range
    3137             :                 , Catch::Matchers::ExceptionMessage("out_of_range: floating point number \"1.79769313486231570814527423732E+309\" out of range."));
    3138             : 
    3139           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3140             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, "5.5E+16389")
    3141             :                 , prinbee::out_of_range
    3142             :                 , Catch::Matchers::ExceptionMessage("out_of_range: floating point number \"5.5E+16389\" out of range."));
    3143             :     }
    3144          27 :     CATCH_END_SECTION()
    3145             : 
    3146          27 :     CATCH_START_SECTION("convert_errors: floats followed by spurious data")
    3147             :     {
    3148           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3149             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, "3.14159k")
    3150             :                 , prinbee::invalid_number
    3151             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"3.14159k\" includes invalid characters."));
    3152             : 
    3153           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3154             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, "3.14159k")
    3155             :                 , prinbee::invalid_number
    3156             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"3.14159k\" includes invalid characters."));
    3157             : 
    3158           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3159             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, "3.14159k")
    3160             :                 , prinbee::invalid_number
    3161             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"3.14159k\" includes invalid characters."));
    3162             :     }
    3163          27 :     CATCH_END_SECTION()
    3164             : 
    3165          27 :     CATCH_START_SECTION("convert_errors: not floats")
    3166             :     {
    3167           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3168             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, "bad float")
    3169             :                 , prinbee::invalid_number
    3170             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"bad float\" includes invalid characters."));
    3171             : 
    3172           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3173             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, "another bad float")
    3174             :                 , prinbee::invalid_number
    3175             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"another bad float\" includes invalid characters."));
    3176             : 
    3177           5 :         CATCH_REQUIRE_THROWS_MATCHES(
    3178             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, "still a bad float")
    3179             :                 , prinbee::invalid_number
    3180             :                 , Catch::Matchers::ExceptionMessage("prinbee_exception: floating point number \"still a bad float\" includes invalid characters."));
    3181             :     }
    3182          27 :     CATCH_END_SECTION()
    3183             : 
    3184          27 :     CATCH_START_SECTION("convert_errors: float size mismatch")
    3185             :     {
    3186          21 :         for(std::size_t size(0); size < 20; ++size)
    3187             :         {
    3188          20 :             if(size != sizeof(float))
    3189             :             {
    3190          38 :                 prinbee::buffer_t buffer(size);
    3191          19 :                 CATCH_REQUIRE_THROWS_MATCHES(
    3192             :                           prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT32, buffer)
    3193             :                         , prinbee::out_of_range
    3194             :                         , Catch::Matchers::ExceptionMessage("out_of_range: value buffer has an unexpected size ("
    3195             :                                 + std::to_string(size)
    3196             :                                 + ") for this field (expected floating point size: "
    3197             :                                 + std::to_string(sizeof(float))
    3198             :                                 + ")."));
    3199          19 :             }
    3200          20 :             if(size != sizeof(double))
    3201             :             {
    3202          38 :                 prinbee::buffer_t buffer(size);
    3203          19 :                 CATCH_REQUIRE_THROWS_MATCHES(
    3204             :                           prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT64, buffer)
    3205             :                         , prinbee::out_of_range
    3206             :                         , Catch::Matchers::ExceptionMessage("out_of_range: value buffer has an unexpected size ("
    3207             :                                 + std::to_string(size)
    3208             :                                 + ") for this field (expected floating point size: "
    3209             :                                 + std::to_string(sizeof(double))
    3210             :                                 + ")."));
    3211          19 :             }
    3212          20 :             if(size != sizeof(long double))
    3213             :             {
    3214          38 :                 prinbee::buffer_t buffer(size);
    3215          19 :                 CATCH_REQUIRE_THROWS_MATCHES(
    3216             :                           prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_FLOAT128, buffer)
    3217             :                         , prinbee::out_of_range
    3218             :                         , Catch::Matchers::ExceptionMessage("out_of_range: value buffer has an unexpected size ("
    3219             :                                 + std::to_string(size)
    3220             :                                 + ") for this field (expected floating point size: "
    3221             :                                 + std::to_string(sizeof(long double))
    3222             :                                 + ")."));
    3223          19 :             }
    3224             :         }
    3225             :     }
    3226          27 :     CATCH_END_SECTION()
    3227             : 
    3228          27 :     CATCH_START_SECTION("convert_buffer: p8string too large")
    3229             :     {
    3230          45 :         for(int j(256); j < 300; ++j)
    3231             :         {
    3232          44 :             std::string const str(SNAP_CATCH2_NAMESPACE::rand_string(j));
    3233          44 :             CATCH_REQUIRE_THROWS_MATCHES(
    3234             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_P8STRING, str)
    3235             :                 , prinbee::out_of_range
    3236             :                 , Catch::Matchers::ExceptionMessage(
    3237             :                       "out_of_range: string too long ("
    3238             :                     + std::to_string(j)
    3239             :                     + ") for this field (max: 255)."));
    3240          44 :         }
    3241             :     }
    3242          27 :     CATCH_END_SECTION()
    3243             : 
    3244          27 :     CATCH_START_SECTION("convert_buffer: p16string too large")
    3245             :     {
    3246         302 :         for(int j(65536); j <= 65536 + 300; ++j)
    3247             :         {
    3248         301 :             std::string const str(SNAP_CATCH2_NAMESPACE::rand_string(j));
    3249         301 :             CATCH_REQUIRE_THROWS_MATCHES(
    3250             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, str)
    3251             :                 , prinbee::out_of_range
    3252             :                 , Catch::Matchers::ExceptionMessage(
    3253             :                       "out_of_range: string too long ("
    3254             :                     + std::to_string(j)
    3255             :                     + ") for this field (max: 65535)."));
    3256         301 :         }
    3257             :     }
    3258          27 :     CATCH_END_SECTION()
    3259             : 
    3260          27 :     CATCH_START_SECTION("convert_buffer: buffer8 too large")
    3261             :     {
    3262          45 :         for(int j(256); j < 300; ++j)
    3263             :         {
    3264          44 :             std::string str;
    3265          44 :             str.reserve(j * 2);
    3266       12254 :             for(int i(0); i < j; ++i)
    3267             :             {
    3268       12210 :                 int const v(rand() & 0x0FF);
    3269       12210 :                 str += snapdev::to_hex(v >> 4);
    3270       12210 :                 str += snapdev::to_hex(v & 15);
    3271             :             }
    3272             : 
    3273          44 :             CATCH_REQUIRE_THROWS_MATCHES(
    3274             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BUFFER8, str)
    3275             :                 , prinbee::out_of_range
    3276             :                 , Catch::Matchers::ExceptionMessage(
    3277             :                       "out_of_range: number of bytes in value is too large ("
    3278             :                     + std::to_string(j)
    3279             :                     + ") for a buffer8."));
    3280          44 :         }
    3281             :     }
    3282          27 :     CATCH_END_SECTION()
    3283             : 
    3284          27 :     CATCH_START_SECTION("convert_buffer: buffer16 too large")
    3285             :     {
    3286         302 :         for(int j(65536); j <= 65536 + 300; ++j)
    3287             :         {
    3288         301 :             std::string str;
    3289         301 :             str.reserve(j * 2);
    3290    19771787 :             for(int i(0); i < j; ++i)
    3291             :             {
    3292    19771486 :                 int const v(rand() & 0xFF);
    3293    19771486 :                 str += snapdev::to_hex(v >> 4);
    3294    19771486 :                 str += snapdev::to_hex(v & 15);
    3295             :             }
    3296             : 
    3297         301 :             CATCH_REQUIRE_THROWS_MATCHES(
    3298             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, str)
    3299             :                 , prinbee::out_of_range
    3300             :                 , Catch::Matchers::ExceptionMessage(
    3301             :                       "out_of_range: number of bytes in value is too large ("
    3302             :                     + std::to_string(j)
    3303             :                     + ") for a buffer16."));
    3304         301 :         }
    3305             :     }
    3306          27 :     CATCH_END_SECTION()
    3307             : 
    3308          27 :     CATCH_START_SECTION("convert_buffer: input too small for buffer size")
    3309             :     {
    3310           1 :         prinbee::buffer_t buffer;
    3311             : 
    3312             :         // empty
    3313           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3314             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER8, buffer)
    3315             :             , prinbee::out_of_range
    3316             :             , Catch::Matchers::ExceptionMessage(
    3317             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (0, expected at least: 1)."));
    3318             : 
    3319           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3320             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, buffer)
    3321             :             , prinbee::out_of_range
    3322             :             , Catch::Matchers::ExceptionMessage(
    3323             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (0, expected at least: 2)."));
    3324             : 
    3325           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3326             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, buffer)
    3327             :             , prinbee::out_of_range
    3328             :             , Catch::Matchers::ExceptionMessage(
    3329             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (0, expected at least: 4)."));
    3330             : 
    3331             :         // size 1
    3332           1 :         buffer.push_back(1);
    3333             : 
    3334           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3335             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, buffer)
    3336             :             , prinbee::out_of_range
    3337             :             , Catch::Matchers::ExceptionMessage(
    3338             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (1, expected at least: 2)."));
    3339             : 
    3340           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3341             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, buffer)
    3342             :             , prinbee::out_of_range
    3343             :             , Catch::Matchers::ExceptionMessage(
    3344             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (1, expected at least: 4)."));
    3345             : 
    3346             :         // size 2
    3347           1 :         buffer.push_back(1);
    3348             : 
    3349           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3350             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, buffer)
    3351             :             , prinbee::out_of_range
    3352             :             , Catch::Matchers::ExceptionMessage(
    3353             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (2, expected at least: 4)."));
    3354             : 
    3355             :         // size 3
    3356           1 :         buffer.push_back(1);
    3357             : 
    3358           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3359             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, buffer)
    3360             :             , prinbee::out_of_range
    3361             :             , Catch::Matchers::ExceptionMessage(
    3362             :                   "out_of_range: buffer too small to incorporate the P-Buffer size (3, expected at least: 4)."));
    3363           1 :     }
    3364          27 :     CATCH_END_SECTION()
    3365             : 
    3366          27 :     CATCH_START_SECTION("convert_buffer: input too small for P-Buffer data")
    3367             :     {
    3368           1 :         prinbee::buffer_t buffer;
    3369             : 
    3370             :         // buffer8
    3371             :         //
    3372           1 :         buffer.push_back(5);
    3373           1 :         buffer.push_back('1');
    3374           1 :         buffer.push_back('2');
    3375           1 :         buffer.push_back('3');
    3376           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3377             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER8, buffer)
    3378             :             , prinbee::out_of_range
    3379             :             , Catch::Matchers::ExceptionMessage(
    3380             :                   "out_of_range: buffer (size: 4 including 1 bytes for the size) too small for the requested number of bytes (6)."));
    3381             : 
    3382             :         // buffer16
    3383             :         //
    3384           1 :         buffer.clear();
    3385           1 :         buffer.push_back(0);    // size 256 (little endian)
    3386           1 :         buffer.push_back(1);
    3387           1 :         buffer.push_back('1');
    3388           1 :         buffer.push_back('2');
    3389           1 :         buffer.push_back('3');
    3390           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3391             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER16, buffer)
    3392             :             , prinbee::out_of_range
    3393             :             , Catch::Matchers::ExceptionMessage(
    3394             :                   "out_of_range: buffer (size: 5 including 2 bytes for the size) too small for the requested number of bytes (258)."));
    3395             : 
    3396             :         // buffer32
    3397             :         //
    3398           1 :         buffer.clear();
    3399           1 :         buffer.push_back(44);
    3400           1 :         buffer.push_back(0);
    3401           1 :         buffer.push_back(0);
    3402           1 :         buffer.push_back(0);
    3403           1 :         buffer.push_back('1');
    3404           1 :         buffer.push_back('2');
    3405           1 :         buffer.push_back('3');
    3406           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3407             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_BUFFER32, buffer)
    3408             :             , prinbee::out_of_range
    3409             :             , Catch::Matchers::ExceptionMessage(
    3410             :                   "out_of_range: buffer (size: 7 including 4 bytes for the size) too small for the requested number of bytes (48)."));
    3411           1 :     }
    3412          27 :     CATCH_END_SECTION()
    3413             : 
    3414          27 :     CATCH_START_SECTION("convert_buffer: buffer too small for P-String size")
    3415             :     {
    3416           1 :         prinbee::buffer_t buffer;
    3417             : 
    3418             :         // empty
    3419           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3420             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P8STRING, buffer)
    3421             :             , prinbee::out_of_range
    3422             :             , Catch::Matchers::ExceptionMessage(
    3423             :                   "out_of_range: buffer too small to incorporate the P-String size (0, expected at least: 1)."));
    3424             : 
    3425           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3426             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, buffer)
    3427             :             , prinbee::out_of_range
    3428             :             , Catch::Matchers::ExceptionMessage(
    3429             :                   "out_of_range: buffer too small to incorporate the P-String size (0, expected at least: 2)."));
    3430             : 
    3431           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3432             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer)
    3433             :             , prinbee::out_of_range
    3434             :             , Catch::Matchers::ExceptionMessage(
    3435             :                   "out_of_range: buffer too small to incorporate the P-String size (0, expected at least: 4)."));
    3436             : 
    3437             :         // size 1
    3438           1 :         buffer.push_back(1);
    3439             : 
    3440           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3441             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, buffer)
    3442             :             , prinbee::out_of_range
    3443             :             , Catch::Matchers::ExceptionMessage(
    3444             :                   "out_of_range: buffer too small to incorporate the P-String size (1, expected at least: 2)."));
    3445             : 
    3446           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3447             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer)
    3448             :             , prinbee::out_of_range
    3449             :             , Catch::Matchers::ExceptionMessage(
    3450             :                   "out_of_range: buffer too small to incorporate the P-String size (1, expected at least: 4)."));
    3451             : 
    3452             :         // size 2
    3453           1 :         buffer.push_back(1);
    3454             : 
    3455           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3456             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer)
    3457             :             , prinbee::out_of_range
    3458             :             , Catch::Matchers::ExceptionMessage(
    3459             :                   "out_of_range: buffer too small to incorporate the P-String size (2, expected at least: 4)."));
    3460             : 
    3461             :         // size 3
    3462           1 :         buffer.push_back(1);
    3463             : 
    3464           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3465             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer)
    3466             :             , prinbee::out_of_range
    3467             :             , Catch::Matchers::ExceptionMessage(
    3468             :                   "out_of_range: buffer too small to incorporate the P-String size (3, expected at least: 4)."));
    3469           1 :     }
    3470          27 :     CATCH_END_SECTION()
    3471             : 
    3472          27 :     CATCH_START_SECTION("convert_buffer: buffer too small for P-String data")
    3473             :     {
    3474           1 :         prinbee::buffer_t buffer;
    3475             : 
    3476             :         // P8 string
    3477             :         //
    3478           1 :         buffer.push_back(5);
    3479           1 :         buffer.push_back('1');
    3480           1 :         buffer.push_back('2');
    3481           1 :         buffer.push_back('3');
    3482           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3483             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P8STRING, buffer)
    3484             :             , prinbee::out_of_range
    3485             :             , Catch::Matchers::ExceptionMessage(
    3486             :                   "out_of_range: buffer too small for the P-String characters (size: 5, character bytes in buffer: 3)."));
    3487             : 
    3488             :         // P16 string
    3489             :         //
    3490           1 :         buffer.clear();
    3491           1 :         buffer.push_back(0);    // size 256 (little endian)
    3492           1 :         buffer.push_back(1);
    3493           1 :         buffer.push_back('1');
    3494           1 :         buffer.push_back('2');
    3495           1 :         buffer.push_back('3');
    3496           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3497             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P16STRING, buffer)
    3498             :             , prinbee::out_of_range
    3499             :             , Catch::Matchers::ExceptionMessage(
    3500             :                   "out_of_range: buffer too small for the P-String characters (size: 256, character bytes in buffer: 3)."));
    3501             : 
    3502             :         // P32 string
    3503             :         //
    3504           1 :         buffer.clear();
    3505           1 :         buffer.push_back(44);
    3506           1 :         buffer.push_back(0);
    3507           1 :         buffer.push_back(0);
    3508           1 :         buffer.push_back(0);
    3509           1 :         buffer.push_back('1');
    3510           1 :         buffer.push_back('2');
    3511           1 :         buffer.push_back('3');
    3512           1 :         CATCH_REQUIRE_THROWS_MATCHES(
    3513             :               prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_P32STRING, buffer)
    3514             :             , prinbee::out_of_range
    3515             :             , Catch::Matchers::ExceptionMessage(
    3516             :                   "out_of_range: buffer too small for the P-String characters (size: 44, character bytes in buffer: 3)."));
    3517           1 :     }
    3518          27 :     CATCH_END_SECTION()
    3519             : 
    3520          27 :     CATCH_START_SECTION("convert_buffer: time with too many decimal")
    3521             :     {
    3522           8 :         for(int i(4); i <= 10; ++i)
    3523             :         {
    3524           7 :             constexpr time_t const three_thousand_years(3'000LL * 365LL * 86'400LL);
    3525           7 :             time_t const d((SNAP_CATCH2_NAMESPACE::rand64() >> 1) % three_thousand_years);
    3526             : 
    3527             :             // we only output back to UTC so use UTC here
    3528             :             //
    3529          14 :             std::string cmd("date -u +%Y-%m-%dT%T.");
    3530          49 :             for(int j(1); j < i; ++j)
    3531             :             {
    3532          42 :                 cmd += std::to_string(rand() % 10);
    3533             :             }
    3534           7 :             cmd += std::to_string(rand() % 9 + 1);
    3535           7 :             cmd += "%z -d @";
    3536           7 :             cmd += std::to_string(d);
    3537           7 :             FILE * p(popen(cmd.c_str(), "r"));
    3538           7 :             CATCH_REQUIRE(p != nullptr);
    3539           7 :             char buf[256] = {};
    3540           7 :             std::size_t sz(fread(buf, 1, sizeof(buf), p));
    3541           7 :             CATCH_REQUIRE(sz >= 1);
    3542           7 :             CATCH_REQUIRE(sz < sizeof(buf));
    3543           7 :             if(buf[sz - 1] == '\n')
    3544             :             {
    3545           7 :                 --sz;
    3546             :             }
    3547           7 :             buf[sz] = '\0';
    3548           7 :             CATCH_REQUIRE(pclose(p) == 0);
    3549             : 
    3550          14 :             std::string mstime(buf);
    3551           7 :             std::string::size_type const pos(mstime.find('+'));
    3552           7 :             CATCH_REQUIRE(pos != std::string::npos);
    3553             : 
    3554          35 :             CATCH_REQUIRE_THROWS_MATCHES(
    3555             :                   prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buf)
    3556             :                 , prinbee::out_of_range
    3557             :                 , Catch::Matchers::ExceptionMessage(
    3558             :                       "out_of_range: time fraction is out of bounds in \""
    3559             :                     + std::string(buf)
    3560             :                     + "\" (expected 3 digits, found "
    3561             :                     + std::to_string(i)
    3562             :                     + ")."));
    3563             : 
    3564           7 :             if(i > 6)
    3565             :             {
    3566          20 :                 CATCH_REQUIRE_THROWS_MATCHES(
    3567             :                       prinbee::string_to_typed_buffer(prinbee::struct_type_t::STRUCT_TYPE_USTIME, buf)
    3568             :                     , prinbee::out_of_range
    3569             :                     , Catch::Matchers::ExceptionMessage(
    3570             :                           "out_of_range: time fraction is out of bounds in \""
    3571             :                         + std::string(buf)
    3572             :                         + "\" (expected 6 digits, found "
    3573             :                         + std::to_string(i)
    3574             :                         + ")."));
    3575             :             }
    3576           7 :         }
    3577             :     }
    3578          27 :     CATCH_END_SECTION()
    3579             : 
    3580          27 :     CATCH_START_SECTION("convert_buffer: wrong buffer size for time")
    3581             :     {
    3582           1 :         prinbee::buffer_t buffer;
    3583          11 :         for(int i(0); i < 10; ++i)
    3584             :         {
    3585          10 :             CATCH_REQUIRE_THROWS_MATCHES(
    3586             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_TIME, buffer)
    3587             :                 , prinbee::out_of_range
    3588             :                 , Catch::Matchers::ExceptionMessage(
    3589             :                       "out_of_range: buffer size is invalid for a time value (size: "
    3590             :                     + std::to_string(buffer.size())
    3591             :                     + ", expected size: 8)."));
    3592             : 
    3593          10 :             CATCH_REQUIRE_THROWS_MATCHES(
    3594             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_MSTIME, buffer)
    3595             :                 , prinbee::out_of_range
    3596             :                 , Catch::Matchers::ExceptionMessage(
    3597             :                       "out_of_range: buffer size is invalid for a time value (size: "
    3598             :                     + std::to_string(buffer.size())
    3599             :                     + ", expected size: 8)."));
    3600             : 
    3601          10 :             CATCH_REQUIRE_THROWS_MATCHES(
    3602             :                   prinbee::typed_buffer_to_string(prinbee::struct_type_t::STRUCT_TYPE_USTIME, buffer)
    3603             :                 , prinbee::out_of_range
    3604             :                 , Catch::Matchers::ExceptionMessage(
    3605             :                       "out_of_range: buffer size is invalid for a time value (size: "
    3606             :                     + std::to_string(buffer.size())
    3607             :                     + ", expected size: 8)."));
    3608             : 
    3609          10 :             buffer.push_back(rand());
    3610          10 :             if(buffer.size() == sizeof(std::uint64_t))
    3611             :             {
    3612           1 :                 buffer.push_back(rand());
    3613             :             }
    3614             :         }
    3615           1 :     }
    3616          27 :     CATCH_END_SECTION()
    3617             : 
    3618          27 :     CATCH_START_SECTION("convert_buffer: unexpected structure type")
    3619             :     {
    3620           1 :         std::vector<prinbee::struct_type_t> unsupported_types{
    3621             :             prinbee::struct_type_t::STRUCT_TYPE_ARRAY8,
    3622             :             prinbee::struct_type_t::STRUCT_TYPE_ARRAY16,
    3623             :             prinbee::struct_type_t::STRUCT_TYPE_ARRAY32,
    3624             :             prinbee::struct_type_t::STRUCT_TYPE_STRUCTURE,
    3625             :             prinbee::struct_type_t::STRUCT_TYPE_END,
    3626             :             prinbee::struct_type_t::STRUCT_TYPE_VOID,
    3627             :             prinbee::struct_type_t::STRUCT_TYPE_RENAMED,
    3628           2 :         };
    3629             : 
    3630           8 :         for(auto const t : unsupported_types)
    3631             :         {
    3632          35 :             CATCH_REQUIRE_THROWS_MATCHES(
    3633             :                   prinbee::string_to_typed_buffer(t, "ignored")
    3634             :                 , prinbee::logic_error
    3635             :                 , Catch::Matchers::ExceptionMessage(
    3636             :                       "logic_error: unexpected structure type ("
    3637             :                     + std::to_string(static_cast<int>(t))
    3638             :                     + ") to convert a string to a buffer"));
    3639             : 
    3640           7 :             prinbee::buffer_t ignored;
    3641           7 :             CATCH_REQUIRE_THROWS_MATCHES(
    3642             :                   prinbee::typed_buffer_to_string(t, ignored)
    3643             :                 , prinbee::logic_error
    3644             :                 , Catch::Matchers::ExceptionMessage(
    3645             :                       "logic_error: unexpected structure type ("
    3646             :                     + std::to_string(static_cast<int>(t))
    3647             :                     + ") to convert a string to a buffer"));
    3648           7 :         }
    3649           1 :     }
    3650          27 :     CATCH_END_SECTION()
    3651          27 : }
    3652             : 
    3653             : 
    3654             : 
    3655             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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