2007-12-14 00:46:32 +00:00
|
|
|
#include "MetalinkProcessorFactory.h"
|
2007-12-04 11:12:56 +00:00
|
|
|
#include "MetalinkParserStateMachine.h"
|
|
|
|
#include "Exception.h"
|
|
|
|
#include "DefaultDiskWriter.h"
|
|
|
|
#include "ByteArrayDiskWriter.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "MetalinkProcessor.h"
|
|
|
|
#include "Metalinker.h"
|
|
|
|
#include "MetalinkEntry.h"
|
|
|
|
#include "MetalinkResource.h"
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "ChunkChecksum.h"
|
|
|
|
# include "Checksum.h"
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
#include "Signature.h"
|
2008-03-03 11:30:12 +00:00
|
|
|
#include <iostream>
|
2007-12-04 11:12:56 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
class MetalinkProcessorTest:public CppUnit::TestFixture {
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
CPPUNIT_TEST_SUITE(MetalinkProcessorTest);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_TEST(testParseFile);
|
|
|
|
CPPUNIT_TEST(testParseFromBinaryStream);
|
|
|
|
CPPUNIT_TEST(testMalformedXML);
|
|
|
|
CPPUNIT_TEST(testMalformedXML2);
|
|
|
|
CPPUNIT_TEST(testBadSize);
|
|
|
|
CPPUNIT_TEST(testBadMaxConn);
|
|
|
|
CPPUNIT_TEST(testNoName);
|
|
|
|
CPPUNIT_TEST(testBadURLPrefs);
|
|
|
|
CPPUNIT_TEST(testBadURLMaxConn);
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_TEST(testUnsupportedType);
|
|
|
|
CPPUNIT_TEST(testMultiplePieces);
|
|
|
|
CPPUNIT_TEST(testBadPieceNo);
|
|
|
|
CPPUNIT_TEST(testBadPieceLength);
|
|
|
|
CPPUNIT_TEST(testUnsupportedType_piece);
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-03-01 06:07:10 +00:00
|
|
|
CPPUNIT_TEST(testLargeFileSize);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void testParseFile();
|
|
|
|
void testParseFromBinaryStream();
|
|
|
|
void testMalformedXML();
|
|
|
|
void testMalformedXML2();
|
|
|
|
void testBadSize();
|
|
|
|
void testBadMaxConn();
|
|
|
|
void testNoName();
|
|
|
|
void testBadURLPrefs();
|
|
|
|
void testBadURLMaxConn();
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
void testUnsupportedType();
|
|
|
|
void testMultiplePieces();
|
|
|
|
void testBadPieceNo();
|
|
|
|
void testBadPieceLength();
|
|
|
|
void testUnsupportedType_piece();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-03-01 06:07:10 +00:00
|
|
|
void testLargeFileSize();
|
2007-12-04 11:12:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkProcessorTest );
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testParseFile()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc(MetalinkProcessorFactory::newInstance());
|
2007-12-04 11:12:56 +00:00
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> metalinker = proc->parseFile("test.xml");
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> >::iterator entryItr = metalinker->entries.begin();
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry1 = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), entry1->getPath());
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0ULL, entry1->getLength());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), entry1->version);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), entry1->language);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), entry1->os);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, entry1->maxConnections);
|
2007-12-04 11:12:56 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry1->checksum->getMessageDigest());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), entry1->checksum->getAlgo());
|
2007-12-04 11:12:56 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
CPPUNIT_ASSERT(!entry1->getSignature().isNull());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("pgp"), entry1->getSignature()->getType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2.sig"),
|
|
|
|
entry1->getSignature()->getFile());
|
|
|
|
// Note that last '\n' character is trimmed.
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string
|
|
|
|
("-----BEGIN PGP SIGNATURE-----\n"
|
|
|
|
"Version: GnuPG v1.4.9 (GNU/Linux)\n"
|
|
|
|
"\n"
|
|
|
|
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n"
|
|
|
|
"ffffffffffffffffffffffff\n"
|
|
|
|
"fffff\n"
|
|
|
|
"-----END PGP SIGNATURE-----"),
|
|
|
|
entry1->getSignature()->getBody());
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkResource> >::iterator resourceItr1 = entry1->resources.begin();
|
|
|
|
SharedHandle<MetalinkResource> resource1 = *resourceItr1;
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, resource1->type);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JP"), resource1->location);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(100, resource1->preference);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"),
|
2007-12-04 11:12:56 +00:00
|
|
|
resource1->url);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, resource1->maxConnections);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
resourceItr1++;
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkResource> resource2 = *resourceItr1;
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTP, resource2->type);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("US"), resource2->location);
|
2008-03-11 12:31:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(100, resource2->preference);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://httphost/aria2-0.5.2.tar.bz2"),
|
2007-12-04 11:12:56 +00:00
|
|
|
resource2->url);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(-1, resource2->maxConnections);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
entryItr++;
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry2 = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.1.tar.bz2"), entry2->getPath());
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)345689ULL, entry2->getLength());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), entry2->version);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), entry2->language);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), entry2->os);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(-1, entry2->maxConnections);
|
2007-12-04 11:12:56 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry2->checksum->getMessageDigest());
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, entry2->chunkChecksum->countChecksum());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)262144, entry2->chunkChecksum->getChecksumLength());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("179463a88d79cbf0b1923991708aead914f26142"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry2->chunkChecksum->getChecksum(0));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fecf8bc9a1647505fe16746f94e97a477597dbf3"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry2->chunkChecksum->getChecksum(1));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), entry2->checksum->getAlgo());
|
2007-12-04 11:12:56 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
// See that signature is null
|
|
|
|
CPPUNIT_ASSERT(entry2->getSignature().isNull());
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
entryItr++;
|
|
|
|
|
|
|
|
// test case: verification hash is not provided
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry3 = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("NoVerificationHash"), entry3->getPath());
|
2007-12-04 11:12:56 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
CPPUNIT_ASSERT(entry3->checksum.isNull());
|
|
|
|
CPPUNIT_ASSERT(entry3->chunkChecksum.isNull());
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
|
|
|
|
entryItr++;
|
|
|
|
|
|
|
|
// test case: unsupported verification hash is included
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkEntry> entry4 = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("UnsupportedVerificationHashTypeIncluded"), entry4->getPath());
|
2007-12-04 11:12:56 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry4->checksum->getAlgo());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry4->checksum->getMessageDigest());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"),
|
2007-12-04 11:12:56 +00:00
|
|
|
entry4->chunkChecksum->getAlgo());
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
|
|
|
|
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testParseFromBinaryStream()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
DefaultDiskWriterHandle dw(new DefaultDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->openExistingFile("test.xml");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> >::iterator entryItr = m->entries.begin();
|
|
|
|
SharedHandle<MetalinkEntry> entry1 = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), entry1->getPath());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testMalformedXML()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink><files></file></metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace() << std::endl;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testMalformedXML2()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink><files></files>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace() << std::endl;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadSize()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>abc</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> >::iterator entryItr = m->entries.begin();
|
|
|
|
SharedHandle<MetalinkEntry> e = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), e->getPath());
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0ULL, e->getLength());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), e->version);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), e->language);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), e->os);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadMaxConn()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>43743838</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
" <resources maxconnections=\"abc\"/>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> >::iterator entryItr = m->entries.begin();
|
|
|
|
SharedHandle<MetalinkEntry> e = *entryItr;
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)43743838ULL, e->getLength());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testNoName()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file>"
|
|
|
|
" <size>1024</size>"
|
|
|
|
" <version>0.0.1</version>"
|
|
|
|
" <language>GB</language>"
|
|
|
|
" <os>Linux-x64</os>"
|
|
|
|
"</file>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>43743838</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> >::iterator entryItr = m->entries.begin();
|
|
|
|
SharedHandle<MetalinkEntry> e = *entryItr;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), e->getPath());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadURLPrefs()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>43743838</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
" <resources>"
|
|
|
|
" <url type=\"ftp\" maxconnections=\"1\" preference=\"xyz\" location=\"JP\">ftp://mirror/</url>"
|
|
|
|
" </resources>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<MetalinkResource> r = e->resources[0];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, r->type);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, r->preference);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, r->maxConnections);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JP"), r->location);
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadURLMaxConn()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>43743838</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
" <resources>"
|
|
|
|
" <url maxconnections=\"xyz\" type=\"ftp\" preference=\"100\" location=\"JP\">ftp://mirror/</url>"
|
|
|
|
" </resources>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<MetalinkResource> r = e->resources[0];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, r->type);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(100, r->preference);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-1, r->maxConnections);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JP"), r->location);
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testUnsupportedType()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2-0.5.2.tar.bz2\">"
|
|
|
|
" <size>43743838</size>"
|
|
|
|
" <version>0.5.2</version>"
|
|
|
|
" <language>en-US</language>"
|
|
|
|
" <os>Linux-x86</os>"
|
|
|
|
" <resources>"
|
|
|
|
" <url type=\"ftp\">ftp://mirror/</url>"
|
|
|
|
" <url type=\"magnet\">magnet:xt=XYZ</url>"
|
|
|
|
" <url type=\"http\">http://mirror/</url>"
|
|
|
|
" </resources>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, e->resources.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkResource> r1 = e->resources[0];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, r1->type);
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkResource> r2 = e->resources[1];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_NOT_SUPPORTED, r2->type);
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkResource> r3 = e->resources[2];
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTP, r3->type);
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testMultiplePieces()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2.tar.bz2\">"
|
|
|
|
" <verification>"
|
|
|
|
" <pieces length=\"512\" type=\"md5\">"
|
|
|
|
" </pieces>"
|
|
|
|
" <pieces length=\"1024\" type=\"sha1\">"
|
|
|
|
" </pieces>"
|
|
|
|
" <pieces length=\"2048\" type=\"sha256\">"
|
|
|
|
" </pieces>"
|
|
|
|
" </verification>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
|
|
|
// aria2 prefers sha1
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), c->getAlgo());
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getChecksumLength());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadPieceNo()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2.tar.bz2\">"
|
|
|
|
" <verification>"
|
|
|
|
" <pieces length=\"512\" type=\"sha1\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" <hash piece=\"xyz\">xyz</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" <pieces length=\"512\" type=\"sha256\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" </verification>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha256"), c->getAlgo());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testBadPieceLength()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2.tar.bz2\">"
|
|
|
|
" <verification>"
|
|
|
|
" <pieces length=\"xyz\" type=\"sha1\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" <pieces length=\"1024\" type=\"sha256\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" </verification>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha256"), c->getAlgo());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 00:46:32 +00:00
|
|
|
void MetalinkProcessorTest::testUnsupportedType_piece()
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2007-12-04 11:12:56 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"aria2.tar.bz2\">"
|
|
|
|
" <verification>"
|
|
|
|
" <pieces length=\"512\" type=\"ARIA2\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" <pieces length=\"1024\" type=\"sha256\">"
|
|
|
|
" <hash piece=\"0\">abc</hash>"
|
|
|
|
" </pieces>"
|
|
|
|
" </verification>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
|
|
|
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("sha256"), c->getAlgo());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-03-01 06:07:10 +00:00
|
|
|
void MetalinkProcessorTest::testLargeFileSize()
|
|
|
|
{
|
|
|
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
|
2008-03-01 06:07:10 +00:00
|
|
|
dw->setString("<metalink>"
|
|
|
|
"<files>"
|
|
|
|
"<file name=\"dvd.iso\">"
|
|
|
|
" <size>9223372036854775807</size>"
|
|
|
|
" <resources>"
|
|
|
|
" <url type=\"http\">ftp://mirror/</url>"
|
|
|
|
" </resources>"
|
|
|
|
"</file>"
|
|
|
|
"</files>"
|
|
|
|
"</metalink>");
|
|
|
|
|
|
|
|
try {
|
|
|
|
SharedHandle<Metalinker> m = proc->parseFromBinaryStream(dw);
|
|
|
|
SharedHandle<MetalinkEntry> e = m->entries[0];
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)9223372036854775807ULL, e->getLength());
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
CPPUNIT_FAIL(e.stackTrace());
|
2008-03-01 06:07:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|