2007-12-04 11:12:56 +00:00
|
|
|
#include "MetalinkParserController.h"
|
2010-02-25 14:40:18 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
#include "Metalinker.h"
|
|
|
|
#include "MetalinkEntry.h"
|
|
|
|
#include "MetalinkResource.h"
|
2010-03-01 17:20:41 +00:00
|
|
|
#include "MetalinkMetaurl.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
# include "Checksum.h"
|
|
|
|
# include "ChunkChecksum.h"
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
#include "Signature.h"
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
class MetalinkParserControllerTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(MetalinkParserControllerTest);
|
|
|
|
CPPUNIT_TEST(testEntryTransaction);
|
|
|
|
CPPUNIT_TEST(testResourceTransaction);
|
2010-03-01 17:20:41 +00:00
|
|
|
CPPUNIT_TEST(testMetaurlTransaction);
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_TEST(testChecksumTransaction);
|
|
|
|
CPPUNIT_TEST(testChunkChecksumTransaction);
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_TEST(testChunkChecksumTransactionV4);
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
CPPUNIT_TEST(testSignatureTransaction);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testEntryTransaction();
|
|
|
|
void testResourceTransaction();
|
2010-03-01 17:20:41 +00:00
|
|
|
void testMetaurlTransaction();
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
void testChecksumTransaction();
|
|
|
|
void testChunkChecksumTransaction();
|
2010-02-25 14:40:18 +00:00
|
|
|
void testChunkChecksumTransactionV4();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
void testSignatureTransaction();
|
2007-12-04 11:12:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkParserControllerTest );
|
|
|
|
|
|
|
|
void MetalinkParserControllerTest::testEntryTransaction()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.setFileNameOfEntry("aria2.tar.bz2");
|
|
|
|
ctrl.setFileLengthOfEntry(1024*1024);
|
|
|
|
ctrl.setVersionOfEntry("1.0");
|
|
|
|
ctrl.setLanguageOfEntry("ja_JP");
|
|
|
|
ctrl.setOSOfEntry("Linux");
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
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
|
|
|
SharedHandle<MetalinkEntry> e = m->entries.front();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), e->file->getPath());
|
2008-07-31 12:28:12 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)(1024*1024ULL), e->file->getLength());
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((off_t)0, e->file->getOffset());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("1.0"), e->version);
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ja_JP"), e->languages[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux"), e->oses[0]);
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.cancelEntryTransaction();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, ctrl.getResult()->entries.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserControllerTest::testResourceTransaction()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newResourceTransaction();
|
|
|
|
ctrl.setURLOfResource("http://mirror/aria2.tar.bz2");
|
|
|
|
ctrl.setTypeOfResource("http");
|
|
|
|
ctrl.setLocationOfResource("US");
|
2010-02-25 14:40:18 +00:00
|
|
|
ctrl.setPriorityOfResource(100);
|
2007-12-04 11:12:56 +00:00
|
|
|
ctrl.setMaxConnectionsOfResource(1);
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries.front()->resources.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkResource> res = m->entries.front()->resources[0];
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.tar.bz2"), res->url);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTP, res->type);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("US"), res->location);
|
2010-02-25 14:40:18 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(100, res->priority);
|
2007-12-04 11:12:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, res->maxConnections);
|
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newResourceTransaction();
|
|
|
|
ctrl.cancelResourceTransaction();
|
|
|
|
ctrl.commitEntryTransaction();
|
2010-03-01 17:20:41 +00:00
|
|
|
{
|
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, m->entries.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries[0]->resources.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, m->entries[1]->resources.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserControllerTest::testMetaurlTransaction()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newMetaurlTransaction();
|
|
|
|
ctrl.setURLOfMetaurl("http://example.org/chocolate.torrent");
|
|
|
|
ctrl.setMediatypeOfMetaurl("torrent");
|
|
|
|
ctrl.setPriorityOfMetaurl(999);
|
|
|
|
ctrl.setNameOfMetaurl("mybirthdaycake");
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries[0]->metaurls.size());
|
|
|
|
SharedHandle<MetalinkMetaurl> metaurl = m->entries[0]->metaurls[0];
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/chocolate.torrent"),
|
|
|
|
metaurl->url);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("torrent"), metaurl->mediatype);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("mybirthdaycake"), metaurl->name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(999, metaurl->priority);
|
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newMetaurlTransaction();
|
|
|
|
ctrl.cancelMetaurlTransaction();
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, ctrl.getResult()->entries.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries[0]->metaurls.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, m->entries[1]->metaurls.size());
|
|
|
|
}
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
void MetalinkParserControllerTest::testChecksumTransaction()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChecksumTransaction();
|
|
|
|
ctrl.setTypeOfChecksum("md5");
|
|
|
|
ctrl.setHashOfChecksum("hash");
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
SharedHandle<Checksum> md = m->entries.front()->checksum;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getAlgo());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash"), md->getMessageDigest());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChecksumTransaction();
|
|
|
|
ctrl.cancelChecksumTransaction();
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
CPPUNIT_ASSERT(ctrl.getResult()->entries[1]->checksum.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserControllerTest::testChunkChecksumTransaction()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChunkChecksumTransaction();
|
|
|
|
ctrl.setTypeOfChunkChecksum("md5");
|
|
|
|
ctrl.setLengthOfChunkChecksum(256*1024);
|
|
|
|
ctrl.addHashOfChunkChecksum(4, "hash4");
|
|
|
|
ctrl.addHashOfChunkChecksum(1, "hash1");
|
|
|
|
ctrl.addHashOfChunkChecksum(3, "hash3");
|
|
|
|
ctrl.addHashOfChunkChecksum(2, "hash2");
|
|
|
|
ctrl.addHashOfChunkChecksum(5, "hash5");
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
SharedHandle<ChunkChecksum> md = m->entries.front()->chunkChecksum;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getAlgo());
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)256*1024, md->getChecksumLength());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, md->countChecksum());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash1"), md->getChecksums()[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash2"), md->getChecksums()[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash3"), md->getChecksums()[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash4"), md->getChecksums()[3]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash5"), md->getChecksums()[4]);
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChunkChecksumTransaction();
|
|
|
|
ctrl.cancelChunkChecksumTransaction();
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
CPPUNIT_ASSERT(ctrl.getResult()->entries[1]->chunkChecksum.isNull());
|
|
|
|
}
|
2010-02-25 14:40:18 +00:00
|
|
|
|
|
|
|
void MetalinkParserControllerTest::testChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChunkChecksumTransactionV4();
|
|
|
|
ctrl.setTypeOfChunkChecksumV4("md5");
|
|
|
|
ctrl.setLengthOfChunkChecksumV4(256*1024);
|
|
|
|
ctrl.addHashOfChunkChecksumV4("hash1");
|
|
|
|
ctrl.addHashOfChunkChecksumV4("hash2");
|
|
|
|
ctrl.addHashOfChunkChecksumV4("hash3");
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
{
|
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
SharedHandle<ChunkChecksum> md = m->entries.front()->chunkChecksum;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getAlgo());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)256*1024, md->getChecksumLength());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, md->countChecksum());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash1"), md->getChecksums()[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash2"), md->getChecksums()[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("hash3"), md->getChecksums()[2]);
|
|
|
|
}
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newChunkChecksumTransactionV4();
|
|
|
|
ctrl.cancelChunkChecksumTransactionV4();
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
CPPUNIT_ASSERT(ctrl.getResult()->entries[1]->chunkChecksum.isNull());
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-07-12 13:35:35 +00:00
|
|
|
void MetalinkParserControllerTest::testSignatureTransaction()
|
|
|
|
{
|
|
|
|
static std::string pgpSignature =
|
|
|
|
"-----BEGIN PGP SIGNATURE-----\n"
|
|
|
|
"Version: GnuPG v1.4.9 (GNU/Linux)\n"
|
|
|
|
"\n"
|
|
|
|
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n"
|
|
|
|
"ffffffffffffffffffffffff\n"
|
|
|
|
"fffff\n"
|
|
|
|
"-----END PGP SIGNATURE-----\n";
|
|
|
|
|
|
|
|
MetalinkParserController ctrl;
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
|
|
|
|
ctrl.newSignatureTransaction();
|
|
|
|
ctrl.setTypeOfSignature("pgp");
|
|
|
|
ctrl.setFileOfSignature("aria2.sig");
|
|
|
|
ctrl.setBodyOfSignature(pgpSignature);
|
|
|
|
// commitEntryTransaction also commits signature transaction.
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
|
|
|
|
SharedHandle<Metalinker> m = ctrl.getResult();
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries.size());
|
|
|
|
SharedHandle<Signature> sig = m->entries.front()->getSignature();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("pgp"), sig->getType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sig"), sig->getFile());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(pgpSignature, sig->getBody());
|
|
|
|
|
|
|
|
// See when signature transaction is canceled:
|
|
|
|
ctrl.newEntryTransaction();
|
|
|
|
ctrl.newSignatureTransaction();
|
|
|
|
ctrl.cancelSignatureTransaction();
|
|
|
|
ctrl.commitEntryTransaction();
|
|
|
|
CPPUNIT_ASSERT(ctrl.getResult()->entries[1]->getSignature().isNull());
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|