Protocols::Generics::Testing::SocketTransportTest Class Reference

Inherits TestFixture.

Inheritance diagram for Protocols::Generics::Testing::SocketTransportTest:

Inheritance graph
[legend]
Collaboration diagram for Protocols::Generics::Testing::SocketTransportTest:

Collaboration graph
[legend]
List of all members.

Detailed Description

Tests for SocketTransport implementation of the interface Transport.

Definition at line 38 of file SocketTransportTest.cpp.

Public Member Functions

 SocketTransportTest ()
void setUp ()
void tearDown ()
void stateDisconnected ()
void testStartConnecting ()
 Initiate a connection attempt (competes asynchronously).
void stateConnecting ()
void testConnectionEstablished ()
 A connection attempt succeeds.
void stateConnected ()
void testConnectionRejected ()
 The remote node rejects the incoming connection or attempt fails.
void testAbortConnectionAttempt ()
 We abort a connection attempt before it has either succeeded or failed.
void refStartDisconnecting ()
void testStartDisconnecting ()
 Initiate a disconnection (completes asynchronously).
void stateDisconnecting ()
void testDisconnectingCompletes ()
 A disconnection initiated with disconnectFromNode() completes.
void testAbortWhileDisconnecting ()
 Calling abort() while still disconnecting disconnects immediately.
void testConnectionDisconnectedBySocket ()
 A disconnected socket results in a disconnected transport.
void testAbortDueToSocketError ()
 Verify that socket is aborted upon a socket error.
void testSocketConnectedTwice ()
 Test correct behavior in case socketConnected() is called twice.
void testSocketDisconnectedTwice ()
 Test correct behavior in case socketDisconnected() is called twice.
void testSocketErrorTwice ()
 Test correct behavior in case socketError() is called twice.
void testSocketErrorSocketDisconnected ()
 QAbstractSocket emits error() and disconnected() in sequence.
void testSocketDisconnectedSocketError ()
 Test correct behavior in socketDisconnected(), socketError() sequence.
void refWriteBytes (const QByteArray &bytes, bool flush, bool succeeds)
 Helper that verfies the expectations of transport->write().
void testWriteDelegatesToSocketBufferAndTriesToWriteToSocket ()
 Verify that write() just delegates the call to buffer.
void refReadsDelegateToBuffer ()
void testReadsDelegateToSocketBufferThenTriesToReadMoreFromSocket ()
 Verify that all read functions just delegate the call to buffer.
void refPeedsDelegateToSocketBuffer ()
void testPeeksDelegateToSocketBuffer ()
 Verify that all peek functions just delegate the call to buffer.
void refCanReadDelegatesToBuffer (int count, bool canRead)
void refCanWriteDelegatesToBuffer (int count, bool canWrite)
void testCanReadCanWriteDelegateToSocketBuffer ()
 Should delegate canRead() and canWrite() to the SocketBuffer object.
void testSocketReadMakesBufferToReadFromSocketAndEmitsReadyRead ()
 Socket can read bytes, have the buffer read them and send readyRead().
void testSocketWrittenMakesBufferToWriteToSocketAndEmitsReadyWrite ()
 Socket can write bytes, flush the buffer and send readyWrite().
void testSocketWrittenReadyWriteNotCalledRecursively ()
 readyWrite() must not be called recursively even if socketWritten() is.
void testReadyWriteNotCalledFromWrite ()
 readyWrite() must not be called from withing a write() call.
void testSocketWrittenDoesNotCallTryWriteToRecursively ()
 socketWritten() might be called recursively, second call should return.
void testSocketReadReadyReadNofCalledRecursively ()
 readRead() must never be called recursovely.
void testReadyReadNotCalledFromRead ()
 readyRead() must not be send from read().
void testSocketReadDoesNotCallTryReadFromRecursively ()
 socketRead() might be called recursively, second call should return.

Private Member Functions

 CPPUNIT_TEST_SUITE (SocketTransportTest)
 CPPUNIT_TEST (testStartConnecting)
 CPPUNIT_TEST (testConnectionEstablished)
 CPPUNIT_TEST (testConnectionRejected)
 CPPUNIT_TEST (testAbortConnectionAttempt)
 CPPUNIT_TEST (testStartDisconnecting)
 CPPUNIT_TEST (testDisconnectingCompletes)
 CPPUNIT_TEST (testAbortWhileDisconnecting)
 CPPUNIT_TEST (testConnectionDisconnectedBySocket)
 CPPUNIT_TEST (testAbortDueToSocketError)
 CPPUNIT_TEST (testSocketConnectedTwice)
 CPPUNIT_TEST (testSocketDisconnectedTwice)
 CPPUNIT_TEST (testSocketErrorTwice)
 CPPUNIT_TEST (testSocketErrorSocketDisconnected)
 CPPUNIT_TEST (testSocketDisconnectedSocketError)
 CPPUNIT_TEST (testWriteDelegatesToSocketBufferAndTriesToWriteToSocket)
 CPPUNIT_TEST (testReadsDelegateToSocketBufferThenTriesToReadMoreFromSocket)
 CPPUNIT_TEST (testPeeksDelegateToSocketBuffer)
 CPPUNIT_TEST (testCanReadCanWriteDelegateToSocketBuffer)
 CPPUNIT_TEST (testSocketReadMakesBufferToReadFromSocketAndEmitsReadyRead)
 CPPUNIT_TEST (testSocketWrittenMakesBufferToWriteToSocketAndEmitsReadyWrite)
 CPPUNIT_TEST (testSocketWrittenReadyWriteNotCalledRecursively)
 CPPUNIT_TEST (testReadyWriteNotCalledFromWrite)
 CPPUNIT_TEST (testSocketWrittenDoesNotCallTryWriteToRecursively)
 CPPUNIT_TEST (testSocketReadReadyReadNofCalledRecursively)
 CPPUNIT_TEST (testReadyReadNotCalledFromRead)
 CPPUNIT_TEST (testSocketReadDoesNotCallTryReadFromRecursively)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

