Protocols::Generics::Testing::PacketStub Class Reference

#include <PacketStub.h> [code]

Inherits Protocols::Generics::PacketBase.

Inheritance diagram for Protocols::Generics::Testing::PacketStub:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

A stub class for the class Packet.

R1 A simple concrete Packet class is useful for unit tests.

U1.1 A concrete Packet object is needed to test the functionality implemented in the abstract base class.

U1.2 A concrete Packet object is needed as part of the controlled environment when unit testing another class.

Implements a very simple concrete packet. Header, payload and trailer are interpreted simply as raw byte buffers (QByteArray). You can use an object of this class for unit tests where a pointer/reference to Packet is required. If you use PacketStub together with PacketDriver you will have more control on the state and behavior of the PacketStub object.

In the ctor there is a special option (the last argument checkReadBytes), which controls the behavior of readHeader(), readPayload() and readTrailer(). Take a look at PacketStub::PacketStub() for more info.

Definition at line 53 of file PacketStub.h.

Public Member Functions

 PacketStub (const QByteArray &header=QByteArray(), const QByteArray &payload=QByteArray(), bool checkReadBytes=false)
 Constructs a PacketStub object.
QString name () const
 Returns the name of the PacketBase type the dynamic object belongs to.
QString protocol () const
 Returns the name of the protocol this PacketBase belongs to.
auto_ptr< DataBasecopy () const
 Virtual copy constructor.
bool readHeader (const QByteArray &)
bool readPayload (const QByteArray &)
QByteArray writeHeader () const
QByteArray writePayload () const
QByteArray header () const
QByteArray payload () const
QByteArray rawPacket () const
 Returns rawHeader() + rawPayload().

Protected Member Functions

 Q_DECLARE_SHARED_DATA (Data)

Classes

class  Data


Constructor & Destructor Documentation

PacketStub::PacketStub const QByteArray &  header = QByteArray(),
const QByteArray &  payload = QByteArray(),
bool  checkReadBytes = false
 

Constructs a PacketStub object.

The last argument checkReadBytes controls the behavior of readHeader() and readPayload(). If checkReadBytes is true, then the raw byte passed as arguments to readHeader() and readPayload() will be compared with header and payload respectively and the result of the comparison will be returned (i.e. true if equal, false if different).

The write functions writeHeader() and writePayload() will return respectively the values of header and payload.

Definition at line 39 of file PacketStub.cpp.


Member Function Documentation

auto_ptr< DataBase > PacketStub::copy  )  const [virtual]
 

Virtual copy constructor.

Implements Protocols::Generics::PacketBase.

Definition at line 60 of file PacketStub.cpp.

QByteArray Protocols::Generics::Testing::PacketStub::header  )  const [inline]
 

Definition at line 91 of file PacketStub.h.

QString PacketStub::name  )  const [virtual]
 

Returns the name of the PacketBase type the dynamic object belongs to.

Todo:
Better use PacketId (which possibly contains the ProtocolId)?

Implements Protocols::Generics::PacketBase.

Definition at line 50 of file PacketStub.cpp.

QByteArray Protocols::Generics::Testing::PacketStub::payload  )  const [inline]
 

Definition at line 94 of file PacketStub.h.

QString PacketStub::protocol  )  const [virtual]
 

Returns the name of the protocol this PacketBase belongs to.

Todo:
Better use ProtocolId?

Implements Protocols::Generics::PacketBase.

Definition at line 55 of file PacketStub.cpp.

Protocols::Generics::Testing::PacketStub::Q_DECLARE_SHARED_DATA Data   )  [protected]
 

QByteArray Protocols::Generics::Testing::PacketStub::rawPacket  )  const [inline]
 

Returns rawHeader() + rawPayload().

Reimplemented from Protocols::Generics::PacketBase.

Definition at line 97 of file PacketStub.h.

bool PacketStub::readHeader const QByteArray &  rawHeader  )  [virtual]
 

If checkReadBytes was set to true in the ctor, then the function returns true only if rawHeader is equal header(). If checkReadBytes was set to false, then header() will be set to rawHeader and true will be returned.

Implements Protocols::Generics::PacketBase.

Definition at line 70 of file PacketStub.cpp.

bool PacketStub::readPayload const QByteArray &  rawPayload  )  [virtual]
 

If checkReadBytes was set to true in the ctor, then the function returns true only if rawPayload is equal payload(). If checkReadBytes was set to false, then payload() will be set to rawPayload and true will be returned.

Implements Protocols::Generics::PacketBase.

Definition at line 85 of file PacketStub.cpp.

QByteArray PacketStub::writeHeader  )  const [virtual]
 

Implements Protocols::Generics::PacketBase.

Definition at line 94 of file PacketStub.cpp.

QByteArray PacketStub::writePayload  )  const [virtual]
 

Implements Protocols::Generics::PacketBase.

Definition at line 100 of file PacketStub.cpp.


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