CTestTransport

Name

CTestTransport -- Transport class for test purposes.

Synopsis


#include <CTestTransport.h>

class CTestTransport : public CTransport
{
public:
    typedef std::vector<uint8_t> message;
    typedef std::deque<message> messageList;
    
public:
    typedef std::vector<message> multipartMessage;
    std::vector<multipartMessage>  m_sentMessages;
    messageList m_messages;

public:
    
    virtual void recv(void** ppData, size_t& size);
    virtual  void    send(iovec* parts, size_t numParts);
    
    void addMessage(void* pData, size_t nBytes);
};
        

DESCRIPTION

This class provides a transport that can be used for unit testing. Data that have been sent are retained for examination. Data can be put into the object for later receipt via recv calls. In this way a known load of inbound message can be injected into users of the transport and messages resulting from processing can be pulled out to ensure they are as expected.

METHODS

See CTransport(3daq) for a description of the send and recv methods.

The added method for this class is: void addMessage(void* pData, size_t nBytes);

This method adds the described message to a queue of messages that will be retrieved by recv calls.

TYPES and PUBLIC DATA

The following data types are public:

message

This represents a message or a message part in the case of a multipart message. It's defined to be an std::vector<uint8_t>. The elements of the vector are the ordered bytes of the message itself.

multipartMessage

This type represents a sent message which can have more than one part. It's defined as a std::vector<message>.

messageList

This is a list of simple messages. It's used to represent the messages that will be received by recv and gets loaded by addMessagse. It is of type std::deque<message>.

std::vector<multiPartMessage>

This type is used to represent messages that have been sent.

For testing purposes you may need to see the set of messages remaining for consumption via recv and the messages that have been sent via send.

m_sendMessages is of type std::vector<multipartMessage> are the messages sent by send calls. Each element of the outer vector is a message. Each element of the inner vector is a message part (the contents of an element described by an iovec element).

m_messages is of type messageList and represents the list of messages that have not yet been consumed by recv. addMessage adds new messages to the back of the deque while recv gets the message at the front of the deque. If there are no remaining messages when recv is called, an empty message is returned.