auto_ptr< SocketMock > socket
auto_ptr< SocketBufferMock > buffer
auto_ptr< TransportStatusMock > status
auto_ptr< SocketTransporttransport_real
auto_ptr< SocketTransportDriver > transport


Constructor & Destructor Documentation

Protocols::Generics::Testing::SocketTransportTest::SocketTransportTest  )  [inline]
 

Definition at line 76 of file SocketTransportTest.cpp.


Member Function Documentation

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketReadDoesNotCallTryReadFromRecursively   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testReadyReadNotCalledFromRead   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketReadReadyReadNofCalledRecursively   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketWrittenDoesNotCallTryWriteToRecursively   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testReadyWriteNotCalledFromWrite   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketWrittenReadyWriteNotCalledRecursively   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketWrittenMakesBufferToWriteToSocketAndEmitsReadyWrite   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketReadMakesBufferToReadFromSocketAndEmitsReadyRead   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testCanReadCanWriteDelegateToSocketBuffer   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testPeeksDelegateToSocketBuffer   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testReadsDelegateToSocketBufferThenTriesToReadMoreFromSocket   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testWriteDelegatesToSocketBufferAndTriesToWriteToSocket   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketDisconnectedSocketError   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketErrorSocketDisconnected   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketErrorTwice   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketDisconnectedTwice   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testSocketConnectedTwice   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testAbortDueToSocketError   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testConnectionDisconnectedBySocket   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testAbortWhileDisconnecting   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testDisconnectingCompletes   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testStartDisconnecting   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testAbortConnectionAttempt   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testConnectionRejected   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testConnectionEstablished   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST testStartConnecting   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST_SUITE SocketTransportTest   )  [private]
 

Protocols::Generics::Testing::SocketTransportTest::CPPUNIT_TEST_SUITE_END  )  [private]
 

void Protocols::Generics::Testing::SocketTransportTest::refCanReadDelegatesToBuffer int  count,
bool  canRead
[inline]
 

Definition at line 414 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::refCanWriteDelegatesToBuffer int  count,
bool  canWrite
[inline]
 

Definition at line 422 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::refPeedsDelegateToSocketBuffer  )  [inline]
 

Definition at line 377 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::refReadsDelegateToBuffer  )  [inline]
 

Definition at line 328 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::refStartDisconnecting  )  [inline]
 

Definition at line 178 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::refWriteBytes const QByteArray &  bytes,
bool  flush,
bool  succeeds
[inline]
 

Helper that verfies the expectations of transport->write().

It is important that buffer->tryWriteTo() is called to make sure that any data already buffered can be passed to the OS. It could have happened that a socketWritten() notification was received but the write buffer was empty so we had nothing to write. In this case we should retry right after some new data has been written to the write buffer.

Definition at line 303 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::setUp  )  [inline]
 

Definition at line 81 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::stateConnected  )  [inline]
 

Definition at line 135 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::stateConnecting  )  [inline]
 

Definition at line 119 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::stateDisconnected  )  [inline]
 

This one just uses the normal setUp(), the idea is to have functions representing a state invariant.

Definition at line 103 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::stateDisconnecting  )  [inline]
 

Definition at line 193 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::tearDown  )  [inline]
 

Definition at line 90 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testAbortConnectionAttempt  )  [inline]
 

We abort a connection attempt before it has either succeeded or failed.

Todo:
check the todo in SocketTransport::abort()

Definition at line 164 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testAbortDueToSocketError  )  [inline]
 

Verify that socket is aborted upon a socket error.

Definition at line 236 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testAbortWhileDisconnecting  )  [inline]
 

Calling abort() while still disconnecting disconnects immediately.

Definition at line 210 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testCanReadCanWriteDelegateToSocketBuffer  )  [inline]
 

Should delegate canRead() and canWrite() to the SocketBuffer object.

While in "disconnecting" state we are allowed to try to read bytes but we are not allowed to try to write bytes.

Definition at line 435 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testConnectionDisconnectedBySocket  )  [inline]
 

A disconnected socket results in a disconnected transport.

Definition at line 225 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testConnectionEstablished  )  [inline]
 

