Inheritance diagram for Protocols::Generics::Testing::TcpSocketBufferTest:


TcpSocketBuffer is implemented as a ring buffer. We want to make sure that all data read from the socket in the buffer (using tryReadSocket()) can be read by the user calling any of read(), readTo() and readAll(). Similarly, all data written by the user calling write() should be written to the socket (using tryWriteSocket).
We also want to test that the ring buffers do not overflow.
Definition at line 82 of file TcpSocketBufferTest.cpp.
Public Member Functions | |
| TcpSocketBufferTest () | |
| void | setUp () |
| void | tearDown () |
| void | refWriteBytesFails (const QByteArray &bytes, bool flush=true) |
| Writing bytes to buffer will fail because there is not enough space. | |
| void | refWriteBytesSucceeds (const QByteArray &bytes, bool flush=true) |
| Writing bytes will succeed as there is enough space in buffer. | |
| void | testWritingZeroBytesAlwaysSucceeds () |
| Writing zero bytes is correct and should always succeed. | |
| void | testWriteBufferSizeBytesAtOnce () |
| After filling the buffer at once and no more data could be written. | |
| void | testWriteBufferSizeBytesAtOnceTwoTimes () |
| We should be able to fill the buffer and purge it at least twice. | |
| void | testWriteBufferSizeBytesAtTwoWrites () |
| Fill the buffer in two writes, then no more data could be written. | |
| void | testWriteMoreThanBufferSize () |
| Trying to an empty buffer more bytes than can fit fails. | |
| void | refWriteToSocketAtOnce (const QByteArray &bytes) |
| Check that a single tryWriteTo() writes bytes to socket. | |
| void | refWriteToSocketAtOncePartially (const QByteArray &bytes, int countWritten) |
| A single tryWriteTo() should write countWritten bytes from bytes. | |
| void | refWriteToSocketAtTwoChunks (const QByteArray &bytes1, const QByteArray &bytes2) |
| A single tryWriteTo() should write bytes1 and bytes2 to socket. | |
| void | refWriteToSocketAtTwoChunksSecondPartially (const QByteArray &bytes1, const QByteArray &bytes2, int countWrittenBytes2) |
| void | testRingBufferRotate () |
| Some chunks may be stored/written in two parts. | |
| void | scenarioPartialWriteToSocketDoesNotLooseData (int countAll, int countWritten) |
| Only the part of the buffer that the socket accepted should be purged. | |
| void | testPartialWriteToSocket7of10 () |
| Only 7 bytes out of 10 should be purged. | |
| void | testPartialWriteToSocket0of10 () |
| No buffered data should be lost if tryWriteTo() returns 0. | |
| void | testPartialWriteToSocket_1of10 () |
| No buffered data should be lost if tryWriteTo() returns -1. | |
| void | scenarioPartialWriteToSocketWithRotationDoesNotLoseData (int offset, int count) |
| Test that no data is lost when tryToWrite() after the ring rotates. | |
| void | testPartialWriteToSocketWithRotate3ofLast5 () |
| Only 3 of the 5 bytes from the second chunk should be written. | |
| void | testPartialWriteToSocketWithRotate0ofLast5 () |
| No bytes (0) of the 5 bytes from the second chunk should be written. | |
| void | testPartialWriteToSocketWithRotate_1ofLast5 () |
| No bytes (-1) of the 5 bytes from the second chunk should be written. | |
| void | refReadBytesSucceeds (const QByteArray &bytes) |
| read() succeeds if bytes returned for a bytes.size() bytes request. | |
| void | refReadBytesFails (int count) |
| read() fails if count bytes requested but an empty buffer returned. | |
| void | refTryReadFromAtOnce (const QByteArray &bytes) |
| tryReadFrom() produces one socket read operation. | |
| void | refTryReadFromAtTwoReads (const QByteArray &bytes1, const QByteArray &bytes2) |
| tryReadFrom() produces two socket read operations. | |
| void | testTryReadFromFillsBuffer () |
| tryReadFrom() fills our internal read buffer. | |
| void | testTryReadFromReadsNothing () |
| tryReadFrom() reads nothing. | |
| void | testReadingZeroBytesAlwaysSucceeds () |
| If should always be possible to read zero bytes. | |
| void | scenarioReadsWhatWasReadFrom (int offset, int secondSize) |
| The bytes read() from the buffer are the ones read from the socket. | |
| void | testReadsWhatWasReadFrom5rotate5 () |
| Read 5 bytes, rotate read buffer and read 5 more. | |
| void | testReadsWhatWasReadFrom5rotate0 () |
| Read 5 bytes, rotate read buffer and try to read more but 0 returned. | |
| void | testTryReadFromAtOnceSocketReadReturns_1NoDataLost () |
| No data should be lost if the socket read operation returns -1. | |
| void | testTryReadFromAtTwoReadsSocketReadReturns_1NoDataLost () |
| No data should be lost if the socket read operation returns -1. | |
| void | testTryReadFromOnceThemMultipleNormalReads () |
| It should be possible to buffer bytes and then read them only partially. | |
| void | testReadAll () |
| readAll() should return all buffered data. | |
| void | testPeekAndPeekAll () |
| Test that peek() and peekAll() do not purge bytes from the read buffer. | |
| void | refPeekToAndReadTo (const QByteArray &delimiter, const QByteArray &bytes) |
| First peekTo() then readTo() delimieter and expect bytes. | |
| void | testPeekToAndReadTo () |
| Test that peekTo() and readTo() work correctly. | |
| void | testPeekToAndReadToWhenSeparatorInTwoChunks () |
| peekTo()/readTo() should work even if delimiter is stored in two chunks. | |
| void | refCanRead (int count, bool canRead) |
| void | testCanRead () |
| void | refCanWrite (int count, bool canWrite) |
| void | testCanWrite () |
| void | testPeekAtMostThenReadAtMost () |
Private Member Functions | |
| CPPUNIT_TEST_SUITE (TcpSocketBufferTest) | |
| CPPUNIT_TEST (testWritingZeroBytesAlwaysSucceeds) | |
| CPPUNIT_TEST (testWriteBufferSizeBytesAtOnce) | |
| CPPUNIT_TEST (testWriteBufferSizeBytesAtOnceTwoTimes) | |
| CPPUNIT_TEST (testWriteBufferSizeBytesAtTwoWrites) | |
| CPPUNIT_TEST (testWriteMoreThanBufferSize) | |
| CPPUNIT_TEST (testPartialWriteToSocket7of10) | |
| CPPUNIT_TEST (testPartialWriteToSocket0of10) | |
| CPPUNIT_TEST (testPartialWriteToSocket_1of10) | |
| CPPUNIT_TEST (testPartialWriteToSocketWithRotate3ofLast5) | |
| CPPUNIT_TEST (testPartialWriteToSocketWithRotate0ofLast5) | |
| CPPUNIT_TEST (testPartialWriteToSocketWithRotate_1ofLast5) | |
| CPPUNIT_TEST (testTryReadFromFillsBuffer) | |
| CPPUNIT_TEST (testTryReadFromReadsNothing) | |
| CPPUNIT_TEST (testReadingZeroBytesAlwaysSucceeds) | |
| CPPUNIT_TEST (testReadsWhatWasReadFrom5rotate5) | |
| CPPUNIT_TEST (testReadsWhatWasReadFrom5rotate0) | |
| CPPUNIT_TEST (testTryReadFromAtOnceSocketReadReturns_1NoDataLost) | |
| CPPUNIT_TEST (testTryReadFromAtTwoReadsSocketReadReturns_1NoDataLost) | |
| CPPUNIT_TEST (testTryReadFromOnceThemMultipleNormalReads) | |
| CPPUNIT_TEST (testReadAll) | |
| CPPUNIT_TEST (testPeekAndPeekAll) | |
| CPPUNIT_TEST (testPeekToAndReadTo) | |
| CPPUNIT_TEST (testPeekToAndReadToWhenSeparatorInTwoChunks) | |
| CPPUNIT_TEST (testCanRead) | |
| CPPUNIT_TEST (testCanWrite) | |
| CPPUNIT_TEST (testPeekAtMostThenReadAtMost) | |
| CPPUNIT_TEST_SUITE_END () | |
Private Attributes | |
| auto_ptr< SocketMock > | socket |
| auto_ptr< TcpSocketBuffer > | buffer_real |
| auto_ptr< TcpSocketBufferDriver > | buffer |
Static Private Attributes | |
| static const int | ReadBufferSize = 20 |
| static const int | WriteBufferSize = 20 |
|
|
Definition at line 121 of file TcpSocketBufferTest.cpp. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
Definition at line 536 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
Definition at line 556 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
First peekTo() then readTo() delimieter and expect bytes.
Definition at line 501 of file TcpSocketBufferTest.cpp. |
|
|
read() fails if count bytes requested but an empty buffer returned.
Definition at line 338 of file TcpSocketBufferTest.cpp. |
|
|
read() succeeds if bytes returned for a bytes.size() bytes request.
Definition at line 331 of file TcpSocketBufferTest.cpp. |
|
|
tryReadFrom() produces one socket read operation.
Definition at line 345 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
tryReadFrom() produces two socket read operations. The reason is that the internal read buffer "rotates". Definition at line 357 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
Writing bytes to buffer will fail because there is not enough space.
Definition at line 141 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
Writing bytes will succeed as there is enough space in buffer.
Definition at line 148 of file TcpSocketBufferTest.cpp. |
|
|
Check that a single tryWriteTo() writes bytes to socket.
Definition at line 192 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
A single tryWriteTo() should write countWritten bytes from bytes.
Definition at line 198 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
A single tryWriteTo() should write bytes1 and bytes2 to socket. Since we use a round buffer, we sometimes may need to write the buffered bytes in two writes from a single tryWriteTo() call. Definition at line 213 of file TcpSocketBufferTest.cpp. |
|
||||||||||||||||
|
A single tryWriteTo() writes bytes1 completely and bytes2 partially (only countWrittenBytes2 number of bytes) to socket. Definition at line 223 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
Only the part of the buffer that the socket accepted should be purged. Some special cases are countWritten == -1 and coundWritten == 0 but they are all correctly covered by the use of QByteArray::mid(). Definition at line 252 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
Test that no data is lost when tryToWrite() after the ring rotates. offset is the number of bytes to write first and then purge, so that the subsequent write() and tryToWrite() would be done in two chunks. offset is also equivalent to the size of the second chunk. If must be bigger than 0, otherwise we will not have a partial write. count is the number of bytes that will be returned by socket->write() and determines how much actually were written. Only this number of bytes should be purged from the read buffer. A special case for count would be -1 but it is correctly handled by QByteArray::mid(). Definition at line 292 of file TcpSocketBufferTest.cpp. |
|
||||||||||||
|
The bytes read() from the buffer are the ones read from the socket. offset is the number of bytes to read first. secondSize is the size of the second chunk.read by the second tryReadFrom(). Definition at line 398 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 125 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 133 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 542 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 562 of file TcpSocketBufferTest.cpp. |
|
|
No buffered data should be lost if tryWriteTo() returns 0.
Definition at line 269 of file TcpSocketBufferTest.cpp. |
|
|
Only 7 bytes out of 10 should be purged.
Definition at line 263 of file TcpSocketBufferTest.cpp. |
|
|
No buffered data should be lost if tryWriteTo() returns -1.
Definition at line 275 of file TcpSocketBufferTest.cpp. |
|
|
No bytes (0) of the 5 bytes from the second chunk should be written.
Definition at line 319 of file TcpSocketBufferTest.cpp. |
|
|
Only 3 of the 5 bytes from the second chunk should be written.
Definition at line 313 of file TcpSocketBufferTest.cpp. |
|
|
No bytes (-1) of the 5 bytes from the second chunk should be written.
Definition at line 325 of file TcpSocketBufferTest.cpp. |
|
|
Test that peek() and peekAll() do not purge bytes from the read buffer.
Definition at line 484 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 580 of file TcpSocketBufferTest.cpp. |
|
|
Test that peekTo() and readTo() work correctly.
Definition at line 512 of file TcpSocketBufferTest.cpp. |
|
|
peekTo()/readTo() should work even if delimiter is stored in two chunks.
Definition at line 521 of file TcpSocketBufferTest.cpp. |
|
|
readAll() should return all buffered data.
Definition at line 466 of file TcpSocketBufferTest.cpp. |
|
|
If should always be possible to read zero bytes.
Definition at line 381 of file TcpSocketBufferTest.cpp. |
|
|
Read 5 bytes, rotate read buffer and try to read more but 0 returned.
Definition at line 418 of file TcpSocketBufferTest.cpp. |
|
|
Read 5 bytes, rotate read buffer and read 5 more.
Definition at line 412 of file TcpSocketBufferTest.cpp. |
|
|
Some chunks may be stored/written in two parts.
Definition at line 237 of file TcpSocketBufferTest.cpp. |
|
|
No data should be lost if the socket read operation returns -1.
Definition at line 424 of file TcpSocketBufferTest.cpp. |
|
|
No data should be lost if the socket read operation returns -1.
Definition at line 438 of file TcpSocketBufferTest.cpp. |
|
|
tryReadFrom() fills our internal read buffer.
Definition at line 369 of file TcpSocketBufferTest.cpp. |
|
|
It should be possible to buffer bytes and then read them only partially.
Definition at line 456 of file TcpSocketBufferTest.cpp. |
|
|
tryReadFrom() reads nothing.
Definition at line 375 of file TcpSocketBufferTest.cpp. |
|
|
After filling the buffer at once and no more data could be written.
Definition at line 162 of file TcpSocketBufferTest.cpp. |
|
|
We should be able to fill the buffer and purge it at least twice.
Definition at line 169 of file TcpSocketBufferTest.cpp. |
|
|
Fill the buffer in two writes, then no more data could be written.
Definition at line 178 of file TcpSocketBufferTest.cpp. |
|
|
Trying to an empty buffer more bytes than can fit fails.
Definition at line 186 of file TcpSocketBufferTest.cpp. |
|
|
Writing zero bytes is correct and should always succeed.
Definition at line 155 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 118 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 117 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 113 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 116 of file TcpSocketBufferTest.cpp. |
|
|
Definition at line 114 of file TcpSocketBufferTest.cpp. |