Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - tests/wispers/service - ServiceTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 32 32 100.0 %
Date: 2012-04-09 Functions: 21 23 91.3 %
Branches: 67 132 50.8 %

           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 <unistd.h>
      17                 :            : 
      18                 :            : #include <ssrc/wispers/service/service.h>
      19                 :            : #include <ssrc/wispers/utility/NumberVisitor.h>
      20                 :            : #include <ssrc/wispers/test/ServiceTestFixture.h>
      21                 :            : 
      22                 :            : #define BOOST_TEST_MODULE ServiceTest
      23                 :            : #include <boost/test/unit_test.hpp>
      24                 :            : 
      25                 :            : using namespace ssrc::wispers::test;
      26                 :            : using NS_SSRC_WISP_PROTOCOL::message_info_ptr;
      27                 :            : using namespace NS_SSRC_WSPR_SERVICE;
      28                 :            : using NS_SSRC_WSPR_UTILITY::get_number;
      29                 :            : 
      30                 :            : struct TestServiceProtocolProcessor : public ServiceProtocolProcessor {
      31                 :            :   typedef ServiceProtocolProcessor super;
      32                 :            : 
      33                 :          2 :   explicit TestServiceProtocolProcessor(super::caller_type & caller) :
      34                 :          2 :     super(caller)
      35                 :          2 :   { }
      36                 :            : 
      37         [ -  + ]:          2 :   virtual ~TestServiceProtocolProcessor() { }
      38                 :            : 
      39                 :          4 :   virtual void transition(super::State state) {
      40         [ +  + ]:          4 :     if(state == super::Starting)
      41                 :          2 :       state = super::Started;
      42         [ +  - ]:          2 :     else if(state == super::Stopping)
      43                 :          2 :       state = super::Stopped;
      44                 :          4 :     super::transition(state);
      45                 :          4 :   }
      46                 :            : };
      47                 :            : 
      48                 :          4 : struct ServiceFixture :
      49                 :            :   public ServiceTestFixture<TestServiceProtocolProcessor, ServiceEventHandler>
      50                 :            : {
      51                 :            :   WISP_IMPORT(ServiceProtocol, MessageEchoRequest);
      52                 :            :   WISP_IMPORT(ServiceProtocol, MessageEchoReply);
      53                 :            :   WISP_IMPORT(ServiceProtocol, CallEchoRequest);
      54                 :            :   WISP_IMPORT(ServiceProtocol, MessageStatusReply);
      55                 :            :   WISP_IMPORT(ServiceProtocol, CallStatusRequest);
      56                 :            : };
      57                 :            : 
      58                 :          1 : BOOST_FIXTURE_TEST_SUITE(all, ServiceFixture)
      59                 :            : 
      60   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_call_echo_request) {
                   +  - ]
      61                 :          2 :   service_thread call(*serv);
      62                 :            :   MessageEchoReply echo_reply;
      63                 :            : 
      64   [ +  -  +  - ]:          1 :   call(CallEchoRequest(), serv->name(), &echo_reply);
      65                 :            : 
      66   [ +  -  +  -  :          1 :   BOOST_CHECK(true);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      67                 :          1 : }
      68                 :            : 
      69   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_call_status_request) {
                   +  - ]
      70                 :          2 :   service_thread call(*serv);
      71                 :            : 
      72   [ +  -  +  -  :          1 :   call(CallStatusRequest(), serv->name());
                   +  - ]
      73                 :            : 
      74   [ +  -  +  - ]:          2 :   message_info_ptr info;
      75   [ +  -  +  - ]:          2 :   MessageStatusReply status_reply;
      76         [ +  - ]:          1 :   call.receive_request(info);
      77                 :            : 
      78   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(info->id(), MessageStatusReply::id);
          +  -  +  -  +  
                -  -  + ]
      79                 :            : 
      80         [ +  - ]:          1 :   call.unpack(status_reply, *info);
      81                 :            : 
      82   [ +  -  +  -  :          4 :   BOOST_CHECK_EQUAL(status_reply.status->get<std::string>("", "srv", "name"),
             +  -  -  + ]
      83   [ +  -  +  -  :          3 :                     serv->name());
          +  -  +  -  +  
                -  +  - ]
      84   [ +  -  +  -  :          3 :   BOOST_CHECK_EQUAL(get_number<int>(*status_reply.status, -1, "srv", "pid"),
             +  -  -  + ]
      85   [ +  -  +  -  :          2 :                     ::getpid());
             +  -  +  - ]
      86                 :          1 : }
      87                 :            : 
      88   [ +  -  +  -  :         16 : BOOST_AUTO_TEST_SUITE_END()
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]