LCOV - code coverage report
Current view: top level - tests - test_as2js_message.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 397 397 100.0 %
Date: 2014-11-22 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* test_as2js_message.cpp -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       2             : 
       3             : /*
       4             : 
       5             : Copyright (c) 2005-2014 Made to Order Software Corp.
       6             : 
       7             : http://snapwebsites.org/project/as2js
       8             : 
       9             : Permission is hereby granted, free of charge, to any
      10             : person obtaining a copy of this software and
      11             : associated documentation files (the "Software"), to
      12             : deal in the Software without restriction, including
      13             : without limitation the rights to use, copy, modify,
      14             : merge, publish, distribute, sublicense, and/or sell
      15             : copies of the Software, and to permit persons to whom
      16             : the Software is furnished to do so, subject to the
      17             : following conditions:
      18             : 
      19             : The above copyright notice and this permission notice
      20             : shall be included in all copies or substantial
      21             : portions of the Software.
      22             : 
      23             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      24             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      25             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      26             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      27             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      28             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      29             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      30             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      31             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      32             : SOFTWARE.
      33             : 
      34             : */
      35             : 
      36             : #include    "test_as2js_message.h"
      37             : #include    "test_as2js_main.h"
      38             : 
      39             : #include    "as2js/message.h"
      40             : #include    "as2js/exceptions.h"
      41             : 
      42             : #include    <controlled_vars/controlled_vars_limited_auto_enum_init.h>
      43             : 
      44             : #include    <cstring>
      45             : #include    <algorithm>
      46             : 
      47             : #include    <cppunit/config/SourcePrefix.h>
      48           4 : CPPUNIT_TEST_SUITE_REGISTRATION( As2JsMessageUnitTests );
      49             : 
      50             : 
      51             : 
      52             : namespace
      53             : {
      54             : 
      55           2 : class test_callback : public as2js::MessageCallback
      56             : {
      57             : public:
      58      524498 :     test_callback()
      59      524498 :     {
      60      524498 :         as2js::Message::set_message_callback(this);
      61      524498 :         g_warning_count = as2js::Message::warning_count();
      62      524498 :         g_error_count = as2js::Message::error_count();
      63      524498 :     }
      64             : 
      65      524499 :     ~test_callback()
      66     1048998 :     {
      67             :         // make sure the pointer gets reset!
      68      524499 :         as2js::Message::set_message_callback(nullptr);
      69      524499 :     }
      70             : 
      71             :     // implementation of the output
      72     1802630 :     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     1802630 :         CPPUNIT_ASSERT(f_expected_call);
      79     1802630 :         CPPUNIT_ASSERT(message_level == f_expected_message_level);
      80     1802630 :         CPPUNIT_ASSERT(error_code == f_expected_error_code);
      81     1802630 :         CPPUNIT_ASSERT(pos.get_filename() == f_expected_pos.get_filename());
      82     1802630 :         CPPUNIT_ASSERT(pos.get_function() == f_expected_pos.get_function());
      83     1802630 :         CPPUNIT_ASSERT(pos.get_page() == f_expected_pos.get_page());
      84     1802630 :         CPPUNIT_ASSERT(pos.get_page_line() == f_expected_pos.get_page_line());
      85     1802630 :         CPPUNIT_ASSERT(pos.get_paragraph() == f_expected_pos.get_paragraph());
      86     1802630 :         CPPUNIT_ASSERT(pos.get_line() == f_expected_pos.get_line());
      87     1802630 :         CPPUNIT_ASSERT(message == f_expected_message);
      88             : 
      89     1802630 :         if(message_level == as2js::message_level_t::MESSAGE_LEVEL_WARNING)
      90             :         {
      91      299712 :             ++g_warning_count;
      92      299712 :             CPPUNIT_ASSERT(g_warning_count == as2js::Message::warning_count());
      93             :         }
      94             : 
      95     1802630 :         if(message_level == as2js::message_level_t::MESSAGE_LEVEL_FATAL
      96     1278134 :         || message_level == as2js::message_level_t::MESSAGE_LEVEL_ERROR)
      97             :         {
      98     1053350 :             ++g_error_count;
      99             : //std::cerr << "error: " << g_error_count << " / " << as2js::Message::error_count() << "\n";
     100     1053350 :             CPPUNIT_ASSERT(g_error_count == as2js::Message::error_count());
     101             :         }
     102             : 
     103     1802630 :         f_got_called = true;
     104     1802630 :     }
     105             : 
     106             :     controlled_vars::tlbool_t   f_expected_call;
     107             :     controlled_vars::flbool_t   f_got_called;
     108             :     as2js::message_level_t      f_expected_message_level;
     109             :     as2js::err_code_t           f_expected_error_code;
     110             :     as2js::Position             f_expected_pos;
     111             :     std::string                 f_expected_message; // UTF-8 string
     112             :     static controlled_vars::zint32_t   g_warning_count;
     113             :     static controlled_vars::zint32_t   g_error_count;
     114             : };
     115             : 
     116           4 : controlled_vars::zint32_t   test_callback::g_warning_count;
     117           4 : controlled_vars::zint32_t   test_callback::g_error_count;
     118             : 
     119             : }
     120             : // no name namespace
     121             : 
     122             : 
     123             : 
     124           1 : void As2JsMessageUnitTests::test_message()
     125             : {
     126           8 :     for(as2js::message_level_t i(as2js::message_level_t::MESSAGE_LEVEL_OFF);
     127             :                                i <= as2js::message_level_t::MESSAGE_LEVEL_TRACE;
     128             :                                i = static_cast<as2js::message_level_t>(static_cast<int>(i) + 1))
     129             :     {
     130             : //i = static_cast<as2js::message_level_t>(static_cast<int>(i) + 1);
     131           7 :         std::cerr << "[" << static_cast<int32_t>(i) << "]";
     132             : 
     133         595 :         for(as2js::err_code_t j(as2js::err_code_t::AS_ERR_NONE); j <= as2js::err_code_t::AS_ERR_max; j = static_cast<as2js::err_code_t>(static_cast<int>(j) + 1))
     134             :         {
     135         588 :             std::cerr << ".";
     136             : 
     137             :             {
     138         588 :                 test_callback c;
     139         588 :                 c.f_expected_message_level = i;
     140         588 :                 c.f_expected_error_code = j;
     141         588 :                 c.f_expected_pos.set_filename("unknown-file");
     142         588 :                 c.f_expected_pos.set_function("unknown-func");
     143             : 
     144        4704 :                 for(as2js::message_level_t k(as2js::message_level_t::MESSAGE_LEVEL_OFF); k <= as2js::message_level_t::MESSAGE_LEVEL_TRACE; k = static_cast<as2js::message_level_t>(static_cast<int>(k) + 1))
     145             :                 {
     146        4116 :                     as2js::Message::set_message_level(k);
     147        4116 :                     as2js::message_level_t min(k < as2js::message_level_t::MESSAGE_LEVEL_ERROR ? as2js::message_level_t::MESSAGE_LEVEL_ERROR : k);
     148             : //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";
     149             :                     {
     150        4116 :                         c.f_expected_call = false;
     151        4116 :                         c.f_got_called = false;
     152        4116 :                         c.f_expected_message = "";
     153        4116 :                         as2js::Message msg(i, j);
     154             :                     }
     155        4116 :                     CPPUNIT_ASSERT(!c.f_got_called); // no message no call
     156             :                     {
     157        4116 :                         c.f_expected_call = i != as2js::message_level_t::MESSAGE_LEVEL_OFF && i <= min;
     158        4116 :                         c.f_got_called = false;
     159        4116 :                         c.f_expected_message = "with a message";
     160        4116 :                         as2js::Message msg(i, j);
     161        4116 :                         msg << "with a message";
     162             :                     }
     163        4116 :                     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     164         588 :                 }
     165             :             }
     166             : 
     167         588 :             as2js::Position pos;
     168         588 :             pos.set_filename("file.js");
     169         588 :             int total_line(1);
     170        5880 :             for(int page(1); page < 10; ++page)
     171             :             {
     172             :                 //std::cerr << "+";
     173             : 
     174        5292 :                 int paragraphs(rand() % 10 + 10);
     175        5292 :                 int page_line(1);
     176        5292 :                 int paragraph(1);
     177      529200 :                 for(int line(1); line < 100; ++line)
     178             :                 {
     179      523908 :                     CPPUNIT_ASSERT(pos.get_page() == page);
     180      523908 :                     CPPUNIT_ASSERT(pos.get_page_line() == page_line);
     181      523908 :                     CPPUNIT_ASSERT(pos.get_paragraph() == paragraph);
     182      523908 :                     CPPUNIT_ASSERT(pos.get_line() == total_line);
     183             : 
     184      523908 :                     std::stringstream pos_str;
     185      523908 :                     pos_str << pos;
     186     1047816 :                     std::stringstream test_str;
     187      523908 :                     test_str << "file.js:" << total_line << ":";
     188      523908 :                     CPPUNIT_ASSERT(pos_str.str() == test_str.str());
     189             : 
     190             :                     {
     191      523908 :                         test_callback c;
     192      523908 :                         c.f_expected_message_level = i;
     193      523908 :                         c.f_expected_error_code = j;
     194      523908 :                         c.f_expected_pos = pos;
     195      523908 :                         c.f_expected_pos.set_filename("file.js");
     196      523908 :                         c.f_expected_pos.set_function("unknown-func");
     197             : 
     198     4191264 :                         for(as2js::message_level_t k(as2js::message_level_t::MESSAGE_LEVEL_OFF); k <= as2js::message_level_t::MESSAGE_LEVEL_TRACE; k = static_cast<as2js::message_level_t>(static_cast<int>(k) + 1))
     199             :                         {
     200     3667356 :                             as2js::Message::set_message_level(k);
     201     3667356 :                             as2js::message_level_t min(k < as2js::message_level_t::MESSAGE_LEVEL_ERROR ? as2js::message_level_t::MESSAGE_LEVEL_ERROR : k);
     202             :                             {
     203     3667356 :                                 c.f_expected_call = false;
     204     3667356 :                                 c.f_got_called = false;
     205     3667356 :                                 c.f_expected_message = "";
     206     3667356 :                                 as2js::Message msg(i, j, pos);
     207             :                             }
     208     3667356 :                             CPPUNIT_ASSERT(!c.f_got_called);
     209             :                             {
     210     3667356 :                                 c.f_expected_call = i != as2js::message_level_t::MESSAGE_LEVEL_OFF && i <= min;
     211     3667356 :                                 c.f_got_called = false;
     212     3667356 :                                 c.f_expected_message = "and a small message";
     213     3667356 :                                 as2js::Message msg(i, j, pos);
     214     3667356 :                                 msg << "and a small message";
     215             :                             }
     216     3667356 :                             CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     217      523908 :                         }
     218             :                     }
     219             : 
     220      523908 :                     if(line % paragraphs == 0)
     221             :                     {
     222       35329 :                         pos.new_paragraph();
     223       35329 :                         ++paragraph;
     224             :                     }
     225      523908 :                     pos.new_line();
     226      523908 :                     ++total_line;
     227      523908 :                     ++page_line;
     228      523908 :                 }
     229        5292 :                 pos.new_page();
     230             :             }
     231         588 :         }
     232             :     }
     233           1 : }
     234             : 
     235             : 
     236           1 : void As2JsMessageUnitTests::test_operator()
     237             : {
     238           1 :     test_callback c;
     239           1 :     c.f_expected_message_level = as2js::message_level_t::MESSAGE_LEVEL_ERROR;
     240           1 :     c.f_expected_error_code = as2js::err_code_t::AS_ERR_CANNOT_COMPILE;
     241           1 :     c.f_expected_pos.set_filename("operator.js");
     242           1 :     c.f_expected_pos.set_function("compute");
     243           1 :     as2js::Message::set_message_level(as2js::message_level_t::MESSAGE_LEVEL_INFO);
     244             : 
     245             :     // test the copy constructor and operator
     246             :     {
     247           1 :         test_callback try_copy(c);
     248           2 :         test_callback try_assignment;
     249           2 :         try_assignment = c;
     250             :     }
     251             :     // this is required as the destructors called on the previous '}'
     252             :     // will otherwise clear that pointer...
     253           1 :     as2js::Message::set_message_callback(&c);
     254             : 
     255           2 :     as2js::Position pos;
     256           1 :     pos.set_filename("operator.js");
     257           1 :     pos.set_function("compute");
     258           1 :     c.f_expected_pos = pos;
     259             : 
     260             :     // test with nothing
     261             :     {
     262           1 :         c.f_expected_call = false;
     263           1 :         c.f_got_called = false;
     264           1 :         c.f_expected_message = "";
     265           1 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     266             :     }
     267           1 :     CPPUNIT_ASSERT(!c.f_got_called); // no message no call
     268             : 
     269             :     // test with char *
     270             :     {
     271           1 :         c.f_expected_call = true;
     272           1 :         c.f_got_called = false;
     273           1 :         c.f_expected_message = "with a message";
     274           1 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     275           1 :         msg << "with a message";
     276             :     }
     277           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     278             : 
     279             :     // test with std::string
     280             :     {
     281           1 :         c.f_expected_call = true;
     282           1 :         c.f_got_called = false;
     283           1 :         c.f_expected_message = "with an std::string message";
     284           1 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     285           2 :         std::string str("with an std::string message");
     286           2 :         msg << str;
     287             :     }
     288           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     289             : 
     290             :     // test with ASCII wchar_t
     291             :     {
     292           1 :         c.f_expected_call = true;
     293           1 :         c.f_got_called = false;
     294           1 :         c.f_expected_message = "Simple wide char string";
     295           1 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     296           1 :         wchar_t const *str(L"Simple wide char string");
     297           1 :         msg << str;
     298             :     }
     299           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     300             : 
     301             :     // test with Unicode wchar_t
     302             :     {
     303           1 :         wchar_t const *str(L"Some: \x2028 Unicode \xA9");
     304           1 :         as2js::String unicode(str);
     305           1 :         c.f_expected_call = true;
     306           1 :         c.f_got_called = false;
     307           1 :         c.f_expected_message = unicode.to_utf8();
     308           2 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     309           2 :         msg << str;
     310             :     }
     311           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     312             : 
     313             :     // test with ASCII std::wstring
     314             :     {
     315           1 :         c.f_expected_call = true;
     316           1 :         c.f_got_called = false;
     317           1 :         c.f_expected_message = "with an std::string message";
     318           1 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     319           2 :         std::wstring str(L"with an std::string message");
     320           2 :         msg << str;
     321             :     }
     322           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     323             : 
     324             :     // test with Unicode std::wstring
     325             :     {
     326           1 :         std::wstring str(L"Some: \x2028 Unicode \xA9");
     327           2 :         as2js::String unicode(str);
     328           1 :         c.f_expected_call = true;
     329           1 :         c.f_got_called = false;
     330           1 :         c.f_expected_message = unicode.to_utf8();
     331           2 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     332           2 :         msg << str;
     333             :     }
     334           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     335             : 
     336             :     // test with as2js::String too
     337             :     {
     338           1 :         std::wstring str(L"Some: \x2028 Unicode \xA9");
     339           2 :         as2js::String unicode(str);
     340           1 :         c.f_expected_call = true;
     341           1 :         c.f_got_called = false;
     342           1 :         c.f_expected_message = unicode.to_utf8();
     343           2 :         as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     344           2 :         msg << unicode;
     345             :     }
     346           1 :     CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     347             : 
     348             :     // test with char
     349         256 :     for(int idx(1); idx <= 255; ++idx)
     350             :     {
     351         255 :         char ci(static_cast<char>(idx));
     352             :         {
     353         255 :             std::stringstream str;
     354         255 :             str << ci;
     355         255 :             c.f_expected_call = true;
     356         255 :             c.f_got_called = false;
     357         255 :             c.f_expected_message = str.str();
     358         510 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     359         510 :             msg << ci;
     360             :         }
     361         255 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     362             :     }
     363             : 
     364             :     // test with signed char
     365         257 :     for(int idx(-128); idx <= 127; ++idx)
     366             :     {
     367         256 :         signed char ci(static_cast<signed char>(idx));
     368             :         {
     369         256 :             std::stringstream str;
     370         256 :             str << static_cast<int>(ci);
     371         256 :             c.f_expected_call = true;
     372         256 :             c.f_got_called = false;
     373         256 :             c.f_expected_message = str.str();
     374         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     375         512 :             msg << ci;
     376             :         }
     377         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     378             :     }
     379             : 
     380             :     // test with unsigned char
     381         257 :     for(int idx(-128); idx <= 127; ++idx)
     382             :     {
     383         256 :         unsigned char ci(static_cast<unsigned char>(idx));
     384             :         {
     385         256 :             std::stringstream str;
     386         256 :             str << static_cast<int>(ci);
     387         256 :             c.f_expected_call = true;
     388         256 :             c.f_got_called = false;
     389         256 :             c.f_expected_message = str.str();
     390         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     391         512 :             msg << ci;
     392             :         }
     393         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     394             :     }
     395             : 
     396             :     // test with signed short
     397         257 :     for(int idx(0); idx < 256; ++idx)
     398             :     {
     399         256 :         signed short ci(static_cast<signed short>(rand()));
     400             :         {
     401         256 :             std::stringstream str;
     402         256 :             str << static_cast<int>(ci);
     403         256 :             c.f_expected_call = true;
     404         256 :             c.f_got_called = false;
     405         256 :             c.f_expected_message = str.str();
     406         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     407         512 :             msg << ci;
     408             :         }
     409         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     410             :     }
     411             : 
     412             :     // test with unsigned short
     413         257 :     for(int idx(0); idx < 256; ++idx)
     414             :     {
     415         256 :         unsigned short ci(static_cast<unsigned short>(rand()));
     416             :         {
     417         256 :             std::stringstream str;
     418         256 :             str << static_cast<int>(ci);
     419         256 :             c.f_expected_call = true;
     420         256 :             c.f_got_called = false;
     421         256 :             c.f_expected_message = str.str();
     422         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     423         512 :             msg << ci;
     424             :         }
     425         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     426             :     }
     427             : 
     428             :     // test with signed int
     429         257 :     for(int idx(0); idx < 256; ++idx)
     430             :     {
     431         256 :         signed int ci((static_cast<unsigned int>(rand()) << 16) ^ static_cast<unsigned int>(rand()));
     432             :         {
     433         256 :             std::stringstream str;
     434         256 :             str << ci;
     435         256 :             c.f_expected_call = true;
     436         256 :             c.f_got_called = false;
     437         256 :             c.f_expected_message = str.str();
     438         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     439         512 :             msg << ci;
     440             :         }
     441         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     442             :     }
     443             : 
     444             :     // test with unsigned int
     445         257 :     for(int idx(0); idx < 256; ++idx)
     446             :     {
     447         256 :         unsigned int ci((static_cast<unsigned int>(rand()) << 16) ^ static_cast<unsigned int>(rand()));
     448             :         {
     449         256 :             std::stringstream str;
     450         256 :             str << ci;
     451         256 :             c.f_expected_call = true;
     452         256 :             c.f_got_called = false;
     453         256 :             c.f_expected_message = str.str();
     454         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     455         512 :             msg << ci;
     456             :         }
     457         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     458             :     }
     459             : 
     460             :     // test with signed long
     461         257 :     for(int idx(0); idx < 256; ++idx)
     462             :     {
     463             :         signed long ci(
     464             : #if (ULONG_MAX) != 0xfffffffful
     465         256 :                   (static_cast<unsigned long>(rand()) << 48)
     466         256 :                 ^ (static_cast<unsigned long>(rand()) << 32)
     467         256 :                 ^
     468             : #endif
     469         256 :                   (static_cast<unsigned long>(rand()) << 16)
     470         256 :                 ^ (static_cast<unsigned long>(rand()) <<  0));
     471             :         {
     472         256 :             std::stringstream str;
     473         256 :             str << ci;
     474         256 :             c.f_expected_call = true;
     475         256 :             c.f_got_called = false;
     476         256 :             c.f_expected_message = str.str();
     477         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     478         512 :             msg << ci;
     479             :         }
     480         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     481             :     }
     482             : 
     483             :     // test with unsigned long
     484         257 :     for(int idx(0); idx < 256; ++idx)
     485             :     {
     486             :         unsigned long ci(
     487             : #if (ULONG_MAX) != 0xfffffffful
     488         256 :                   (static_cast<unsigned long>(rand()) << 48)
     489         256 :                 ^ (static_cast<unsigned long>(rand()) << 32)
     490         256 :                 ^
     491             : #endif
     492         256 :                   (static_cast<unsigned long>(rand()) << 16)
     493         256 :                 ^ (static_cast<unsigned long>(rand())));
     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         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     501         512 :             msg << ci;
     502             :         }
     503         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     504             :     }
     505             : 
     506             :     // if not 64 bits, then the next 2 tests should probably change a bit
     507             :     // to support the additional bits
     508           1 :     CPPUNIT_ASSERT(sizeof(unsigned long long) == 64 / 8);
     509             : 
     510             :     // test with signed long long
     511         257 :     for(int idx(0); idx < 256; ++idx)
     512             :     {
     513             :         signed long long ci(
     514         256 :                   (static_cast<unsigned long long>(rand()) << 48)
     515         256 :                 ^ (static_cast<unsigned long long>(rand()) << 32)
     516         256 :                 ^ (static_cast<unsigned long long>(rand()) << 16)
     517         256 :                 ^ (static_cast<unsigned long long>(rand()) <<  0));
     518             :         {
     519         256 :             std::stringstream str;
     520         256 :             str << ci;
     521         256 :             c.f_expected_call = true;
     522         256 :             c.f_got_called = false;
     523         256 :             c.f_expected_message = str.str();
     524         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     525         512 :             msg << ci;
     526             :         }
     527         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     528             :     }
     529             : 
     530             :     // test with unsigned long long
     531         257 :     for(int idx(0); idx < 256; ++idx)
     532             :     {
     533             :         unsigned long long ci(
     534         256 :                   (static_cast<unsigned long long>(rand()) << 48)
     535         256 :                 ^ (static_cast<unsigned long long>(rand()) << 32)
     536         256 :                 ^ (static_cast<unsigned long long>(rand()) << 16)
     537         256 :                 ^ (static_cast<unsigned long long>(rand())));
     538             :         {
     539         256 :             std::stringstream str;
     540         256 :             str << ci;
     541         256 :             c.f_expected_call = true;
     542         256 :             c.f_got_called = false;
     543         256 :             c.f_expected_message = str.str();
     544         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     545         512 :             msg << ci;
     546             :         }
     547         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     548             :     }
     549             : 
     550             :     // test with Int64
     551         257 :     for(int idx(0); idx < 256; ++idx)
     552             :     {
     553             :         as2js::Int64::int64_type ci(
     554         256 :                   (static_cast<as2js::Int64::int64_type>(rand()) << 48)
     555         256 :                 ^ (static_cast<as2js::Int64::int64_type>(rand()) << 32)
     556         256 :                 ^ (static_cast<as2js::Int64::int64_type>(rand()) << 16)
     557         256 :                 ^ (static_cast<as2js::Int64::int64_type>(rand()) <<  0));
     558         256 :         as2js::Int64 value(ci);
     559             :         {
     560         256 :             std::stringstream str;
     561         256 :             str << ci;
     562         256 :             c.f_expected_call = true;
     563         256 :             c.f_got_called = false;
     564         256 :             c.f_expected_message = str.str();
     565         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     566         512 :             msg << value;
     567             :         }
     568         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     569             :     }
     570             : 
     571             :     // test with float
     572         257 :     for(int idx(0); idx < 256; ++idx)
     573             :     {
     574         256 :         float s1(rand() & 1 ? -1 : 1);
     575         256 :         float n1(static_cast<float>((static_cast<int64_t>(rand()) << 48)
     576         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     577         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     578         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     579         256 :         float d1(static_cast<float>((static_cast<int64_t>(rand()) << 48)
     580         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     581         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     582         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     583         256 :         float r(n1 / d1 * s1);
     584             :         {
     585         256 :             std::stringstream str;
     586         256 :             str << r;
     587         256 :             c.f_expected_call = true;
     588         256 :             c.f_got_called = false;
     589         256 :             c.f_expected_message = str.str();
     590         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     591         512 :             msg << r;
     592             :         }
     593         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     594             :     }
     595             : 
     596             :     // test with double
     597         257 :     for(int idx(0); idx < 256; ++idx)
     598             :     {
     599         256 :         double s1(rand() & 1 ? -1 : 1);
     600         256 :         double n1(static_cast<double>((static_cast<int64_t>(rand()) << 48)
     601         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     602         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     603         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     604         256 :         double d1(static_cast<double>((static_cast<int64_t>(rand()) << 48)
     605         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     606         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     607         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     608         256 :         double r(n1 / d1 * s1);
     609             :         {
     610         256 :             std::stringstream str;
     611         256 :             str << r;
     612         256 :             c.f_expected_call = true;
     613         256 :             c.f_got_called = false;
     614         256 :             c.f_expected_message = str.str();
     615         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     616         512 :             msg << r;
     617             :         }
     618         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     619             :     }
     620             : 
     621             :     // test with Float64
     622         257 :     for(int idx(0); idx < 256; ++idx)
     623             :     {
     624         256 :         double s1(rand() & 1 ? -1 : 1);
     625         256 :         double n1(static_cast<double>((static_cast<int64_t>(rand()) << 48)
     626         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     627         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     628         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     629         256 :         double d1(static_cast<double>((static_cast<int64_t>(rand()) << 48)
     630         256 :                                   ^ (static_cast<int64_t>(rand()) << 32)
     631         256 :                                   ^ (static_cast<int64_t>(rand()) << 16)
     632         256 :                                   ^ (static_cast<int64_t>(rand()) <<  0)));
     633         256 :         double r(n1 / d1 * s1);
     634         256 :         as2js::Float64 f(r);
     635             :         {
     636         256 :             std::stringstream str;
     637         256 :             str << r;
     638         256 :             c.f_expected_call = true;
     639         256 :             c.f_got_called = false;
     640         256 :             c.f_expected_message = str.str();
     641         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     642         512 :             msg << f;
     643             :         }
     644         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     645             :     }
     646             : 
     647             :     // test with bool
     648         257 :     for(int idx(0); idx <= 255; ++idx)
     649             :     {
     650         256 :         bool ci(static_cast<char>(idx));
     651             :         {
     652         256 :             std::stringstream str;
     653         256 :             str << static_cast<int>(ci);
     654         256 :             c.f_expected_call = true;
     655         256 :             c.f_got_called = false;
     656         256 :             c.f_expected_message = str.str();
     657         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     658         512 :             msg << ci;
     659             :         }
     660         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     661             :     }
     662             : 
     663             :     // test with pointers
     664         257 :     for(int idx(0); idx <= 255; ++idx)
     665             :     {
     666         256 :         int *ptr(new int[5]);
     667             :         {
     668         256 :             std::stringstream str;
     669         256 :             str << ptr;
     670         256 :             c.f_expected_call = true;
     671         256 :             c.f_got_called = false;
     672         256 :             c.f_expected_message = str.str();
     673         512 :             as2js::Message msg(as2js::message_level_t::MESSAGE_LEVEL_ERROR, as2js::err_code_t::AS_ERR_CANNOT_COMPILE, pos);
     674         512 :             msg << ptr;
     675             :         }
     676         256 :         CPPUNIT_ASSERT(c.f_expected_call == c.f_got_called);
     677           1 :     }
     678          13 : }
     679             : 
     680             : 
     681             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.10