LCOV - code coverage report
Current view: top level - asiolink - io_socket.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 11 11 100.0 %
Date: 2012-05-15 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 12 66.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #include "io_socket.h"
      16                 :            : 
      17                 :            : #include <asio.hpp>
      18                 :            : 
      19                 :            : namespace isc {
      20                 :            : namespace asiolink {
      21                 :            : 
      22                 :            : /// \brief The \c DummySocket class is a concrete derived class of
      23                 :            : /// \c IOSocket that is not associated with any real socket.
      24                 :            : ///
      25                 :            : /// This main purpose of this class is tests, where it may be desirable to
      26                 :            : /// instantiate an \c IOSocket object without involving system resource
      27                 :            : /// allocation such as real network sockets.
      28                 :         12 : class DummySocket : public IOSocket {
      29                 :            : private:
      30                 :            :     DummySocket(const DummySocket& source);
      31                 :            :     DummySocket& operator=(const DummySocket& source);
      32                 :            : public:
      33                 :            :     /// \brief Constructor from the protocol number.
      34                 :            :     ///
      35                 :            :     /// The protocol must validly identify a standard network protocol.
      36                 :            :     /// For example, to specify TCP \c protocol must be \c IPPROTO_TCP.
      37                 :            :     ///
      38                 :            :     /// \param protocol The network protocol number for the socket.
      39                 :         24 :     DummySocket(const int protocol) : protocol_(protocol) {}
      40                 :            : 
      41                 :            :     /// \brief A dummy derived method of \c IOSocket::getNative().
      42                 :            :     ///
      43                 :            :     /// This version of method always returns -1 as the object is not
      44                 :            :     /// associated with a real (native) socket.
      45                 :         11 :     virtual int getNative() const { return (-1); }
      46                 :            : 
      47                 :         73 :     virtual int getProtocol() const { return (protocol_); }
      48                 :            : private:
      49                 :            :     const int protocol_;
      50                 :            : };
      51                 :            : 
      52                 :            : IOSocket&
      53                 :        136 : IOSocket::getDummyUDPSocket() {
      54 [ +  + ][ +  - ]:        136 :     static DummySocket socket(IPPROTO_UDP);
      55                 :        136 :     return (socket);
      56                 :            : }
      57                 :            : 
      58                 :            : IOSocket&
      59                 :         28 : IOSocket::getDummyTCPSocket() {
      60 [ +  + ][ +  - ]:         28 :     static DummySocket socket(IPPROTO_TCP);
      61                 :         28 :     return (socket);
      62                 :            : }
      63                 :            : 
      64                 :            : } // namespace asiolink
      65 [ +  - ][ +  - ]:         30 : } // namespace isc

Generated by: LCOV version 1.9