Protocols::BitTorrent::Transfers::Testing::PacketSessionTest Class Reference

Inherits TestFixture.

Inheritance diagram for Protocols::BitTorrent::Transfers::Testing::PacketSessionTest:

Inheritance graph
[legend]
Collaboration diagram for Protocols::BitTorrent::Transfers::Testing::PacketSessionTest:

Collaboration graph
[legend]
List of all members.

Detailed Description

Test for PacketSession.

PacketSession is an aggregate that combines a number of components without implementing new functionality itself. We use a combination of mocks and stubs to perform the tests. We mock the required interface SessionStatus and we stub the Transport interface because we do not care in with exactly what sequence of read, peek and write operations are called. Instead we are only interested in the state of the read and write buffers after packets have been read or written.

Most of the functionality of PacketSession has already been tested by the tests of GenericSession. Now we only need to once again test functionality that is spread over more than one of the components we are integrating.

Here we have the packet reading/writing funtionality that is spread this way. We want to make sure that PacketSession does read and write the type of packets (BitTorrent packets and not Gnutella packets) that it is supposed to. We run just a few test to make sure that the simple cases of reading/writing one and two packets with/without buffering work and we assume that the more complex will work too.

We also want to verify that the correct DataQueue is aggregated - FifoQueue in our case, so buffered packets should be written in the order in which they were buffered.

The TransportStatus notifications connected() and disconnected() and handled solely by GenericSession, so there are no potential integration problems.

Definition at line 62 of file PacketSessionTest.cpp.

Public Member Functions

 PacketSessionTest ()
 Default constructor.
void setUp ()
void tearDown ()
void stateOpenedSession ()
 Drive session to the state OpenedSession.
void testReadNothing ()
 When not bytes are buffered in Transport, nothing can be read.
void testReadOnePacket ()
 When exactly one packet is buffered in Transport, it should be read.
void testReadTwoPackets ()
 When exactly two packets are buffered in Transport, both should be read.
void testReadOnePacketAndHalfPacketStillBuffered ()
 When one and a half packet are buffered in Transport, only one is read.
void testSendPacketWritesPacketDirectly ()
 Sending a packet results in writing it directly to Transport.
void testSendTwoPacketsBuffersThem ()
 When no bytes can be written to Transport, the packets will be buffered.
void testSendTwoPacketsBuffersThemThenWritesThem ()
 Buffered packets will be written when Transport's write buffer is free.

Private Member Functions

 PacketSessionTest (const PacketSessionTest &)
PacketSessionTestoperator= (const PacketSessionTest &)
 CPPUNIT_TEST_SUITE (PacketSessionTest)
 CPPUNIT_TEST (testReadNothing)
 CPPUNIT_TEST (testReadOnePacket)
 CPPUNIT_TEST (testReadTwoPackets)
 CPPUNIT_TEST (testReadOnePacketAndHalfPacketStillBuffered)
 CPPUNIT_TEST (testSendPacketWritesPacketDirectly)
 CPPUNIT_TEST (testSendTwoPacketsBuffersThem)
 CPPUNIT_TEST (testSendTwoPacketsBuffersThemThenWritesThem)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

TransportStub * transport
auto_ptr< SessionStatusMock > status
auto_ptr< PacketSessionsessionReal
auto_ptr< PacketSessionDriver > session
const Packet packet1
const Packet packet2
const QByteArray halfPacketBytes


Constructor & Destructor Documentation

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::PacketSessionTest const PacketSessionTest  )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::PacketSessionTest  )  [inline]
 

Default constructor.

Definition at line 88 of file PacketSessionTest.cpp.


Member Function Documentation

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testSendTwoPacketsBuffersThemThenWritesThem   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testSendTwoPacketsBuffersThem   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testSendPacketWritesPacketDirectly   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testReadOnePacketAndHalfPacketStillBuffered   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testReadTwoPackets   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testReadOnePacket   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST testReadNothing   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST_SUITE PacketSessionTest   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::CPPUNIT_TEST_SUITE_END  )  [private]
 

PacketSessionTest& Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::operator= const PacketSessionTest  )  [private]
 

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::setUp  )  [inline]
 

Definition at line 94 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::stateOpenedSession  )  [inline]
 

Drive session to the state OpenedSession.

Definition at line 112 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::tearDown  )  [inline]
 

Definition at line 103 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testReadNothing  )  [inline]
 

When not bytes are buffered in Transport, nothing can be read.

Definition at line 119 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testReadOnePacket  )  [inline]
 

When exactly one packet is buffered in Transport, it should be read.

Definition at line 128 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testReadOnePacketAndHalfPacketStillBuffered  )  [inline]
 

When one and a half packet are buffered in Transport, only one is read.

Definition at line 161 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testReadTwoPackets  )  [inline]
 

When exactly two packets are buffered in Transport, both should be read.

Definition at line 144 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testSendPacketWritesPacketDirectly  )  [inline]
 

Sending a packet results in writing it directly to Transport.

Definition at line 176 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testSendTwoPacketsBuffersThem  )  [inline]
 

When no bytes can be written to Transport, the packets will be buffered.

Definition at line 191 of file PacketSessionTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::testSendTwoPacketsBuffersThemThenWritesThem  )  [inline]
 

Buffered packets will be written when Transport's write buffer is free.

Definition at line 210 of file PacketSessionTest.cpp.


Member Data Documentation

const QByteArray Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::halfPacketBytes [private]
 

Definition at line 84 of file PacketSessionTest.cpp.

const Packet Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::packet1 [private]
 

Definition at line 82 of file PacketSessionTest.cpp.

const Packet Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::packet2 [private]
 

Definition at line 83 of file PacketSessionTest.cpp.

auto_ptr<PacketSessionDriver> Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::session [private]
 

Definition at line 80 of file PacketSessionTest.cpp.

auto_ptr<PacketSession> Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::sessionReal [private]
 

Definition at line 79 of file PacketSessionTest.cpp.

auto_ptr<SessionStatusMock> Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::status [private]
 

Definition at line 78 of file PacketSessionTest.cpp.

TransportStub* Protocols::BitTorrent::Transfers::Testing::PacketSessionTest::transport [private]
 

Definition at line 77 of file PacketSessionTest.cpp.


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