Web Wispers 1.2.0 C++ Unit Test Coverage
Current view: top level - tests/wispers/group_session - GroupSessionProtocolTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.0 C++ Unit Tests Lines: 91 91 100.0 %
Date: 2010-05-27 Functions: 20 21 95.2 %
Branches: 694 1388 50.0 %

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