TorrentTest.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 "../Torrent.h"
00025 #include "../TorrentParser.h"
00026 #include "TorrentLoadFunctions.h"
00027 #include "Imports.cpp"
00028 
00029 namespace Protocols {
00030 namespace BitTorrent {
00031 namespace Torrents {
00032 namespace Testing {
00033 
00035 
00039 class TorrentTest : public CppUnit::TestFixture
00040 {
00041     CPPUNIT_TEST_SUITE (TorrentTest);
00042     CPPUNIT_TEST (testCompareTwoEqualNonEmptyTorrents);
00043     CPPUNIT_TEST (testCompareTwoEqualEmptyTorrents);
00044     CPPUNIT_TEST (testCompareTwoDifferentNonEmptyTorrents);
00045     CPPUNIT_TEST (testCompareEmptyAndNonEmptyTorrents);
00046     CPPUNIT_TEST (testCopyCtor);
00047     CPPUNIT_TEST (testAssignment);
00048     CPPUNIT_TEST (testModifyingACopyDoesNotChangeTheOriginal);
00049     CPPUNIT_TEST_SUITE_END();
00050 
00051     const QString TorrentFileOk1;
00052     const QString TorrentFileOk2;
00053 
00054 public:
00055     TorrentTest();
00056 
00058     void testCompareTwoEqualNonEmptyTorrents()
00059     {
00060         Torrent torrent1, torrent2;
00061         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00062         bool loadedOk2 = loadTorrentData (TorrentFileOk1, torrent2);
00063         CPPUNIT_ASSERT (loadedOk1 && loadedOk2);
00064 
00065         CPPUNIT_ASSERT (torrent1 == torrent2);
00066         CPPUNIT_ASSERT (!(torrent1 != torrent2));
00067     }
00068 
00070     void testCompareTwoEqualEmptyTorrents()
00071     {
00072         Torrent torrent1, torrent2;
00073 
00074         CPPUNIT_ASSERT (torrent1 == torrent2);
00075         CPPUNIT_ASSERT (!(torrent1 != torrent2));
00076     }
00077 
00079     void testCompareTwoDifferentNonEmptyTorrents()
00080     {
00081         Torrent torrent1, torrent2;
00082         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00083         bool loadedOk2 = loadTorrentData (TorrentFileOk2, torrent2);
00084         CPPUNIT_ASSERT (loadedOk1 && loadedOk2);
00085 
00086         CPPUNIT_ASSERT (torrent1 != torrent2);
00087         CPPUNIT_ASSERT (!(torrent1 == torrent2));
00088     }
00089 
00091     void testCompareEmptyAndNonEmptyTorrents()
00092     {
00093         Torrent torrent1;
00094         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00095         CPPUNIT_ASSERT (loadedOk1);
00096 
00097         CPPUNIT_ASSERT (torrent1 != Torrent());
00098         CPPUNIT_ASSERT (!(torrent1 == Torrent()));
00099     }
00100 
00102     void testCopyCtor()
00103     {
00104         Torrent torrent1;
00105         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00106         CPPUNIT_ASSERT (loadedOk1);
00107 
00108         Torrent torrent2 (torrent1);
00109         CPPUNIT_ASSERT (torrent1 == torrent2);
00110     }
00111 
00113     void testAssignment()
00114     {
00115         Torrent torrent1, torrent2;
00116         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00117         CPPUNIT_ASSERT (loadedOk1);
00118 
00119         CPPUNIT_ASSERT (torrent1 != torrent2);
00120         torrent2 = torrent1;
00121         CPPUNIT_ASSERT (torrent1 == torrent2);
00122     }
00123 
00125     void testModifyingACopyDoesNotChangeTheOriginal()
00126     {
00127         Torrent torrent1, torrent2;
00128         bool loadedOk1 = loadTorrentData (TorrentFileOk1, torrent1);
00129         CPPUNIT_ASSERT (loadedOk1);
00130 
00131         torrent2 = torrent1;
00132         // After loading the new torrent file the two objects should be different.
00133         bool loadedOk2 = loadTorrentData (TorrentFileOk2, torrent2);
00134         CPPUNIT_ASSERT (loadedOk2);
00135         CPPUNIT_ASSERT (torrent1 != torrent2);
00136     }
00137 };
00138 
00140 
00145 TorrentTest::TorrentTest()
00146     : TorrentFileOk1 ("Protocols/BitTorrent/Torrents/Testing/Samples/sample.torrent"),
00147     TorrentFileOk2 ("Protocols/BitTorrent/Torrents/Testing/Samples/sample2.torrent")
00148 {
00149 }
00150 
00151 CPPUNIT_TEST_SUITE_REGISTRATION(TorrentTest);
00152 
00153 } // namespace Testing
00154 } // namespace Torrents
00155 } // namespace BitTorrent
00156 } // namespace Protocols