IdentityReadAllBodyReaderTest.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "../IdentityReadAllBodyReader.h"
00025 #include "generated/IdentityReadAllBodyReaderDriver.h"
00026 #include "Imports.cpp"
00027 
00028 namespace Protocols {
00029 namespace Http {
00030 namespace Testing {
00031 
00033 
00035 class IdentityReadAllBodyReaderTest : public CppUnit::TestFixture
00036 {
00037     CPPUNIT_TEST_SUITE (IdentityReadAllBodyReaderTest);
00038     CPPUNIT_TEST (testReadFailsNoBytesAvailable);
00039     CPPUNIT_TEST (testReadSomeData);
00040     CPPUNIT_TEST_SUITE_END();
00041 
00042     auto_ptr <TransportMock>                    transport;
00043     auto_ptr <IdentityReadAllBodyReader>        bodyReaderReal;
00044     auto_ptr <IdentityReadAllBodyReaderDriver>  bodyReader;
00045 
00046 public:
00047     void setUp()
00048     {
00049         transport.reset (new TransportMock);
00050         bodyReaderReal.reset (new IdentityReadAllBodyReader);
00051         bodyReader.reset (new IdentityReadAllBodyReaderDriver (*bodyReaderReal));
00052     }
00053 
00054     void tearDown()
00055     {
00056         bodyReader.reset();
00057         bodyReaderReal.reset();
00058         transport.reset();
00059     }
00060 
00061     void testReadFailsNoBytesAvailable()
00062     {
00063         call (bodyReader->read (*transport))
00064             .willCall (transport->readAll())
00065             .willReturn (QByteArray())
00066         .willReturn (Data());
00067     }
00068 
00069     void testReadSomeData()
00070     {
00071         QByteArray bytes (20, '1');
00072         RawData data = bytes;
00073         call (bodyReader->read (*transport))
00074             .willCall (transport->readAll())
00075             .willReturn (bytes)
00076         .willReturn (data);
00077     }
00078 };
00079 
00080 CPPUNIT_TEST_SUITE_REGISTRATION (IdentityReadAllBodyReaderTest);
00081 
00082 } // namespace Testing
00083 } // namespace Http
00084 } // namespace Protocols