LCOV - code coverage report
Current view: top level - tests - catch_message.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 424 430 98.6 %
Date: 2023-07-29 22:00:24 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2011-2023  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/as2js
       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             : // snapdev
      20             : //
      21             : #include    <as2js/message.h>
      22             : 
      23             : 
      24             : 
      25             : // self
      26             : //
      27             : #include    "catch_main.h"
      28             : 
      29             : 
      30             : // snapdev
      31             : //
      32             : #include    <snapdev/enum_class_math.h>
      33             : 
      34             : 
      35             : // libutf8
      36             : //
      37             : #include    <libutf8/libutf8.h>
      38             : 
      39             : 
      40             : // C++
      41             : //
      42             : #include    <climits>
      43             : 
      44             : 
      45             : // last include
      46             : //
      47             : #include    <snapdev/poison.h>
      48             : 
      49             : 
      50             : 
      51             : namespace
      52             : {
      53             : 
      54             : class test_callback
      55             :     : public as2js::message_callback
      56             : {
      57             : public:
      58      536986 :     test_callback()
      59      536986 :     {
      60      536986 :         as2js::set_message_callback(this);
      61      536986 :         g_warning_count = as2js::warning_count();
      62      536986 :         g_error_count = as2js::error_count();
      63      536986 :     }
      64             : 
      65      536987 :     ~test_callback()
      66      536987 :     {
      67             :         // make sure the pointer gets reset!
      68      536987 :         as2js::set_message_callback(nullptr);
      69      536987 :     }
      70             : 
      71             :     // implementation of the output
      72      926278 :     virtual void output(as2js::message_level_t message_level, as2js::err_code_t error_code, as2js::position const& pos, std::string const& message)
      73             :     {
      74             : 
      75             : //std::cerr<< " filename = " << pos.get_filename() << " / " << f_expected_pos.get_filename() << "\n";
      76             : //std::cerr<< " msg = [" << message << "] / [" << f_expected_message << "]\n";
      77             : 
      78      926278 :         CATCH_REQUIRE(f_expected_call);
      79      926278 :         CATCH_REQUIRE(message_level == f_expected_message_level);
      80      926278 :         CATCH_REQUIRE(error_code == f_expected_error_code);
      81      926278 :         CATCH_REQUIRE(pos.get_filename() == f_expected_pos.get_filename());
      82      926278 :         CATCH_REQUIRE(pos.get_function() == f_expected_pos.get_function());
      83      926278 :         CATCH_REQUIRE(pos.get_page() == f_expected_pos.get_page());
      84      926278 :         CATCH_REQUIRE(pos.get_page_line() == f_expected_pos.get_page_line());
      85      926278 :         CATCH_REQUIRE(pos.get_paragraph() == f_expected_pos.get_paragraph());
      86      926278 :         CATCH_REQUIRE(pos.get_line() == f_expected_pos.get_line());
      87      926278 :         CATCH_REQUIRE(message == f_expected_message);
      88             : 
      89      926278 :         if(message_level == as2js::message_level_t::MESSAGE_LEVEL_WARNING)
      90             :         {
      91      153682 :             ++g_warning_count;
      92      153682 :             CATCH_REQUIRE(g_warning_count == as2js::warning_count());
      93             :         }
      94             : 
      95      926278 :         if(message_level == as2js::message_level_t::MESSAGE_LEVEL_FATAL
      96      772424 :         || message_level == as2js::message_level_t::MESSAGE_LEVEL_ERROR)
      97             :         {
      98      312066 :             ++g_error_count;
      99             : //std::cerr << "error: " << g_error_count << " / " << as2js::error_count() << "\n";
     100      312066 :             CATCH_REQUIRE(g_error_count == as2js::error_count());
     101             :         }
     102             : 
     103      926278 :         f_got_called = true;
     104      926278 :     }
     105             : 
     106             :     bool                        f_expected_call = true;
     107             :     bool                        f_got_called = false;
     108             :     as2js::message_level_t      f_expected_message_level = as2js::message_level_t::MESSAGE_LEVEL_OFF;
     109             :     as2js::err_code_t           f_expected_error_code = as2js::err_code_t::AS_ERR_NONE;
     110             :     as2js::position             f_expected_pos = as2js::position();
     111             :     std::string                 f_expected_message = std::string(); // UTF-8 string
     112             : 
     113             :     static int32_t              g_warning_count;
     114             :     static int32_t              g_error_count;
     115             : };
     116             : 
     117             : int32_t   test_callback::g_warning_count = 0;
     118             : int32_t   test_callback::g_error_count = 0;
     119             : 
     120             : }
     121             : // no name namespace
     122             : 
     123             : 
     124             : 
     125           1 : CATCH_TEST_CASE("message_string", "[message]")
     126             : {
     127           1 :     CATCH_START_SECTION("message_string: check message outputs (use --verbose to see dots while processing)")
     128             :     {
     129           1 :         for(as2js::message_level_t i(as2js::message_level_t::MESSAGE_LEVEL_OFF);
     130           8 :                                    i <= as2js::message_level_t::MESSAGE_LEVEL_FATAL;
     131           7 :                                    ++i)
     132             :         {
     133             : //i = static_cast<as2js::message_level_t>(static_cast<int>(i) + 1);
     134           7 :             if(SNAP_CATCH2_NAMESPACE::g_verbose())
     135             :             {
     136           0 :                 std::cerr << "[" << static_cast<int32_t>(i) << "]";
     137             :             }
     138             : 
     139           7 :             for(as2js::err_code_t j(as2js::err_code_t::AS_ERR_NONE);
     140         609 :                                   j <= as2js::err_code_t::AS_ERR_max;
     141         602 :                                   ++j)
     142             :             {
     143         602 :                 if(SNAP_CATCH2_NAMESPACE::g_verbose())
     144             :                 {
     145           0 :                     std::cerr << ".";
     146             :                 }
     147             : 
     148             :                 {
     149         602 :                     test_callback c;
     150         602 :                     c.f_expected_message_level = i;
     151         602 :                     c.f_expected_error_code = j;
     152         602 :                     c.f_expected_pos.set_filename("unknown-file");
     153         602 :                     c.f_expected_pos.set_function("unknown-func");
     154             : 
     155         602 :                     for(as2js::message_level_t k(as2js::message_level_t::MESSAGE_LEVEL_OFF);
     156        4816 :                                                k <= as2js::message_level_t::MESSAGE_LEVEL_FATAL;
     157        4214 :                                                ++k)
     158             :                     {
     159        4214 :                         as2js::set_message_level(k);
     160        4214 :                         as2js::message_level_t const min(std::min(k, as2js::message_level_t::MESSAGE_LEVEL_ERROR));
     161             : //std::cerr << "i: " << static_cast<int32_t>(i) << ", k: " << static_cast<int32_t>(k) << ", min: " << static_cast<int32_t>(min) << " expect: " << c.f_expected_call << "\n";
     162             :                         {
     163        4214 :                             c.f_expected_call = false;
     164        4214 :                             c.f_got_called = false;
     165        4214 :                             c.f_expected_message = "";
     166        4214 :                             as2js::message msg(i, j);
     167        4214 :                         }
     168        4214 :                         CATCH_REQUIRE_FALSE(c.f_got_called); // no message no call
     169             :                         {
     170        4214 :                             char32_t unicode(random_char(SNAP_CATCH2_NAMESPACE::character_t::CHARACTER_UNICODE));
     171        4214 :                             c.f_expected_call = i != as2js::message_level_t::MESSAGE_LEVEL_OFF && i >= min;
     172        4214 :                             c.f_got_called = false;
     173        4214 :                             c.f_expected_message = "with a message: " + libutf8::to_u8string(unicode);
     174        4214 :                             as2js::message msg(i, j);
     175        4214 :                             msg << "with a message: " << unicode;
     176        4214 :                         }
     177        4214 :                         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     178             :                     }
     179         602 :                 }
     180             : 
     181         602 :                 as2js::position pos;
     182         602 :                 pos.set_filename("file.js");
     183         602 :                 int total_line(1);
     184        6020 :                 for(int page(1); page < 10; ++page)
     185             :                 {
     186             :                     //std::cerr << "+";
     187             : 
     188        5418 :                     int paragraphs(rand() % 10 + 10);
     189        5418 :                     int page_line(1);
     190        5418 :                     int paragraph(1);
     191      541800 :                     for(int line(1); line < 100; ++line)
     192             :                     {
     193      536382 :                         CATCH_REQUIRE(pos.get_page() == page);
     194      536382 :                         CATCH_REQUIRE(pos.get_page_line() == page_line);
     195      536382 :                         CATCH_REQUIRE(pos.get_paragraph() == paragraph);
     196      536382 :                         CATCH_REQUIRE(pos.get_line() == total_line);
     197             : 
     198      536382 :                         std::stringstream pos_str;
     199      536382 :                         pos_str << pos;
     200      536382 :                         std::stringstream test_str;
     201      536382 :                         test_str << "file.js:" << total_line << ":";
     202      536382 :                         CATCH_REQUIRE(pos_str.str() == test_str.str());
     203             : 
     204             :                         {
     205      536382 :                             test_callback c;
     206      536382 :                             c.f_expected_message_level = i;
     207      536382 :                             c.f_expected_error_code = j;
     208      536382 :                             c.f_expected_pos = pos;
     209      536382 :                             c.f_expected_pos.set_filename("file.js");
     210      536382 :                             c.f_expected_pos.set_function("unknown-func");
     211             : 
     212      536382 :                             for(as2js::message_level_t k(as2js::message_level_t::MESSAGE_LEVEL_OFF);
     213     1609146 :                                                        k <= as2js::message_level_t::MESSAGE_LEVEL_TRACE;
     214     1072764 :                                                        ++k)
     215             :                             {
     216     1072764 :                                 as2js::set_message_level(k);
     217     1072764 :                                 as2js::message_level_t const min(std::min(k, as2js::message_level_t::MESSAGE_LEVEL_ERROR));
     218             :                                 {
     219     1072764 :                                     c.f_expected_call = false;
     220     1072764 :                                     c.f_got_called = false;
     221     1072764 :                                     c.f_expected_message = "";
     222     1072764 :                                     as2js::message msg(i, j, pos);
     223     1072764 :                                 }
     224     1072764 :                                 CATCH_REQUIRE(!c.f_got_called);
     225             :                                 {
     226     1072764 :                                     c.f_expected_call = i != as2js::message_level_t::MESSAGE_LEVEL_OFF && i >= min;
     227     1072764 :                                     c.f_got_called = false;
     228     1072764 :                                     c.f_expected_message = "and a small message";
     229     1072764 :                                     as2js::message msg(i, j, pos);
     230     1072764 :                                     msg << "and a small message";
     231     1072764 :                                 }
     232     1072764 :                                 CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     233             :                             }
     234      536382 :                         }
     235             : 
     236      536382 :                         if(line % paragraphs == 0)
     237             :                         {
     238       36296 :                             pos.new_paragraph();
     239       36296 :                             ++paragraph;
     240             :                         }
     241      536382 :                         pos.new_line();
     242      536382 :                         ++total_line;
     243      536382 :                         ++page_line;
     244      536382 :                     }
     245        5418 :                     pos.new_page();
     246             :                 }
     247         602 :             }
     248             : 
     249           7 :             if(SNAP_CATCH2_NAMESPACE::g_verbose())
     250             :             {
     251           0 :                 std::cerr << '\n';
     252             :             }
     253             :         }
     254             :     }
     255           1 :     CATCH_END_SECTION()
     256           1 : }
     257             : 
     258             : 
     259           1 : CATCH_TEST_CASE("message_operator", "[message]")
     260             : {
     261           1 :     CATCH_START_SECTION("message_operator: verify operators")
     262             :     {
     263           1 :         test_callback c;
     264           1 :         c.f_expected_message_level = as2js::message_level_t::MESSAGE_LEVEL_ERROR;
     265           1 :         c.f_expected_error_code = as2js::err_code_t::AS_ERR_CANNOT_COMPILE;
     266           1 :         c.f_expected_pos.set_filename("operator.js");
     267           1 :         c.f_expected_pos.set_function("compute");
     268           1 :         as2js::set_message_level(as2js::message_level_t::MESSAGE_LEVEL_INFO);
     269             : 
     270             :         // test the copy constructor and operator
     271             :         {
     272           1 :             test_callback try_copy(c);
     273           1 :             test_callback try_assignment;
     274           1 :             try_assignment = c;
     275           1 :         }
     276             :         // this is required as the destructors called on the previous '}'
     277             :         // will otherwise clear that pointer...
     278           1 :         as2js::set_message_callback(&c);
     279             : 
     280           1 :         as2js::position pos;
     281           1 :         pos.set_filename("operator.js");
     282           1 :         pos.set_function("compute");
     283           1 :         c.f_expected_pos = pos;
     284             : 
     285             :         // test with nothing
     286             :         {
     287           1 :             c.f_expected_call = false;
     288           1 :             c.f_got_called = false;
     289           1 :             c.f_expected_message = "";
     290           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     291           1 :         }
     292           1 :         CATCH_REQUIRE(!c.f_got_called); // no message no call
     293             : 
     294             :         // test with char *
     295             :         {
     296           1 :             c.f_expected_call = true;
     297           1 :             c.f_got_called = false;
     298           1 :             c.f_expected_message = "with a message";
     299           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     300           1 :             msg << "with a message";
     301           1 :         }
     302           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     303             : 
     304             :         // test with std::string
     305             :         {
     306           1 :             c.f_expected_call = true;
     307           1 :             c.f_got_called = false;
     308           1 :             c.f_expected_message = "with an std::string message";
     309           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     310           2 :             std::string str("with an std::string message");
     311           1 :             msg << str;
     312           1 :         }
     313           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     314             : 
     315             :         // test with ASCII wchar_t
     316             :         {
     317           1 :             c.f_expected_call = true;
     318           1 :             c.f_got_called = false;
     319           1 :             c.f_expected_message = "Simple wide char string";
     320           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     321           1 :             wchar_t const *str(L"Simple wide char string");
     322           1 :             msg << str;
     323           1 :         }
     324           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     325             : 
     326             :         // test with Unicode wchar_t
     327             :         {
     328           1 :             wchar_t const *str(L"Some: \x2028 Unicode \xA9");
     329           3 :             std::string unicode(as2js::convert(str));
     330           1 :             c.f_expected_call = true;
     331           1 :             c.f_got_called = false;
     332           1 :             c.f_expected_message = unicode;
     333           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     334           1 :             msg << str;
     335           1 :         }
     336           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     337             : 
     338             :         // test with ASCII std::wstring
     339             :         {
     340           1 :             c.f_expected_call = true;
     341           1 :             c.f_got_called = false;
     342           1 :             c.f_expected_message = "with an std::string message";
     343           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     344           2 :             std::string str("with an std::string message");
     345           1 :             msg << str;
     346           1 :         }
     347           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     348             : 
     349             :         // test with Unicode std::wstring
     350             :         {
     351           2 :             std::wstring str(L"Some: \x2028 Unicode \xA9");
     352           1 :             std::string unicode(as2js::convert(str));
     353           1 :             c.f_expected_call = true;
     354           1 :             c.f_got_called = false;
     355           1 :             c.f_expected_message = unicode;
     356           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     357           1 :             msg << unicode;
     358           1 :         }
     359           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     360             : 
     361             :         // test with std::string too
     362             :         {
     363           2 :             std::wstring str(L"Some: \x2028 Unicode \xA9");
     364           1 :             std::string unicode(as2js::convert(str));
     365           1 :             c.f_expected_call = true;
     366           1 :             c.f_got_called = false;
     367           1 :             c.f_expected_message = unicode;
     368           1 :             as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     369           1 :             msg << unicode;
     370           1 :         }
     371           1 :         CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     372             : 
     373             :         // test with char
     374         256 :         for(int idx(1); idx <= 255; ++idx)
     375             :         {
     376         255 :             char ci(static_cast<char>(idx));
     377             :             {
     378         255 :                 std::stringstream str;
     379         255 :                 str << ci;
     380         255 :                 c.f_expected_call = true;
     381         255 :                 c.f_got_called = false;
     382         255 :                 c.f_expected_message = str.str();
     383         255 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     384         255 :                 msg << ci;
     385         255 :             }
     386         255 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     387             :         }
     388             : 
     389             :         // test with signed char
     390         257 :         for(int idx(-128); idx <= 127; ++idx)
     391             :         {
     392         256 :             signed char ci(static_cast<signed char>(idx));
     393             :             {
     394         256 :                 std::stringstream str;
     395         256 :                 str << static_cast<int>(ci);
     396         256 :                 c.f_expected_call = true;
     397         256 :                 c.f_got_called = false;
     398         256 :                 c.f_expected_message = str.str();
     399         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     400         256 :                 msg << ci;
     401         256 :             }
     402         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     403             :         }
     404             : 
     405             :         // test with unsigned char
     406         257 :         for(int idx(-128); idx <= 127; ++idx)
     407             :         {
     408         256 :             unsigned char ci(static_cast<unsigned char>(idx));
     409             :             {
     410         256 :                 std::stringstream str;
     411         256 :                 str << static_cast<int>(ci);
     412         256 :                 c.f_expected_call = true;
     413         256 :                 c.f_got_called = false;
     414         256 :                 c.f_expected_message = str.str();
     415         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     416         256 :                 msg << ci;
     417         256 :             }
     418         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     419             :         }
     420             : 
     421             :         // test with signed short
     422         257 :         for(int idx(0); idx < 256; ++idx)
     423             :         {
     424         256 :             signed short ci;
     425         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     426             :             {
     427         256 :                 std::stringstream str;
     428         256 :                 str << static_cast<int>(ci);
     429         256 :                 c.f_expected_call = true;
     430         256 :                 c.f_got_called = false;
     431         256 :                 c.f_expected_message = str.str();
     432         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     433         256 :                 msg << ci;
     434         256 :             }
     435         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     436             :         }
     437             : 
     438             :         // test with unsigned short
     439         257 :         for(int idx(0); idx < 256; ++idx)
     440             :         {
     441         256 :             unsigned short ci;
     442         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     443             :             {
     444         256 :                 std::stringstream str;
     445         256 :                 str << static_cast<int>(ci);
     446         256 :                 c.f_expected_call = true;
     447         256 :                 c.f_got_called = false;
     448         256 :                 c.f_expected_message = str.str();
     449         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     450         256 :                 msg << ci;
     451         256 :             }
     452         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     453             :         }
     454             : 
     455             :         // test with signed int
     456         257 :         for(int idx(0); idx < 256; ++idx)
     457             :         {
     458         256 :             signed int ci;
     459         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     460             :             {
     461         256 :                 std::stringstream str;
     462         256 :                 str << ci;
     463         256 :                 c.f_expected_call = true;
     464         256 :                 c.f_got_called = false;
     465         256 :                 c.f_expected_message = str.str();
     466         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     467         256 :                 msg << ci;
     468         256 :             }
     469         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     470             :         }
     471             : 
     472             :         // test with unsigned int
     473         257 :         for(int idx(0); idx < 256; ++idx)
     474             :         {
     475         256 :             unsigned int ci;
     476         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     477             :             {
     478         256 :                 std::stringstream str;
     479         256 :                 str << ci;
     480         256 :                 c.f_expected_call = true;
     481         256 :                 c.f_got_called = false;
     482         256 :                 c.f_expected_message = str.str();
     483         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     484         256 :                 msg << ci;
     485         256 :             }
     486         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     487             :         }
     488             : 
     489             :         // test with signed long
     490         257 :         for(int idx(0); idx < 256; ++idx)
     491             :         {
     492         256 :             signed long ci;
     493         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     494             :             {
     495         256 :                 std::stringstream str;
     496         256 :                 str << ci;
     497         256 :                 c.f_expected_call = true;
     498         256 :                 c.f_got_called = false;
     499         256 :                 c.f_expected_message = str.str();
     500         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     501         256 :                 msg << ci;
     502         256 :             }
     503         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     504             :         }
     505             : 
     506             :         // test with unsigned long
     507         257 :         for(int idx(0); idx < 256; ++idx)
     508             :         {
     509         256 :             unsigned long ci;
     510         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     511             :             {
     512         256 :                 std::stringstream str;
     513         256 :                 str << ci;
     514         256 :                 c.f_expected_call = true;
     515         256 :                 c.f_got_called = false;
     516         256 :                 c.f_expected_message = str.str();
     517         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     518         256 :                 msg << ci;
     519         256 :             }
     520         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     521             :         }
     522             : 
     523             :         // if not 64 bits, then the next 2 tests should probably change a bit
     524             :         // to support the additional bits
     525           1 :         CATCH_REQUIRE(sizeof(unsigned long long) == 64 / 8);
     526             : 
     527             :         // test with signed long long
     528         257 :         for(int idx(0); idx < 256; ++idx)
     529             :         {
     530         256 :             signed long long ci;
     531         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     532             :             {
     533         256 :                 std::stringstream str;
     534         256 :                 str << ci;
     535         256 :                 c.f_expected_call = true;
     536         256 :                 c.f_got_called = false;
     537         256 :                 c.f_expected_message = str.str();
     538         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     539         256 :                 msg << ci;
     540         256 :             }
     541         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     542             :         }
     543             : 
     544             :         // test with unsigned long long
     545         257 :         for(int idx(0); idx < 256; ++idx)
     546             :         {
     547         256 :             unsigned long long ci;
     548         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     549             :             {
     550         256 :                 std::stringstream str;
     551         256 :                 str << ci;
     552         256 :                 c.f_expected_call = true;
     553         256 :                 c.f_got_called = false;
     554         256 :                 c.f_expected_message = str.str();
     555         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     556         256 :                 msg << ci;
     557         256 :             }
     558         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     559             :         }
     560             : 
     561             :         // test with Int64
     562         257 :         for(int idx(0); idx < 256; ++idx)
     563             :         {
     564         256 :             as2js::integer::value_type ci;
     565         256 :             SNAP_CATCH2_NAMESPACE::random(ci);
     566         256 :             as2js::integer value(ci);
     567             :             {
     568         256 :                 std::stringstream str;
     569         256 :                 str << ci;
     570         256 :                 c.f_expected_call = true;
     571         256 :                 c.f_got_called = false;
     572         256 :                 c.f_expected_message = str.str();
     573         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     574         256 :                 msg << value;
     575         256 :             }
     576         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     577             :         }
     578             : 
     579             :         // test with float
     580         257 :         for(int idx(0); idx < 256; ++idx)
     581             :         {
     582         256 :             float s1(rand() & 1 ? -1.0f : 1.0f);
     583         256 :             std::uint64_t rnd(0);
     584         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     585         256 :             float n1(static_cast<float>(rnd));
     586         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     587         256 :             while(rnd == 0) // denominator should not be zero
     588             :             {
     589           0 :                 SNAP_CATCH2_NAMESPACE::random(rnd);
     590             :             }
     591         256 :             float d1(static_cast<float>(rnd));
     592         256 :             float r(n1 / d1 * s1);
     593             :             {
     594         256 :                 std::stringstream str;
     595         256 :                 str << r;
     596         256 :                 c.f_expected_call = true;
     597         256 :                 c.f_got_called = false;
     598         256 :                 c.f_expected_message = str.str();
     599         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     600         256 :                 msg << r;
     601         256 :             }
     602         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     603             :         }
     604             : 
     605             :         // test with double
     606         257 :         for(int idx(0); idx < 256; ++idx)
     607             :         {
     608         256 :             double s1(rand() & 1 ? -1.0 : 1.0);
     609         256 :             std::uint64_t rnd(0);
     610         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     611         256 :             double n1(static_cast<double>(rnd));
     612         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     613         256 :             while(rnd == 0) // denominator should not be zero
     614             :             {
     615           0 :                 SNAP_CATCH2_NAMESPACE::random(rnd);
     616             :             }
     617         256 :             double d1(static_cast<double>(rnd));
     618         256 :             double r(n1 / d1 * s1);
     619             :             {
     620         256 :                 std::stringstream str;
     621         256 :                 str << r;
     622         256 :                 c.f_expected_call = true;
     623         256 :                 c.f_got_called = false;
     624         256 :                 c.f_expected_message = str.str();
     625         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     626         256 :                 msg << r;
     627         256 :             }
     628         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     629             :         }
     630             : 
     631             :         // test with Float64
     632         257 :         for(int idx(0); idx < 256; ++idx)
     633             :         {
     634         256 :             double s1(rand() & 1 ? -1.0 : 1.0);
     635         256 :             std::uint64_t rnd(0);
     636         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     637         256 :             double n1(static_cast<double>(rnd));
     638         256 :             SNAP_CATCH2_NAMESPACE::random(rnd);
     639         256 :             while(rnd == 0) // denominator should not be zero
     640             :             {
     641           0 :                 SNAP_CATCH2_NAMESPACE::random(rnd);
     642             :             }
     643         256 :             double d1(static_cast<double>(rnd));
     644         256 :             double r(n1 / d1 * s1);
     645         256 :             as2js::floating_point f(r);
     646             :             {
     647         256 :                 std::stringstream str;
     648         256 :                 str << r;
     649         256 :                 c.f_expected_call = true;
     650         256 :                 c.f_got_called = false;
     651         256 :                 c.f_expected_message = str.str();
     652         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     653         256 :                 msg << f;
     654         256 :             }
     655         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     656             :         }
     657             : 
     658             :         // test with bool
     659         257 :         for(int idx(0); idx <= 255; ++idx)
     660             :         {
     661         256 :             bool ci(static_cast<char>(idx));
     662             :             {
     663         256 :                 std::stringstream str;
     664         256 :                 str << static_cast<int>(ci);
     665         256 :                 c.f_expected_call = true;
     666         256 :                 c.f_got_called = false;
     667         256 :                 c.f_expected_message = str.str();
     668         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     669         256 :                 msg << ci;
     670         256 :             }
     671         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     672             :         }
     673             : 
     674             :         // test with pointers
     675         257 :         for(int idx(0); idx <= 255; ++idx)
     676             :         {
     677         256 :             int *ptr(new int[5]);
     678             :             {
     679         256 :                 std::stringstream str;
     680         256 :                 str << ptr;
     681         256 :                 c.f_expected_call = true;
     682         256 :                 c.f_got_called = false;
     683         256 :                 c.f_expected_message = str.str();
     684         256 :                 as2js::message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     685         256 :                 msg << ptr;
     686         256 :             }
     687         256 :             CATCH_REQUIRE(c.f_expected_call == c.f_got_called);
     688         256 :             delete [] ptr;
     689             :         }
     690           1 :     }
     691           1 :     CATCH_END_SECTION()
     692           1 : }
     693             : 
     694             : 
     695             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14