2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added test for Metaurl transaction.
	* src/MetalinkParserController.cc
	* test/MetalinkParserControllerTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-03-01 17:20:41 +00:00
parent 94e306cec4
commit eb32f56479
3 changed files with 50 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added test for Metaurl transaction.
* src/MetalinkParserController.cc
* test/MetalinkParserControllerTest.cc
2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-03-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Avoid costly BtMessage::toString() if info level log is not Avoid costly BtMessage::toString() if info level log is not

View File

@ -137,6 +137,7 @@ void MetalinkParserController::commitEntryTransaction()
return; return;
} }
commitResourceTransaction(); commitResourceTransaction();
commitMetaurlTransaction();
commitChecksumTransaction(); commitChecksumTransaction();
commitChunkChecksumTransactionV4(); commitChunkChecksumTransactionV4();
commitChunkChecksumTransaction(); commitChunkChecksumTransaction();
@ -148,6 +149,7 @@ void MetalinkParserController::commitEntryTransaction()
void MetalinkParserController::cancelEntryTransaction() void MetalinkParserController::cancelEntryTransaction()
{ {
cancelResourceTransaction(); cancelResourceTransaction();
cancelMetaurlTransaction();
cancelChecksumTransaction(); cancelChecksumTransaction();
cancelChunkChecksumTransactionV4(); cancelChunkChecksumTransactionV4();
cancelChunkChecksumTransaction(); cancelChunkChecksumTransaction();

View File

@ -5,6 +5,7 @@
#include "Metalinker.h" #include "Metalinker.h"
#include "MetalinkEntry.h" #include "MetalinkEntry.h"
#include "MetalinkResource.h" #include "MetalinkResource.h"
#include "MetalinkMetaurl.h"
#include "FileEntry.h" #include "FileEntry.h"
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
# include "Checksum.h" # include "Checksum.h"
@ -19,6 +20,7 @@ class MetalinkParserControllerTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MetalinkParserControllerTest); CPPUNIT_TEST_SUITE(MetalinkParserControllerTest);
CPPUNIT_TEST(testEntryTransaction); CPPUNIT_TEST(testEntryTransaction);
CPPUNIT_TEST(testResourceTransaction); CPPUNIT_TEST(testResourceTransaction);
CPPUNIT_TEST(testMetaurlTransaction);
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_TEST(testChecksumTransaction); CPPUNIT_TEST(testChecksumTransaction);
CPPUNIT_TEST(testChunkChecksumTransaction); CPPUNIT_TEST(testChunkChecksumTransaction);
@ -36,6 +38,7 @@ public:
void testEntryTransaction(); void testEntryTransaction();
void testResourceTransaction(); void testResourceTransaction();
void testMetaurlTransaction();
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
void testChecksumTransaction(); void testChecksumTransaction();
void testChunkChecksumTransaction(); void testChunkChecksumTransaction();
@ -99,7 +102,45 @@ void MetalinkParserControllerTest::testResourceTransaction()
ctrl.newResourceTransaction(); ctrl.newResourceTransaction();
ctrl.cancelResourceTransaction(); ctrl.cancelResourceTransaction();
ctrl.commitEntryTransaction(); ctrl.commitEntryTransaction();
CPPUNIT_ASSERT_EQUAL((size_t)1, ctrl.getResult()->entries.front()->resources.size()); {
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());
}
} }
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST