IdentityContentLengthBodyWriterTest.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "../IdentityContentLengthBodyWriter.h"
00025 #include "../BodyEnd.h"
00026 #include "generated/IdentityContentLengthBodyWriterDriver.h"
00027 #include "Imports.cpp"
00028
00029 namespace Protocols {
00030 namespace Http {
00031 namespace Testing {
00032
00034
00036 class IdentityContentLengthBodyWriterTest : public CppUnit::TestFixture
00037 {
00038 CPPUNIT_TEST_SUITE (IdentityContentLengthBodyWriterTest);
00039 CPPUNIT_TEST (testWriteBodyAtOnce);
00040 CPPUNIT_TEST (testWriteBodyFailsFirstButThenSucceeds);
00041 CPPUNIT_TEST (testWriteBodyInTwoChunksFailsFirstButThenSucceed);
00042 CPPUNIT_TEST_SUITE_END();
00043
00044 auto_ptr <TransportMock> transport;
00045 auto_ptr <IdentityContentLengthBodyWriter> writerReal;
00046 auto_ptr <IdentityContentLengthBodyWriterDriver> writer;
00047
00048 static const int ContentLength = 40;
00049 const QByteArray chunk1;
00050 const QByteArray chunk2;
00051 const QByteArray body;
00052
00053 public:
00054 IdentityContentLengthBodyWriterTest()
00055 : chunk1 (20, '1'), chunk2 (20, '2'), body (chunk1 + chunk2)
00056 {
00057 }
00058
00059 void setUp()
00060 {
00061 transport.reset (new TransportMock);
00062 writerReal.reset (new IdentityContentLengthBodyWriter (ContentLength));
00063 writer.reset (new IdentityContentLengthBodyWriterDriver (*writerReal));
00064 }
00065
00066 void tearDown()
00067 {
00068 writer.reset();
00069 writerReal.reset();
00070 transport.reset();
00071 }
00072
00073 void refWriteBodyChunk (const QByteArray &chunk, bool willSucceed)
00074 {
00075 call (writer->write (RawData (chunk), *transport))
00076 .willCall (transport->write (chunk))
00077 .willReturn (willSucceed)
00078 .willReturn (willSucceed);
00079 }
00080
00081 void refWriteBodyEnd()
00082 {
00083 call (writer->write (BodyEnd(), *transport))
00084 .willReturn (true);
00085 }
00086
00087 void testWriteBodyAtOnce()
00088 {
00089 refWriteBodyChunk (body, true);
00090 refWriteBodyEnd();
00091 }
00092
00093 void testWriteBodyFailsFirstButThenSucceeds()
00094 {
00095 refWriteBodyChunk (body, false);
00096 refWriteBodyChunk (body, true);
00097 refWriteBodyEnd();
00098 }
00099
00100 void testWriteBodyInTwoChunksFailsFirstButThenSucceed()
00101 {
00102 refWriteBodyChunk (chunk1, false);
00103 refWriteBodyChunk (chunk1, true);
00104 refWriteBodyChunk (chunk2, false);
00105 refWriteBodyChunk (chunk2, true);
00106 refWriteBodyEnd();
00107 }
00108 };
00109
00110 CPPUNIT_TEST_SUITE_REGISTRATION (IdentityContentLengthBodyWriterTest);
00111
00112 }
00113 }
00114 }