TorrentTest.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 "../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
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 }
00154 }
00155 }
00156 }