Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - tests/wispers/group_session - GroupSessionProtocolTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 76 76 100.0 %
Date: 2012-04-09 Functions: 18 19 94.7 %
Branches: 369 736 50.1 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright 2006-2009 Savarese Software Research Corporation
       2                 :            :  *
       3                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       4                 :            :  * you may not use this file except in compliance with the License.
       5                 :            :  * You may obtain a copy of the License at
       6                 :            :  *
       7                 :            :  *     https://www.savarese.com/software/ApacheLicense-2.0
       8                 :            :  *
       9                 :            :  * Unless required by applicable law or agreed to in writing, software
      10                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      11                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :            :  * See the License for the specific language governing permissions and
      13                 :            :  * limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include <ssrc/wispers/group_session/protocol.h>
      17                 :            : #include <ssrc/wispers/utility/Random.h>
      18                 :            : 
      19                 :            : #define BOOST_TEST_MODULE GroupSessionProtocolTest
      20                 :            : #include <boost/test/unit_test.hpp>
      21                 :            : 
      22                 :            : using namespace NS_SSRC_WSPR_GROUP_SESSION;
      23                 :            : using namespace NS_SSRC_WSPR_UTILITY;
      24                 :            : using ssrc::wispers::gsid_type;
      25                 :            : 
      26   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_min) {
      27   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(0) == GroupSessionProtocol::GSIDMin);
          +  -  +  -  -  
                      + ]
      28   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(1) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace));
          +  -  +  -  -  
                      + ]
      29                 :          1 : }
      30                 :            : 
      31   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_max) {
      32   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(0) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace - 1));
          +  -  +  -  -  
                      + ]
      33   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(1) == (GroupSessionProtocol::GSIDMin + 2*GroupSessionProtocol::GSIDSpace - 1));
          +  -  +  -  -  
                      + ]
      34                 :          1 : }
      35                 :            : 
      36   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_min_partition) {
      37   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(0, 0, 1) == GroupSessionProtocol::GSIDMin);
          +  -  +  -  -  
                      + ]
      38   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(1, 0, 1) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace));
          +  -  +  -  -  
                      + ]
      39   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(0, 0, 2) == GroupSessionProtocol::GSIDMin);
          +  -  +  -  -  
                      + ]
      40   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(1, 0, 2) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace));
          +  -  +  -  -  
                      + ]
      41   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(0, 1, 2) == GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace / 2);
          +  -  +  -  -  
                      + ]
      42   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_min(1, 1, 2) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace + GroupSessionProtocol::GSIDSpace / 2));
          +  -  +  -  -  
                      + ]
      43                 :          1 : }
      44                 :            : 
      45   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_max_partition) {
      46   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(0, 0, 1) == GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace - 1);
          +  -  +  -  -  
                      + ]
      47   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(1, 0, 1) == (GroupSessionProtocol::GSIDMin + 2*GroupSessionProtocol::GSIDSpace - 1));
          +  -  +  -  -  
                      + ]
      48   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(0, 0, 2) == GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace/2 - 1 );
          +  -  +  -  -  
                      + ]
      49   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(1, 0, 2) == (GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace +  GroupSessionProtocol::GSIDSpace/2 - 1));
          +  -  +  -  -  
                      + ]
      50   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(0, 1, 2) == GroupSessionProtocol::GSIDMin + GroupSessionProtocol::GSIDSpace - 1);
          +  -  +  -  -  
                      + ]
      51   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_max(1, 1, 2) == (GroupSessionProtocol::GSIDMin + 2*GroupSessionProtocol::GSIDSpace - 1));
          +  -  +  -  -  
                      + ]
      52                 :          1 : }
      53                 :            : 
      54   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_to_protocol) {
      55   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(0)) == 0);
          +  -  +  -  +  
                -  -  + ]
      56   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(0)) == 0);
          +  -  +  -  +  
                -  -  + ]
      57   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(1)) == 1);
          +  -  +  -  +  
                -  -  + ]
      58   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(1)) == 1);
          +  -  +  -  +  
                -  -  + ]
      59   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(2)) == 2);
          +  -  +  -  +  
                -  -  + ]
      60   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(2)) == 2);
          +  -  +  -  +  
                -  -  + ]
      61   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(10222)) == 10222);
          +  -  +  -  +  
                -  -  + ]
      62   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(10222)) == 10222);
          +  -  +  -  +  
                -  -  + ]
      63   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(32655)) == 32655);
          +  -  +  -  +  
                -  -  + ]
      64   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(32655)) == 32655);
          +  -  +  -  +  
                -  -  + ]
      65   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(32766)) == 32766);
          +  -  +  -  +  
                -  -  + ]
      66   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(32766)) == 32766);
          +  -  +  -  +  
                -  -  + ]
      67   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_min(32767)) == 32767);
          +  -  +  -  +  
                -  -  + ]
      68   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(gsid_max(32767)) == 32767);
          +  -  +  -  +  
                -  -  + ]
      69   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol(0) == boost::integer_traits<wisp_message_protocol>::const_min / -2);
          +  -  +  -  -  
                      + ]
      70                 :          1 : }
      71                 :            : 
      72   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_gsid_to_protocol_partition) {
      73   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0), 1) == 0);
          +  -  +  -  +  
                -  -  + ]
      74   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0), 2) == 0);
          +  -  +  -  +  
                -  -  + ]
      75   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0), 3) == 0);
          +  -  +  -  +  
                -  -  + ]
      76   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0), 4) == 0);
          +  -  +  -  +  
                -  -  + ]
      77   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_max(0), 1) == 0);
          +  -  +  -  +  
                -  -  + ]
      78   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_max(0), 2) == 1);
          +  -  +  -  +  
                -  -  + ]
      79   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_max(0), 3) == 2);
          +  -  +  -  +  
                -  -  + ]
      80   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_max(0), 4) == 3);
          +  -  +  -  +  
                -  -  + ]
      81                 :            : 
      82   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0) + GroupSessionProtocol::GSIDSpace / 2, 1) == 0);
          +  -  +  -  +  
                -  -  + ]
      83   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0) + GroupSessionProtocol::GSIDSpace / 2, 2) == 1);
          +  -  +  -  +  
                -  -  + ]
      84   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0) + GroupSessionProtocol::GSIDSpace / 2, 3) == 1);
          +  -  +  -  +  
                -  -  + ]
      85   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_to_protocol_partition(gsid_min(0) + GroupSessionProtocol::GSIDSpace / 2, 4) == 2);
          +  -  +  -  +  
                -  -  + ]
      86                 :          1 : }
      87                 :            : 
      88   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_protocol_group) {
      89                 :          2 :   GSToGroup gs_to_group;
      90                 :            : 
      91   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_protocol_group(10) == "wspr.gs.protocol.10");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
      92   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_protocol_partition_group(1024, 4) == "wspr.gs.protocol.1024.4");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
      93   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_protocol_group(gsid_min(1392)) == "wspr.gs.protocol.1392");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
      94   [ +  -  +  -  :          1 :   BOOST_CHECK(gsid_protocol_group(gsid_max(1392)) == "wspr.gs.protocol.1392");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
      95   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_to_group.gs_protocol_group(10) == "wspr.gs.protocol.10");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
      96   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_to_group.gs_protocol_partition_group(1024, 4) == "wspr.gs.protocol.1024.4");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
      97   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_to_group.gsid_protocol_group(gsid_min(1392)) == "wspr.gs.protocol.1392");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
      98   [ +  -  +  -  :          1 :   BOOST_CHECK(gs_to_group.gsid_protocol_group(gsid_max(1392)) == "wspr.gs.protocol.1392");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
      99                 :          1 : }
     100                 :            : 
     101   [ +  -  +  -  :          3 : BOOST_AUTO_TEST_CASE(test_random_gsid) {
             -  +  #  # ]
     102         [ +  + ]:         11 :   for(wisp_message_protocol p = 0;
     103                 :            :       p < 10;
     104                 :            :       //p < boost::integer_traits<wisp_message_protocol>::const_max;
     105                 :            :       ++p)
     106                 :            :   {
     107                 :         10 :     const gsid_type min = gsid_min(p, 0, 1);
     108                 :         10 :     const gsid_type max = gsid_max(p, 0, 1);
     109                 :            :     /*
     110                 :            :       Random<gsid_type, boost::uniform_int, random_engine<gsid_type> >
     111                 :            :       random(min, max);
     112                 :            :     */
     113                 :         20 :     Random<gsid_type> random(min, max);
     114                 :            : 
     115         [ +  + ]:        110 :     for(unsigned int i = 0; i < 10; ++i) {
     116         [ +  - ]:        100 :       gsid_type gsid = random();
     117   [ +  -  +  -  :        100 :       BOOST_CHECK(gsid >= min);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     118   [ +  -  +  -  :        100 :       BOOST_CHECK(gsid <= max);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     119                 :            :     }
     120                 :            :   }
     121   [ +  -  +  - ]:          4 : }