Ssrc C++ Binding for Spread 1.0.15 Unit Test Coverage
Current view: top level - tests/spread - MessageTest.cc (source / functions) Hit Total Coverage
Test: Ssrc C++/Lua/Perl/Python/Ruby Bindings for Spread 1.0.15 Unit Tests Lines: 63 63 100.0 %
Date: 2017-11-28 00:28:17 Functions: 24 24 100.0 %
Branches: 285 566 50.4 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright 2006,2007,2011 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                 :            :  *     http://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/spread.h> 
      17                 :            : 
      18                 :            : #include <cstdlib>
      19                 :            : #include <algorithm>
      20                 :            : 
      21                 :            : #define BOOST_TEST_MODULE MessageTest
      22                 :            : #include <boost/test/unit_test.hpp>
      23                 :            : 
      24                 :            : using namespace NS_SSRC_SPREAD; 
      25                 :            : 
      26                 :            : class MessageFixture {
      27                 :            : public:
      28                 :            :   Message *message;
      29                 :            : 
      30                 :          5 :   MessageFixture() {
      31         [ +  - ]:          5 :     message = new Message();
      32                 :          5 :   }
      33                 :            : 
      34                 :         10 :   ~MessageFixture() {
      35         [ +  - ]:          5 :     delete message;
      36                 :          5 :     message = 0;
      37                 :          5 :   }
      38                 :            : };
      39                 :            : 
      40   [ +  -  +  - ]:          1 : BOOST_FIXTURE_TEST_SUITE(all, MessageFixture)
      41                 :            : 
      42   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_set_self_discard) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      43   [ +  -  +  -  :          1 :   BOOST_REQUIRE(!message->is_self_discard());
          +  -  +  -  +  
                -  -  + ]
      44                 :          1 :   message->set_self_discard();
      45   [ +  -  +  -  :          1 :   BOOST_REQUIRE(message->is_self_discard());
          +  -  +  -  +  
                -  -  + ]
      46                 :          1 :   message->set_self_discard(false);
      47   [ +  -  +  -  :          1 :   BOOST_REQUIRE(!message->is_self_discard());
          +  -  +  -  +  
                -  -  + ]
      48                 :          1 : }
      49                 :            : 
      50   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_service) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      51                 :          1 :   Message::service_type service = Message::ReliableSelfDiscard;
      52                 :          1 :   message->set_service(service);
      53   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(message->service(), service);
          +  -  +  -  +  
                -  -  + ]
      54                 :          1 : }
      55                 :            : 
      56   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_write) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      57                 :          1 :   message->write("test_scatter_send", 17);
      58   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(std::memcmp("test_scatter_send",&(*message)[0],17), 0);
          +  -  +  -  -  
                      + ]
      59   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(message->size(), 17u);
          +  -  +  -  +  
                -  -  + ]
      60                 :          1 :   message->clear();
      61                 :          1 :   message->write("test_scatter_send2", 18);
      62   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(message->size(), 18u);
          +  -  +  -  +  
                -  -  + ]
      63   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(std::memcmp("test_scatter_send2",&(*message)[0],18), 0);
          +  -  +  -  -  
                      + ]
      64                 :          1 : }
      65                 :            : 
      66   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_begin_end) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      67         [ +  - ]:          2 :   string str("this is a test");
      68                 :            : 
      69   [ +  -  +  - ]:          1 :   message->write(&str[0], str.size());
      70                 :            : 
      71   [ +  -  +  -  :          1 :   BOOST_REQUIRE(std::equal(message->begin(), message->end(), str.begin()));
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      72   [ +  -  +  -  :          1 :   BOOST_REQUIRE(std::equal(message->rbegin(), message->rend(),
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
      73                 :            :                            str.rbegin()));
      74                 :            : 
      75                 :          1 :   Message const *cm = message;
      76                 :            : 
      77   [ +  -  +  -  :          1 :   BOOST_REQUIRE(std::equal(cm->begin(), cm->end(), str.begin()));
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      78   [ +  -  +  -  :          1 :   BOOST_REQUIRE(std::equal(cm->rbegin(), cm->rend(), str.rbegin()));
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
      79                 :          1 : }
      80                 :            : 
      81   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_resize) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      82         [ +  - ]:          2 :   Message m(16);
      83         [ +  - ]:          1 :   m.write("test_scatter_send2", 18);
      84   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.size(), 18u);
          +  -  +  -  +  
             -  +  -  -  
                      + ]
      85   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(std::memcmp("test_scatter_send2", &m[0], 18), 0);
          +  -  +  -  +  
                -  -  + ]
      86                 :            : 
      87                 :          1 :   const unsigned int capacity = 1048576;
      88         [ +  - ]:          2 :   Message m2(capacity);
      89                 :            : 
      90         [ +  + ]:     524289 :   while(m2.offset() < capacity) {
      91                 :     262144 :     const int j = std::rand();
      92         [ +  - ]:     262144 :     m2.write(&j, sizeof(j));
      93                 :            :   }
      94                 :            : 
      95                 :            :   // Test non-destructive resize.
      96                 :          1 :   const unsigned int chunk_size = 131072;
      97         [ +  - ]:          1 :   m.clear();
      98                 :            : 
      99   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.offset(), 0u);
          +  -  +  -  +  
                -  -  + ]
     100                 :            : 
     101         [ +  - ]:          1 :   m.write(&m2[0], chunk_size);
     102                 :            : 
     103   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.offset(), chunk_size);
          +  -  +  -  +  
                -  -  + ]
     104                 :            : 
     105   [ +  -  +  - ]:          1 :   m.resize(m2.size() / 2);
     106   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.size(), m2.size() / 2);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     107   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.capacity(), m2.size() / 2);
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     108                 :            : 
     109         [ +  + ]:          8 :   for(unsigned int i = chunk_size; i < capacity; i+=chunk_size) {
     110         [ +  - ]:          7 :     m.write(&m2[i], chunk_size);
     111                 :            :   }
     112                 :            : 
     113   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m2.size(), capacity);
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     114   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(m.size(), m2.size());
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     115   [ +  -  +  -  :          1 :   BOOST_REQUIRE_EQUAL(std::memcmp(&m[0], &m2[0], capacity), 0);
          +  -  +  -  +  
                -  -  + ]
     116                 :          1 : }
     117                 :            : 
     118   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_SUITE_END()