KeepaliveTest.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-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 "../Keepalive.h"
00025 #include "Imports.cpp"
00026 
00027 namespace Protocols {
00028 namespace BitTorrent {
00029 namespace Packets {
00030 namespace Testing {
00031 
00033 
00051 class KeepaliveTest : public CppUnit::TestFixture
00052 {
00053     CPPUNIT_TEST_SUITE(KeepaliveTest);
00054     CPPUNIT_TEST(testPacketProperties);
00055     CPPUNIT_TEST(testReadPacketOK);
00056     CPPUNIT_TEST(testWritePacketOK);
00057     CPPUNIT_TEST_SUITE_END();
00058 
00059     auto_ptr <Keepalive>    packet;
00060 
00061 public:
00062     void setUp()
00063     {
00064         packet.reset (new Keepalive());
00065     }
00066 
00067     void tearDown()
00068     {
00069         packet.reset();
00070     }
00071 
00073 
00077     void scenarioReadPacket (const QByteArray &rawHeader,
00078                              const QByteArray &rawPayload,
00079                              bool parsedOk) {
00080         CPPUNIT_ASSERT (packet->parse (rawHeader, rawPayload) == parsedOk);
00081     }
00082 
00084 
00088     void scenarioWritePacket (const QByteArray &rawHeader,
00089                               const QByteArray &rawPayload) {
00090         CPPUNIT_ASSERT (packet->rawHeader() == rawHeader);
00091         CPPUNIT_ASSERT (packet->rawPayload() == rawPayload);
00092     }
00093 
00095 
00103     void scenarioReadSetWritePacket (const QByteArray &rawHeader,
00104                                      const QByteArray &rawPayload,
00105                                      const QByteArray &rawHeader2,
00106                                      const QByteArray &rawPayload2) {
00107         CPPUNIT_ASSERT (packet->parse (rawHeader, rawPayload));
00108 
00109         CPPUNIT_ASSERT (packet->rawHeader() == rawHeader2);
00110         CPPUNIT_ASSERT (packet->rawPayload() == rawPayload2);
00111     }
00112 
00114     void testPacketProperties()
00115     {
00116         CPPUNIT_ASSERT (KeepalivePacket == packet->packetType());
00117         CPPUNIT_ASSERT (QString ("Keepalive") == packet->name());
00118     }
00119 
00120     void testReadPacketOK() {
00121         scenarioReadPacket(
00122             QByteArray ("\0\0\0\0", 4),
00123             QByteArray(),
00124             true);
00125     }
00126 
00127     void testWritePacketOK() {
00128         scenarioWritePacket(
00129             QByteArray ("\0\0\0\0", 4),
00130             QByteArray());
00131     }
00132 };
00133 
00134 CPPUNIT_TEST_SUITE_REGISTRATION(KeepaliveTest);
00135 
00136 } // namespace Testing
00137 } // namespace Packets
00138 } // namespace BitTorrent
00139 } // namespace Protocols