Protocols::Generics::Testing::TransportStub Class Reference

#include <TransportStub.h> [code]

Inherits Protocols::Generics::Transport.

Inheritance diagram for Protocols::Generics::Testing::TransportStub:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

Stub for interface Transport.

This class can be used to perform state-based test verification. You can set and get the stub's state by accessing the public member variables readBuffer and writeBuffer. All read functions will read bytes from the start of readBuffer and will then purge the read bytes. All peek functions will only read the start of the readBuffer without purging anything from it. The write function will append the write bytes to the beginning of writeBuffer. You should call writeBuffer.reserve(count) to set the maximum size of the write buffer, so that canWrite() functions correctly.

Todo:
It may be interesting to record also calls to connectToNode(), disconnectFromNode() and abort() so that we could check whether they were indeed called afterwards. Another option would be to come up with a combination of a mock and a stub.
Todo:
Write tests for the stub?

Definition at line 51 of file TransportStub.h.

Public Member Functions

 TransportStub ()
 Default constructor.
void connectToNode (const Uri &)
 Tries to establish a connection to node.
void disconnectFromNode ()
 Disconnects from the remote node.
void abort ()
 Aborts the connection with the remote node.
bool canRead (int count) const
QByteArray peek (int count) const
QByteArray peekAtMost (int count) const
QByteArray peekTo (const QByteArray &delimiter) const
QByteArray peekAll () const
QByteArray read (int count)
QByteArray readAtMost (int count)
QByteArray readTo (const QByteArray &delimiter)
QByteArray readAll ()
bool canWrite (int count) const
bool write (const QByteArray &bytes, bool flush)
void setTransportStatus (TransportStatus *)
 operator Transport * ()

Public Attributes

QByteArray readBuffer
QByteArray writeBuffer
TransportStatusstatus


Constructor & Destructor Documentation

TransportStub::TransportStub  ) 
 

Default constructor.

Definition at line 28 of file TransportStub.cpp.


Member Function Documentation

void TransportStub::abort  )  [virtual]
 

Aborts the connection with the remote node.

Implements Protocols::Generics::Connection.

Definition at line 44 of file TransportStub.cpp.

bool TransportStub::canRead int  count  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 48 of file TransportStub.cpp.

bool TransportStub::canWrite int  count  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 107 of file TransportStub.cpp.

void TransportStub::connectToNode const Uri  )  [virtual]
 

Tries to establish a connection to node.

Implements Protocols::Generics::Connection.

Definition at line 34 of file TransportStub.cpp.

void TransportStub::disconnectFromNode  )  [virtual]
 

Disconnects from the remote node.

Implements Protocols::Generics::Connection.

Definition at line 39 of file TransportStub.cpp.

TransportStub::operator Transport *  ) 
 

Definition at line 133 of file TransportStub.cpp.

QByteArray TransportStub::peek int  count  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 53 of file TransportStub.cpp.

QByteArray TransportStub::peekAll  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 73 of file TransportStub.cpp.

QByteArray TransportStub::peekAtMost int  count  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 59 of file TransportStub.cpp.

QByteArray TransportStub::peekTo const QByteArray &  delimiter  )  const [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 66 of file TransportStub.cpp.

QByteArray TransportStub::read int  count  )  [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 79 of file TransportStub.cpp.

QByteArray TransportStub::readAll  )  [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 100 of file TransportStub.cpp.

QByteArray TransportStub::readAtMost int  count  )  [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 86 of file TransportStub.cpp.

QByteArray TransportStub::readTo const QByteArray &  delimiter  )  [virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 93 of file TransportStub.cpp.

void TransportStub::setTransportStatus TransportStatus  )  [virtual]
 

Implements Protocols::Generics::Transport.

Definition at line 128 of file TransportStub.cpp.

bool TransportStub::write const QByteArray &  bytes,
bool  flush
[virtual]
 

Implements Protocols::Generics::Buffer.

Definition at line 112 of file TransportStub.cpp.


Member Data Documentation

QByteArray Protocols::Generics::Testing::TransportStub::readBuffer
 

Definition at line 88 of file TransportStub.h.

TransportStatus* Protocols::Generics::Testing::TransportStub::status
 

Definition at line 90 of file TransportStub.h.

QByteArray Protocols::Generics::Testing::TransportStub::writeBuffer
 

Definition at line 89 of file TransportStub.h.


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