A connection attempt succeeds.

Definition at line 125 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testConnectionRejected  )  [inline]
 

The remote node rejects the incoming connection or attempt fails.

We simulate a socket error by directly invoking the socketError() slot of TcpTransport. We assume that QTcpConnection behaves the same way in simulation.

Definition at line 146 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testDisconnectingCompletes  )  [inline]
 

A disconnection initiated with disconnectFromNode() completes.

Definition at line 199 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testPeeksDelegateToSocketBuffer  )  [inline]
 

Verify that all peek functions just delegate the call to buffer.

Just test all different read variants once.

Peeking data should be possible even while in "disconnecting" state.

Definition at line 406 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testReadsDelegateToSocketBufferThenTriesToReadMoreFromSocket  )  [inline]
 

Verify that all read functions just delegate the call to buffer.

Just test all different read variants once.

It is important that buffer->tryReadFrom() is called to make sure that any data already buffered by the OS could be read. It could have happened that a socketRead() notification was received but the read buffer was full so we could read nothing. In this case we should retry right after some space in the read buffer is available.

Definition at line 369 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testReadyReadNotCalledFromRead  )  [inline]
 

readyRead() must not be send from read().

If readyRead() is called from withing read(), the result could be a recursive call of read() from the client code and we do not want that.

Definition at line 572 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testReadyWriteNotCalledFromWrite  )  [inline]
 

readyWrite() must not be called from withing a write() call.

Because write() will try to write the bytes to the socket, the socket might call socketWritten(), which should not try to write to the socket again.

Definition at line 509 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketConnectedTwice  )  [inline]
 

Test correct behavior in case socketConnected() is called twice.

Definition at line 251 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketDisconnectedSocketError  )  [inline]
 

Test correct behavior in socketDisconnected(), socketError() sequence.

Definition at line 287 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketDisconnectedTwice  )  [inline]
 

Test correct behavior in case socketDisconnected() is called twice.

Definition at line 260 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketErrorSocketDisconnected  )  [inline]
 

QAbstractSocket emits error() and disconnected() in sequence.

Definition at line 278 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketErrorTwice  )  [inline]
 

Test correct behavior in case socketError() is called twice.

Definition at line 269 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketReadDoesNotCallTryReadFromRecursively  )  [inline]
 

socketRead() might be called recursively, second call should return.

Definition at line 585 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketReadMakesBufferToReadFromSocketAndEmitsReadyRead  )  [inline]
 

Socket can read bytes, have the buffer read them and send readyRead().

Definition at line 452 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketReadReadyReadNofCalledRecursively  )  [inline]
 

readRead() must never be called recursovely.

The client code could read() in response to readyRead(), which would trigger a call to tryReadFrom() which might emit socketRead() again. The second time sockerRead() is entered it should return right away.

Note:
We only test read() but code was checked and there are comments saying that all read variants should have analogical implementation!

Definition at line 547 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketWrittenDoesNotCallTryWriteToRecursively  )  [inline]
 

socketWritten() might be called recursively, second call should return.

Definition at line 524 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketWrittenMakesBufferToWriteToSocketAndEmitsReadyWrite  )  [inline]
 

Socket can write bytes, flush the buffer and send readyWrite().

Definition at line 465 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testSocketWrittenReadyWriteNotCalledRecursively  )  [inline]
 

readyWrite() must not be called recursively even if socketWritten() is.

socketWritten() emits readyWrite(), from which the client code could call write() to srite bytes to socket, which might send socketWritten() again. We should handle the case to avoid recursion.

Definition at line 483 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testStartConnecting  )  [inline]
 

Initiate a connection attempt (competes asynchronously).

Definition at line 108 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testStartDisconnecting  )  [inline]
 

Initiate a disconnection (completes asynchronously).

Definition at line 187 of file SocketTransportTest.cpp.

void Protocols::Generics::Testing::SocketTransportTest::testWriteDelegatesToSocketBufferAndTriesToWriteToSocket  )  [inline]
 

Verify that write() just delegates the call to buffer.

Just try the different permutations of the parameters to make sure all parameters are simply passed through.

Definition at line 318 of file SocketTransportTest.cpp.


Member Data Documentation

auto_ptr<SocketBufferMock> Protocols::Generics::Testing::SocketTransportTest::buffer [private]
 

Definition at line 70 of file SocketTransportTest.cpp.

auto_ptr<SocketMock> Protocols::Generics::Testing::SocketTransportTest::socket [private]
 

Definition at line 69 of file SocketTransportTest.cpp.

auto_ptr<TransportStatusMock> Protocols::Generics::Testing::SocketTransportTest::status [private]
 

Definition at line 71 of file SocketTransportTest.cpp.

auto_ptr<SocketTransportDriver> Protocols::Generics::Testing::SocketTransportTest::transport [private]
 

Definition at line 73 of file SocketTransportTest.cpp.

auto_ptr<SocketTransport> Protocols::Generics::Testing::SocketTransportTest::transport_real [private]
 

Definition at line 72 of file SocketTransportTest.cpp.


The documentation for this class was generated from the following file: