Protocols::Generics::Testing::PacketTest Class Reference

Inherits TestFixture.

Inheritance diagram for Protocols::Generics::Testing::PacketTest:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

Blackbox and whitebox tests for class PacketBase.

Using PacketStub, a very light wieght concrete PacketBase, we test the abstract class PacketBase.

Blackbox tests:

Whitebox tests:

The derived classes are recommended to implement scenarios similar to:

    void scenarioReadPacket()
    {
        refParsePacket();
        refReadHeaderFields();
        refReadPayloadFields();
    }
    void scenarioWritePacket()
    {
        refSetHeaderFields();
        refSetPayloadFields();
        refWritePacket();
    }

scenarioReadPacket() would parse the packet and would then verify that all fields have been read correctly, whereas scenarioWritePacket() would set all the fields and then verify they are written correctly.

All derived classes are advised to write a single test to verify that a default constructed object is correctly initialized (i.e. all fields get the correct default values). Changing the default values would brake the test and that could be a sign that client code has also been broken.

Definition at line 86 of file PacketBaseTest.cpp.

Public Member Functions

void testReadPacket ()
 Test that header and payload fields are correctly parsed.
void testWritePacket ()
 Verify that header, payload and trailer fields are correctly written.
void testReferenceCountIncreaseCopyPacket ()
 Verify that copying a packet results in impicit sharing of private data.
void testReferenceCountIncreaseAssignPacket ()
 Assigning a packet to another should result in sharing of private data.
void testReferenceCountDecreaseAssignPacket ()
 When assigning a packet, the ref count of its old data is decreased.
void testReferenceCountDecreaseDestroyPacket ()
 Destroying a packet would decrease the ref count of the shared data.
void testReferenceCountDecreaseModifyPacketCopyPrivateData ()
 Calling non-const functions result in copying the private data.
void testCtorNoRawDataCached ()
 Verify that the ctor does not cache any raw bytes.
void testParseRawDataCached ()
 Verify that parse() caches the raw bytes passed to it.
void testInvalidateHeader ()
 Verifies that invalidateHeader() invalidates the cached raw header.
void testInvalidatePayload ()
 Verifies that invalidatePayload() invalidates the cached raw payload.
void testRawHeaderUsingCachedHeader ()
 Verifies that the cached header bytes are returned when available.
void testRawHeaderRebuildingAndCachingHeader ()
 Verifies that the raw header bytes are correctly cached.
void testRawPayloadUsingCachedPayload ()
 Verifies that the cached raw payload bytes are returned when available.
void testRawPayloadRebuildingAndCachingPayload ()
 Verifies that the raw payload bytes are correctly cached.
void testRebuildPacketNotModifyingReferenceCount ()

Private Member Functions

 CPPUNIT_TEST_SUITE (PacketTest)
 CPPUNIT_TEST (testReadPacket)
 CPPUNIT_TEST (testWritePacket)
 CPPUNIT_TEST (testReferenceCountIncreaseCopyPacket)
 CPPUNIT_TEST (testReferenceCountIncreaseAssignPacket)
 CPPUNIT_TEST (testReferenceCountDecreaseAssignPacket)
 CPPUNIT_TEST (testReferenceCountDecreaseDestroyPacket)
 CPPUNIT_TEST (testReferenceCountDecreaseModifyPacketCopyPrivateData)
 CPPUNIT_TEST (testCtorNoRawDataCached)
 CPPUNIT_TEST (testParseRawDataCached)
 CPPUNIT_TEST (testInvalidateHeader)
 CPPUNIT_TEST (testInvalidatePayload)
 CPPUNIT_TEST (testRawHeaderUsingCachedHeader)
 CPPUNIT_TEST (testRawHeaderRebuildingAndCachingHeader)
 CPPUNIT_TEST (testRawPayloadUsingCachedPayload)
 CPPUNIT_TEST (testRawPayloadRebuildingAndCachingPayload)
 CPPUNIT_TEST (testRebuildPacketNotModifyingReferenceCount)
 CPPUNIT_TEST_SUITE_END ()


Member Function Documentation

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testRebuildPacketNotModifyingReferenceCount   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testRawPayloadRebuildingAndCachingPayload   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testRawPayloadUsingCachedPayload   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testRawHeaderRebuildingAndCachingHeader   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testRawHeaderUsingCachedHeader   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testInvalidatePayload   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testInvalidateHeader   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testParseRawDataCached   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testCtorNoRawDataCached   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReferenceCountDecreaseModifyPacketCopyPrivateData   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReferenceCountDecreaseDestroyPacket   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReferenceCountDecreaseAssignPacket   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReferenceCountIncreaseAssignPacket   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReferenceCountIncreaseCopyPacket   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testWritePacket   )  [private]
 

Protocols::Generics::Testing::PacketTest::CPPUNIT_TEST testReadPacket   )  [private]
 

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

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

void Protocols::Generics::Testing::PacketTest::testCtorNoRawDataCached  )  [inline]
 

Verify that the ctor does not cache any raw bytes.

Definition at line 206 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testInvalidateHeader  )  [inline]
 

Verifies that invalidateHeader() invalidates the cached raw header.

Definition at line 233 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testInvalidatePayload  )  [inline]
 

Verifies that invalidatePayload() invalidates the cached raw payload.

Definition at line 242 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testParseRawDataCached  )  [inline]
 

Verify that parse() caches the raw bytes passed to it.

Todo:
If we use a test driver we could also verify that the virtual functions writeHeader() and writePayload() are NOT called. Alternatively, we could set the fields, then unset the rewrite flags and verify that the cached bytes are returned.

Definition at line 220 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testRawHeaderRebuildingAndCachingHeader  )  [inline]
 

Verifies that the raw header bytes are correctly cached.

Definition at line 263 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testRawHeaderUsingCachedHeader  )  [inline]
 

Verifies that the cached header bytes are returned when available.

Definition at line 251 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testRawPayloadRebuildingAndCachingPayload  )  [inline]
 

Verifies that the raw payload bytes are correctly cached.

Definition at line 286 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testRawPayloadUsingCachedPayload  )  [inline]
 

Verifies that the cached raw payload bytes are returned when available.

Definition at line 274 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReadPacket  )  [inline]
 

Test that header and payload fields are correctly parsed.

Definition at line 109 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testRebuildPacketNotModifyingReferenceCount  )  [inline]
 

Packets sharing private data should only be rebuilt once. If there are multiple copies of a packet sharing the same private data, then the first packet that is forced to rebuild and cache its raw bytes representation would do so without detaching itself from the shared private data. In effect the other copies would be able to reuse the cached bytes!

Note:
If different copies are used in distinct threads it might happen that the raw bytes are rebuilt multiple times, however, that would not corrupt the shared state (Is that really true? Would there be a problem if e.g. d->rawHeader is returned by one thread while it is being assigned from another?). Keep in mind that the class Packet is not thread-safe by design.

Definition at line 310 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReferenceCountDecreaseAssignPacket  )  [inline]
 

When assigning a packet, the ref count of its old data is decreased.

Definition at line 162 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReferenceCountDecreaseDestroyPacket  )  [inline]
 

Destroying a packet would decrease the ref count of the shared data.

Definition at line 183 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReferenceCountDecreaseModifyPacketCopyPrivateData  )  [inline]
 

Calling non-const functions result in copying the private data.

Definition at line 194 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReferenceCountIncreaseAssignPacket  )  [inline]
 

Assigning a packet to another should result in sharing of private data.

Definition at line 148 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testReferenceCountIncreaseCopyPacket  )  [inline]
 

Verify that copying a packet results in impicit sharing of private data.

Definition at line 137 of file PacketBaseTest.cpp.

void Protocols::Generics::Testing::PacketTest::testWritePacket  )  [inline]
 

Verify that header, payload and trailer fields are correctly written.

Definition at line 129 of file PacketBaseTest.cpp.


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