2006-07-03 14:19:59 +00:00
|
|
|
#include "MetalinkEntry.h"
|
2010-02-25 14:40:18 +00:00
|
|
|
|
2006-07-03 14:19:59 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
#include "MetalinkResource.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-07-03 14:19:59 +00:00
|
|
|
|
|
|
|
class MetalinkEntryTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(MetalinkEntryTest);
|
|
|
|
CPPUNIT_TEST(testDropUnsupportedResource);
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_TEST(testReorderResourcesByPriority);
|
|
|
|
CPPUNIT_TEST(testSetLocationPriority);
|
|
|
|
CPPUNIT_TEST(testSetProtocolPriority);
|
2006-07-03 14:19:59 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
void tearDown() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testDropUnsupportedResource();
|
2010-02-25 14:40:18 +00:00
|
|
|
void testReorderResourcesByPriority();
|
|
|
|
void testSetLocationPriority();
|
|
|
|
void testSetProtocolPriority();
|
2006-07-03 14:19:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkEntryTest );
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkEntry> createTestEntry() {
|
|
|
|
SharedHandle<MetalinkEntry> entry(new MetalinkEntry());
|
|
|
|
SharedHandle<MetalinkResource> res1(new MetalinkResource());
|
2006-07-03 14:19:59 +00:00
|
|
|
res1->url = "ftp://myhost/aria2.tar.bz2";
|
|
|
|
res1->type = MetalinkResource::TYPE_FTP;
|
2010-02-25 14:40:18 +00:00
|
|
|
res1->location = "ro";
|
|
|
|
res1->priority = 50;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkResource> res2(new MetalinkResource());
|
2006-07-03 14:19:59 +00:00
|
|
|
res2->url = "http://myhost/aria2.tar.bz2";
|
|
|
|
res2->type = MetalinkResource::TYPE_HTTP;
|
2010-02-25 14:40:18 +00:00
|
|
|
res2->location = "at";
|
|
|
|
res2->priority = 1;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkResource> res3(new MetalinkResource());
|
2006-07-03 14:19:59 +00:00
|
|
|
res3->url = "http://myhost/aria2.torrent";
|
|
|
|
res3->type = MetalinkResource::TYPE_BITTORRENT;
|
2010-02-25 14:40:18 +00:00
|
|
|
res3->location = "al";
|
|
|
|
res3->priority = 40;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkResource> res4(new MetalinkResource());
|
2006-07-03 14:19:59 +00:00
|
|
|
res4->url = "http://myhost/aria2.ext";
|
|
|
|
res4->type = MetalinkResource::TYPE_NOT_SUPPORTED;
|
2010-02-25 14:40:18 +00:00
|
|
|
res4->location = "ad";
|
|
|
|
res4->priority = 90;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkResource> res5(new MetalinkResource());
|
2006-08-07 16:05:00 +00:00
|
|
|
res5->url = "https://myhost/aria2.tar.bz2";
|
|
|
|
res5->type = MetalinkResource::TYPE_HTTPS;
|
2010-02-25 14:40:18 +00:00
|
|
|
res5->location = "jp";
|
|
|
|
res5->priority = 10;
|
2006-07-03 14:19:59 +00:00
|
|
|
|
|
|
|
entry->resources.push_back(res1);
|
|
|
|
entry->resources.push_back(res2);
|
|
|
|
entry->resources.push_back(res3);
|
|
|
|
entry->resources.push_back(res4);
|
2006-08-07 16:05:00 +00:00
|
|
|
entry->resources.push_back(res5);
|
2006-07-03 14:19:59 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkEntryTest::testDropUnsupportedResource() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry(createTestEntry());
|
2006-07-03 14:19:59 +00:00
|
|
|
|
|
|
|
entry->dropUnsupportedResource();
|
2008-05-31 10:27:21 +00:00
|
|
|
#if defined ENABLE_SSL && defined ENABLE_BITTORRENT
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, entry->resources.size());
|
2008-05-31 10:27:21 +00:00
|
|
|
#elif defined ENABLE_SSL || defined ENABLE_BITTORRENT
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, entry->resources.size());
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#else
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, entry->resources.size());
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2006-07-03 14:19:59 +00:00
|
|
|
|
2010-02-27 15:14:40 +00:00
|
|
|
std::vector<SharedHandle<MetalinkResource> >::const_iterator itr =
|
2008-02-08 15:53:45 +00:00
|
|
|
entry->resources.begin();
|
2007-07-21 08:56:16 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP,
|
2010-01-05 16:01:46 +00:00
|
|
|
(*itr++)->type);
|
2007-07-21 08:56:16 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTP,
|
2010-01-05 16:01:46 +00:00
|
|
|
(*itr++)->type);
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2007-07-21 08:56:16 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_BITTORRENT,
|
2010-01-05 16:01:46 +00:00
|
|
|
(*itr++)->type);
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
#ifdef ENABLE_SSL
|
2007-07-21 08:56:16 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTPS,
|
2010-01-05 16:01:46 +00:00
|
|
|
(*itr++)->type);
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
#endif // ENABLE_SSL
|
2006-07-03 14:19:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void MetalinkEntryTest::testReorderResourcesByPriority() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry(createTestEntry());
|
2006-07-03 14:19:59 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
entry->reorderResourcesByPriority();
|
2006-07-03 14:19:59 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, entry->resources.at(0)->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(10, entry->resources.at(1)->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(40, entry->resources.at(2)->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(50, entry->resources.at(3)->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(90, entry->resources.at(4)->priority);
|
2006-07-03 14:19:59 +00:00
|
|
|
}
|
2007-11-13 13:49:10 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void MetalinkEntryTest::testSetLocationPriority()
|
2007-11-13 13:49:10 +00:00
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry(createTestEntry());
|
2007-11-13 13:49:10 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
const char* locationsSrc[] = { "jp", "al", "ro" };
|
2007-11-13 13:49:10 +00:00
|
|
|
|
2010-02-27 15:14:40 +00:00
|
|
|
std::vector<std::string> locations(&locationsSrc[0], &locationsSrc[3]);
|
2007-11-13 13:49:10 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
entry->setLocationPriority(locations, -100);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ro"), entry->resources[0]->location);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-50, entry->resources[0]->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("at"), entry->resources[1]->location);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, entry->resources[1]->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("al"), entry->resources[2]->location);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-60, entry->resources[2]->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ad"), entry->resources[3]->location);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(90, entry->resources[3]->priority);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("jp"), entry->resources[4]->location);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-90, entry->resources[4]->priority);
|
2007-11-13 13:49:10 +00:00
|
|
|
}
|
2007-12-12 13:53:33 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void MetalinkEntryTest::testSetProtocolPriority()
|
2007-12-12 13:53:33 +00:00
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry(createTestEntry());
|
2010-02-25 14:40:18 +00:00
|
|
|
entry->setProtocolPriority("http", -1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(50, entry->resources[0]->priority); // ftp
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, entry->resources[1]->priority); // http, -1
|
|
|
|
CPPUNIT_ASSERT_EQUAL(40, entry->resources[2]->priority); // bittorrent
|
|
|
|
CPPUNIT_ASSERT_EQUAL(90, entry->resources[3]->priority); // not supported
|
|
|
|
CPPUNIT_ASSERT_EQUAL(10, entry->resources[4]->priority); // https
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|