Web Wispers 1.2.1 C++ Unit Test Coverage
Current view: top level - tests/wispers/service - ServiceTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.1 C++ Unit Tests Lines: 36 36 100.0 %
Date: 2011-11-11 Functions: 21 23 91.3 %
Branches: 115 230 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 <unistd.h>
      18                 :            : 
      19                 :            : #include <tests/TestCommon.h>
      20                 :            : #include <ssrc/wispers/service/service.h>
      21                 :            : #include <ssrc/wispers/utility/NumberVisitor.h>
      22                 :            : 
      23                 :            : using NS_SSRC_WISP_PROTOCOL::message_info_ptr;
      24                 :            : using namespace NS_SSRC_WSPR_SERVICE;
      25                 :            : using NS_SSRC_WSPR_UTILITY::get_number;
      26                 :            : 
      27                 :            : struct TestServiceProtocolProcessor : public ServiceProtocolProcessor {
      28                 :            :   typedef ServiceProtocolProcessor super;
      29                 :            : 
      30                 :          2 :   explicit TestServiceProtocolProcessor(super::caller_type & caller) :
      31                 :          2 :     super(caller)
      32                 :          2 :   { }
      33                 :            : 
      34         [ -  + ]:          2 :   virtual ~TestServiceProtocolProcessor() { }
      35                 :            : 
      36                 :          4 :   virtual void transition(super::State state) {
      37         [ +  + ]:          4 :     if(state == super::Starting)
      38                 :          2 :       state = super::Started;
      39         [ +  - ]:          2 :     else if(state == super::Stopping)
      40                 :          2 :       state = super::Stopped;
      41                 :          4 :     super::transition(state);
      42                 :          4 :   }
      43                 :            : };
      44                 :            : 
      45         [ -  + ]:          6 : class ServiceTest :
      46                 :            :   public ServiceTestCase<TestServiceProtocolProcessor, ServiceEventHandler>
      47                 :            : {
      48                 :            :   WISP_IMPORT(ServiceProtocol, MessageEchoRequest);
      49                 :            :   WISP_IMPORT(ServiceProtocol, MessageEchoReply);
      50                 :            :   WISP_IMPORT(ServiceProtocol, CallEchoRequest);
      51                 :            :   WISP_IMPORT(ServiceProtocol, MessageStatusReply);
      52                 :            :   WISP_IMPORT(ServiceProtocol, CallStatusRequest);
      53                 :            : 
      54                 :            : public:
      55                 :            : 
      56                 :          1 :   void test_call_echo_request() {
      57                 :          2 :     service_thread call(*serv);
      58                 :            :     MessageEchoReply echo_reply;
      59                 :            : 
      60   [ +  -  +  - ]:          1 :     call(CallEchoRequest(), serv->name(), &echo_reply);
      61                 :            : 
      62   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(true);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
      63                 :          1 :   }
      64                 :            : 
      65                 :          1 :   void test_call_status_request() {
      66                 :          2 :     service_thread call(*serv);
      67                 :            : 
      68   [ +  -  +  -  :          1 :     call(CallStatusRequest(), serv->name());
                   +  - ]
      69                 :            : 
      70   [ +  -  +  - ]:          2 :     message_info_ptr info;
      71   [ +  -  +  - ]:          2 :     MessageStatusReply status_reply;
      72         [ +  - ]:          1 :     call.receive_request(info);
      73                 :            : 
      74   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(info->id() == MessageStatusReply::id);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
      75                 :            : 
      76         [ +  - ]:          1 :     call.unpack(status_reply, *info);
      77                 :            : 
      78   [ +  -  +  -  :          2 :     CPPUNIT_ASSERT(status_reply.status->get<std::string>("", "srv", "name") ==
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      79         [ +  - ]:          1 :                    serv->name());
      80   [ +  -  +  -  :          2 :     CPPUNIT_ASSERT(get_number<int>(*status_reply.status, -1, "srv", "pid") ==
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      81         [ +  - ]:          1 :                    ::getpid());
      82                 :          1 :   }
      83                 :            : 
      84   [ +  -  +  -  :          4 :   CPPUNIT_TEST_SUITE(ServiceTest);
             +  -  #  # ]
      85   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_call_echo_request);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      86   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_call_status_request);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      87   [ +  -  +  -  :          2 :   CPPUNIT_TEST_SUITE_END();
          +  -  +  -  +  
                -  +  - ]
      88                 :            : };
      89                 :            : 
      90                 :          1 : CPPUNIT_TEST_SUITE_REGISTRATION(ServiceTest);
      91   [ +  -  +  -  :         16 : WISP_TEST_MAIN()
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]